5

When using the TikZ externalization library within a \ffigbox from the floatrow package, the external image is created two times. The reason is, that the argument of \ffigbox gets parsed two times. Obviously the result is as expected, but I would nevertheless like to prevent the generation of those unnecessary duplicates. How can one achieve that?

Here's a MWE to start with:

\documentclass{article}

\usepackage{floatrow}

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

\begin{document}
  \ffigbox{\tikz{\node{a};}}{}
\end{document}
  • 1
    Welcome to TeX.SX! You may have a look on our starter guide. – texenthusiast May 19 '13 at 22:19
  • Please note that using \tikzsetnextfilename does avoid the duplicate files. However the external image will contain two pages with the same content. So, strictly speaking, this does not prevent the redundancy. – michel May 19 '13 at 23:35
  • I guess you need to dig in the bowels of the package and add \tikzexternaldisable and \tikzexternalenable around the 2nd parsing of the file argument. Maybe possible with the \patchcmd command from etoolbox? – Martin H May 20 '13 at 1:41
  • @MartinH Thanks for suggesting \patchcmd – I wasn't aware of it. But I was already fearing I would need to dive in the code of floatrow.sty and had a quick look. I am not sure if I can read that (it looks a lot like Fortran to me...) – michel May 20 '13 at 8:49
1

As a preliminary solution I propose a dirty hack:

\documentclass{article}

\usepackage{floatrow}

\makeatletter
\newif\ifFBgettingBox
\let\OldFBget@box\FBget@box
\renewcommand\FBget@box[3]{%
  \FBgettingBoxtrue%
  \OldFBget@box{#1}{#2}{#3}%
  \FBgettingBoxfalse}
\makeatother

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

\usepackage{calc} % needed just for demonstration

\begin{document}
  \ffigbox{
    \ifFBgettingBox
      \rule{\widthof{a}}{\heightof{a}}
    \else
      \tikz{\node{a};}
    \fi
  }{}
\end{document}

Obviously a real use case would look more complicated, but often one is in the lucky position of knowing width and height of one's graphics. (In the example I worked around it with the help of \widthof{a} from the calc package.)

Of course it is annoying to type the if clause every time one uses a \ffigbox. This may be circumvented by defining a macro.

I would have preferred a solution using \tikzifexternalizing or similar. The problem with this approach is, that when disabling externalization of a usually externalized image only during externalization itself, makes the externalization dizzy...

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.