# Creating TiKz Libraries

How does one go about creating a TiKz library (is it even possible)? Is this a formidable task for a beginner? As a chemical engineer, I would very much like to have a library to create process flow diagram, like the one below, in which you place nodes with certain shapes and connect them based on specific ports.

• Well, the fact they exist stands testament to the possibility. Usually, the answer to 'is it possible' is yes, so it's best to get on to the real question :) – Sean Allred May 28 '15 at 3:46
• @SeanAllred I add the possible statement because I saw that circuitikz is provided as a package not library. So I thought maybe a package would be the correct choice. – jak123 May 28 '15 at 4:10
• Ah, I see :) A reasonable guess. If I recall correctly, the difference between LaTeX packages and TikZ libraries is nominal – literally. TikZ libraries follow a naming convention. – Sean Allred May 28 '15 at 4:36

I think the simplest answer is "it depends". The purpose of this answer is to show you how easy it is to set up a library.

Creating a library itself is not hard. It's just a naming convention.

tikzlibrary<library name>.code.tex


I don't know anything about chemical engineering or the symbols you wish to use. So the following is just a very simple presentation of how you might consider approaching this.

Here's a very simple and rather boring example of a library which I call unitcircle. Save this to a file called tikzlibraryunitcircle.code.tex and either place it in the current directory for the document or wherever you store your custom code.

I've never created node shapes: if you want to create new shapes, you might want to check out creating node shapes. So, I'll leave that part up to you. But, creating pics is relatively easy. And, that's what I do here.

\def\aeunitcircleradius{1cm}
\tikzset{
\path (0,0)                  coordinate (-center)
-- ++ (0.5,-0.5) coordinate (-se)
-- ++ (0,1.0)    coordinate (-ne)
-- ++ (-1,0)     coordinate (-nw)
-- ++ (0,-1)     coordinate (-sw);
},
\path (0,0)                  coordinate (-center)
-- ++ (0.5,-0.5) coordinate (-se)
-- ++ (0,1.0)    coordinate (-ne)
-- ++ (-1,0)     coordinate (-nw)
-- ++ (0,-1)     coordinate (-sw);
},
\path (0,0)                  coordinate (-center)
-- ++ (0.5,-0.5) coordinate (-se)
-- ++ (0,1.0)    coordinate (-ne)
-- ++ (-1,0)     coordinate (-nw)
-- ++ (0,-1)     coordinate (-sw);
},
\path (0,0)                  coordinate (-center)
-- ++ (0.5,-0.5) coordinate (-se)
-- ++ (0,1.0)    coordinate (-ne)
-- ++ (-1,0)     coordinate (-nw)
-- ++ (0,-1)     coordinate (-sw);
},
}


Here's a standalone document that calls this new TikZ library:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{unitcircle}
\begin{document}

\begin{tikzpicture}

\path
-- ++ (1,0) pic (LR) {quadrant IV}
-- ++ (0,1) pic (UR) {quadrant I}
-- cycle
-- ++ (0,1) pic (UL) {quadrant II}
;
\draw[blue] (LR-ne) -- (LR-sw);

\draw[red] (LL-ne) rectangle (LL-sw);

\draw (LL-center) -- (UR-center)
-- (UL-center)
-- (LR-center);
\end{tikzpicture}

\end{document}


Here's the result:

You might take some time to examine some of the TikZ library files on your system such as tikzlibraryarrows.code.tex. There are also libraries created by others such as hobby and tikzmark. It may be worth your time to open up those files and look at how things are done there.

The program DIA can export your drawing as a tex file. I point this out because it already has a Chemical engineering library. My answer doesn't help users learn how to write shape libraries, but it can help a user get quality latex images a chemical engineering document/drawing... or at least give some basic tex code to build a library off of.