1

I have a tikz file that contains a matlab scatter plot. It is created by matlab2tikz. The tikz file (sample.tikz) looks as follows and compiles fine in the document without the externalization.

\begin{tikzpicture}

\begin{axis}[%
width=\figurewidth,
height=\figureheight,
scale only axis,
xmin=1, xmax=8,
xtick={1,2,3,4,5,6,7,8},
legend style={at={(1.03,1)},anchor=north west,draw=black,fill=white,legend cell align=left}
]
\addplot [
color=blue,
solid,
line width=1.5pt
]
table{
0 1.15086549555392
8 1.15086549555392
};
\addlegendentry{baseline};

\addplot[only marks,mark=o,color=green!50!black] plot coordinates{
(1,1.14776993023436)
(2,1.14877635969775)
(3,1.15086549555392)
(4,1.15104679449109)
(5,1.13229950771559)
(6,1.14459533891626)
(7,1.13874295199852)
(8,1.14110592572754)
};
\addlegendentry{$\text{C}_\text{D}$};

\end{axis}
\end{tikzpicture}%

My tex files looks like this:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}               % needed to import .tikz graphics
\usetikzlibrary{plotmarks}          % needed for tikz scatter plot
\usetikzlibrary{external}
\tikzexternalize[prefix=tikz/]
\newlength\figureheight                 %Tikz plot setup 
\newlength\figurewidth                  %Tikz plot setup

\begin{document}
\begin{figure}[htpb]
    \centering
    \setlength\figureheight{0.45\linewidth} 
    \setlength\figurewidth{0.6\linewidth}
    \input{./images/sample.tikz}
    \caption{Caption}
    \label{fig:}
\end{figure}
\end{document}

Compiling it and checking the ./tikz directory I find an empty .dpth file and a .log file with the following error:

Missing character: There is no ; in font nullfont!
Missing character: There is no ; in font nullfont!
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <7> on input line 34.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <5> on input line 34.
! Undefined control sequence.
<recently read> \text 

l.34 \end{axis}

If I comment out the second \addlegendentry in my tikz file it compiles fine and externalizes to the tikz directory. But naturally without the second legend entry.

Why can't I externalize a tikz file with two legend entries?

1
  • 2
    Try adding \usepackage{amsmath} to the preamble. \text is a macro defined by that package. Jan 16, 2014 at 15:00

1 Answer 1

2

The error has nothing to do with the externalization.

! Undefined control sequence.
<recently read> \text 

means that the command \text, that is used in the second legend, is undefined. \text is defined in the amsmath (well, actually amstext) package, so adding

\usepackage{amsmath}

to the preamble will fix the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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