# Is there a combination of LaTeX gnuplot flowchart?

I know this is not always a good idea, but I think it might be a good idea in some situation.

Is there an improved LaTeX version or something, can have the gnuplot scripts inside of the LaTeX file, so during compilation, it can compile the gnuplot scripts as well. Now we have to generate the EPS file first, or .tex file first.

The same apply to flowchart, I really wish there could be a solution that can dynamically compile and build in the flowchart scripts in the LaTeX file.

Am I missing something or what?

-
 There is the gnuplot package. Also, pgfplots can work with gnuplot. – cgnieder May 18 '12 at 22:18

## migrated from stackoverflow.comMay 18 '12 at 21:35

There's the package gnuplottex that does exactly what you want. Here's an example document, say test.tex:

\documentclass[a4paper]{article}
\usepackage{graphicx,amssymb,ifthen,moreverb,gnuplottex}

\pagestyle{empty}

\begin{document}

\begin{gnuplot}[terminal=pdf]
set   autoscale                        # scale axes automatically
unset log                              # remove any log-scaling
unset label                            # remove any previous labels
set xtic auto                          # set xtics automatically
set ytic auto                          # set ytics automatically
set title "Force Deflection Data for a Beam and a Column"
set xlabel "Deflection (meters)"
set ylabel "Force (kN)"
set key 0.01,100
set label "Yield Point" at 0.003,260
set arrow from 0.0028,250 to 0.003,280
set xr [0.0:0.022]
set yr [0:325]
plot    "force.dat" using 1:2 title 'Column' with linespoints , \
"force.dat" using 1:3 title 'Beam' with points
\end{gnuplot}

\begin{gnuplot}[terminal=pdf]
plot sin(x)
\end{gnuplot}

\end{document}


along with the standard force.dat file

# This file is called   force.dat
# Force-Deflection data for a beam and a bar
# Deflection    Col-Force       Beam-Force
0.000              0              0
0.001            104             51
0.002            202            101
0.003            298            148
0.0031           290            149
0.004            289            201
0.0041           291            209
0.005            310            250
0.010            311            260
0.020            280            240


If compiled with

pdflatex --shell-escape test


the result will be

You can use the gnuplot environment just like any other LaTeX environment.

-

You can either do it via the \write18 command

\documentclass{article}

\begin{document}
\immediate\write18{dir > test}
\end{document}


You just have to exchange the dir > test against the gnuplot call you need. The \immediate prefix will ensure that the command is executed immediately. The content of the write18 command will be expanded and executed on the shell.

For \write18 to work you have to enable it (is is disable for security reasons, so that an arbitrary package can't e.g. format you harddrive). Enabling \write18 is done with the --enable-write18 command line switch. E.g.

pdflatex --enable-write18 myfile.tex


I can't provide a exact gnuplot example, since I'm on windows and don't have gnuplot installed, but you should get the idea.

-
 The option is --shell-escape on Unix systems and TeX Live on Windows, and it should work also with MiKTeX 2.9. – egreg May 18 '12 at 22:17 I'm running texlive on windows & linux, and --enable-write18 & --shell-escape both seem to work both. – Andreas Wallner May 18 '12 at 22:22 Apparently both distributions accept both options. Good news. – egreg May 18 '12 at 23:10