Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

when I try to display a math equation with LaTeX, there is always whitespace to the right and left of the math equation. I am trying it with code like this:

\documentclass{standalone}
\begin{document}
%Math equation here
\end{document}

This method works for regular text, it just doesn't seem to work for math. Is there a solution?

share|improve this question
1  
Doesn't happen to me. May you give a real example? –  egreg Oct 9 '11 at 20:17
2  
It would be great if you could give a complete document that acts like this. For example, what kind of "math equation" are you using? $...$? \[...\]? \begin{align}...\end{align}? –  Ryan Reich Oct 9 '11 at 20:18
    
@egreg: can easily been seen with \[ y \] –  Herbert Oct 9 '11 at 20:39
    
I only didn't post it because I didn't see it as relevant, but, here it is: \documentclass{standalone \begin{document} \[ \int_1^a{\frac{dx}{x}} = \ln a \] \[ \int{x^n} = \frac{x^{n+1}}{n+1}\] \end{document} –  mebob Oct 9 '11 at 20:42
    
The one work-around is to use pdfcrop, as suggested in my comment where this original problem arose. However, this may be related to some options of preview. –  Werner Oct 9 '11 at 20:43
show 4 more comments

3 Answers 3

up vote 13 down vote accepted

The construction \[...\] builds a whole paragraph, so that standalone is forced to leave space for it.

A formula written as

$\displaystyle <formula>$

will give the same result as \[<formula>\], but will not produce excess white space.

If you want two "centered" formulas one after the other, then

\documentclass{standalone}
\usepackage{amsmath}
\begin{document}
$\begin{gathered}
\int_1^a{\frac{dx}{x}} = \ln a \\
\int{x^n} = \frac{x^{n+1}}{n+1}
\end{gathered}$
\end{document}

is the way to go. For aligned equations you can use aligned.

share|improve this answer
add comment

Based on the code in the comments this seems to have been an issue with how the standalone package is begin used. With the latest version of standalone, the [varwidth] option is needed. The MWE below does not produce any space around the formulas:

enter image description here

Note:

Code:

\documentclass[varwidth]{standalone} 
\usepackage{amsmath}
\begin{document} 
  \[ \int_1^a \frac{dx}{x} = \ln a \]
  \[ \int {x^n} = \frac{x^{n+1}}{n+1}\] 
\end{document}
share|improve this answer
    
Re varwidth: The v1.0 version uses crop by default, not preview as before, and this uses a horizontal box for the content. The \[ \] doesn't like restricted horizontal mode. The varwidth options wraps the content into a varwidth environment (from the varwidth package) which is a minipage with a variable width. Unfortunately I had to sacrifice 100% backwards compatibility in order to provide a good default setting. crop avoids a few drawbacks of preview. The default setting can be easily changed using the config file. See the manual, especially the "Version update" section –  Martin Scharrer Jan 25 '12 at 17:00
add comment

try

\documentclass{article}
\pagestyle{empty}
\usepackage{auto-pst-pdf}
\PreviewEnvironment{displaymath}
\begin{document}
\begin{displaymath}y=f(x)\end{displaymath}
\end{document}

it creates a file <file>-pics.pdf which holds the equation as a cropped pdf

Run it with pdflatex -shell-escape <file> or alternetively with xelatex or lualatex

share|improve this answer
    
I tried to typeset your code using TeXShop first, with XeLaTeX selected and second, with LuaLaTeX selected. However, in both cases, I get "!undefined control sequence. \PreviewEnvironment". –  Sony Oct 9 '11 at 22:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.