2

I am preparing a document, which uses pgfplots, for submission. I externalized figures etc. successfully. Though, now I'm facing a serious problem: On the target system the tikzexternal.sty file may not be used (not even if I supply it). So, I tried to inline it in my .tex file. This results in the following error:

) (./tikzexternal.sty
! Missing number, treated as zero.
<to be read again> 
               @
l.24 \toksdef\t@
            tikzexternal@tmpa=0
A number should have been here; I inserted `0'.

However, in tikzexternal.sty there is a comment, that inlining the code is in principle possible. I'd like to know what I'm doing wrong or how to modify the tikzexternal code to make it work.

Here is an MWE, assuming that external figures have been generated:

\documentclass[]{article}


\usepackage{graphicx}

%\usepackage{pgfplots}
%\usepgfplotslibrary{external}
%\tikzexternalize[mode=list and make]



%\usepackage{tikzexternal}  % <--- WORKS!!
\input{tikzexternal.sty}    % <--- FAILS!!

\tikzexternalize



\begin{document}

\begin{figure}[h]
\begin{tikzpicture} 
    \begin{axis}[width=\columnwidth]
        \addplot[dashed,very thick,color=gray]{sin(x)}; \label{tikz:test_1};
    \end{axis}
\end{tikzpicture}
\caption[labelInTOC]{ \ref{tikz:test_1}}
\label{fig:test}
\end{figure}

\end{document}
Werner
  • 603,163
irotas
  • 21
  • 3
    I think you need to surround the \input line with \makeatletter ... \makeatother. See http://tex.stackexchange.com/q/8351/86 for more details. – Andrew Stacey Nov 06 '12 at 16:21
  • 1
    If you are submitting to a journal, I have to disappoint you that they would still require the external figures in pdf format with \includegraphics in place. They would even convert your pdf files to eps. Hard to accept it but it's the way it goes with them. I would really recommend you to keep the modern way to yourself and comply with their standards. – percusse Nov 06 '12 at 16:47
  • @AndrewStacey Please make that a (slightly extended) answer. – Joseph Wright Nov 20 '12 at 08:08

1 Answers1

3

Digging deep into the LaTeX code, one can trace what happens when you do \usepackage{tikzexternal}. A lot of it is about checking that the package hasn't already been loaded and handling options and similar things that aren't relevant. What is relevant is that before the file is actually loaded, the command \makeatletter is invoked. This is explained in full in What do \makeatletter and \makeatother do? but in brief it means that command names can include the @ symbol (which they can't usually). Looking in tikzexternal.sty we see lots of commands with @s in them.

So when inlining tikzexternal.sty (by which I presume you mean cutting-and-pasting it into your preamble) you need to invoke \makeatletter yourself since you are bypassing all the junk that sits between \usepackage{tikzexternal} and when the file is actually read. (Then afterwards you put \makeatother to put things back as they were.)

Your test document should thus read:

\documentclass[]{article}


\usepackage{graphicx}

%\usepackage{pgfplots}
%\usepgfplotslibrary{external}
%\tikzexternalize[mode=list and make]



%\usepackage{tikzexternal}  % <--- WORKS!!
\makeatletter
\input{tikzexternal.sty}    % <--- ALSO WORKS!!
\makeatother
\tikzexternalize



\begin{document}

\begin{figure}[h]
\begin{tikzpicture} 
    \begin{axis}[width=\columnwidth]
        \addplot[dashed,very thick,color=gray]{sin(x)}; \label{tikz:test_1};
    \end{axis}
\end{tikzpicture}
\caption[labelInTOC]{ \ref{tikz:test_1}}
\label{fig:test}
\end{figure}

\end{document}
Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751