2

I am using tikz to prepare diagrams for a project. Later I have to include these diagrams in the project files, and that's why I want to save each diagram with a given name. Let's say the following is my MWE

\documentclass[border=1mm,tikz]{standalone}
\begin{document}

%========================== \label{my-first-figure} \begin{tikzpicture} \draw[thick,rounded corners=8pt] (0,0) -- (0,2) -- (1,3.25) -- (2,2) -- (2,0) -- (0,2) -- (2,2) -- (0,0) -- (2,0); \end{tikzpicture}

%========================== \label{my-second-figure} \begin{tikzpicture} \filldraw [gray] (0,0) circle [radius=2pt] (1,1) circle [radius=2pt] (2,1) circle [radius=2pt] (2,0) circle [radius=2pt]; \draw (0,0) .. controls (1,1) and (2,1) .. (2,0); \end{tikzpicture}

\end{document}

I would like to save each tikzpicture, i.e., each page of the standalone pdf as separate pdf files. For example, after compiling the MWE, I would like to have the first tikzpicture as my-first-figure.pdf and the second tikzpicture as my-second-figure.pdf.

I am seeking a solution to reduce inconveniences if, at a later stage, I need to modify a particular diagram. I am not sure if this is possible or not. Any advice would be very helpful.

ddas
  • 1,205

1 Answers1

1

I found the process description at this question.

In the link the author suggests that you can automate the process by modifying the externalization command as in 2 or 3.

It features a code, which allows you to convert only the figures you want to convert.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[mode=list and make]

\tikzset{ png export/.style={ % First we call ImageMagick; change settings to requirements external/system call/.add={}{; convert -density 300 -transparent white "\image.pdf" "\image.png"}, % Now we force the PNG figure to be used instead of the PDF /pgf/images/external info, /pgf/images/include external/.code={ \includegraphics[width=\pgfexternalwidth,height=\pgfexternalheight]{##1.png} }, } }

\begin{document}

{ % Here we specify the figure will be converted and inserted as PNG \tikzset{png export} \begin{tikzpicture} \draw (0,0) circle (1) ; \end{tikzpicture} }

% This figure will be inserted as PDF
\begin{tikzpicture}
    \draw (0,0) circle (1) ;
\end{tikzpicture}

\end{document}

  • 4
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – José Carlos Santos Jan 10 '23 at 02:40
  • @JoséCarlosSantos given that the link is to another answer on this site then I think the dangers of link rot are not relevant. – Andrew Stacey Jan 10 '23 at 06:47
  • @AndrewStacey indeed the link will be ok but it seems that the question to which the current answer is posted is a duplicate of the linked question (or at least a very near duplicate) and should be closed as such, or maybe as a duplicate of a different externalization question that is a bit more tailored towards pdf output. – Marijn Jan 10 '23 at 09:45
  • Thanks for all the comments, I've edited the answer and hope to collaborate in a better way. – Emílio Kavamura Jan 12 '23 at 02:37