Skip to content

Instantly share code, notes, and snippets.

@holazt
Forked from psaikko/tex2clip.sh
Created March 28, 2020 03:42
Show Gist options
  • Save holazt/4ee5f4bfe7d480232f208086a7a3ae44 to your computer and use it in GitHub Desktop.
Save holazt/4ee5f4bfe7d480232f208086a7a3ae44 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