This is a script that takes an ASCII representation of a quantum circuit and
generates commands to draw it in LaTeX's picture
environment.
To use it, you must first copy the gates.tex file into the same folder as your document and then, once, do:
\input{gates.tex}
The picture
command generated by the script can be placed anywhere in your
document below that line.
This script takes a text description of the circuit as input. Circuits are encoded as follows:
- Each line of the file is one qubit (horizontal line in the circuit).
- Each character on a line corresponds to what to draw from that position. This
could be a single-qubit gate (e.g.
Z
for the Z gate), or part of a multi-qubit gate with a line extending upwards or downwards (explained below).
You can draw circuits using the following primitives:
- Single Qubit Gates:
X
,Z
,H
, andI
(identity). - Control lines:
U
for a control dot with a line going up, leaving room for a boxed gate above, andP
for a control dot with a line going up, touching the line above. Similarly, for control lines going down,D
(leaving room for a boxed gate below), andN
(touching the line below). - For the XOR/OPLUS symbol part of a CNOT gate, use
O
. - For circuits with more than two qubits, you may have to draw a line "crossing
over" another one without touching. This can be done using
L
(going up) andV
going down. - Swap gates can be drawn by putting an
S
on the topmost qubit of the swap andW
on the bottommost qubit of the swap (with optional crossover lines withL
as necessary).
Your input is not sanity checked, i.e. you can have lines extending upward from the top qubit, so make sure you get your input right.
Here is a three-qubit circuit illustrating how to use the primitives:
SSHXIHNN
WLHZONNV
IWUIPOOO
Once the output commands are rendered, it looks like: