Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This is a follow-up to Draft mode in Tikz externalize hides graphics, but not without externalize

I'm writing a long document and compilation takes time. Some plots are included as tikz (export from matlab2tikz) and other images are simply included with \includegraphics. I'm using the latex -> dvips -> ps2pdf workflow. For speedup, the document is in draft mode (most often, I'm not interested in seeing all images). For tikz speedup the externalization works fine.

However, as explained in Draft mode in Tikz externalize hides graphics, but not without externalize, the tikz-draft results in small boxes. The original figure size seems lost and the document starts to move around quite a bit.

I get the warnings:

Package pgf Warning: Missing width for image "pgflastimage" ("images/tikz/figure8") in draft mode.
(pgf)                Using 1cm instead on input line 980.

Package pgf Warning: Missing height for image "pgflastimage" ("images/tikz/figure8") in draft mode.
(pgf)                Using 1cm instead on input line 980.

and the result is just a small box. It looks like it is trying to find the correct box size and fails. Is there a workaound or fix for this bug?

My externalization is done by

\tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error 
-interaction=batchmode -jobname "\image" "\texsource" &&
dvips -o "\image".ps "\image".dvi && ps2eps "\image".ps;}}

which generates good .eps images. The generated images are fine and the box would be of the correct size, when included manually with \includegraphics{figure0.eps}.


Here is an approach for a possible hack. At first, I included my figures with \subimport{path}{filename.tikz} which helps with sub-directories, based on the package import.

Based on this idea I began to replace this import with \tikzimport{path}{filename.tikz} containing

\newcommand{\tikzimport}[2]{%
\ifdraft{%
  % create counter, increment
  \newstepcounter{\pgfkeysvalueof{/tikz/external/figure name}}%
  % define next filename of externalized tikz file
  \def\mynextfile{images/tikz/%
  \pgfkeysvalueof{/tikz/external/figure name}%
  \arabic{\pgfkeysvalueof{/tikz/external/figure name}}.eps}%
  % check is file is there, then includegraphics the file
  % as we are in draft, this gives a nice box
  \IfFileExists{\mynextfile}{% show tikz
  \includegraphics[scale=1]{\mynextfile}}{% fallback
  \mbox{\nolinkurl{\mynextfile}}
}
}{% nodraft
  \subimport{#1}{#2}%
}

This requires the ifdraft package and a counter for each figure name suffix. Creating a counter (if it does not exist) is achieved by

\makeatletter
\def\newstepcounter#1{%
\@ifundefined{c@#1}{%
\newcounter{#1}}{%
\stepcounter{#1}}%
}
\makeatother

Problems

  • This is not really nice ...

  • the tikz externalized prefix is hardcoded, I have no idea how to extract the prefix from the tikz internals. The prefix is set by \tikzexternalize[prefix=images/tikz/] but \pgfkeys{/tikz/external/prefix} comes back empty

  • I have a few graphics not being externalized, as they come back wrong if externalized. It would be good to test for each call, if externalization is enabled for each graph.

I tired

\newif\isexternal
\pgfkeys{/tikz/external/export/.is if=isexternal}
\isexternal
  external
\else
  not external
\fi

But this test comes back false all the time.

share|improve this question

closed as too localized by percusse, Qrrbrbirlbel, Alan Munn, Paul Gaborit, Tom Bombadil Oct 7 '12 at 13:17

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
TikZ uses \pgfimage{figure0.eps} to include the external graphics. And \pgfimage has some deficiancies... perhaps you can use \pgfkeys{/pgf/images/include external/.code=\includegraphics{#1}} to fix your issue... (untested at the time of this writing) –  Christian Feuersänger Jun 17 '12 at 16:08

Browse other questions tagged or ask your own question.