Gnuplot - latex commands & output window

Viewed 82

LaTeX is pretty common tool for typsetting symbols and formulas (i.e. \alpha, \frac) and I have learned that there are different terminals that support it, of which I especially like tikz which I often use in LaTeX. However those terminals have output as a file only. Is there any terminal or other option that allows using LaTeX commands and still shows the result instantly in a separate window?

1 Answers

Here is what I would do, and have done on occasion. The refresh does not happen "instantly" since pdflatex is far from instantaneous. However it does have the advantage of keeping you inside the gnuplot session as you work on your figure.

# Create a pdf file holding the initial plot
MYFIGURE = "myfigure.tex"
set term tikz standalone
set output MYFIGURE    gnuplot> replot; unset out; system("pdflatex myfigure"); set out MYFIGURE
gnuplot> ... tweak the title, layout, colors, whatever
gnuplot> history !replot
plot PLOT1
unset output

# Display the pdf on the screen using whatever the standard pdf viewer
# is on your system.  For me (KDE desktop) this is okular.
system("pdflatex myfigure")
system("okular myfigure.pdf &")

# Draw new or updated versions of the figure into the same file
# okular will notice that the file has changed and refresh the display

set out MYFIGURE
set title "Same figure, new title"
replot
unset out; system("pdflatex myfigure")

set out MYFIGURE
set title "Different figure entirely"
splot FOO with pm3d
unset out; system("pdflatex myfigure")

# ... and so on 

If you are continually tweaking the layout of the same figure so that the sequence always involves a replot, then putting the sequence on a single line gnuplot command allows you to re-execute in a singe step using gnuplot's history commands or hitting up-arrow a few times to retrieve the command. For example:

gnuplot> replot; unset out; system("pdflatex myfigure"); set out MYFIGURE
gnuplot> ... tweak the title, layout, colors, whatever ...
gnuplot> history !replot
gnuplot> ... tweak the figure some more ...
gnuplot> history !replot

Note: TeX will want to find the gnuplot support packages in its normal search path. If they are not already present in your TeX installation, you can follow the instructions in the gnuplot source .../term/lua/README (copied here)

Generating style and help file
==============================

To generate the style files and wrapper for the various TeX flavors enter

  lua gnuplot-tikz.lua style

on the command line. The files generated should be

  t-gnuplot-lua-tikz.tex        (Context wrapper)
  gnuplot-lua-tikz.tex          (plain TeX wrapper)
  gnuplot-lua-tikz.sty          (LaTeX wrapper)
  gnuplot-lua-tikz-common.tex   (common definitions)

and can be copied to the appropriate places.
Related