What is the quickest and best way to export a plot image from Mathematica to a $\LaTeX$ Editor? Is there something quicker than exporting it to an image and then including it in the $\LaTeX$ document?
Answer
I usually Export
to hi-res PNG bitmaps for ease of use (there are a number of discussions on how best to export high-quality images on this forum. Take a peek at the right column of this page under "Related"). Personally I like notebooks that do not need any mouse-clicking or any other user interaction to produce output which makes reruns that much more comfortable and and most of all reproducible.
For ease of use when dealing with many different graphics I prepare a notebook for each of these and also generate the LaTeX code for insertion in my document. The graphics get their name from the notebook so you can easily spawn different versions by renaming the notebook.
plot = Plot[Sin[x], {x, 0, 10}]
(*gfxname = StringTake[FileNameSplit[NotebookFileName[]][[-1]], {1, -4}]*)
EDIT: more concise and portable:
gfxname = FileBaseName[NotebookFileName[]]
"2012-05-04_Plot_Export"
Export[gfxname <> ".png", plot];
StringReplace["\\begin{figure}[!htb]\\centering
\\includegraphics[width=1\\textwidth]{XXX}
\\caption{Put your caption here.}
\\label{fig:XXX}
\\end{figure}
", "XXX" -> gfxname]
The resulting output can be copied as plaintext or you might even splice it directly into your document (although this is a bit much for casual use).
\begin{figure}[!htb]\centering
\includegraphics[width=1\textwidth]{2012-05-04_Plot_Export}
\caption{Put your caption here.}
\label{fig:2012-05-04_Plot_Export}
\end{figure}
Comments
Post a Comment