snippets/latexpic

46 lines
856 B
Plaintext
Raw Permalink Normal View History

2020-11-23 17:14:08 +01:00
#!/bin/bash
set -e
2020-11-25 13:39:14 +01:00
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
2020-11-23 17:14:08 +01:00
color=$1
input=$2
2020-11-25 13:39:14 +01:00
fg="${color% on *}"
bg="${color##* on }"
2020-11-23 17:14:08 +01:00
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}
2020-11-25 13:39:14 +01:00
\color{$fg}
2020-11-23 17:14:08 +01:00
\begin{document}
$input
\end{document}
EOF
2020-11-25 13:39:14 +01:00
if [ "$fg" = "$bg" ]; then
convert -density 600 "$outpdf" -quality 90 "$outpng"
else
convert -background "$bg" -flatten -density 600 "$outpdf" -quality 90 "$outpng"
fi
2020-11-23 17:14:08 +01:00
xdg-open "$outpng"