2

I'm trying to figure out why the externalization of tikzpictures does not work any more (used to).

I have the following in the preamble:

\usepgfplotslibrary{external}
% \tikzexternalize[prefix=fig/ext/]

If I uncomment the second (to externalize all the plots and figures) line all the figures fail the externalization.

If the line is commented out (no externalization), the final pdf is generated without errors.

Unfortunately, I cannot recognize useful elements in the externalized log files.

Which is the best way to troubleshoot this? I suspect packages incompatibilities.

Can't post a MWE right away (will write one as soon as I am able to),

Here's a not-so-minimal non WE, reproducing the behavior described above:

\RequirePackage[hyphens]{url}
\RequirePackage[final]{graphicx}
\documentclass[a4paper,twoside,openright,final]{memoir}
\usepackage{filecontents,lipsum}

\begin{filecontents*}{packages.tex}
    \usepackage{calc}
    \usepackage{ifoddpage}
    \usepackage[osf]{mathpazo}
    \linespread{1.1}
    \usepackage[scaled]{helvet}
    \usepackage{courier}
    \normalfont

    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage[italian,english]{babel}
    \usepackage[obeyFinal]{todonotes}

    \usepackage{pgfplots,tikzscale}
    \pgfplotsset{compat=newest}
    \usepgfplotslibrary{units}
    \usetikzlibrary{plotmarks,positioning,chains,fit,shapes,calc}

    \usepackage{array,booktabs,tabularx}
    \usepackage{mdframed,colortbl}
    \usepackage{multirow}
    \usepackage{pdflscape,rotating}

    \usepackage[shortcuts,noredefwarn,toc,symbols,acronym,nonumberlist]{glossaries}

    \usepackage{amsfonts,amsmath,amssymb,amsthm,bm,bigints}
    \usepackage{dsfont}
    \usepackage{siunitx}
    \usepackage{xspace}
    \usepackage{csquotes}
    \usepackage{soul}

    \usepackage[vlined,ruled,commentsnumbered,linesnumbered]{algorithm2e}
    \usepackage[%
        bibstyle     = ieee,
        citestyle    = numeric,
        isbn         = true,
        doi          = false,
        sorting      = nty,
        % sorting     = none,
        % sorting     = debug,
        url          = false,
        defernumbers = true,
        bibencoding  = utf8,
        backend      = biber
    ]{biblatex}

    % % do not externalize todonotes' graphics
    \usepackage{letltxmacro} % https://tex.stackexchange.com/a/115095/177

    \LetLtxMacro{\oldmissingfigure}{\missingfigure}
    \renewcommand{\missingfigure}[2][]{\tikzexternaldisable\oldmissingfigure[{#1}]{#2}\tikzexternalenable}
    \LetLtxMacro{\oldtodo}{\todo}
    \renewcommand{\todo}[2][]{\tikzexternaldisable\oldtodo[#1]{#2}\tikzexternalenable}

    \usepackage[pdfusetitle,final]{hyperref}
    \hypersetup{
        % bookmarksopen=true
        hidelinks,
        % colorlinks,
        pdfinfo={
            % Author={Alessandro Cuttin},
            Subject={PhD Thesis},
            % Title={Title to be defined},
       }
    }

    \usepackage[open,openlevel=1]{bookmark}
    \usepackage[noabbrev,capitalise]{cleveref}
\end{filecontents*}

\begin{filecontents*}{other-commands.tex}
    \hyphenation{a-chieved mil-li-me-ter-wave na-no-sat-el-lite}
    \newcommand{\Rho}{\textrm{P}}
    \newcommand{\matlab}{Matlab\textsuperscript\textregistered\xspace}
    \newcommand{\logand}{$\wedge$\xspace}
    \newcommand{\logor}{$\vee$\xspace}
    \newcolumntype{m}{>{$}c <{$}}
    % adapted from https://tex.stackexchange.com/a/36003/177
    \usepackage{ifmtarg}% http://ctan.org/pkg/ifmtarg
    \makeatletter
    \newcommand{\algtoprule}{\hrule height.8pt depth0pt \kern2pt} % Caption top horizontal rule+skip
    \newcommand{\algmidrule}{\kern2pt\hrule\kern2pt} % Caption bottom (or mid) horizontal rule+skip
    \newcommand{\algbottomrule}{\kern2pt\hrule\relax}% Algorithm bottom rule
    \newcommand{\algcaption}[2][]{%
      \refstepcounter{algorithm}%
      \@ifmtarg{#1}
        {\addcontentsline{loa}{figure}{\protect\numberline{\thealgorithm}{\ignorespaces #2}}}
        {\addcontentsline{loa}{figure}{\protect\numberline{\thealgorithm}{\ignorespaces #1}}}%
      \algtoprule
      \textbf{\fname@algorithm~\thealgorithm}\ #2\par % Caption
      \algmidrule
    }
    \makeatother
    % https://tex.stackexchange.com/a/68310/177 and https://tex.stackexchange.com/a/10131/177
    \makeatletter
    % \let\runauthor\@author
    \let\runtitle\@title
    \makeatother
    \DeclareMathOperator\erf{erf}
    \DeclareMathOperator\erfc{erfc}
    \newtheorem{theorem}{Proposition}
    \newtheorem{corollary}{Corollary}[theorem]
\end{filecontents*}

\begin{filecontents*}{lit-rev.tex}
    \chapter{Modern random access methods}
    \label{sec:mod-ran-acc-met}
    \lipsum
    \begin{figure}[tb]
        \centering
        \subbottom[ \label{fig:aloha-max-thr}]{%
            \includegraphics[width=0.475\textwidth]{aloha-throughput.tikz}
        }
        \caption{The Aloha System: \subcaptionref{fig:aloha-pac-sch} schematic of the Aloha communication multiplexing \cite{Abramson1970}, and \subcaptionref{fig:aloha-max-thr} network throughput.}
        \label{fig:lit-rev-alo}
    \end{figure}
\end{filecontents*}

\begin{filecontents*}{aloha-throughput.tikz}
    \begin{tikzpicture}
        \begin{axis}[
                ymax = 0.2,
                ymin = 0,
                xmin = 0,
                xmax = 2,
                xlabel={$G$},
                ylabel={$S$},
                ytick distance = 0.1,
                grid                            = major
            ]
            % throughput upper bound of Aloha
            \addplot [
                domain=0:2,
                samples=40,
            ]
            {x * exp(-2*x};
        \end{axis}
    \end{tikzpicture}
\end{filecontents*}
\input{packages}
\input{other-commands}
% \input{set/tufte-like-plots}

% toggle the following lines to prevent tikz plots compilation every time - always use after loading pgfplots package
\usepgfplotslibrary{external}
\tikzexternalize

% memoir settings
\setsecnumdepth{subsection}
\settocdepth{subsection}
\newsubfloat{figure}% Create subfloat in figure environment

\author{myname}
\title{mytitle}

\loadglsentries{example-glossaries-brief.tex}
\makeglossaries
\glstoctrue

\ifdraftdoc
% special things for a draft document
    \usepackage{showkeys}
    \linespread{1.3}        % more linespread for showkeys
    \makeevenfoot{simple}{}{\texttt{Draft: \today}}{ }
    \makeoddfoot{simple}{}{\texttt{Draft: \today}}{}
    % \usepackage{showframe}
\else
% perhaps special things for a non-draft document
\fi

% \includeonly{con/annotations,con/lit-rev,con/introduction,con/jsac}
\begin{document}
\pagestyle{simple}
\frontmatter
\cleardoublepage
\tableofcontents
\glsunsetall
\cleardoublepage
\listoffigures
\cleardoublepage
\listoftables
\printglossaries
\glsresetall
\mainmatter
\part{Background}
\include{lit-rev}
\end{document}

It seems that externalized figures are not created. I suspect a package incompatibility, and will try to comment out the packages one by one.

18
  • 5
    It shouldn't be hard to make an MNWE if any figure at all causes the failure. What error do you get? I.e. exact message? This will direct you to a per-figure log file. What does that log say? Did you remember shell-escape? Does the appropriate directory hierarchy exist?
    – cfr
    Commented Dec 27, 2017 at 1:28
  • 4
    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See minimal working example (MWE). Commented Dec 27, 2017 at 2:07
  • 1
    @HenriMenke Are you going to answer the question ?
    – percusse
    Commented Dec 27, 2017 at 9:06
  • 1
    @HenriMenke You are not the judge of that. If you are not going to answer the question don't engage and possibly annoy people with unnecessary policing.
    – percusse
    Commented Dec 27, 2017 at 9:11
  • 2
    You asked what is the best way to troubleshoot. Well in my opinion the most important this is no to waste too much time with random searches and speculation. You can google for 30 minutes hoping to find the red button but then you should stop and switch to a systematic debugging. And the first step of systematic debugging in tex is creating an mwe. Beside this I agree with Henri that your question as it is can't be answered, the Runaway argument? is certainly a problem and should be corrected but it is unclear if is also the source of your other problem. Commented Dec 27, 2017 at 15:59

2 Answers 2

5

It is not a pgfplots problem and also not directly cause by pdflscape. Imho it is a problem of tikzscale.

tikzexternalshared.code.tex calls at the end in \AtBeginDocument (after tikzscale has added all its code) if it detects pdflscape this here:

\tikzset{
            external/.cd,
            optimize command away=\landscape,
            optimize command away=\endlandscape
        }%

The problem is that this code not only adds the new commands to the internal code of optimize command away but also reapplies older code and as \includegraphics is in the list it breaks.

This document reproduce the problem (\jobname-figure0.pdf shouldn't exist):

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{testinput.tikz}
 \begin{tikzpicture}
  \draw (0,0) rectangle (1,1);
 \end{tikzpicture}
\end{filecontents*}


\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize

\usepackage{tikzscale}


%breaks:
\AtBeginDocument{
        \tikzset{%           
           external/optimize command away=\blub,
        }%
        }%      

%  work around, uncomment to avoid the error:
% \tikzset{%
%         external/optimize/install/.code={},
%         }

\begin{document}

\includegraphics[width=0.475\textwidth]{testinput.tikz}

\end{document}

A work around is to disable the optimization or at least to remove \includegraphics from the list.

3
  • it is probably like you say, because I'm again at the starting point, even if removing pdflanscape seemed to work at first. How do I disable the optimization? Commented Dec 29, 2017 at 21:40
  • My example shows a work-around. Commented Dec 29, 2017 at 21:43
  • I tried it, but didn't work :( Commented Dec 29, 2017 at 21:52
2

Comment out \usepackage{pdflscape}. Sorry, I don't have an explanation.

2

Not the answer you're looking for? Browse other questions tagged .