I want to generate an image from a Tex file. I use a template and then programmatically insert LaTeX inside it. For example, if I want to create an image for x^2 + \phi, this would be the resulting template file:

x^2 + \phi
\advance\textheight by 1cm
\advance\textwidth by 1cm

I don't really know LaTeX, because I've only used it on Math.SE for equations. I've taken this template somewhere and if it can be made better I'm open for suggestions.

However, the problem is that this does not compile! Running latex source.tex produces

Missing character: There is no x in font nullfont!

! Missing $ inserted.
<inserted text> 
l.10 x^
       2 + \phi

My understanding is that some packages are setting the nullfont mode, so I cannot input the equation correctly.

  • 3
    Never use the minimal class and never set boxes before \begin{document}. The reason for the error message is that ^ is legal only in math mode. – egreg Dec 8 '14 at 9:42
  • @egreg Why not use the minimal class? I find it quite handy, especially for TikZ pictures. – Benedikt Bauer Dec 8 '14 at 9:59
  • 5
    @BenediktBauer The minimal class was not designed to be used for anything: it's there as it does the minimum necessary to allow LaTeX to process a \begin{document} line. Various core/expected definitions are not made by minimal as a result. It was set up for testing in the early 1990s in a very different computing situation. – Joseph Wright Dec 8 '14 at 10:26

I don't understand the need for the \setbox, \vbox, and \hbox instructions. If all you want to do is to create an image file containing a certain math expression, in a font size of 12pt, you could achieve this objective by writing

$ x^2 + \phi $

More elaborate contents than $ x^2 + \phi $ can be created nearly as easily. E.g., to render the preceding content in displaymath mode and an equation number, you'd write

x^2 + \phi
  • If I add \begin{equation} can I get rid of the dollar signs? – rubik Dec 8 '14 at 10:02
  • @rubik - The short answer to your follow-up question is,"yes". I've edited my answer to flesh out this short answer a bit. :-) – Mico Dec 8 '14 at 11:40
  • Thanks! Now it's clearer! I'm also considering the double dollars sign. – rubik Dec 8 '14 at 12:16
  • @rubik - For LaTeX documents, use of $$ is deprecated. For more information, see the posting Why is \[ ... \] preferable to $$ ... $$? For unnumbered displaystyle equations, do use \[ ... \]. – Mico Dec 8 '14 at 13:30
  • Damn, I had just got used to $$... Thanks for the info! – rubik Dec 8 '14 at 13:38


  $x^2 + \phi$%



\[ x^2 + \phi \]

  • Could you please a little more detail, like, why this works, and what was the original problem. That will make it look like an answer, and not a comment. – Masroor Dec 8 '14 at 10:26

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.