2

I am preparing the final version of a paper to be processed (and edited) by a publisher. This means converting the source to the publisher style, and removing dependency on certain packages.

One of those packages is tikz, and the source contains quite a few tikz figures. It's not so hard to compile all the figures into pdfs using the tikz/externalize library, but this does not remove the dependency on the package since tikz takes care of the inclusion.

Basically, I would like to convert a document:

\documentclass{acmart}

\usepackage{tikz}
  %\usetikzlibrary{external}
  %\tikzexternalize[prefix=figures/]

\begin{document}

\title{A paper with tikz figures}
\author{Jakub Opršal}
\email{[email protected]}

\maketitle

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

\begin{figure}
  \begin{tikzpicture}
    \draw (0,0) circle (1);
  \end{tikzpicture}

  \caption{A circle}
\end{figure}

\end{document}

Into:

\documentclass{acmart}

\begin{document}

\title{A paper with tikz figures}
\author{Jakub Opršal}
\email{[email protected]}

\maketitle

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

\begin{figure}
  \includegraphics{figures/stack-exchange-figure0.pdf}

  \caption{A circle}
\end{figure}

\end{document}

While compiling all tikz figures in the process (which not such a big issue, since it is enough to compile the original document once).

Do you know of some efficient way to replace the tikz figures in the code by the corresponding graphics include?

16
  • @JohnKormylo Naturally. But that is not a problem for me, since the files that I will submit are just the resulting pdf figures and the main source file. Commented Mar 18, 2021 at 13:04
  • The endfloat package can copy/move any environment (such as tikzpicture) to a separate file. However it will not change the source code. See tex.stackexchange.com/questions/412829/longtable-with-endfloat/… and tex.stackexchange.com/questions/423109/… Commented Mar 18, 2021 at 13:13
  • 2
    Just run the tikz in their own document (or use externalize) and then edit the source file to use \includegraphics as you suggest. That is just an editing question, so depends on your editor how easy that is, but I assume in a journal submission you don't have thousands of these to edit. Commented Mar 18, 2021 at 14:14
  • 1
    TikZ and the external library can be switched out for the tikzexternal package that only imports the pdfs where \tikz and tikzpictures are (without having to change the actual document (just the preamble). Is this what you're after? The tikzexternal.sty can be simply placed besides the main tex file. Commented Oct 18, 2022 at 13:24
  • 1
    Copy tikzexternal.sty into your preamble? Presumably a dependency on graphicx.sty is permissible. But I expect you've either written the script by now or discovered the virtues of organising your projects differently ;).
    – cfr
    Commented Jun 10 at 6:10

2 Answers 2

2

I think the best solution is to organise the document with this usage in mind. However, defining tikzpicture to include the generated images yourself may provide a quick fix in simple cases. Note that there are complexities here which such a definition doesn't capture. Most straightforwardly, if you've used \tikz, you'd need to handle that case as well.

But cases where a picture is invoked by another environment or command are more complicated. If you use forest, for example, or tikzmark or if you use any of the many pgf/tikz facilities incompatible with externalisation, this will fail.

But if your document is entirely straightforward in its use of tikzpicture, you might try something like the following.

\documentclass{acmart}
% \usepackage{tikz}
% \usetikzlibrary{external}
% \tikzexternalize[prefix=ffigurau/]
\newcounter{tikzpiccount}
\usepackage{graphicx}
\NewDocumentEnvironment {tikzpicture} {+b}
{%
  \includegraphics{ffigurau/\jobname-figure\thetikzpiccount}%
  \stepcounter{tikzpiccount}%
}{}

\begin{document}
  
  \title{A paper with tikz figures}
  \author{Jakub Opršal}
  \email{[email protected]}
  
  \maketitle
  
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  
  \begin{figure}
    \begin{tikzpicture}
      \draw (0,0) circle (1);
    \end{tikzpicture}
    
    \caption{A circle}
  \end{figure}
  
\end{document}

[I used ffigurau because the directory already existed. Obviously you can customise the prefix to suit whatever you used when generating the images.]

1
  • This is perfect! Works like magic, thank you very much! Commented Jun 17 at 8:59
0

You could use the ifthen package.

Here is an example:

\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage{ifthen}
\newif\ifsubmit
%\submitfalse % work with this
\submittrue % submit this
\newcommand{\submissionfigure}[2]{\ifsubmit #1 \else #2 \fi}

\submissionfigure{}{
    \usepackage{tikz}
    \usetikzlibrary{external}
    \tikzexternalize[prefix=figures/]
}

\begin{document}
    \begin{figure}
        \submissionfigure{
            \includegraphics[scale=1]{figures/submission-figure-figure0.pdf}
        }{      
        \begin{tikzpicture}
            \draw (0,0) circle (1);
        \end{tikzpicture}
        }
        \caption{A circle}
    \end{figure}
\end{document}

In principle this should allow you to keep the tikz code in your document, but it should not be processed by the journals systems. Although whether this approach works or not will depend on the journal and how the files are processed, which to me appears a bit intransparent tbh.

2
  • Unfortunately, this does not solve my problem since it amounts to editing the source by hand. I could just replace each \begin{tikzpicture}...\end{tikzpicture} with \includegraphics{...} as @DavidCarlisle suggested. The point is that the paper is already written, I just need to produce an intermediate output which is a latex source (to be edited by the journal typesetters) as opposed to pdf or dvi. Commented Mar 19, 2021 at 13:06
  • 3
    In that case, you should play with an external tool like Python for example such as to produce automatically a new source from yours.
    – projetmbc
    Commented Apr 18, 2021 at 7:56

You must log in to answer this question.

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