Skip to content

Instantly share code, notes, and snippets.

@psaikko
Created August 12, 2019 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save psaikko/1315f11b5c6bc1abefe7b20acfeb71b8 to your computer and use it in GitHub Desktop.
Save psaikko/1315f11b5c6bc1abefe7b20acfeb71b8 to your computer and use it in GitHub Desktop.
Read LaTeX source from standard input, render to PNG and move to clipboard. Paste nice equations anywhere.
#!/usr/bin/env bash
tmpdir="$(mktemp -d)"
texfile="$tmpdir/tmp.tex"
echo "\documentclass[varwidth]{standalone}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{color}
\usepackage[utf8]{inputenc}
\begin{document}
" > "$texfile"
cat >> "$texfile"
echo "\end{document}" >> "$texfile"
pdflatex -output-directory "$tmpdir" tmp.tex
pdftocairo -r 600 -png -transp -singlefile "$tmpdir/tmp.pdf" "$tmpdir/tmp"
xclip -selection clipboard -t image/png -i "$tmpdir/tmp.png"
rm -r "$tmpdir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment