# Remove dependency on Tikz package by compiling figures

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{jakub@example.com}

\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{jakub@example.com}

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

• @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. 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/… Mar 18, 2021 at 13:13
• @JohnKormylo That's interesting, but I am afraid not so useful for me. Changing the source code (or producing a new source code) is literally what I would like to do. The tikz/standalone package produces as a byproduct the pdfs of the figures, so in the worst case, I can use those. Mar 18, 2021 at 13:27
• 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. Mar 18, 2021 at 14:14
• @DavidCarlisle Well, I would prefer to automate that. I am sure I will do the same thing next time, I get a paper published. It's surprising that nobody has done that before. We have scripts for simplifying many source files into one (latexpand) but not for this? Mar 18, 2021 at 14:20

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.

• 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. Mar 19, 2021 at 13:06
• In that case, you should play with an external tool like Python for example such as to produce automatically a new source from yours. Apr 18, 2021 at 7:56