C6. Labels set by LaTeX
Goal: a figure whose texts LaTeX sets, in the paper's own fonts and with its math.
gp
# the drawing as a PDF, the texts in a LaTeX picture that LaTeX sets: \input{pc06.tex} in a paper
set terminal cairolatex pdf size single
set output 'pc06.tex'
set xlabel '$t/\tau$'
set ylabel '$x/x_0$'
set key top right
plot [0:4] exp(-x)*cos(2*pi*x) title '$e^{-t/\tau}\cos\omega t$', exp(-x) title '$e^{-t/\tau}$' dt 2console
$ foresight pc06_latex_labels.gp && ls pc06* && grep -F '\put' pc06.tex
foresight: pc06_standalone.tex
pc06.pdf
pc06.tex
pc06_latex_labels.gp
pc06_standalone-inc.pdf
pc06_standalone.tex
\put(853,566){\makebox(0,0){\strut{}$0$}}%
\put(1330,566){\makebox(0,0){\strut{}$0.5$}}%
\put(1807,566){\makebox(0,0){\strut{}$1$}}%
\put(2284,566){\makebox(0,0){\strut{}$1.5$}}%
\put(2761,566){\makebox(0,0){\strut{}$2$}}%
\put(3238,566){\makebox(0,0){\strut{}$2.5$}}%
\put(3715,566){\makebox(0,0){\strut{}$3$}}%
\put(4192,566){\makebox(0,0){\strut{}$3.5$}}%
\put(4669,566){\makebox(0,0){\strut{}$4$}}%
\put(763,770){\makebox(0,0)[r]{\strut{}$-0.8$}}%
\put(763,1036){\makebox(0,0)[r]{\strut{}$-0.6$}}%
\put(763,1302){\makebox(0,0)[r]{\strut{}$-0.4$}}%
\put(763,1568){\makebox(0,0)[r]{\strut{}$-0.2$}}%
\put(763,1834){\makebox(0,0)[r]{\strut{}$0$}}%
\put(763,2100){\makebox(0,0)[r]{\strut{}$0.2$}}%
\put(763,2366){\makebox(0,0)[r]{\strut{}$0.4$}}%
\put(763,2632){\makebox(0,0)[r]{\strut{}$0.6$}}%
\put(763,2898){\makebox(0,0)[r]{\strut{}$0.8$}}%
\put(763,3164){\makebox(0,0)[r]{\strut{}$1$}}%
\put(2761,256){\makebox(0,0){\strut{}$t/\tau$}}%
\put(264,1967){\rotatebox{90.00}{\makebox(0,0){\strut{}$x/x_0$}}}%
\put(3901,2964){\makebox(0,0)[r]{\strut{}$e^{-t/\tau}\cos\omega t$}}%
\put(3901,2744){\makebox(0,0)[r]{\strut{}$e^{-t/\tau}$}}%
\put(0,0){\includegraphics[width={240.94bp},height={170.08bp}]{pc06}}%pc06.tex is a LaTeX picture: its drawing, pc06.pdf, has no text, and each label is a \put that LaTeX sets where foresight would have drawn it. A paper includes it with \input:
latex
\usepackage{graphicx,color} % in the preamble: gnuplot's picture defines a color, \definecolor
...
\begin{figure}
\centering
\input{pc06.tex}
\caption{The response and its envelope.}
\end{figure}paper.pdf does, in its Figures 5 and 6 (this figure and the cookbook's gain): the axis labels and the keys are the paper's Latin Modern, its math italic and Greek.
A standalone document
gp
# a whole document, its graphics pc06_standalone-inc.pdf: lualatex pc06_standalone.tex
set terminal cairolatex pdf standalone size single font ',10' header '\usepackage{lmodern}'
set output 'pc06_standalone.tex'
replotstandalone writes a whole document, the figure alone on a page of its size (lualatex pc06_standalone.tex gives pc06_standalone.pdf), its graphics pc06_standalone-inc.pdf; header adds LaTeX code to its preamble, the font size (,10) chooses its size10.clo.
Why it works
- The file is gnuplot's cairolatex file: the same macros, the same
\put(x,y){\makebox(0,0)[r]{\strut{}...}}, so a document set up for gnuplot's figures (agnuplot.cfg,\GPblacktextfalse) takes foresight's unchanged. - The figure is laid out before LaTeX sets the texts: foresight counts a label's characters as gnuplot does (
$, braces,_and^none,\alphaone) in an 8.8 pt font (font ",11"atfontscale 0.6, gnuplot's defaults), which leaves room for LaTeX's 10 or 11 pt. - The tick numbers are math (
$-0.5$): the same digits and minus as the paper's equations.
Try this
colortext: the texts in their colors (set label ... textcolor), when the paper loadscolor.set ylabel '[r]{\shortstack{first \\ second}}': a text opening with[or{is its own box, two lines here.header '\bfseries'withoutstandalone: the figure's texts bold, the paper's untouched.
Pitfalls
- Texts are LaTeX:
_,^,%,&,#outside math stop LaTeX ('run_1'must be'run\_1'). Automatic titles are escaped for you, as gnuplot does. - Enhanced text (
{/Symbol a},x^2outside$) is not read: the terminal refusesenhanced. \inputreadspc06.pdfby the name written in the file, relative to the document: keep the two files together, or set\graphicspath.- The picture needs
coloras well asgraphicx, whateverblacktext: gnuplot's macros define a color (\definecolor{tbcol}), foresight's are gnuplot's.