TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from stackoverflow.com May 18 '12 at 21:35

This question came from our site for professional and enthusiast programmers.

There is the gnuplot package. Also, pgfplots can work with gnuplot. – clemens May 18 '12 at 22:18
up vote 9 down vote accepted

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




      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

plot sin(x)


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

enter image description here

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

share|improve this answer

You can either do it via the \write18 command


 \immediate\write18{dir > test}

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.

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.