merge template with RTS10
This commit is contained in:
69
converters/headers.lua
Normal file
69
converters/headers.lua
Normal file
@@ -0,0 +1,69 @@
|
||||
local pagebreak = {
|
||||
asciidoc = '<<<\n\n',
|
||||
context = '\\page',
|
||||
epub = '<p style="page-break-after: always;"> </p>',
|
||||
html = '<div style="page-break-after: always;"></div>',
|
||||
latex = '\\newpage{}',
|
||||
ms = '.bp',
|
||||
ooxml = '<w:p><w:r><w:br w:type="page"/></w:r></w:p>',
|
||||
odt = '<text:p text:style-name="Pagebreak"/>'
|
||||
}
|
||||
local title = '';
|
||||
local title_inHaders = true;
|
||||
|
||||
local stringify_orig = (require 'pandoc.utils').stringify
|
||||
|
||||
local function stringify(x)
|
||||
return type(x) == 'string' and x or stringify_orig(x)
|
||||
end
|
||||
|
||||
local function newpage(format)
|
||||
if format:match 'asciidoc' then
|
||||
return pandoc.RawBlock('asciidoc', pagebreak.asciidoc)
|
||||
elseif format == 'context' then
|
||||
return pandoc.RawBlock('context', pagebreak.context)
|
||||
elseif format == 'docx' then
|
||||
return pandoc.RawBlock('openxml', pagebreak.ooxml)
|
||||
elseif format:match 'epub' then
|
||||
return pandoc.RawBlock('html', pagebreak.epub)
|
||||
elseif format:match 'html.*' then
|
||||
return pandoc.RawBlock('html', pagebreak.html)
|
||||
elseif format:match 'latex' then
|
||||
return pandoc.RawBlock('tex', pagebreak.latex)
|
||||
elseif format:match 'ms' then
|
||||
return pandoc.RawBlock('ms', pagebreak.ms)
|
||||
elseif format:match 'odt' then
|
||||
return pandoc.RawBlock('opendocument', pagebreak.odt)
|
||||
else
|
||||
-- fall back to insert a form feed character
|
||||
return pandoc.Para{pandoc.Str '\f'}
|
||||
end
|
||||
end
|
||||
|
||||
function Meta(meta)
|
||||
title = (meta.title and stringify(meta.title)) or title
|
||||
if title ~= '' then
|
||||
title_inHaders = false;
|
||||
end
|
||||
end
|
||||
|
||||
function Header(el)
|
||||
if title_inHaders then
|
||||
if el.level == 1 then
|
||||
title = el.content
|
||||
return {}
|
||||
else
|
||||
el.level = el.level - 1;
|
||||
end
|
||||
end
|
||||
|
||||
if el.level == 1 or el.level == 2 then
|
||||
return { newpage(FORMAT), el }
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
{Meta = Meta},
|
||||
{Header = Header},
|
||||
{Meta = function (meta) meta.title = title; return meta end}
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
MD_FILE="$1"
|
||||
|
||||
set -e
|
||||
|
||||
BASE_DIR="$(pwd)"
|
||||
TEX_FILE="${BASE_DIR}/latex/$(basename "$MD_FILE" | sed -e 's/\.md$/.latex/')"
|
||||
PDF_FILE="${BASE_DIR}/pdf/$(basename "$MD_FILE" | sed -e 's/\.md$/.pdf/')"
|
||||
BUILD_DIR="${BASE_DIR}/build/$(basename "$MD_FILE" | sed -e 's/\.md$//')"
|
||||
TEMP_MD_FILE="$BUILD_DIR/$(basename "$MD_FILE")"
|
||||
TEMP_TEX_FILE="$BUILD_DIR/$(basename "$MD_FILE" | sed -e 's|md$|latex|')"
|
||||
|
||||
mkdir -p "$(dirname "$TEMP_MD_FILE")"
|
||||
|
||||
cp "$MD_FILE" "$TEMP_MD_FILE"
|
||||
@@ -14,11 +18,17 @@ function download_images() {
|
||||
for line in $(grep '!\[.*\](https://.*\.png)' "$1" | sed -e 's/ /%20;/g')
|
||||
do
|
||||
src=$(echo "$line" | sed -e 's/^.*(//' -e 's/).*$//' -e 's/%20;/ /g')
|
||||
echo "remote image found: $src"
|
||||
echo "download remote image: $src"
|
||||
|
||||
mkdir -p "${BASE_DIR}/latex/images"
|
||||
mkdir -p "${BASE_DIR}/pdf/images"
|
||||
name=$(echo "$src" | sed -e 's|^.*/\([^/]*\)$|\1|')
|
||||
curl "$src" > "${BASE_DIR}/latex/images/$name"
|
||||
if [[ ! -f "${BASE_DIR}/pdf/images/$name" ]]
|
||||
then
|
||||
curl "$src" >"${BASE_DIR}/pdf/images/$name"
|
||||
else
|
||||
echo " image already exists"
|
||||
fi
|
||||
sed -i "$1" -e "s|$src|${BASE_DIR}/pdf/images/$name|"
|
||||
done
|
||||
echo "download done"
|
||||
}
|
||||
@@ -26,66 +36,40 @@ function download_images() {
|
||||
for line in $(grep '^!\[.*\](.*\.md)$' "$TEMP_MD_FILE" | sed -e 's/ /%20;/g')
|
||||
do
|
||||
md_src=$(echo "$line" | sed -e 's/^.*(//' -e 's/).*$//' -e 's/%20;/ /g')
|
||||
echo "include found: markdown/$md_src"
|
||||
echo "include found: $md_src"
|
||||
|
||||
download_images "markdown/$md_src"
|
||||
cp "$(pwd)/markdown/$md_src" "$BUILD_DIR/$(basename "$md_src")"
|
||||
|
||||
cp "markdown/$md_src" "$BUILD_DIR/$md_src"
|
||||
sed -i "$BUILD_DIR/$md_src" \
|
||||
download_images "$BUILD_DIR/$(basename "$md_src")"
|
||||
|
||||
sed -i "$BUILD_DIR/$(basename "$md_src")" \
|
||||
-e 's|\[toc\]||' \
|
||||
-e 's|^\[parent\].*$||' \
|
||||
-e 's|^# |\\newpage\n# |' \
|
||||
-e 's|^## |\\newpage\n## |' \
|
||||
-e 's|\[\([^]]*\)\](#\([^)]*\))|[\1](#\L\2)|' \
|
||||
-e 's|^> \[!todo\]|> \\textcolor{cyan}{TODO:}|' \
|
||||
-e 's|^> \[!warn\]|> \\textcolor{orange}{WARNING:}|' \
|
||||
-e "s|https://live.kladjes.nl/uploads|${BASE_DIR}/latex/images|" \
|
||||
-e "s|\`\`\`mermaid|\`\`\`{.mermaid loc=${BASE_DIR}/latex/images/$(basename "$md_src")}|"
|
||||
download_images "$BUILD_DIR/$md_src"
|
||||
-e "s|\`\`\`mermaid|\`\`\`{.mermaid loc=${BASE_DIR}/pdf/images/$(basename "$md_src")}|"
|
||||
|
||||
sed -i "$TEMP_MD_FILE" \
|
||||
-e "s/^\!\[.*\]($md_src)\$/\`\`\`\\{.include shift-heading-level-by=1\\}\n${md_src}\n\`\`\`/"
|
||||
-e "s|^\!\[.*\]($md_src)\$|\`\`\`\\{.include shift-heading-level-by=1\\}\n$(basename "$md_src")\n\`\`\`|"
|
||||
|
||||
done
|
||||
|
||||
download_images "$TEMP_MD_FILE"
|
||||
|
||||
title="$(grep '^# ' "$MD_FILE" | head -n 1 | sed 's|^# ||')"
|
||||
|
||||
sed -i "$TEMP_MD_FILE" \
|
||||
-e 's|\[toc\]|\\tableofcontents|' \
|
||||
-e 's|^\[parent\].*$||' \
|
||||
-e 's|^# .*$||' \
|
||||
-e 's|^#||' \
|
||||
-e 's|^# |\\newpage\n# |' \
|
||||
-e 's|\[\([^]]*\)\](#\([^)]*\))|[\1](#\L\2)|' \
|
||||
-e 's|^> \[!todo\]|> \\textcolor{cyan}{TODO:}|' \
|
||||
-e 's|^> \[!warn\]|> \\textcolor{orange}{WARNING:}|' \
|
||||
-e "s|https://live.kladjes.nl/uploads|${BASE_DIR}/latex/images|" \
|
||||
-e "s|\`\`\`mermaid|\`\`\`{.mermaid loc=${BASE_DIR}/latex/images/$(basename "$MD_FILE")}|"
|
||||
-e "s|\`\`\`mermaid|\`\`\`{.mermaid loc=${BASE_DIR}/pdf/images/$(basename "$MD_FILE")}|"
|
||||
|
||||
# -e 's|```\([^ \t]\)=|```\1 {linenumbers}|'
|
||||
|
||||
mkdir -p ${BASE_DIR}/latex/images/$(basename "$MD_FILE")
|
||||
mkdir -p ${BASE_DIR}/pdf/images/$(basename "$MD_FILE")
|
||||
cd "$BUILD_DIR"
|
||||
pandoc --lua-filter=../../converters/include-files.lua \
|
||||
--to=latex \
|
||||
pandoc --standalone \
|
||||
--lua-filter=../../converters/include-files.lua \
|
||||
--lua-filter=../../converters/headers.lua \
|
||||
-t latex --pdf-engine=xelatex \
|
||||
--from=markdown+abbreviations \
|
||||
--template "${BASE_DIR}/converters/template.latex" \
|
||||
-o "$TEX_FILE" \
|
||||
-F /home/laila/.local/share/npm/bin/mermaid-filter \
|
||||
--dpi 300 \
|
||||
-F "${XDG_DATA_HOME}/npm/bin/mermaid-filter" \
|
||||
-o "$PDF_FILE" \
|
||||
"$(basename "$TEMP_MD_FILE")"
|
||||
cd "$BASE_DIR"
|
||||
|
||||
# for line in $(grep '^!\[.*\](.*\.md)$' "$TEMP_MD_FILE" | sed 's/ /%20;/g')
|
||||
# do
|
||||
# src=$(echo "$line" | sed -e 's/^.*(//' -e 's/).*$//' -e 's/%20;/ /g')
|
||||
|
||||
# sed -i "$TEMP_MD_FILE" \
|
||||
# -e "s/^!\[.*\]($src)\$/\\include{$src}/"
|
||||
# done
|
||||
|
||||
sed --in-place \
|
||||
-e "s|?title?|$title|" \
|
||||
"$TEX_FILE"
|
||||
|
||||
109
converters/pagebreak.lua
Normal file
109
converters/pagebreak.lua
Normal file
@@ -0,0 +1,109 @@
|
||||
--[[
|
||||
pagebreak – convert raw LaTeX page breaks to other formats
|
||||
|
||||
Copyright © 2017-2021 Benct Philip Jonsson, Albert Krewinkel
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
]]
|
||||
local stringify_orig = (require 'pandoc.utils').stringify
|
||||
|
||||
local function stringify(x)
|
||||
return type(x) == 'string' and x or stringify_orig(x)
|
||||
end
|
||||
|
||||
--- configs – these are populated in the Meta filter.
|
||||
local pagebreak = {
|
||||
asciidoc = '<<<\n\n',
|
||||
context = '\\page',
|
||||
epub = '<p style="page-break-after: always;"> </p>',
|
||||
html = '<div style="page-break-after: always;"></div>',
|
||||
latex = '\\newpage{}',
|
||||
ms = '.bp',
|
||||
ooxml = '<w:p><w:r><w:br w:type="page"/></w:r></w:p>',
|
||||
odt = '<text:p text:style-name="Pagebreak"/>'
|
||||
}
|
||||
|
||||
local function pagebreaks_from_config (meta)
|
||||
local html_class =
|
||||
(meta.newpage_html_class and stringify(meta.newpage_html_class))
|
||||
or os.getenv 'PANDOC_NEWPAGE_HTML_CLASS'
|
||||
if html_class and html_class ~= '' then
|
||||
pagebreak.html = string.format('<div class="%s"></div>', html_class)
|
||||
end
|
||||
|
||||
local odt_style =
|
||||
(meta.newpage_odt_style and stringify(meta.newpage_odt_style))
|
||||
or os.getenv 'PANDOC_NEWPAGE_ODT_STYLE'
|
||||
if odt_style and odt_style ~= '' then
|
||||
pagebreak.odt = string.format('<text:p text:style-name="%s"/>', odt_style)
|
||||
end
|
||||
end
|
||||
|
||||
--- Return a block element causing a page break in the given format.
|
||||
local function newpage(format)
|
||||
if format:match 'asciidoc' then
|
||||
return pandoc.RawBlock('asciidoc', pagebreak.asciidoc)
|
||||
elseif format == 'context' then
|
||||
return pandoc.RawBlock('context', pagebreak.context)
|
||||
elseif format == 'docx' then
|
||||
return pandoc.RawBlock('openxml', pagebreak.ooxml)
|
||||
elseif format:match 'epub' then
|
||||
return pandoc.RawBlock('html', pagebreak.epub)
|
||||
elseif format:match 'html.*' then
|
||||
return pandoc.RawBlock('html', pagebreak.html)
|
||||
elseif format:match 'latex' then
|
||||
return pandoc.RawBlock('tex', pagebreak.latex)
|
||||
elseif format:match 'ms' then
|
||||
return pandoc.RawBlock('ms', pagebreak.ms)
|
||||
elseif format:match 'odt' then
|
||||
return pandoc.RawBlock('opendocument', pagebreak.odt)
|
||||
else
|
||||
-- fall back to insert a form feed character
|
||||
return pandoc.Para{pandoc.Str '\f'}
|
||||
end
|
||||
end
|
||||
|
||||
local function is_newpage_command(command)
|
||||
return command:match '^\\newpage%{?%}?$'
|
||||
or command:match '^\\pagebreak%{?%}?$'
|
||||
end
|
||||
|
||||
-- Filter function called on each RawBlock element.
|
||||
function RawBlock (el)
|
||||
-- Don't do anything if the output is TeX
|
||||
if FORMAT:match 'tex$' then
|
||||
return nil
|
||||
end
|
||||
-- check that the block is TeX or LaTeX and contains only
|
||||
-- \newpage or \pagebreak.
|
||||
if el.format:match 'tex' and is_newpage_command(el.text) then
|
||||
-- use format-specific pagebreak marker. FORMAT is set by pandoc to
|
||||
-- the targeted output format.
|
||||
return newpage(FORMAT)
|
||||
end
|
||||
-- otherwise, leave the block unchanged
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Turning paragraphs which contain nothing but a form feed
|
||||
-- characters into line breaks.
|
||||
function Para (el)
|
||||
if #el.content == 1 and el.content[1].text == '\f' then
|
||||
return newpage(FORMAT)
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
{Meta = pagebreaks_from_config},
|
||||
{RawBlock = RawBlock, Para = Para}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
\documentclass[11pt]{article}
|
||||
\usepackage[a4paper, portrait, includehead, includefoot, margin=1.5cm]{geometry}
|
||||
|
||||
\usepackage[dutch]{babel}
|
||||
\usepackage[$if(lang)$$lang$$else$dutch$endif$]{babel}
|
||||
|
||||
\usepackage{pdfpages}
|
||||
|
||||
@@ -40,8 +40,9 @@
|
||||
\usepackage{graphbox}
|
||||
\usepackage{sectsty}
|
||||
\sectionfont{\clearpage}
|
||||
\newcommand\pandocbounded{}
|
||||
|
||||
\setkeys{Gin}{width=.95\linewidth}
|
||||
\setkeys{Gin}{width=.99\linewidth}
|
||||
|
||||
% add bookmarks with \hypertarget
|
||||
\usepackage{bookmark}
|
||||
@@ -64,79 +65,78 @@
|
||||
\let\tmpenditem\enditemize
|
||||
\renewenvironment{itemize}{\tmpitem\setlength\itemsep{-.4em}}{\tmpenditem}
|
||||
|
||||
$if(highlighting-macros)$
|
||||
$highlighting-macros$
|
||||
%\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
|
||||
$endif$
|
||||
|
||||
\begin{document}
|
||||
\raggedright
|
||||
\pagecolor{darkishyellow}
|
||||
|
||||
\begin{titlepage}
|
||||
\null\vfill
|
||||
.
|
||||
\vskip 10em
|
||||
\begin{center}
|
||||
{\Huge\fontUbuntu ?title? \par}
|
||||
{\Huge\fontUbuntu $title$ \par}
|
||||
\vskip 3em
|
||||
% \includegraphics{assets/eriks.50.png}
|
||||
\vskip 3em
|
||||
{\huge\fontUbuntu Superlight Personal Carrier \par}
|
||||
{\huge\fontUbuntu $sub_title$ \par}
|
||||
\end{center}
|
||||
\vskip 25em
|
||||
\null\vfill
|
||||
{
|
||||
\large
|
||||
\lineskip .75em
|
||||
\begin{tabular}{r l}
|
||||
gemaakt door: $for(auther)$& $auther.name$ <$auther.email$> \\
|
||||
$endfor$\\
|
||||
vak code: & ELEPEE51 \\\\
|
||||
ge\"exporteerd op: & \today
|
||||
$if(lang)$Auther$else$Gemaakt door$endif$: $for(auther)$& $auther.name$ <$auther.email$> \\
|
||||
$endfor$\\
|
||||
$if(class_code)$
|
||||
$if(lang)$Class code$else$Vak code$endif$: & $class_code$ \\\\
|
||||
$endif$
|
||||
$if(lang)$Exported on$else$Ge\"exporteerd op$endif$: & \today
|
||||
\end{tabular}
|
||||
}
|
||||
\vfill\null
|
||||
\end{titlepage}
|
||||
|
||||
\pagestyle{fancy}
|
||||
\fancyhead{} % clear all header fields
|
||||
\fancyhead[LO]{\color{gray}\fontUbuntu ?title?}
|
||||
\fancyhead[RO]{\color{gray}\fontUbuntu Superlight Personal Carrier}
|
||||
\fancyhead[LO]{\color{gray}\fontUbuntu $title$}
|
||||
\fancyhead[RO]{\color{gray}\fontUbuntu $sub_title$}
|
||||
\fancyfoot{} % clear all footer fields
|
||||
\fancyfoot[LO]{\color{gray}\fontUbuntu $for(auther)$$auther.name_short$${sep}, $endfor$}
|
||||
\fancyfoot[CO]{\color{gray}\fontUbuntu }
|
||||
\fancyfoot[RO]{\color{gray}\fontUbuntu \thepage}
|
||||
|
||||
|
||||
$if(toc)$
|
||||
\tableofcontents
|
||||
$endif$
|
||||
$if(lof)$
|
||||
\listoffigures
|
||||
$endif$
|
||||
$if(lot)$
|
||||
\listoftables
|
||||
$endif$
|
||||
$if(linestretch)$
|
||||
\setstretch{$linestretch$}
|
||||
$endif$
|
||||
|
||||
|
||||
$body$
|
||||
|
||||
|
||||
$if(nocite-ids)$
|
||||
\nocite{$for(nocite-ids)$$it$$sep$, $endfor$}
|
||||
$endif$
|
||||
$if(natbib)$
|
||||
$if(bibliography)$
|
||||
$if(biblio-title)$
|
||||
$if(has-chapters)$
|
||||
\renewcommand\bibname{$biblio-title$}
|
||||
$else$
|
||||
\renewcommand\refname{$biblio-title$}
|
||||
$endif$
|
||||
$endif$
|
||||
\bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
|
||||
% $if(nocite-ids)$
|
||||
% \nocite{$for(nocite-ids)$$it$$sep$, $endfor$}
|
||||
% $endif$
|
||||
% $if(natbib)$
|
||||
% $if(bibliography)$
|
||||
% $if(biblio-title)$
|
||||
% $if(has-chapters)$
|
||||
% \renewcommand\bibname{$biblio-title$}
|
||||
% $else$
|
||||
% \renewcommand\refname{$biblio-title$}
|
||||
% $endif$
|
||||
% $endif$
|
||||
% \bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
|
||||
|
||||
$endif$
|
||||
$endif$
|
||||
$if(biblatex)$
|
||||
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
|
||||
% $endif$
|
||||
% $endif$
|
||||
% $if(biblatex)$
|
||||
% \printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
|
||||
|
||||
$endif$
|
||||
% $endif$
|
||||
|
||||
\end{document}
|
||||
|
||||
Reference in New Issue
Block a user