I'd like to generate an image with math formulas with TeX from command line. Something like:
$ tex-executable "E=\frac{m_1v^2}{2}" e2.png
I have MacTex 2009 installed and I'm pretty sure that something like that already exists in this distribution. If not please suggest me a tool.
Best Answer
Update: 2012-01:
The
standalone
class now has avarwidth
option, so with the current release, one would simply use the[varwidth]
package option:Save the following as
formula.tex
:The
standalone
class is used for cropping. Thevarwidth
environment is similar to theminipage
environment, but sets its width to match the narrower natural width based on the content.The
ifdefined...\fi
is only necessary so that this file can be compiled by itself, which is useful to test to ensure that there are no errors in it, in case you decide to make changes to it.Then you can process this file as:
where
convert
is part of ImageMagick. This yields the following PNG file:I have not used it, but the current development version of
standalone
can generate the PNG directly if you useAlternatively you could also use
GIMP
as per this link from Wikibooks.