This is for generating the plots. It needs the pdflatex option --shell-escape
. You can use gnuplottex
or pgfplots
(with/without gnuplot
) packages for plotting.
\documentclass[a4paper]{article}
\usepackage[miktex]{gnuplottex}
\usepackage{pgfplots}
\begin{document}
\section{GnuplotTeX}
\begin{gnuplot}[terminal=pdf, terminaloptions={font "Arial"}]
plot 2*x+1
\end{gnuplot}
\section{PGFPLOTS}
\begin{tikzpicture}
\begin{axis}[domain=-10:10, samples=50, smooth, no markers, enlargelimits=false]
\addplot {2*x+1};
\end{axis}
\end{tikzpicture}
\section{PGFPLOTS and GNUPLOT}
\begin{tikzpicture}
\begin{axis}[domain=-10:10, samples=50, smooth, no markers, enlargelimits=false]
\addplot gnuplot {2*x+1};
\end{axis}
\end{tikzpicture}
\end{document}
To produce .png
files you can use standalone
class with imagemagick
. But my preferred way is by using write18
facility.
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{my-graph}
%
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel={$x-$ axis label},
ylabel={$y-$ axis label},xtick={-10,-8,-6,-4,-2,0,2,4,6,8,10},ytick={-18,-14,-10,-6,-2,2,6,10,14,18,21},
grid=both,domain=-10:10, samples=50, smooth, no markers, enlargelimits=false]
\addplot {2*x+1};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[xlabel={$x-$ axis label},
ylabel={$y-$ axis label},xtick={-10,-8,-6,-4,-2,0,2,4,6,8,10},ytick={-18,-14,-10,-6,-2,2,6,10,14,18,21},
grid=both,domain=-10:10, samples=50, smooth, no markers, enlargelimits=false]
\addplot gnuplot {2*x+1};
\end{axis}
\end{tikzpicture}
\end{document}
\end{filecontents*}
%
%pdflatexing my-graph
%
\immediate\write18{pdflatex --shell-escape my-graph}
% convert to PNG
\makeatletter
\immediate\write18{convert -density 200 -alpha on my-graph.pdf my-graph-\@percentchar02d.png}
\makeatother
\begin{document}
Check the folder containing this file. you will have \texttt{my-graph-00.png} and \texttt{my-graph-01.png} there.
\end{document}
For this image magick
should have been installed. And you will find .png
files in the same folder as this main file.
First, about the trouble with the executable name:
convert
is also the MS tool for FAT to NTFS conversion of hard disk drives, therefore the recommendation is to rename Image Magick's convert.exe
to imgconvert.exe
. In order not to be blamed for any data loss due to my standalone
package (even if this is very unlikely) I put the default executable name to imgconvert
. This can be change using the convert={convertexe={convert.exe}}
class option.
This all is also described in detail in the standalone
manual.
I would recommend Windows users to either rename or copy the convert.exe
file to imgconvert.exe
or change the standalone.cfg
file to include:
\standaloneconfig{convert={convertexe={convert.exe},false}}
Now to the error message you get:
I tried this under Windows and found out that it depends on the version of Image Magick. With v6.6.9 I get the same error. Here it doesn't matter if it is called from standalone
or manually from the command line. However with v6.8.1 I just downloaded today from here it works without any issues (after selecting the right executable name as mentioned above).
It seems there is an issue with PDF using v6.6.9 and maybe other versions after it before v6.8.1.
Therefore the fix for your problem is to update Image Magick. If this doesn't fix your issue, or if you already have v6.8.1 installed, then please post the used version number here. Also try to convert it manually using the command line
convert.exe -density 300 file.pdf -quality 90 file.png
. If this also throws the same error it isn't an issue with standalone
but only with ImageMagick.
Best Answer
According to the documentation, is only possible if you set it within "standalone.cfg" not within the document, however, is more like using:
the log :
or
after compiled document (mogrify prserve name of the image files :). regards