update template

This commit is contained in:
2025-10-06 21:09:07 +02:00
parent 0732a9d82c
commit 421966bf9e
6 changed files with 61 additions and 80 deletions

View File

@@ -1,10 +1,10 @@
MD_FILE="$1"
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 +14,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"
}
@@ -28,15 +34,14 @@ do
md_src=$(echo "$line" | sed -e 's/^.*(//' -e 's/).*$//' -e 's/%20;/ /g')
echo "include found: $md_src"
download_images "$(pwd)$md_src"
cp "$(pwd)$md_src" "$BUILD_DIR/$(basename "$md_src")"
download_images "$BUILD_DIR/$(basename "$md_src")"
sed -i "$BUILD_DIR/$(basename "$md_src")" \
-e 's|\[toc\]||' \
-e 's|^\[parent\].*$||' \
-e 's|\[\([^]]*\)\](#\([^)]*\))|[\1](#\L\2)|' \
-e "s|https://live.kladjes.nl/uploads|${BASE_DIR}/latex/images|" \
-e "s|\`\`\`mermaid|\`\`\`{.mermaid loc=${BASE_DIR}/latex/images/$(basename "$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$(basename "$md_src")\n\`\`\`|"
@@ -46,23 +51,16 @@ done
download_images "$TEMP_MD_FILE"
sed -i "$TEMP_MD_FILE" \
-e 's|\[toc\]|\\tableofcontents|' \
-e 's|^\[parent\].*$||' \
-e 's|\[\([^]]*\)\](#\([^)]*\))|[\1](#\L\2)|' \
-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 \
pandoc --standalone \
--lua-filter=../../converters/include-files.lua \
--lua-filter=../../converters/headers.lua \
--to=latex \
-t latex --pdf-engine=xelatex \
--from=markdown+abbreviations \
--template "${BASE_DIR}/converters/template.latex" \
-o "$TEX_FILE" \
--dpi 300 \
-o "$PDF_FILE" \
"$(basename "$TEMP_MD_FILE")"
cd "$BASE_DIR"

View File

@@ -1,7 +1,7 @@
\documentclass[11pt]{article}
\usepackage[a4paper, portrait, includehead, includefoot, margin=1.5cm]{geometry}
\usepackage[english]{babel}
\usepackage[$if(lang)$$lang$$else$dutch$endif$]{babel}
\usepackage{pdfpages}
@@ -85,11 +85,12 @@ $endif$
\large
\lineskip .75em
\begin{tabular}{r l}
Auther: $for(auther)$& $auther.name$ <$auther.email$> \\
$if(lang)$Auther$else$Gemaakt door$endif$: $for(auther)$& $auther.name$ <$auther.email$> \\
$endfor$\\
Class code: & $class_code$ \\\\
Exported on: & \today
$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}
}
\end{titlepage}
@@ -103,40 +104,38 @@ $endif$
\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}