# Gnuplot to SVG to LaTeX with formulas

I create plots in gnuplot that I export as svg and include in a LaTeX document.

I would like to type simple LaTeX formula directly in gnuplot that appear properly in the LaTeX document. I noticed that I can do for instance:

set output "pic.svg"
set terminal svg
set label "$x$" at 1,1
plot 1/0


and the "x" is properly typeset in italics just like in LaTeX math mode. If I try the same with a more sophisticated formula like

set label "$\frac{x}{2}$ at 1,1
plot 1/0


I run into two problems:

1. The exported svg does not contain backslash nor curly braces. The label appears as "$fracx2". 2. Even if I edit the svg manually to add the braces and backslash back, the resulting pdf after running pdflatex --shell-escape document.tex does not contain the fraction. How can this be fixed? Ideally I'd stick with the svg-route if possible. I use \usepackage{svg} , \includesvg and pdflatex to include the svg file. • Why are you exporting as SVG? Why don't you just use the epslatex, cairolatex, or tikz terminal? Nov 10, 2019 at 9:33 • @HenriMenke Because that's what I've always been doing. Sometimes I would like to add additional elements to the plot in inkscape which I believe would be difficult to do with the other methods. Nov 10, 2019 at 9:50 ## 1 Answer By default, Gnuplot is in enhanced mode, which means that strings are checked for formatting characters. You can for example use set label "x^{2+3}" at 1,3" resulting in a superscript (dy="-6.00px"): <tspan font-family="Arial" >x</tspan> <tspan font-family="Arial" font-size="9.6" dy="-6.00px">2+3</tspan>  However, if you want to use the SVG in LaTeX this does not work as intended, because the {} characters are removed and the text ends up in different <tspan> tags. The option can be switched off by using set terminal svg noenhanced. The second problem is the backslash \, which must be escaped (by preceding it with another backslash) because it is used as a control character (for example the tab character \t). MWE: set terminal svg noenhanced set label "$\\frac{x}{3}\$" at 1,3
set output "pic.svg"
plot x
unset output

\documentclass{article}
\usepackage{svg}
\begin{document}
\includesvg{pic}
\end{document}


Result: