Skip to content

Instantly share code, notes, and snippets.

@mildsunrise
Last active October 30, 2021 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mildsunrise/f0905f3838f566f8d344153f86c66ff6 to your computer and use it in GitHub Desktop.
Save mildsunrise/f0905f3838f566f8d344153f86c66ff6 to your computer and use it in GitHub Desktop.
Render LaTeX inline code to a small image

Quick boilerplate for when you need a LaTeX inline thing converted to an image. Enter the expression in fig.tex, and run:

pdflatex fig.tex < /dev/null && convert -density 600 fig.pdf -flatten -scale 50% -quality 90 fig.jpg

Things you may want to change:

  • To render block content (i.e. an equation) instead of a float or inline content, add varwidth=40em to the document options, or use \minipage for a fixed width.
  • Tweak the -density, -quality and border accordingly, or produce a .png.
  • Change the language.

The standalone class has a convert option but this makes babel go nuts for unknown reasons.

%
\documentclass[english,border=10pt]{standalone}
% encoding
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{babel}
% formatting and fixes
\frenchspacing
\usepackage{csquotes}
\MakeAutoQuote{«}{»}
% ADD ANY SPECIFIC PACKAGES HERE
% (CHEMISTRY, CODE, PUBLISHING)
\usepackage{mathtools}
\usepackage{nicefrac}
\begin{document}
$ \int_{-\infty}^{\infty} \delta(t) \, u(t) e^{-st} \,{\mathrm d}t $
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment