3

I would like to output only one equation, not on a whole page, but document to fit size of the equation.

Just like the image output from the codecogs website.

How can I do this with LaTeX?

  • 1
    You can use an empty and via the standalone document class create an equation-only "page". – Werner Jun 04 '13 at 17:35

1 Answers1

4

For example, class standalone can be used:

\documentclass[border=1pt]{standalone}
\begin{document}
\mbox{$\displaystyle E=mc^2$}
\end{document}

Result

Remarks:

  • TeX only sees character bounding boxes of the font, not the bounding boxes of the visual appearance of the glyphs, thus it is possible that the visual appearances exceed the font character boxes. There I have added 1pt additional margin here by option border=1pt.

  • I do not know, why \[...\] or environment displaymath is not working, therefore I have simulated it by \mbox{$\displaystyle ...$}.

Alternative

You can also generate the equation on a page on its own with page style empty:

\documentclass{article}
\pagestyle{empty}
\begin{document}
\[ E=mc^2 \]
\end{document}

After the pdflatex run the white margins can be cropped by pdfcrop, that uses Ghostscript's bbox device to determine the visual bounding box.

Heiko Oberdiek
  • 271,626
  • ??? i don't see border=1pt in the example code. (in my experience, standalone results in a page that is much too tight.) regarding pdfcrop, i can confirm that it does a very nice job. – barbara beeton Jun 04 '13 at 17:45
  • @barbarabeeton: Thanks, I have forgotten to paste the updated test file. – Heiko Oberdiek Jun 04 '13 at 17:47