snippets/latexpic
2020-11-25 13:39:14 +01:00

46 lines
856 B
Bash
Executable File

#!/bin/bash
set -e
if [ "$#" -ne 2 ]; then
echo "Usage: `basename $0` COLOR LATEXSRC"
echo
echo "with COLOR being either a single color for text on transparent background or 'color1 on color2'"
exit 1
fi
color=$1
input=$2
fg="${color% on *}"
bg="${color##* on }"
outpdf="/tmp/latexpic.pdf"
outpng="/tmp/latexpic.png"
cat <<EOF | pdflatex --output-directory /tmp --jobname latexpic --
\documentclass[12pt,varwidth]{standalone}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{pagecolor}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\color{$fg}
\begin{document}
$input
\end{document}
EOF
if [ "$fg" = "$bg" ]; then
convert -density 600 "$outpdf" -quality 90 "$outpng"
else
convert -background "$bg" -flatten -density 600 "$outpdf" -quality 90 "$outpng"
fi
xdg-open "$outpng"