# rendering of tikzcd code to get an image file

I have Kile and Texstudio in my computer.

For some reason, I want to save commutative diagrams as image files.

There is http://presheaf.com/ that compiles xymatrix codes and gives an image file.

I am not aware of anything that runs tikzcd code and gives an image file.

There is https://tikzcd.yichuanshen.de/ that gives tikzcd code but do not give image.

Is there any way to run tikzcd code in kile/Texstudio and get an image file? Not the full file as image file but can I be able to save diagram in pdf output as an image?

Taking a screen shot in pdf output and cropping is not an option for me.

EDIT : It seems it was not clear what I was asking. I just want to get an image file from my tikzcd code. Even if it is a website just like presheaf.com you write a xypic code, you get an image file I am ok with it if it takes tikzcd code to give an image. I have no preference for format of image file svg png anything is ok.

• I am ok with any pages online also that renders tikz code and give me an image file.. But asking that may be off topic here.. Jul 10 '18 at 13:22
• I'd just make a standalone doc for each, using the standalone class, then each generated PDF is a cropped stand alone image Jul 10 '18 at 13:38
• @daleif I am not aware of what standalone doc is... and i dont understand what is "then each generated PDF is a cropped stand alone image" Jul 10 '18 at 13:41
• It is a documentclass just like article, just very good for compiling images to just the images. Jul 10 '18 at 14:40
• @daleif can you please make it as an answer adding some more details.. Jul 10 '18 at 15:31

You can make your commutative diagrams with the standalone class and include the resulting .pdf in another file with \includegraphicx{mycd}:

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}
A \arrow{r}{φ} \arrow[swap]{d}{\varrho_f} & B \arrow{d}{\varrho_g} \\%
A_f \arrow{r}{\varphi_f}& B_g
\end{tikzcd}

\end{document}


Resulting in (slightly zoomed)– note how the .pdf is cropped :

Demo on how to use it: the previous.pdf being saved as cdaspdf.pdf and being automatically cropped by the standalone class, the following code incorporates the diagram in another .pdf with this example-code:

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}

\begin{document}

\lipsum[10]
\begin{center}
\includegraphics{cdaspdf}
\end{center}
\lipsum[11]

\end{document}


Note that as the diagram is incorporated as a vector image, it can be zoomed without any problem.

• I do not understand what does it mean to say "include the resulting .pdf in another file with \includegraphicx{mycd}" Jul 10 '18 at 17:32
• I did not understand what you said but I converted pdf to image and then added in my question.. please let me know if this is not what you mean to say and if anything better can be done Jul 10 '18 at 17:37
• @PraphullaKoushik: I've added a demo using the resulting pdf directly in another file (not converted to .png or .jpeg), so that it can be zoomed ad libitum. Jul 10 '18 at 18:32
• Thanks for your answer.. it was not for adding in another file.. I can just add the code itself, why round I create another file and then add as include graphics? I wanted to get a image file to add in a website.. Jul 10 '18 at 18:59
• It seeems I misunderstood what you really wanted. There remains that you might want to convert the cropped diagram to svg to have it zoomable? Jul 10 '18 at 19:44

You can try externalizing the tikz graphics using this code in the preamble:

\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\tikzsetexternalprefix{ext-tikz/} % files will be stored as a pdf here


You can set a better filename by appending this:

\newcommand{\includetikz}[1]{%
\tikzsetnextfilename{#1}%
\input{#1.tex}%
}

• I do not understand (very new to these)... can you tell me step by step what to do.. apologies. Jul 10 '18 at 13:40

Here's an answer native to TeXstudio and making use of its inline preview functionality. No need for external documents, post-processing with scripts, nor modifying of your existing preamble.

Modifying @Bernard's example code to something you would typically have in a normal document:

\documentclass{article}
\usepackage{tikz-cd}

\begin{document}

% Some other stuff here in your document...

\begin{tikzcd}
A \arrow{r}{\phi} \arrow[swap]{d}{\varrho_f} & B \arrow{d}{\varrho_g} \\%
A_f \arrow{r}{\varphi_f}& B_g
\end{tikzcd}

% Some other stuff here in your document...

\end{document}


Highlight the tikzcd environment, right click and select Preview selection / Parenthesis in the dropdown menu. A resulting preview image will be generated, which you can then right-click on to save as a .jpg/.png file.