Update: 2012-01:
The standalone
class now has a varwidth
option, so with the current release, one would simply use the [varwidth]
package option:
\ifdefined\formula
\else
\def\formula{E = m c^2}
\fi
\documentclass[border=2pt,varwidth]{standalone}
\usepackage{standalone}
\usepackage{amsmath}
\begin{document}
\[ \formula \]
\end{document}
Save the following as formula.tex
:
\ifdefined\formula
\else
\def\formula{E = m c^2}
\fi
\documentclass[border=2pt]{standalone}
\usepackage{amsmath}
\usepackage{varwidth}
\begin{document}
\begin{varwidth}{\linewidth}
\[ \formula \]
\end{varwidth}
\end{document}
The standalone
class is used for cropping. The varwidth
environment is similar to the minipage
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:
pdflatex "\def\formula{E=\frac{m_1v^2}{2}}\input{formula.tex}"
convert -density 300 formula.pdf -quality 90 formula.png
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 use
\documentclass[convert={density=300,size=1080x800,outext=.png}]{standalone}
Alternatively you could also use GIMP
as per this link from Wikibooks.
LaTeX already separates content from formatting. E.g. the look of \section{ABC}
can be different depending on packages and classes. It is also easy to translate your XML-example in something more LaTeX-like e.g.
\begin{timeline}{title=Australian History}
\timepoint{year=60000BC,event=Aboriginal Migration,text=Aboriginal ...}
\timepoint{...}
\end{timeline}
Now you only need to write sensible definitions to get a suitable formatting.
The main difference between the markup from LaTeX and XML is that the first is less strict – and so better suited for normal, more or less messy human documents, where not everything can be pressed in the XML-model.
Best Answer
XML is a file format not a language of any sort so asking for a general XML to latex is like asking for ASCII to latex. In general it depends what is in the XML file, one would not expect the same latex formatting for an XSLT program as a XHTML document, just because they both happened to use an XML syntax.
In general you need to specify the styling you want for the XML language in use. XSLT is perhaps the canonical tool for this, however it is possible to get TeX to read the XML directly and apply formatting from a stylesheet.
xmltex
does this for LaTeX and ConTeXt has similar facilities built in.For example, one specific translation: If you want to translate mathematics encoded in XML as MathML to LaTeX markup you could use the pmml2tex XSLT translation available from http://code.google.com/p/web-xslt/source/browse/trunk/pmml2tex