# Where to get the tikz source of a logic gate?

I'm looking for the latex implementation of the logic gates in tikz.

More specifically, I want to create a European XOR gate with more than two legs. As there already exists an OR gate with more than two legs (and the only difference between OR and XOR is an equals sign vs. a greater-equals sign, see figure), it should be very easy to create a multi-leg XOR from the code of the OR gate.

However, the tikz code is very large, and I was not able to find the implementation of OR.

• – Denis Dec 23 '15 at 10:35
• Where do you find the code of an OR gate? – Karlo Dec 23 '15 at 10:39

# TikZ

Not exactly sure which library you're referring to, but the general procedure applies.

If you have \usetikzlibrary{shapes.gates.logic.IEC}, then this loads the file tikzlibraryshapes.gates.logic.IEC.code.tex which is found (in my system) in /usr/local/texlive/2015/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/. You can find the location by running kpsewhich tikzlibraryshapes.gates.logic.IEC.code.tex in a terminal.

This file sets up some styles, and loads pgflibraryshapes.gates.logic.IEC.code.tex (which is in the folder .../texmf-dist/tex/generic/pgf/libraries/shapes/circuits/), and this is where the actual code for the gates are found. The or gate IEC is defined from line 343 onwards.

# circuitikz

Assuming you're actually talking about circuitikz, and not tikz.

As far as I can see, without being very familiar with circuitkz, the definition of european xor gate, as demonstrated in runartrollet's answer, can be found in the file pgfcirctripoles.tex. As above, you can find the location of this with kpsewhich pgfcirctripoles.tex, I have it in /usr/local/texlive/2015/texmf-dist/tex/generic/circuitikz/pgfcirctripoles.tex.

The different types of gates are made with a macro called \pgfcircdeclareeurologicport, which is defined in lines 892--1022 of said file. (See the lines immediately below the macro definition.)

• I was referring to actually tikz, not circuitikz. But thanks for both - this was exactly what I was looking for! – lukas.coenig Dec 23 '15 at 14:06
• Having inspected the file, I found that the only difference between the XOR gate and all the other gates is this command: \pgf@lib@sh@logicgate@parseinputs{1024}. For the XOR gate, the constant is set to 2 for no obvious reason. Setting it to 1024 works fine. I would guess, this is a bug. – lukas.coenig Dec 23 '15 at 14:21
• @lukas.coenig Judging by the documentation this seems like a conscious decision, the description for or gate IEC says two or more inputs, the description for xor gate IEC says two inputs. You could add a bug report or feature request at sourceforge.net/p/pgf/_list/tickets?source=navbar – Torbjørn T. Dec 23 '15 at 14:40
• Yes, I saw that, but it still simply might have been forgotten... I'll consider adding a request. – lukas.coenig Dec 23 '15 at 15:01

This might not be the best way, as it does not really add any ports, put it would look the part. You might want a better solution than this, but in a pinch it might be what you are after. This uses the circuitikz package.

\documentclass[11pt]{article}
\usepackage[european]{circuitikz}
\begin{document}
\begin{circuitikz} \draw
(0,2) node[european or port] (OR1) {}
(0,0) node[european xor port] (XOR1) {}
(XOR1.west) -- ++(0.4,0)
(OR1.west) -- ++(0.4,0)
;\end{circuitikz}

\end{document}


This is based on John Kormylo's answer from Three (or more leg) xor gate for tikz

EDIT: I've read through some of your other posts, and you seem well aware of circuitikz, and I realize my answer probably does not help, and that it doesn't really help you finding the source code for the logic gate. Maybe you could add some info about why you need this approach?

• Yeah, you're right, I'm not using circuitikz, and I was also aware of the post you suggested. (The reason is simply that circuitikz doesn't allow more than two legs for any of the logic gates...) Still, your answer is good and might help others, thanks! – lukas.coenig Dec 23 '15 at 14:09

Following Torbjørn T.'s answer, I inspected this file:

pgflibraryshapes.gates.logic.IEC.code.tex


I found that the basic difference between the XOR gate and the other gates that do support three and more legs is this line:

\pgf@lib@sh@logicgate@parseinputs{1024}


For the XOR gate, the constant is set to 2 (instead of 1024). I set it to 1024, and it worked fine.

I guess this is a bug in the tikz implementation... (or there is some non-obvious reason).