Description:

Shell script, gnuplot code, and data files to create a data plot (PDF)
with a gnuplot/latex combination. For the template to work out of the
box, make sure you have texlive version 2024 or later installed with
STIX2 font packages, or another TeX distribution with the same
functionality. Other required software includes the 'epstopdf' script
included with texlive, ghostscript, gnuplot, obviously, and perhaps
other tools.

Files:

make-gnuplot-figure.sh: shell script used to create the figure 
gnuplot-script.plt:     Gnuplot input file, needs to be adapted
figure-template.tex:    xelatex preamble template used to create
                        the latex file for creating the figure
*.dat:                  data files used for the figure

File 'figure-template.tex' gets compiled with xelatex by the script to
produce the PDF figure

Usage:

Edit file 'gnuplot-script.plt' to assign input files, select what you
want to plot and how, set axis labels, plot styles, and so on. It is
recommended that after editing file 'gnuplot-script.plt' you run
'gnuplot gnuplot-script.plt' on the command line to make sure there
are no obvious syntax errors.

Then run the script 'make-gnuplot-figure.sh' to produce the figure in
'gnuplot-figure.pdf'. If you keep the PDF open in a viewer that
updates the view when the file is re-created, it is easy to tweak the
gnuplot input as needed by editing 'gnuplot-script.plt' and re-running
the shell script to adapt the figure to your liking.

File 'figure-template.tex' contains most of the user-provided preamble
Latex code. The latex file created by gnuplot with the 'epslatex'
terminal gets combined with the template in file
'gnuplot-figure.tex'. The gnuplot run also creates an EPS file with
the plot (sans labels), which gets converted to PDF (files
'embedded-figure.[eps|pdf]') when running the shell script. File
'gnuplot-figure.tex' then gets compiled with xelatex. If you are
missing fonts or prefer to use pdflatex or plain latex, modify
'figure-template.tex' and the 'make-gnuplot-figure.sh' script
accordingly.

The example provided here creates a plot of a calculated electronic
spectrum of a molecule in the form of a 'stick spectrum' and a
broadened curve shown together. The data files are
'mmm_spectrum_sticks.txt' and 'abs_mmm_450xs.txt', respectively. You
will find these file names in 'gnuplot-script.plt' and of course they
can be changed as needed. The figure created by gnuplot in the example
has a figure canvas of 8cm width and 5 cm height (close to the Golden
ratio) with 10pt base font, which is suitable for a figure intended to
fit in a single column in a journal publication.

The resulting file gnuplot-figure.pdf was converted to PNG with the
command

f="gnuplot-figure"; pdftoppm -r 300 -png ${f}.pdf > ${f}.png

The image shown at https://ja01.chem.buffalo.edu/etcetera/latex-gnuplot.html
and included in this collection is the resulting PNG file after scaling 
by 50%. This was done with GraphicsMagick, using

mogrify -scale 50% gnuplot-figure.png

(c) 2025  Jochen Autschbach
