scripts/latexpic.sh

35 lines
800 B
Bash
Executable File

#!/usr/bin/env bash
# shellception since nix-shell and shebang does not work with combining texlive
if ! command -v xelatex >> /dev/null; then
nix-shell -p 'texlive.combine { inherit (pkgs.texlive) scheme-small chemfig simplekv siunitx standalone varwidth; }' --run "$0 $@"
exit $?
fi
tmpdir=$(mktemp -d)
cd $tmpdir
cat > doc.tex << EOF
\documentclass[varwidth]{standalone}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\sisetup{
per-mode=fraction,
quotient-mode=fraction
}
\usepackage{chemfig}
\renewcommand*\familydefault{\sfdefault}
\begin{document}
$(cat $OLDPWD/$1)
\end{document}
EOF
xelatex doc.tex
mutool draw -o doc.svg doc.pdf
inkscape -D -A doc.pdf doc.svg
mutool draw -r 600 -o $OLDPWD/${1}.png doc.pdf
mutool draw -o $OLDPWD/${1}.svg doc.pdf
cd -
rm -rf $tmpdir