3

I was trying to use the answer from this question to make a png of a math equation. I'm using the very simple file:

\documentclass[convert={density=300,size=800x800,outext=.png},border=1pt]{standalone}

\begin{document}

\[
a = \left\lceil\frac{b}{c}\right\rceil
\]

\end{document}

Which generates the error

! Missing $ inserted
<inserted text>
                $
l.6 a = \left
             \lceil\frac{b}{c}\right\rceil

Obviously this is an error with the actual .tex source itself, and doesn't really have anything to do with convert, but do note that I have the ImageMagick utilities installed and in working order. In fact, I was able to generate a simple png using the inline math environment.

Why doesn't \LaTeX like my \left?

  • 2
    Welcome to TeX.SX! Use $\displaystyle...$ instead of \[...\]. See tex.stackexchange.com/a/417837/4427 for an explanation. – egreg Mar 1 '18 at 17:25
  • @egreg that worked. Why though? I've written loads of LaTeX and I've always used $$ or \[ for multiline math. Also: can I do linebreaks inside of $\displaystyle? If you'd like to write up an answer that addresses these questions, I'd be happy to accept it. – anoneemus Mar 1 '18 at 17:29
  • 1
    Standalone is a bit special. Not at pc, but have you tried the varwidth option? That might help. – daleif Mar 1 '18 at 17:31
  • 1
    Well, you should never use $$ in LaTeX. For line breaks like in align, use $\begin{aligned}...\end{aligned}$. – egreg Mar 1 '18 at 17:31
  • 1
    You are not answering the question? What is being centered here the mwe has nothing to center as it is one line. Again be a lot more specific, then perhaps people can give you better advise. Right now we're flying blanks because of limited information – daleif Mar 1 '18 at 17:39
6

standalone is a bit special, because it's aimed at typesetting a single object for conversion to PNG (or other graphic format) or for later inclusion in another document. So its normal way of doing is making a box much like \mbox, where one cannot use \[...\].

There's a simple way out use inline math mode with \displaystyle that makes formulas like between \[ and \].

\documentclass{standalone}
\usepackage{amsmath}

\begin{document}
$\displaystyle
a = \left\lceil\frac{b}{c}\right\rceil
$
\end{document}

Another possibility is to use varwidth:

\documentclass[varwidth]{standalone}
\usepackage{amsmath}

\begin{document}
\[
a = \left\lceil\frac{b}{c}\right\rceil
\]
\end{document}

but beware this won't work with multiline alignments. For this you can use the “inner” forms such as aligned and gathered:

\documentclass{standalone}
\usepackage{amsmath}

\begin{document}
$\begin{aligned}
a &= \left\lceil\frac{b}{c}\right\rceil\\
  &= \left\lceil\frac{d}{e}\right\rceil
\end{aligned}$
\end{document}
  • For the record, I was able to get multiline arguments to "work" inside of \[..\] with just varwidth (without amsmath), but to be fair it wasn't pretty and probably shouldn't be done. – anoneemus Mar 1 '18 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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