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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am familiar with using LaTeX on online websites (like MathOverflow or Physicsforums). My input is rendered using MathJax. However, I do not understand the LaTeX environment in its native OS form. I have downloaded MacTeX, and all I would like to do is make tiny little .png or .jpg files that each contain one equation.

After some Googling, I have tried something along the lines of:

\documentclass[preview]{standalone}
\begin{document}
\begin{equation}
\frac{1}{2} = 0.5
\end{equation}
\end{document}

followed by

pdflatex equation.tex
convert -density 300 equation.pdf -quality 95 equation.png

(using ImageMagick's convert program), but the output contains a number next to my equation that I can't seem to get rid of. Also, this seems like a lot of work, and I don't need a whole documentclass just for one equation. Not to mention pdflatex produces a bunch of other auxiliary files that clutter up my directory during the conversion process. Is there some way I can just easily go from a file containing

\frac{1}{2} = 0.5

to equation.png? Better yet, is there a simple way I can take a file containing a list of equations and have each of them converted into their own little .png image?

share|improve this question
6  
replace the equation env with \[and \] – percusse Jan 13 at 18:55
    
Thanks! That helps a lot. Is there also a way to shrinkwrap the generated pdf around the equation? I have huge margins consisting only of whitespace. – Nick Jan 13 at 19:03
    
You could use the geometry package to reduce the size of the page with \usepackage[paperwidth=3in,paperheight=1.5in]{geometry}. It might be better done at the convert stage, though, with the -trim option, which strips all pixels from the outside edges which match the corner pixels in color. – Brian Jan 13 at 19:32
    
I would use a simple math group $ a+b$, or if needed the diplayed mode: $\sum_{0}^{k}$. – Johannes_B Jan 13 at 19:40

standalone class is sufficient. You can enable the multi option, so that the contents of each (math) environment is cropped to its own page in a PDF file. Then you can either save each page directly as a .png image (Acrobat Pro, and perhaps Adobe Reader, allows you to do it in one go), or you can use the convert functionality (need Image Magick) provided with standalone. For the latter method, see Section 4.6 of the standalone documentation.

In the example below I define a new environment mymath, which is basically inline math with display style.

MWE

\documentclass[multi={mymath},border=1pt]{standalone}
% \usepackage{amsmath}
\newenvironment{mymath}{$\displaystyle}{$}

\begin{document}

\begin{mymath}
  \frac{1}{2}=0.5
\end{mymath}

\begin{mymath}
  a^2 + b^2 = c^2
\end{mymath}

\end{document}

Output

enter image description here

share|improve this answer
7  
The standalone using convert route would look something like: \documentclass[convert={density=300,size=800x800,outext=.png}]{standalone} in case anybody wants a quick example. – tpg2114 Jan 14 at 4:23

Here's what I do to go from a file of equations to png files using asymptote. You'll need the following 3 files in a directory.

sample.bat - change the "5" to alter the png resolution

asy sample -noV -render 5 -f png
pause

sample.dat - this file holds your equations.

\frac{1}{2} = 0.5
y = \sin{x}
a^2 + b^2 = c^2

sample.asy - this is the asymptote code

file fin = input("sample.dat").line();
int index = 1;
while (!eof(fin))
{
    string s = fin;
    if (s == "") { continue; }
    label("$\displaystyle " + s + "$", (0,0));
    shipout("eq"+string(index));
    erase();
    ++index;
}

Running the batch file will create the following 3 png files.

enter image description here

enter image description here

enter image description here

share|improve this answer

Since you have MacTeX, use LaTeXiT, which lets you convert equations to images in several formats, including PDF and PNG. There is no need to write LaTeX support code: just enter the equation in the input box and press "LaTeX it!".

If you want to convert equations in batch, you can write a simple script that adds the equation to a template based on the standalone class, runs latex, and then dvipng.

There are also web services, such as Roger's Online Equation Editor.

share|improve this answer

The problem appears to be that latex automatically numbers equations in the equation environment. This default behavior of latex's is likely because authors often need to refer to equations. An easy solution is to remove numbering by using

\begin{equation*}
YOUR EQUATION GOES HERE
\end{equation*}
share|improve this answer

I am missing the reputation to add a comment to Herr K.'s answer...

In order to generate individual PNG files on Windows, you may need to specify the actual convert executable on your path (standalone assumes this to be imgconvert on Windows, instead of convert).

MWE:

\documentclass[
  multi={mymath},
  border=2pt,
  convert={convertexe={convert},density=300,outext=.png}
  ]{standalone}
% \usepackage{amsmath}
\newenvironment{mymath}{$\displaystyle}{$}

\begin{document}

\begin{mymath}
  \frac{1}{2}=0.5
\end{mymath}

\begin{mymath}
  a^2 + b^2 = c^2
\end{mymath}

\end{document}

This generates to following two PNG files:

1st example

2nd example

share|improve this answer

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.