4

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?

anoneemus
  • 143
  • 2
    Welcome to TeX.SX! Use $\displaystyle...$ instead of \[...\]. See https://tex.stackexchange.com/a/417837/4427 for an explanation. – egreg Mar 01 '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 01 '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 01 '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 01 '18 at 17:31
  • Oh, nvm, I just found the second half of your comment. I suppose this is probably a duplicate of that question, though I'd argue it's difficult for a newbie who doesn't know why his stuff is breaking to find that answer. – anoneemus Mar 01 '18 at 17:31
  • @daleif varwidth let me use linebreaks (also I removed the size specification from my convert option), but doesn't do horizontal centering... I'll \centering and such and see where that gets me. – anoneemus Mar 01 '18 at 17:34
  • Center in relation to what exactly? You should probably reformulate your question to be a lot more specific – daleif Mar 01 '18 at 17:36
  • @daleif I've found that if you wrap it in a center env, the compiler will complain and insert a bunch of $, but if you give it +R, when it runs into that error, it will actually spit out exactly what I want. – anoneemus Mar 01 '18 at 17:37
  • @daleif this actually goes beyond the scope of my original question - I have a much more complex set of equations I was trying to typeset, but I broke the problem down to the smallest needed to reproduce my problem to ask this question. Now that I've gotten my question answered, I wanted to go back to typesetting my original equations. I have 4 that I want to each have their own line, all centered horizontally in the image. – anoneemus Mar 01 '18 at 17:39
  • 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 01 '18 at 17:39
  • @daleif don't worry, you answered my question. Frankly everything else like centering etc. is off-topic, and I shouldn't be asking in the comments. – anoneemus Mar 01 '18 at 18:03

1 Answers1

8

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}
egreg
  • 1,121,712
  • 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 01 '18 at 18:05