Created
September 24, 2024 14:19
-
-
Save dtony/c884c5249e4dff40bdc26646304661e9 to your computer and use it in GitHub Desktop.
Convert markdown with mermaid and math formulas to pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
input=$1 | |
set -e | |
if [ "$#" -ne 1 ]; then | |
echo "One argument required" | |
exit 1 | |
fi | |
if [ ! -f $1 ]; then | |
echo "$1 not found!" | |
exit 1 | |
fi | |
math_md=`basename $1 .md`_math.md | |
mmd_md=`basename $1 .md`_mmd.md | |
pdf=`basename $1 .md`.pdf | |
# render mermaid | |
npx -p @mermaid-js/mermaid-cli mmdc -p puppeteerConfigFile.json -s 4 -i $1 --outputFormat=png -o $mmd_md | |
# render math formulas | |
python -m readme2tex --output $math_md $mmd_md --username tony --project test --nocdn | |
# replace git cdn urls by local ones | |
sed -i $math_md -e "s/https:\/\/.*svgs\//svgs\//" | |
# render pdf with pandoc | |
pandoc -V margin-top=2cm -V margin-left=2cm -V margin-right=2cm -V margin-bottom=2cm -V papersize=A4 -t html $math_md -o $pdf --pdf-engine-opt=--enable-local-file-access | |
# cleanup | |
rm svgs/*.svg | |
rmdir svgs | |
rm $math_md | |
rm $mmd_md | |
rm `basename $1 .md`_mmd*.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"executablePath": "/snap/bin/chromium" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requirements:
pip install readme2tex
)apt install pandoc
or whatever)