4

In LaTeX I can make a document to be exactly the size of the content:

\documentclass{article}
\usepackage[active]{preview}
\begin{document}
\begin{preview}
  \[
  \pi = \sqrt{12}\sum^\infty_{k=0} \frac{(-3)^{-k}}{2k+1}
  \]
\end{preview}
\end{document}

And compile that with

latex foo.tex
dvipng -T tight -D 231.26 -o foo.png foo.dvi

it makes an image exactly the size of the content (formula).

How do I get the same with XeLaTeX?

I need that because I use inkscape export to latex for images -- and sometimes I need the images as standalone files, not inside a tex document.

Edit:

Here's a full MWE:

\documentclass{article}
\usepackage{todonotes}

\begin{document}

\missingfigure[figwidth=6cm]{}

\end{document}

I actually use

\begin{figure}
  \centering
  \def\svgwidth{1\columnwidth}
  \input{2dSqFermi_2el.pdf_tex}
\end{figure}

as a figure (that's what "inkscape export to latex" is about) -- but that's not important. So in the initial MWE I've just used formula. I see that the given answers already solve that.

Adobe
  • 3,037

2 Answers2

8
  • Method 1 (Using standalone document class)

    enter image description here

    \documentclass[preview]{standalone}
    \begin{document}
    $
      \displaystyle
      \pi = \sqrt{12}\sum^\infty_{k=0} \frac{(-3)^{-k}}{2k+1}
    $
    \end{document}
    
  • Method 2 (Using geometry package)

    enter image description here

    \documentclass{article}
    \usepackage{graphicx}
    \newsavebox\IBox
    \savebox\IBox{\raisebox{\depth}{$\displaystyle\pi = \sqrt{12}\sum^\infty_{k=0} \frac{(-3)^{-k}}{2k+1}$}}
    \usepackage[paperwidth=\wd\IBox,paperheight=\ht\IBox,margin=0pt]{geometry}
    
    \begin{document}
    \noindent\usebox\IBox
    \end{document}
    
3

Take the look into the standalone package.

Example:

\documentclass[varwidth]{standalone}
\begin{document}
  \[
  \pi = \sqrt{12}\sum^\infty_{k=0} \frac{(-3)^{-k}}{2k+1}
  \]
\end{document}

Result:

result

m0nhawk
  • 9,664