推测 pgfplots-TikZ 和 pdflscape 之间不兼容:所有图像的外部化都失败

推测 pgfplots-TikZ 和 pdflscape 之间不兼容:所有图像的外部化都失败

我试图弄清楚为什么 tikzpictures 的外部化不再起作用(以前)。

我在序言中有以下内容:

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

如果我取消注释第二行(将所有图表和数字外部化)全部数字未能外化。

如果该行被注释掉(没有外部化),则最终生成的 pdf 不会出现错误。

不幸的是,我无法识别外部日志文件中的有用元素。

解决此问题的最佳方法是什么?我怀疑是软件包不兼容。

无法立即发布 MWE(我会尽快写一个),

这是一个不那么简单的我们重现上面描述的行为:

\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}

似乎没有创建外部化图形。我怀疑是软件包不兼容,并将尝试逐个注释掉软件包。

答案1

这不是 pgfplots 的问题,也不是直接由 pdflscape 引起的。在我看来,这是 的问题tikzscale

tikzexternalshared.code.tex如果它检测到 pdflscape,则在最后调用\AtBeginDocument(在 tikzscale 添加其所有代码之后):

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

问题是,此代码不仅将新命令添加到内部代码中,optimize command away而且还重新应用旧代码,并且由于 \includegraphics 在列表中,因此它会中断。

本文档重现了该问题(\jobname-figure0.pdf 不应该存在):

\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}

解决方法是禁用优化或至少将其\includegraphics从列表中删除。

答案2

注释掉\usepackage{pdflscape}。抱歉,我没有解释。

相关内容