summaryrefslogtreecommitdiff
path: root/Master/texmf-dist
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2019-04-08 19:58:26 +0000
committerKarl Berry <karl@freefriends.org>2019-04-08 19:58:26 +0000
commit4d59deb76f0e3491867788ac648af2b2897156bf (patch)
tree6d974d92ad03ed57563ae40e3a151e3b418ad554 /Master/texmf-dist
parent637f449788f666683e90455135e1762079db6d16 (diff)
quantikz (8apr19)
git-svn-id: svn://tug.org/texlive/trunk@50869 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r--Master/texmf-dist/doc/latex/quantikz/manual.pdfbin430372 -> 0 bytes
-rw-r--r--Master/texmf-dist/doc/latex/quantikz/manual.tex788
-rw-r--r--Master/texmf-dist/doc/latex/quantikz/quantikz.pdfbin0 -> 513931 bytes
-rw-r--r--Master/texmf-dist/doc/latex/quantikz/quantikz.tex1101
-rw-r--r--Master/texmf-dist/tex/latex/quantikz/tikzlibraryquantikz.code.tex293
5 files changed, 1325 insertions, 857 deletions
diff --git a/Master/texmf-dist/doc/latex/quantikz/manual.pdf b/Master/texmf-dist/doc/latex/quantikz/manual.pdf
deleted file mode 100644
index e68eaa2b746..00000000000
--- a/Master/texmf-dist/doc/latex/quantikz/manual.pdf
+++ /dev/null
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/quantikz/manual.tex b/Master/texmf-dist/doc/latex/quantikz/manual.tex
deleted file mode 100644
index d89420f3bbb..00000000000
--- a/Master/texmf-dist/doc/latex/quantikz/manual.tex
+++ /dev/null
@@ -1,788 +0,0 @@
-\documentclass[aps,pra,10pt,nofootinbib]{revtex4}
-%\pdfoutput=1
-% Package(s) to include
-%\listfiles
-\usepackage{amsfonts,amssymb,amsmath} % for math symbols.
-\usepackage{lmodern,adjustbox}
-\usepackage[skins,breakable]{tcolorbox}
-\usepackage{tikz}
-\usetikzlibrary{quantikz}
-\tcbuselibrary{listings}
-\tcbuselibrary{breakable}
-\lstset{
-basicstyle=\small\ttfamily,
-columns=flexible,
-breaklines=true
-}
-\usepackage[pdftex,hyperfigures,pdfpagelabels]{hyperref}
-%\lstloadlanguages{Latex}
-
-\newtcolorbox{Code}{enhanced,fonttitle=\sffamily\bfseries\large,valign=center
-,drop fuzzy shadow,sidebyside,lefthand ratio=0.4,lower separated=false}
-
-\begin{document}
-
-\title{Tutorial on the Quantikz Package}
-\date{\today}
-\author{Alastair \surname{Kay}}
-\affiliation{Royal Holloway University of London, Egham, Surrey, TW20 0EX, UK}
-\email{alastair.kay@rhul.ac.uk}
-\begin{abstract}
-\end{abstract}
-\maketitle
-I've always used \href{https://arxiv.org/abs/quant-ph/0406003}{QCircuit} for typesetting quantum circuit diagrams within \LaTeX, but found the Xy-pic based notation rather impenetrable and I struggled to adapt it for my needs (this is probably my failing rather than the package's). Thus, I wanted a tikz package that could do the same. That package is Quantikz. Those familiar with QCircuit will recognise much of the notation, although it has evolved a bit (hopefully simplified!).
-
-\section{Usage}
-
-There is not currently a package that lets you install Quantikz automatically. Instead, you need to obtain the file tikzlibraryquantikz.code.tex (it should accompany the source code of this file, and the most recent version will always be available \href{http://dx.doi.org/10.17637/rh.7000520}{here}.) and put it in the same folder as your main tex document. Then, in the preamble of your document, simply write
-\begin{verbatim}
-\usepackage{tikz}
-\usetikzlibrary{quantikz}
-\end{verbatim}
-Now, each time that you want to include a quantum circuit, you just enclose it in a \verb!tikzcd! environment.
-
-Once you start using this for multiple projects, it gets annoying to have to create a copy every time (but remember that you'll need to include a copy for arXiv/journal submission). It might be easier to create a local texmf branch that contains the relevant file in a sub-folder \verb!tex/latex/quantikz/!. If you use MikTeX, see here for \href{https://miktex.org/howto/miktex-console}{Registering a user-managed TEXMF root directory}. A range of variants can be found on \href{https://tex.stackexchange.com/questions/1137/where-do-i-place-my-own-sty-or-cls-files-to-make-them-available-to-all-my-te}{Stack Exchange}.
-\section{A Single Wire}
-%\expandafter\def\expandafter\mname\expandafter{\getrandomletter}
-Quantum circuits are laid out with a matrix notation, with cells separated by \& (just like all matrices, tables etc.\ in \LaTeX). Here, we typeset a single quantum wire.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
- & \phase{\alpha} & \gate{H} & \phase{\beta} & \gate{H} & \phase{\gamma} & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \phase{\alpha} & \gate{H} & \phase{\beta} & \gate{H} & \phase{\gamma} & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-Single-qubit gates take the form \verb!\gate{H}!, with any sequence of maths allowed in the argument, or, for phase gates, \verb!\phase{phase}!. The first gate should be in the second column rather than the first (so that the preceding quantum wire has somewhere to go). You {\em can} put it in the first column, it just won't have an incoming wire.
-
-Text can be added at the start of a quantum wire using \verb!\lstick{}!, and at the end using \verb!\rstick{}!. These are not maths environments.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-\lstick{$\ket{0}$} & \phase{\alpha} & \gate{H} & \phase{\beta} & \gate{H} & \phase{\gamma} & \rstick{Arbitrary\\pure state}\qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-\lstick{\ket{0}} & \phase{\alpha} & \gate{H} & \phase{\beta} & \gate{H} & \phase{\gamma} & \rstick{Arbitrary\\pure state}\qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-Notice that a multi-line \verb!lstick! or \verb!rstick! is trivial\footnote{The only issue is that the height of the label will not be taken into account in the vertical spacing of quantum wires. You may have to adjust this manually. See Section \ref{sec:align} for an example of how to achieve this.}.
-
-\subsection{Measurements}
-
-There are several measurement devices to choose from, and the measurement basis can be specified as the parameter:
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-& \meter{0} && \meterD{1} & & \measuretab{\text{out}}& & \measure{\text{basis}}
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \meter{0} && \meterD{1} && \measuretab{\text{out}} && \measure{\text{basis}}
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-Thus, in our previous circuit:
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-\lstick{$\ket{0}$} & \phase{\alpha} & \gate{H} & \phase{\beta} & \gate{H} & \phase{\gamma} & \meter{\ket{\pm}}
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-\lstick{\ket{0}} & \phase{\alpha} & \gate{H} & \phase{\beta} & \gate{H} & \phase{\gamma} & \meter{\ket{\pm}}
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-
-\subsection{Wires and Arrows}
-
-There are a few bells and whistles: \verb!\qw! connects a quantum wire from the current cell back to the previous one. Most gates have this built in (\verb!\rstick! is the notable exception). Equally, sometimes you want a `do nothing' operation, and \verb!\qw! is perfect for that. Also, you can just insert text into a cell without boxing it (as you would for a gate). This can be useful for errors, and is achieved with \verb!\push{}!.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-\lstick{$\ket{0}$\\initial state} & \qw & \push{X} & \qw & \rstick{$\ket{1}$} \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-\lstick{$\ket{0}$\\initial state} & \qw & \push{X} & \qw & \rstick{$\ket{1}$} \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-Since we have built quantikz on top of tikzcd, any of the standard arrow commands will work. For example, after a measurement, you might what to use an arrow to report a particular measurement outcome using \verb!\arrow[r]!. The \verb!r! conveys that the arrow should head one cell to the right. You can use combinations of up (u), down (d), left (l) and right as you wish. For more styling options, see the \href{http://mirrors.ctan.org/graphics/pgf/contrib/tikz-cd/tikz-cd-doc.pdf}{tikzcd manual}.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-\lstick{$\ket{0}$\\initial state} & \qw & \push{X} & \qw & \meter{0/1} \arrow[r] & \rstick{\ket{1}}
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-\lstick{$\ket{0}$\\initial state} & \qw & \push{X} & \qw & \meter{0/1} \arrow[r] & \rstick{\ket{1}}
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-
-Sometimes, you may want to group a whole bunch of wires together. Use \verb!\qwbundle! instead of \verb!\qw!.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-\lstick{$\ket{0}^{\otimes n}$} &[2mm] \gate{H}\qwbundle & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-\lstick{$\ket{0}^{\otimes n}$} &[2mm] \gate{H} \qwbundle& \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-The size of the strike can be altered by doing \verb!\pgfkeyssetvalue{/quantikz/Strike Height}{new height}! and \verb!\pgfkeyssetvalue{/quantikz/Strike Width}{new width}!. To adjust the spacing, you'll need to alter the column spacing. This can be done either globally (see later for usage of \verb!row sep! which is similar to the \verb!column sep! you'd need), or on a column by column basis, as done in the previous example with the \verb![2mm]! statement, adding 2mm of horizontal space between two columns.
-
-You can access an alternative form for the multi-qubit wire using the \verb!alternate! key
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-\lstick{$\ket{0}^{\otimes n}$} & \gate{H} \qwbundle[alternate]& \qwbundle[alternate]
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-\lstick{$\ket{0}^{\otimes n}$} & \gate{H} \qwbundle[alternate]& \control\qwbundle[alternate]
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-
-\section{Multiple Qubits}
-
-New rows are started with \textbackslash\textbackslash. If the wires don't interact, then you proceed exactly as before. Naturally, there are several gates that induce interaction between wires: \verb!\ctrl{3}! makes a control-qubit (for controlled-not, controlled-phase, controlled-$U$, etc), where the target is 3 wires below. \verb!\octrl! is near-identical, except the control circle is open, as usually used to convey being controlled off $\ket{0}$ instead of $\ket{1}$. These will need to be matched with target commands. These could be normal gates or \verb!\targ{}! (controlled-not), \verb!\control{}! (controlled-phase), \verb!\ocontrol{}! (controlled-phase, controlled off $\ket{0}$). There is also a swap gate, \verb!\swap{2}!, with target \verb!\targX{}!. These can be combined to qive multi-controlled gates.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-\lstick{$\ket{0}$} & \gate{H} & \ctrl{1} & \gate{U} & \ctrl{1} & \swap{2} & \ctrl{1} & \qw \\
-\lstick{$\ket{0}$} & \gate{H} & \targ{} & \octrl{-1} & \control{} & \qw & \octrl{1} & \qw \\
-&&&&&\targX{} & \gate{U} & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-\lstick{$\ket{0}$} & \gate{H} & \ctrl{1} & \gate{U} & \ctrl{1} & \swap{2} & \ctrl{1} & \qw \\
-\lstick{$\ket{0}$} & \gate{H} & \targ{} & \octrl{-1} & \control{} & \qw & \octrl{1} & \qw \\
-&&&&&\targX{} & \gate{U} & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-
-If you want a gate that is one control and several targets, you need the command \verb!\vqw{1}! (vertical quantum wire) to create vertical connections, or possibly \verb!\vcw{1}! to create the classical version.
-
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-& \targ{} & \gate{U} & \qw \\
-& \ctrl{1} \vqw{-1} & \meter{} \vcw{-1} \\
-& \targ{} & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \targ{} & \gate{U} & \qw \\
-& \ctrl{1} \vqw{-1} & \meter{} \vcw{-1} \\
-& \targ{} & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-If you want to use classical controls with both horizontal and vertical components, you can do the following.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-& \ctrl{1} & \qw & \gate{U} & \gate{V} \\
-& \targ{} \vqw{1} & \meter{} & \cwbend{-1} \\
-& \targ{} & \meter{} & \cw & \cwbend{-2} &
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \ctrl{1} & \qw & \gate{U} & \gate{V} \\
-& \targ{} \vqw{1} & \meter{} & \cwbend{-1} \\
-& \targ{} & \meter{} & \cw & \cwbend{-2} &
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-
-\section{Operating on Many Qubits}
-
-We have already met the \verb!\lstick!, \verb!\rstick!, and \verb!\gate! commands. By default, these all act on a single quantum wire. However, they also take the optional parameter \verb!wires=n! to specify that they should extend over $n$ wires. The syntax is otherwise unchanged.
-
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-\lstick[wires=3]{$\ket{0}^{\otimes 3}$} & \ctrl{1} & \meter{} \\
- & \gate[wires=2]{U} & \qw\rstick[wires=2]{\ket{11}} \\ %
- & & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-\lstick[wires=3]{$\ket{0}^{\otimes 3}$} & \ctrl{1} & \meter{} \\
- & \gate[wires=2]{U} & \qw\rstick[wires=2]{\ket{11}} \\ %
- & & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-
-If you want to add extra width on the \verb!\gate!, you can either alter the text by adding spaces either side, or you could use an \verb!\hphantom! command in one of the underlying cells.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-& \gate{H} & \ctrl{1} & \meter{} \\
-& \gate[wires=2]{U} & \targ{} & \qw \\
-& \hphantom{wide label} & \qw & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \gate{H} & \ctrl{1} & \meter{} \\
-& \gate[wires=2]{U} & \targ{} & \qw \\
-& \hphantom{wide label} & \qw & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-Often, it is nice to be able to label the inputs and outputs on the box, which we do with the \verb!\gateinput! and \verb!\gateoutput! commands. These commands take 1 compulsory argument -- the label text. By default, this applies to a single wire, but you can again use the optional \verb!wires! parameter to extend it. The starting point is determined by where the command is placed.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-&\ctrl{1} & \qw \\
-&\gate[wires=3]{U}
- \gateinput[wires=2]{$x$}
- \gateoutput[wires=2]{$x$}
- &\qw \\
-&\hphantom{U very long} & \qw \\
-&\gateinput{$y$}
-\gateoutput{$y\oplus f(x)$}
-&\qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-&\ctrl{1} & \qw \\
-&\gate[wires=3]{U}
- \gateinput[2]{$x$}
- \gateoutput[wires=2]{$x$}&\qw \\
-&\hphantom{U very long} \qw & \qw \\
-&\qw\gateinput{$y$}\gateoutput{$y\oplus f(x)$}&\qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-
-\section{Slicing}
-
-It is often helpful to `slice' up a circuit for the sake of explaining it step by step. To do this, we provide the \verb!\slice{title}! command, which inserts a dashed vertical line after the column in which the command is added.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-& \gate{H}\slice{step} & \ctrl{1} & \meter{} \\
-& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
-& \qw & \qw & \targ{} & \qw & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \gate{H}\slice{step} & \ctrl{1} & \meter{} \\
-& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
-& \qw & \qw & \targ{} & \qw & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-You can also slice every step by using option \verb!slice all!, and the labels will be automatically numbered. This is likely to behave strangely unless you explicitly ensure that all rows have the same number of entries (i.e.\ short rows should have extra \& characters added).
-\begin{Code}
-\begin{center}
-\begin{tikzcd}[slice all]
-& \gate{H} & \ctrl{1} & \meter{} && \\
-& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
-& \qw & \qw & \targ{} & \qw & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}[slice all]
-& \gate{H} & \ctrl{1} & \meter{} && \\
-& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
-& \qw & \qw & \targ{} & \qw & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-If you need to adjust where the last slice is, use the optional parameter \verb!remove end slices!, which counts the number of columns fewer to add slices to. You can also change the title of each of the slices, by setting \verb!slice titles!. Include the macro \verb!\col! in your specification if you want to use the step number. Note, however, that the columns won't space themselves out to accommodate a very wide label. You can style the slicing lines with the \verb!slice style! key, and the labels with \verb!slice label style!. These can be used to rotate the labels and create a bit more space!
-\begin{Code}
-\begin{center}
-\begin{tikzcd}[slice all,remove end slices=1,slice titles=slice \col,slice style=blue,slice label style={inner sep=1pt,anchor=south west,rotate=40}]
-& \gate{H} & \ctrl{1} & \meter{} && \\
-& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
-& \qw & \qw & \targ{} & \qw & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}[slice all,remove end slices=1,slice titles=slice \col,slice style=blue,slice label style={inner sep=1pt,anchor=south west,rotate=40}]
-& \gate{H} & \ctrl{1} & \meter{} && \\
-& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
-& \qw & \qw & \targ{} & \qw & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-\noindent If you get compile errors when trying to slice, check the last line of your matrix, and make sure it doesn't end in \textbackslash\textbackslash.
-
-\section{Typesetting}
-
-\subsection{Alignment}\label{sec:align}
-
-How do we centre a circuit diagram? Simply surround it with \verb!\begin{center}! and \verb!\end{center}! commands, or within any standard equation environment.
-
-Vertical alignment between different circuits can be more fiddly, depending on how much of a perfectionist you are. Sometimes, they work immediately:
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-& \gate{X} & \ctrl{1} & \qw \\
-& \qw & \targ{} & \qw
-\end{tikzcd}
-=\begin{tikzcd}
-& \ctrl{1} & \gate{X} & \qw \\
-& \targ{} & \gate{X} & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \gate{X} & \ctrl{1} & \qw \\
-& \qw & \targ{} & \qw
-\end{tikzcd}
-=\begin{tikzcd}
-& \ctrl{1} & \gate{X} & \qw \\
-& \targ{} & \gate{X} & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-\noindent but the wires don't always align perfectly with each other. Ensuring an even spacing between rows can help (but is not always appropriate). See Sec.\ \ref{sec:space}.
-
-You might be better off writing it as a single quantum circuit with no wires joining the two parts. The spacing works better if your circuit has an odd number of wires, otherwise you have to add an extra row in the middle, and then change the spacing of that row with its neighbours.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-& \qw & \ctrl{2} & \qw&&& \ctrl{2} & \gate{Z} & \qw \\[-0.3cm]
-&&&&=&\\[-0.3cm]
-& \gate{Z} & \targ{} & \qw&&& \targ{} & \gate{Z} & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \qw & \ctrl{2} & \qw&&& \ctrl{2} & \gate{Z} & \qw \\[-0.3cm]
-&&&&=&\\[-0.3cm]
-& \gate{Z} & \targ{} & \qw&&& \targ{} & \gate{Z} & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-
-
-
-\subsection{Scaling}
-If you want to override the standard size of a circuit, you can make it a node inside a \verb!tikzpicture!:
-\begin{Code}
-\begin{center}
-\begin{tikzpicture}
-\node[scale=2] {
-\begin{tikzcd}
-& \gate{H} & \phase{\beta} & \gate{H} & \qw
-\end{tikzcd}
-};
-\end{tikzpicture}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzpicture}
-\node[scale=2] {
-\begin{tikzcd}
-& \gate{H} & \phase{\beta} & \gate{H} & \qw
-\end{tikzcd}
-};
-\end{tikzpicture}
-\end{lstlisting}
-\end{Code}
-It's also possible to rescale to a fixed width, so long as you declare the \verb!adjustbox! package in the document preamble.
-\begin{Code}
-\begin{center}
-\begin{adjustbox}{width=0.8\textwidth}
-\begin{tikzcd}
-& \gate{H} & \phase{\beta} & \gate{H} & \qw
-\end{tikzcd}
-\end{adjustbox}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{adjustbox}{width=0.8\textwidth}
-\begin{tikzcd}
-& \gate{H} & \phase{\beta} & \gate{H} & \qw
-\end{tikzcd}
-\end{adjustbox}
-\end{lstlisting}
-\end{Code}
-
-\subsection{Spacing}\label{sec:space}
-If you wish, it is possible to adjust spacing in the circuits using standard tikz commands. For example, a ridiculous horizontal spacing:
-\begin{Code}
-\begin{center}
-\begin{tikzcd}[column sep=1cm]
-& \gate{H} & \phase{\beta} & \gate{H} & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}[row sep=0.5cm,column sep=1cm]
-& \gate{H} & \phase{\beta} & \gate{H} & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-For horizontal spacing of an individual column, use \verb!\hphantom{}! if it's a place where there's already a gate, or there shouldn't be a quantum wire. If there's only a quantum wire, use \verb!\hphantomgate{}!. For spacing of an individual row, see the example on typesetting equation identities in Sec.\ \ref{sec:align}.
-
-Depending on what gates you have on each wire, the spacing may not be the same between each wire. Sometimes this is desirable, particularly if a gate in one particular row is much larger than anything in the other rows. At other times, it just makes your diagram look a little odd. If you want to make sure that every quantum wire is equally spaced, do the following to \verb!row sep!:
-\begin{Code}
-\begin{center}
-\begin{tikzcd}[row sep={1cm,between origins}]
-\lstick[wires=3]{$\ket{0}^{\otimes n}$} & \gate{H} & \gate[wires=4]{O}\gateinput[wires=3]{$x$}
-\gateoutput[wires=3]{$x$} & \gate{H} & \meter{} \\
- & \gate{H} & & \gate{H} & \meter{} \\
- & \gate{H} & & \gate{H} & \meter{} \\
-\lstick{$\ket{1}$} & \gate{H} & \phantom{really wide}\gateinput{$y$}\gateoutput{$y\oplus f(x)$} & \gate{H} & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}[row sep={1cm,between origins}]
-\lstick[wires=3]{$\ket{0}^{\otimes n}$} & \gate{H} & \gate[wires=4]{O}\gateinput[wires=3]{$x$}
-\gateoutput[wires=3]{$x$} & \gate{H} & \meter{} \\
- & \gate{H} & & \gate{H} & \meter{} \\
- & \gate{H} & & \gate{H} & \meter{} \\
-\lstick{$\ket{1}$} & \gate{H} & \phantom{really wide}\gateinput{$y$}\gateoutput{$y\oplus f(x)$} & \gate{H} & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-Strictly, the \verb!wires=! statement should not be necessary, as this is presumed to be the default key. Thus, we can get the same results with
-\begin{Code}
-\begin{center}
-\begin{tikzcd}[row sep={1cm,between origins}]
-\lstick[3]{$\ket{0}^{\otimes n}$} & \gate{H} & \gate[4]{O}\gateinput[3]{$x$}
-\gateoutput[3]{$x$} & \gate{H} & \meter{} \\
- & \gate{H} & & \gate{H} & \meter{} \\
- & \gate{H} & & \gate{H} & \meter{} \\
-\lstick{$\ket{1}$} & \gate{H} & \phantom{really wide}\gateinput{$y$}\gateoutput{$y\oplus f(x)$} & \gate{H} & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}[row sep={1cm,between origins}]
-\lstick[3]{$\ket{0}^{\otimes n}$} & \gate{H} & \gate[4]{O}\gateinput[3]{$x$}
-\gateoutput[3]{$x$} & \gate{H} & \meter{} \\
- & \gate{H} & & \gate{H} & \meter{} \\
- & \gate{H} & & \gate{H} & \meter{} \\
-\lstick{$\ket{1}$} & \gate{H} & \phantom{really wide}\gateinput{$y$}\gateoutput{$y\oplus f(x)$} & \gate{H} & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-
-\subsection{Global Styling}
-
-Global properties that affect all circuit elements of a given type can be affected through \verb!tikzset!.
-\begin{Code}
-\begin{center}
-\tikzset{
- operator/.append style={fill=red!20},
- my label/.append style={above right,xshift=0.3cm}
-}
-\begin{tikzcd}
-& \gate{H} & \phase{\beta} & \gate{H} & \qw & \meter{\ket{\pm}}
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\tikzset{
- operator/.append style={fill=red!20},
- my label/.append style={above right,xshift=0.3cm}
-}
-\begin{tikzcd}
-& \gate{H} & \phase{\beta} & \gate{H} & \qw & \meter{\ket{\pm}}
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-The global styles are:
-\begin{center}
-\begin{tabular}{c|c}
-Style Name & Affected Command(s) \\
-\hline
-operator & \verb!\gate! \\
-meter & \verb!\meter! \\
-slice & \verb!\slice! \\
-wave & \verb!\wave! \\
-leftinternal & \verb!\gateinput! \\
-rightinternal & \verb!\gateoutput! \\
-dm & left braces (\verb!\gateoutput!,\verb!\lstick!) \\
-dd & right braces (\verb!\gateinput!,\verb!\rstick!) \\
-phase & \verb!\phase!, \verb!\control! \\
-ophase & \verb!\ophase!, \verb!\ocontrol! \\
-circlewc & \verb!\targ! \\
-crossx2 & \verb!\swap!,\verb!\targX! \\
-my label & measurement bases in \verb!\meter! \\
-phase label & phases in \verb!\phase! \\
-gg label & main gate label in \verb!\gate! \\
-group label & label in \verb!\gategroup!
-\end{tabular}
-\end{center}
-
-\subsection{Per-Gate Styling}
-
-Individual gates can be modified using optional arguments of the calling function.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-& \gate[style={fill=red!20},label style=cyan]{H} & \phase[green]{\beta} & \gate{H} & \qw & \meter{\ket{\pm}}
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \gate[style={fill=red!20},label style=cyan]{H} & \phase[green]{\beta} & \gate{H} & \qw & \meter{\ket{\pm}}
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-The specific syntax varies a little depending on the type of gate
-\begin{center}
-\begin{tabular}{p{0.4\textwidth}|p{0.4\textwidth}}
-gates that don't accept formatting parameters & \verb!\qw!,\verb!\vqw!,\verb!\qwbundle!,\verb!\cw!,\verb!\vcw!,\verb!\cwbend!,\verb!\push! \\
-\hline
-gates that accept tikz node formatting keys directly in optional argument & \verb!\phase!, \verb!\control!, \verb!\ocontrol!, \verb!\targ!, \verb!\targX!, \verb!\meter!, \verb!\meterD!, \verb!\measure!, \verb!\measuretab!, \verb!\wave! \\
-\hline
-gates that accept node formatting keys as \verb!label style! key in optional argument & \verb!\gate!, \verb!\slice!, \verb!\lstick!, \verb!\rstick!, \verb!\gategroup!, \verb!\gateinput!, \verb!\gateoutput!
-\end{tabular}
-\end{center}
-Those that accept the \verb!label style! key also accept a second key for formatting other elements of the display
-\begin{center}
-\begin{tabular}{c|cc}
-\verb!\gate!,\verb!\gategroup! & \verb!style! & styles the box \\
-\verb!\slice! & \verb!style! & styles the line\\
-\verb!\lstick!,\verb!\rstick!,\verb!\gateinput!,\verb!\gateoutput! & \verb!braces! & styles the brace
-\end{tabular}
-\end{center}
-If you want to input several styling parameters with one of these keys, just group them together in a set of curly braces, \{\}. Typical styling parameters include \verb!draw=! specifying line colour, \verb!fill=!, specifying fill colour, \verb!inner xsep=! and \verb!inner ysep=! specifying horizontal and vertical margins respectively, \verb!xshift=! and \verb!yshift=! for adjusting horizontal and vertical positioning. Beyond that, the \href{http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf}{tikz manual} is your friend!
-
-This styling is really quite flexible, as we can override the default shapes with anything that we want:
-\begin{Code}
-\begin{center}
-\tikzset{
- group-1-5/.append style={starburst,fill=yellow,draw=red,line width=2pt,inner ysep=-15pt}
-}
-\begin{tikzcd}[row sep=0.3cm,column sep=0.4cm]%
-& \gate{H} & \ctrl{2}& \qw & \gate[3,style={starburst,fill=yellow,draw=red,line width=2pt,inner xsep=-2pt,inner ysep=-5pt},label style=cyan]{\text{noise}} & \ctrl{3} & \qw & \qw & \qw\\
-\lstick{$\ket{0}$} & \qw & \targ{} & \qw & \qw & \qw & \ctrl{3} & \qw & \qw \\
-\lstick{$\ket{0}$} & \qw & \targ{}& \qw & \qw & \qw & \qw & \ctrl{2} & \qw\\
-&&&&\lstick{$\ket{0}$} & \targ{} & \targ{} & \qw & \meter{} \\
-&&&&\lstick{$\ket{0}$} & \qw & \targ{} & \targ{} & \meter{}
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}[row sep=0.3cm,column sep=0.4cm]%
-& \gate{H} & \ctrl{2}& \qw & \gate[3,style={starburst,fill=yellow,draw=red,line width=2pt,inner xsep=-2pt,inner ysep=-5pt},label style=cyan]{\text{noise}} & \ctrl{3} & \qw & \qw& \qw\\
-\lstick{$\ket{0}$} & \qw & \targ{} & \qw & \qw & \qw & \ctrl{3} & \qw & \qw \\
-\lstick{$\ket{0}$} & \qw & \targ{}& \qw & \qw & \qw & \qw & \ctrl{2} & \qw\\
-&&&&\lstick{$\ket{0}$} & \targ{} & \targ{} & \qw & \meter{} \\
-&&&&\lstick{$\ket{0}$} & \qw & \targ{} & \targ{} & \meter{}
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-We can also supplement with standard tikz commands by using the `execute at end picture' key. The cells of the matrix contain nodes called \verb!\tikzcdmatrixname-i-j!, where i is the row number and j is the column number. Thus,
-\begin{Code}
-\begin{center}
-\begin{tikzcd}[row sep=0.3cm,column sep=0.4cm,execute at end picture={
- \node [fit=(\tikzcdmatrixname-1-6)(\tikzcdmatrixname-4-6)(\tikzcdmatrixname-5-9),draw,dashed,inner sep=4pt,label={[yshift=0.3cm]above:syndrome extraction}] {};
-}]
-& \gate{H} & \ctrl{2}& \qw & \gate[3,style={starburst,fill=yellow,draw=red,line width=2pt,inner xsep=-2pt,inner ysep=-5pt}]{\text{noise}} & \ctrl{3} & \qw & \qw& \qw\\
-\lstick{$\ket{0}$} & \qw & \targ{} & \qw & \qw & \qw & \ctrl{3} & \qw & \qw \\
-\lstick{$\ket{0}$} & \qw & \targ{}& \qw & \qw & \qw & \qw & \ctrl{2} & \qw\\
-&&&&\lstick{$\ket{0}$} & \targ{} & \targ{} & \qw & \meter{} \\
-&&&&\lstick{$\ket{0}$} & \qw & \targ{} & \targ{} & \meter{}
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}[row sep=0.3cm,column sep=0.4cm,execute at end picture={
- \node [fit=(\tikzcdmatrixname-1-6)(\tikzcdmatrixname-4-6)(\tikzcdmatrixname-5-9),draw,dashed,inner sep=4pt,label={[yshift=0.3cm]above:syndrome extraction}] {};
-}]
-& \gate{H} & \ctrl{2}& \qw & \gate[3,style={starburst,fill=yellow,draw=red,line width=2pt,inner xsep=-2pt,inner ysep=-5pt}]{\text{noise}} & \ctrl{3} & \qw & \qw& \qw\\
-\lstick{$\ket{0}$} & \qw & \targ{} & \qw & \qw & \qw & \ctrl{3} & \qw & \qw \\
-\lstick{$\ket{0}$} & \qw & \targ{}& \qw & \qw & \qw & \qw & \ctrl{2} & \qw\\
-&&&&\lstick{$\ket{0}$} & \targ{} & \targ{} & \qw & \meter{} \\
-&&&&\lstick{$\ket{0}$} & \qw & \targ{} & \targ{} & \meter{}
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-
-\subsection{Boxing/Highlighting Parts of a Circuit}
-
-In fact, this boxing command is sufficiently useful that we implement it as \verb!\gategroup!. The optional parameters \verb!wires! (again, the default) and \verb!steps! specify the number of rows and columns that the group spans respectively. The mandatory argument is the label for the box (although this can be empty). The top-left corner of the box coincides with the cell in which the command is placed.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-& \gate{H} & \ctrl{1} & \gate{H}\gategroup[wires=2,steps=3,style={inner sep=6pt}]{reversed c-{\sc not}} & \ctrl{1} & \gate{H} & \ctrl{1} & \qw & \qw \\
-& \qw & \targ{} & \gate{H} & \targ{} & \gate{H} & \targ{} & \gate{H} & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \gate{H} & \ctrl{1} & \gate{H}\gategroup[wires=2,steps=3,style={inner sep=6pt}]{reversed c-{\sc not}} & \ctrl{1} & \gate{H} & \ctrl{1} & \qw & \qw \\
-& \qw & \targ{} & \gate{H} & \targ{} & \gate{H} & \targ{} & \gate{H} & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-By default, this box is drawn on top of the circuit itself. If you want it to be behind (for example, should you want it to have a background colour), then use the \verb!background! option.
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-& \gate{H} & \ctrl{1}\gategroup[2,steps=3,style={dashed,rounded corners,fill=blue!20, inner xsep=2pt},background]{{\sc swap}} & \targ{} & \ctrl{1} & \qw & \qw \\
-& \qw & \targ{} & \ctrl{-1} & \targ{} & \gate{H} & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \gate{H} & \ctrl{1}\gategroup[2,steps=3,style={dashed,rounded corners,fill=blue!20, inner xsep=2pt},background]{{\sc swap}} & \targ{} & \ctrl{1} & \qw & \qw \\
-& \qw & \targ{} & \ctrl{-1} & \targ{} & \gate{H} & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-The \verb!label style! key can be used to tune the label's properties, including positioning. For example,
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-& \gate{H} & \ctrl{1}\gategroup[2,steps=3,style={dashed,rounded corners,fill=blue!20, inner xsep=2pt},background,label style={label position=below,anchor=north,yshift=-0.2cm}]{{\sc swap}} & \targ{} & \ctrl{1} & \qw & \qw \\
-& \qw & \targ{} & \ctrl{-1} & \targ{} & \gate{H} & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \gate{H} & \ctrl{1}\gategroup[2,steps=3,style={dashed,rounded corners,fill=blue!20, inner xsep=2pt},background,label style={label position=below,anchor=north,yshift=-0.2cm}]{{\sc swap}} & \targ{} & \ctrl{1} & \qw & \qw \\
-& \qw & \targ{} & \ctrl{-1} & \targ{} & \gate{H} & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-Note that it is often good to use \verb!anchor=mid! for label anchors because if you have multiple labels, this will help get them horizontally aligned. It just means you have to use some \verb!yshift! to move the label off the border around the gategroup.
-
-
-At this point, we mention an extra option for the gate command. The \verb!swap! keyword turns the gate into a variant of a {\sc swap} gate which explicitly shows the wires (the \verb!wires! setting is fixed to 2, overriding any value you might supply).
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-& \gate{H} & \gate[swap]{} & \qw & \qw \\
-& \qw & & \gate{H} & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \gate{H} & \gate[swap]{} & \qw & \qw \\
-& \qw & & \gate{H} & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-\section{Otherwise Undocumented Features}
-A wave for separating rows. Do we really need this? Perhaps not, but it's fun!
-\begin{Code}
-\begin{center}
-\begin{tikzcd}
-& \gate{H} & \ctrl{3} & \ \ldots\ \qw & \qw & \gate{H} & \qw \\
-\wave&&&&&&\\
-& \gate{H} & \qw & \ \ldots\ \qw & \ctrl{1} & \gate{H} & \qw \\
-& \qw & \gate{U} & \ \ldots\ \qw & \gate{U^k} & \qw & \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}
-& \gate{H} & \ctrl{3} & \ \ldots\ \qw & \qw & \gate{H} & \qw \\
-\wave&&&&&&\\
-& \gate{H} & \qw & \ \ldots\ \qw & \ctrl{1} & \gate{H} & \qw \\
-& \qw & \gate{U} & \ \ldots\ \qw & \gate{U^k} & \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-
-\section{Converting from QCircuit}
-
-I've updated all of my existing teaching materials from QCircuit to Quantikz with very little trouble. There are a few standard replacements:
-\begin{center}
-\begin{tabular}{c|c}
-QCircuit notation & Quantikz notation \\
-\hline
-\verb!\QCircuit @C=n @R=m {#}! & \verb!\begin{tikzcd}[row sep=m,col sep=n]#\end{tikzcd}! \\
-\verb!\multigate{n}! & \verb!\gate[n+1]! \\
-\verb!\targ! & \verb!\targ{}! \\
-\verb!\control! & \verb!\control{}! \\
-\verb!\meter! & \verb!\meter{}! \\
-\verb!\measureD! & \verb!\meterD{}! \\
-\end{tabular}
-\end{center}
-Updating the \verb!\gategroup! command requires a little more care since the first two arguments have to be removed, and the command placed in the correct cell, at which point \verb!\gategroup{i}{j}{k}{l}{m}! becomes \verb!\gategroup[wires=k+1-i,steps=l+1-j]!. My primary use of gategroup was to achieve the effect now achieved with \verb!\lstick[k+1-i]!.
-
-\section{Troubleshooting}
-\begin{itemize}
-\item Have you checked that all commands that need them are followed by an empty argument, \{\}? Things like \verb!meter!, \verb!\control! (basically, those that can accept an optional styling parameter) look like they don't take any parameters, but they have to be followed by the pair of braces or you'll get very odd effects.
-\item If you get a whole bunch of unexpected text in one of your cells instead of a gate, make sure that the gate command is the first command in the cell, and that other commands (such as \verb!\qwbundle!) appear after.
-\item If you're getting errors about cells not being found (and especially if you're doing any slicing), check that your last row doesn't end with \textbackslash\textbackslash, and make sure that your last row contains as many cells (even if they're empty) as there are columns in the matrix.
-\item If you are trying to typeset your circuit inside some sort of tabular or align environment and are getting an error ``single ampersand used with wrong catcode'', trying adding the \verb![ampersand replacement=\&]! option to tikzcd, and instead of separating every cell by \&, use \textbackslash\&. This can also be useful if you want to insert a normal matrix as a gate
-\begin{Code}
-\begin{center}
-\begin{tikzcd}[ampersand replacement=\&]
-\lstick{\ket{0}} \& \gate{\left(\begin{array}{cc} \alpha & \beta \\ \beta & -\alpha \end{array}\right)} \& \ctrl{1} \& \gate{U_1} \& \qw \\
-\lstick{\ket{0}} \& \qw \& \targ{} \& \gate{U_2} \& \qw
-\end{tikzcd}
-\end{center}
-\tcblower
-\begin{lstlisting}
-\begin{tikzcd}[ampersand replacement=\&]
-\lstick{\ket{0}} \& \gate{\left(\begin{array}{cc} \alpha & \beta \\ \beta & -\alpha \end{array}\right)} \& \ctrl{1} \& \gate{U_1} \& \qw \\
-\lstick{\ket{0}} \& \qw \& \targ{} \& \gate{U_2} \& \qw
-\end{tikzcd}
-\end{lstlisting}
-\end{Code}
-Beamer is particularly annoying with doing this. It probably helps to issue a global command
-\begin{lstlisting}
-\tikzcdset{
- every matrix/.style={ampersand replacement=\&}
-}
-\end{lstlisting}
-somewhere in your document preamble. The tikzcd manual suggests another possible strategy, but I haven't had much success with it.
-\item If you have a \verb!\cwbend! in the bottom right cell of the matrix, sometimes you get an error (I have no understanding of why). Add an extra \& after, and all seems to be well.
-\end{itemize}
-\end{document} \ No newline at end of file
diff --git a/Master/texmf-dist/doc/latex/quantikz/quantikz.pdf b/Master/texmf-dist/doc/latex/quantikz/quantikz.pdf
new file mode 100644
index 00000000000..39a11433e58
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/quantikz/quantikz.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/quantikz/quantikz.tex b/Master/texmf-dist/doc/latex/quantikz/quantikz.tex
new file mode 100644
index 00000000000..1153b735af5
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/quantikz/quantikz.tex
@@ -0,0 +1,1101 @@
+\documentclass[aps,pra,10pt,nofootinbib]{revtex4}
+%\pdfoutput=1
+% Package(s) to include
+%\listfiles
+\usepackage{amsfonts,amssymb,amsmath} % for math symbols.
+\usepackage{lmodern,adjustbox}
+\usepackage[skins,breakable]{tcolorbox}
+\usepackage{tikz}
+\usetikzlibrary{quantikz}
+\tcbuselibrary{listings}
+\tcbuselibrary{breakable}
+\lstset{
+basicstyle=\small\ttfamily,
+columns=flexible,
+breaklines=true
+}
+\usepackage[pdftex,hyperfigures,pdfpagelabels]{hyperref}
+%\lstloadlanguages{Latex}
+
+\newtcolorbox{Code}{enhanced,fonttitle=\sffamily\bfseries\large,valign=center
+,drop fuzzy shadow,sidebyside,lefthand ratio=0.4,lower separated=false}
+
+\begin{document}
+
+\title{Tutorial on the Quantikz Package}
+\date{\today}
+\author{Alastair \surname{Kay}}
+\affiliation{Royal Holloway University of London, Egham, Surrey, TW20 0EX, UK}
+\email{alastair.kay@rhul.ac.uk}
+\begin{abstract}
+\end{abstract}
+\maketitle
+I've always used \href{https://arxiv.org/abs/quant-ph/0406003}{QCircuit} for typesetting quantum circuit diagrams within \LaTeX, but found the Xy-pic based notation rather impenetrable and I struggled to adapt it for my needs (this is probably my failing rather than the package's). Thus, I wanted a tikz package that could do the same. That package is Quantikz. Those familiar with QCircuit will recognise much of the notation, although it has evolved a bit (hopefully simplified!).
+
+\section{Usage}
+
+The quantikz package is available on CTAN, and will therefore be available through most (current) TeX distributions. Once installed, simply write
+\begin{verbatim}
+\usepackage{tikz}
+\usetikzlibrary{quantikz}
+\end{verbatim}
+in the preamble of your document
+Now, each time that you want to include a quantum circuit, you just enclose it in a \verb!tikzcd! or \verb!quantikz! environment. (Theoretically, there is an advantange of \verb!quantikz! over \verb!tikzcd!, but \verb!tikzcd! is retained for backwards compatibility\footnote{\texttt{quantikz} should support the external package in tikz. I've never tried it.}.)
+
+The current version of TeX on the arXiv is not up to date enough to provide the quantikz package. When uploading your source to the arXiv, you need to obtain the file tikzlibraryquantikz.code.tex (you will always be able to locate it on your computer in the main tex directory if you have installed the package, but it should also accompany the source code of this file, and the most recent version will is available \href{http://dx.doi.org/10.17637/rh.7000520}{here}). Just include the file in the main directory of your source code.
+\section{A Single Wire}
+%\expandafter\def\expandafter\mname\expandafter{\getrandomletter}
+Quantum circuits are laid out with a matrix notation, with cells separated by \& (just like all matrices, tables etc.\ in \LaTeX). Here, we typeset a single quantum wire.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+\lstick{$\ket{0}$} & \phase{\alpha} & \gate{H} & \phase{\beta} & \gate{H} & \phase{\gamma} & \rstick{Arbitrary\\pure state}\qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+ \begin{quantikz}
+ \lstick{\ket{0}} & \phase{\alpha} & \gate{H}
+ & \phase{\beta} & \gate{H} & \phase{\gamma}
+ & \rstick{Arbitrary\\pure state}\qw
+ \end{quantikz}
+\end{lstlisting}
+\end{Code}
+Single-qubit gates take the form \verb!\gate{H}!, with any sequence of maths allowed in the argument\footnote{See Sec.\ \ref{sec:trouble} in case you need to use \& characters in the maths.}, or, for phase gates, \verb!\phase{phase}!. The first gate should be in the second column rather than the first (so that the preceding quantum wire has somewhere to go). You {\em can} put it in the first column, it just won't have an incoming wire.
+
+Text can be added at the start of a quantum wire using \verb!\lstick{}!, and at the end using \verb!\rstick{}!. These are not maths environments, but you can of course insert maths delimiters such as \$.
+Notice that a multi-line \verb!lstick! or \verb!rstick! is trivial\footnote{The only issue is that the height of the label will not be taken into account in the vertical spacing of quantum wires. You may have to adjust this manually. See Section \ref{sec:align} for an example of how to achieve this.}.
+
+\subsection{Measurements}
+
+There are several measurement devices to choose from, and the measurement basis can be specified as the parameter:
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \meter{0} && \meterD{1} & & \measuretab{\text{out}}& & \measure{\text{basis}}
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \meter{0} && \meterD{1} && \measuretab{\text{out}} && \measure{\text{basis}}
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+Thus, in our previous circuit:
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+\lstick{\ket{0}} & \phase{\alpha} & \gate{H} & \phase{\beta} & \gate{H} & \phase{\gamma} & \meter{$\ket{\pm}$}
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+\lstick{\ket{0}} & \phase{\alpha} & \gate{H} & \phase{\beta} & \gate{H} & \phase{\gamma} & \meter{$\ket{\pm}$}
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+\subsection{Wires and Arrows}
+
+There are a few bells and whistles: \verb!\qw! connects a quantum wire from the current cell back to the previous one. Most gates have this built in (\verb!\rstick! is the notable exception). Equally, sometimes you want a `do nothing' operation, and \verb!\qw! is perfect for that. Also, you can just insert text into a cell without boxing it (as you would for a gate). This can be useful for errors, and is achieved with \verb!\push{}!.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+\lstick{$\ket{0}$\\initial state} & \qw & \push{X} & \qw & \rstick{$\ket{1}$} \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+\lstick{$\ket{0}$\\initial state} & \qw & \push{X} & \qw & \rstick{$\ket{1}$} \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+Since we have built quantikz on top of tikzcd, any of the standard arrow commands will work. For example, after a measurement, you might want to use an arrow to report a particular measurement outcome using \verb!\arrow[r]!. The \verb!r! conveys that the arrow should head one cell to the right. You can use combinations of up (u), down (d), left (l) and right as you wish. For more styling options, see the \href{http://mirrors.ctan.org/graphics/pgf/contrib/tikz-cd/tikz-cd-doc.pdf}{tikzcd manual}.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+\lstick{$\ket{0}$\\initial state} & \qw & \push{X} & \qw & \meter{0/1} \arrow[r] & \rstick{$\ket{1}$}
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+\lstick{$\ket{0}$\\initial state} & \qw & \push{X} & \qw & \meter{0/1} \arrow[r] & \rstick{$\ket{1}$}
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+Sometimes, you may want to group a whole bunch of wires together. Use \verb!\qwbundle! instead of \verb!\qw!.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+\lstick{$\ket{0}^{\otimes n}$} &[2mm] \gate{H}\qwbundle{3} & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+\lstick{$\ket{0}^{\otimes n}$} &[2mm] \gate{H}\qwbundle{3} & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+\noindent The size of the strike can be altered by issuing the commands \verb!\pgfkeyssetvalue{/quantikz/Strike Height}{new height}! and \verb!\pgfkeyssetvalue{/quantikz/Strike Width}{new width}!. I felt this example benefited from some additional spacing (of 2mm) on one column. For more spacing options, see Sec.\ \ref{sec:spacing}.
+
+You can access an alternative form for the multi-qubit wire using the \verb!alternate! key:
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+\lstick{$\ket{0}^{\otimes n}$} & \gate{H} \qwbundle[alternate]{}& \qwbundle[alternate]{}
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+\lstick{$\ket{0}^{\otimes n}$} & \gate{H} \qwbundle[alternate]{}& \control\qwbundle[alternate]{}
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+\noindent The alternate version does not represent how many wires are supposed to be in the bundle.
+
+
+\section{Multiple Qubits}
+
+New rows are started with \textbackslash\textbackslash. If the wires don't interact, then you proceed exactly as before. Naturally, there are several gates that induce interaction between wires: \verb!\ctrl{3}! makes a control-qubit (for controlled-not, controlled-phase, controlled-$U$, etc), where the target is 3 wires below. \verb!\octrl! is near-identical, except the control circle is open, as usually used to convey being controlled off $\ket{0}$ instead of $\ket{1}$. These will need to be matched with target commands. These could be normal gates or \verb!\targ{}! (controlled-not), \verb!\control{}! (controlled-phase), \verb!\ocontrol{}! (controlled-phase, controlled off $\ket{0}$). There is also a swap gate, \verb!\swap{2}!, with target \verb!\targX{}!\footnote{For a variant, see Sec.\ \ref{sec:boxing}.}. These can be combined to give multi-controlled gates.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+\lstick{$\ket{0}$} & \gate{H} & \ctrl{1} & \gate{U} & \ctrl{1} & \swap{2} & \ctrl{1} & \qw \\
+\lstick{$\ket{0}$} & \gate{H} & \targ{} & \octrl{-1} & \control{} & \qw & \octrl{1} & \qw \\
+&&&&&\targX{} & \gate{U} & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+\lstick{$\ket{0}$} & \gate{H} & \ctrl{1} & \gate{U} & \ctrl{1} & \swap{2} & \ctrl{1} & \qw \\
+\lstick{$\ket{0}$} & \gate{H} & \targ{} & \octrl{-1} & \control{} & \qw & \octrl{1} & \qw \\
+&&&&&\targX{} & \gate{U} & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+If you want a gate that is one control and several targets, you may need the command \verb!\vqw{1}! (vertical quantum wire) to create vertical connections, or possibly \verb!\vcw{1}! to create the classical version.
+
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \targ{} & \gate{U} & \qw \\
+& \ctrl{1} \vqw{-1} & \meter{} \vcw{-1} \\
+& \targ{} & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \targ{} & \gate{U} & \qw \\
+& \ctrl{1} \vqw{-1} & \meter{} \vcw{-1} \\
+& \targ{} & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+If you want to use classical controls with both horizontal and vertical components, you can do the following.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \ctrl{1} & \qw & \gate{U} & \gate{V} \\
+& \targ{} \vqw{1} & \meter{} & \cwbend{-1} \\
+& \targ{} & \meter{} & \cw & \cwbend{-2} &
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \ctrl{1} & \qw & \gate{U} & \gate{V} \\
+& \targ{} \vqw{1} & \meter{} & \cwbend{-1} \\
+& \targ{} & \meter{} & \cw & \cwbend{-2} &
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+\section{Operating on Many Qubits}
+
+We have already met the \verb!\lstick!, \verb!\rstick!, and \verb!\gate! commands. By default, these all act on a single quantum wire. However, they also take the optional parameter \verb!wires=n! to specify that they should extend over $n$ wires. The syntax is otherwise unchanged\footnote{Strictly, the \texttt{wires=} statement should not be necessary, as this is presumed to be the default key, but it is useful for readability.}.
+
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+\lstick[wires=3]{$\ket{0}^{\otimes 3}$} & \ctrl{1} & \meter{} \\
+ & \gate[wires=2]{U} & \qw\rstick[wires=2]{$\ket{11}$} \\
+ & & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+\lstick[wires=3]{$\ket{0}^{\otimes 3}$} & \ctrl{1} & \meter{} \\
+ & \gate[wires=2]{U} & \qw\rstick[wires=2]{$\ket{11}$} \\
+ & & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+If you want to add extra width on the \verb!\gate!, use the second optional parameter to specify a width (note that this is a minimum width -- if your supplied text is wider, the box will adjust its width accordingly.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \gate{H} & \ctrl{1} & \meter{} \\
+& \gate[wires=2][2cm]{U} & \targ{} & \qw \\
+& & \qw & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \gate{H} & \ctrl{1} & \meter{} \\
+& \gate[wires=2][2cm]{U} & \targ{} & \qw \\
+& & \qw & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+Often, it is nice to be able to label the inputs and outputs on the box, which we do with the \verb!\gateinput! and \verb!\gateoutput! commands. These commands take 1 compulsory argument -- the label text. By default, this applies to a single wire, but you can again use the optional \verb!wires! parameter to extend it. The starting point is determined by where the command is placed. The width of the gate does not automatically adjust to the contents of these extra labels, so you will have to add it with the second optional parameter of \verb!\gate!.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+&\ctrl{1} & \qw \\
+&\gate[wires=3][1.7cm]{U}
+ \gateinput[wires=2]{$x$}
+ \gateoutput[wires=2]{$x$}
+ &\qw \\
+& & \qw \\
+&\gateinput{$y$}
+\gateoutput{$y\oplus f(x)$}
+&\qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+&\ctrl{1} & \qw \\
+&\gate[wires=3][1.7cm]{U}
+ \gateinput[2]{$x$}
+ \gateoutput[wires=2]{$x$}&\qw \\
+& \qw & \qw \\
+&\qw\gateinput{$y$}\gateoutput{$y\oplus f(x)$}&\qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+You can use standard \LaTeX maths expressions for your labels. Usually, spacing can be automatically adjusted just fine. For example,
+
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \gate{\sqrt{Z}} & \gate[2]{\sqrt{\textsc{swap}}} & \meter{} \\
+& \gate{X} & & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \gate{\sqrt{Z}} & \gate[2]{\sqrt{\textsc{swap}}} & \meter{} \\
+& \gate{X} & & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+Sometimes, it might be that you want a multi-line label, and it should not be that each wire takes the height of those multiple lines. At this point, use the key \verb!disable auto height!. By default, each row will be assigned the height that a gate with label $U$ would be. This can be overridden by the third optional parameter of the gate command, if desired.
+
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+\lstick{$c_0$} & \gate[3,disable auto height]{\begin{array}{c} \text{M} \\ \text{A} \\ \text{J} \end{array}} & \qw & \qw \\
+\lstick{$c_1$} & & \gate[3,disable auto height]{\begin{array}{c} \text{M} \\ \text{A} \\ \text{J} \end{array}} & \qw \\
+\lstick{$c_2$} & & & \qw \\
+\lstick{$c_3$} & \qw & & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+\lstick{$c_0$} & \gate[3,disable auto height]{\begin{array}{c} \text{M} \\ \text{A} \\ \text{J} \end{array}} & \qw & \qw \\
+\lstick{$c_1$} & & \gate[3,disable auto height]{\begin{array}{c} \text{M} \\ \text{A} \\ \text{J} \end{array}} & \qw \\
+\lstick{$c_2$} & & & \qw \\
+\lstick{$c_3$} & \qw & & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+\subsection{Different Connections}
+
+It is assumed that most of the time you want to connect your gates with quantum wires. However, it is possible to override that, and either use classical wires or no wire. These appear as option keys for the gate command, both of which are a comma-separated list of incoming wires that should be altered.
+
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \gate[5,cwires={2,4},nwires={3}]{U} & \qw \\
+& & \cw \\
+& & \qw \\
+& & \cw \\
+& & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \gate[5,cwires={2,4},nwires={3}]{U} & \qw \\
+& & \cw \\
+& & \qw \\
+& & \cw \\
+& & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+\section{Slicing}
+
+It is often helpful to `slice' up a circuit for the sake of explaining it step by step. To do this, we provide the \verb!\slice{title}! command, which inserts a dashed vertical line after the column in which the command is added.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \gate{H}\slice{step} & \ctrl{1} & \meter{} \\
+& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
+& \qw & \qw & \targ{} & \qw & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \gate{H}\slice{step} & \ctrl{1} & \meter{} \\
+& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
+& \qw & \qw & \targ{} & \qw & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+You can also slice every step by using option \verb!slice all!, and the labels will be automatically numbered. This is likely to behave strangely unless you explicitly ensure that all rows have the same number of entries (i.e.\ short rows should have extra \& characters added).
+\begin{Code}
+\begin{center}
+\begin{quantikz}[slice all]
+& \gate{H} & \ctrl{1} & \meter{} && \\
+& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
+& \qw & \qw & \targ{} & \qw & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}[slice all]
+& \gate{H} & \ctrl{1} & \meter{} && \\
+& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
+& \qw & \qw & \targ{} & \qw & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+If you need to adjust where the last slice is, use the optional parameter \verb!remove end slices!, which counts the number of columns fewer to add slices to. You can also change the title of each of the slices, by setting \verb!slice titles!. Include the macro \verb!\col! in your specification if you want to use the step number. Note, however, that the columns won't space themselves out to accommodate a very wide label. You can style the slicing lines with the \verb!slice style! key, and the labels with \verb!slice label style!. These can be used to rotate the labels and create a bit more space!
+\begin{Code}
+\begin{center}
+\begin{quantikz}[slice all,remove end slices=1,slice titles=slice \col,slice style=blue,slice label style={inner sep=1pt,anchor=south west,rotate=40}]
+& \gate{H} & \ctrl{1} & \meter{} && \\
+& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
+& \qw & \qw & \targ{} & \qw & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}[slice all,remove end slices=1,slice titles=slice \col,slice style=blue,slice label style={inner sep=1pt,anchor=south west,rotate=40}]
+& \gate{H} & \ctrl{1} & \meter{} && \\
+& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
+& \qw & \qw & \targ{} & \qw & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+\noindent This also gives the possibility to alter spacing if it would otherwise be a bit too tight.
+\begin{Code}
+\begin{center}
+\begin{quantikz}[slice all,slice style={shorten <=-0.1cm,shorten >=-0.1cm},slice label style={yshift=0.1cm}]
+\lstick{$\ket{0}$} & \gate{H} & \phase{\varphi} & \gate{H} & \rstick{$\cos\frac{\varphi}{2}\ket{0}-i\sin\frac{\varphi}{2}\ket{1}$}\qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}[slice all,slice style={shorten <=-0.1cm,shorten >=-0.1cm},slice label style={yshift=0.1cm}]
+\lstick{$\ket{0}$} & \gate{H} & \phase{\varphi} & \gate{H} & \rstick{$\cos\frac{\varphi}{2}\ket{0}-i\sin\frac{\varphi}{2}\ket{1}$}\qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+\noindent If you get compile errors when trying to slice, check the last line of your matrix, and make sure it doesn't end in \textbackslash\textbackslash.
+
+The \verb!vertical slice labels! key reorients the labels as below.
+\begin{Code}
+\begin{center}
+\begin{quantikz}[slice all,remove end slices=1,slice titles=slice \col,vertical slice labels]
+& \gate{H} & \ctrl{1} & \meter{} && \\
+& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
+& \qw & \qw & \targ{} & \qw & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}[slice all,remove end slices=1,slice titles=slice \col,vertical slice labels]
+& \gate{H} & \ctrl{1} & \meter{} && \\
+& \qw & \targ{} & \ctrl{1} & \gate{H} & \qw \\
+& \qw & \qw & \targ{} & \qw & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+\section{Spacing}\label{sec:spacing}
+
+\subsection{Local Adjustment}
+
+There are several different ways in which we can manipulate the spacing of a diagram. Adding space to an individual row or column can be done in the standard way of tables in LaTeX. Here we add 2cm of space to the column between the $H$ and $X$ gates, and 1cm of space between the top two rows.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \gate{H} &[2cm] \gate{X} & \gate{H} & \qw \\[1cm]
+& \gate{X} & \gate{Z} & \gate{Z} &\qw \\
+& \gate{X} & \gate{Z} & \gate{Z} & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \gate{H} &[2cm] \gate{X} & \gate{H} & \qw \\[1cm]
+& \gate{X} & \gate{Z} & \gate{Z} & \qw \\
+& \gate{X} & \gate{Z} & \gate{Z} & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+If you don't know how much space you need, but it should be determined by the size of some text, you can use \verb!\hphantom{}! (widens the gate, in a similar way to \verb!\gate[1cm]{}!) or \verb!\hphantomgate{}! (increases the length of a wire) for horizontal spacing, and \verb!\ghost{}! for vertical spacing.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \gate{X} \hphantom{very wide} & \gate{X} & \hphantomgate{wide}\qw & \gate{X}
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+ & \gate{X} \hphantom{very wide} & \gate{X} & \hphantomgate{wide}\qw & \gate{X}
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+\subsection{Global Adjustment}
+
+Standard tikz commands facilitate a global adjustment of row and column spacing. For example, a ridiculous horizontal spacing:
+\begin{Code}
+\begin{center}
+\begin{quantikz}[column sep=1cm]
+& \gate{H} & \phase{\beta} & \gate{H} & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}[column sep=1cm]
+& \gate{H} & \phase{\beta} & \gate{H} & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+This specifically adjusts the \emph{gap} between the rows and columns, not the distance between the centres of the rows and columns. Depending on what gates you have on each wire, the spacing may not be the same between each wire. Sometimes this is desirable, particularly if a gate in one particular row is much larger than anything in the other rows. At other times, it just makes your diagram look a little odd. For example, look at the gap between the top two wires and the bottom two wires:
+\begin{Code}
+\begin{center}
+\begin{quantikz}[row sep=0.1cm]
+& \gate{X} & \ctrl{1} & \gate{X} & \qw \\
+& \qw & \control{} & \qw & \qw \\
+& \gate{X} & \qw & \qw & \qw \\
+& \gate{H} & \qw & \qw & \qw
+
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}[row sep=0.1cm]
+& \gate{X} & \ctrl{1} & \gate{X} & \qw \\
+& \qw & \control{} & \qw & \qw \\
+& \gate{X} & \qw & \qw & \qw \\
+& \gate{H} & \qw & \qw & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+If you want to make sure that every quantum wire is equally spaced, do the following to \verb!row sep!:
+\begin{Code}
+\begin{center}
+\begin{quantikz}[row sep={0.6cm,between origins}]
+& \gate{X} & \ctrl{1} & \gate{X} & \qw \\
+& \qw & \control{} & \qw & \qw \\
+& \gate{X} & \qw & \qw & \qw \\
+& \gate{H} & \qw & \qw & \qw
+
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}[row sep={0.6cm,between origins}]
+& \gate{X} & \ctrl{1} & \gate{X} & \qw \\
+& \qw & \control{} & \qw & \qw \\
+& \gate{X} & \qw & \qw & \qw \\
+& \gate{H} & \qw & \qw & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+This is particularly useful to achieve alignment of several circuits, as in \ref{sec:align}.
+
+\subsection{Alignment}\label{sec:align}
+
+How do we centre a circuit diagram? Simply surround it with \verb!\begin{center}! and \verb!\end{center}! commands, or within any standard equation environment.
+
+Vertical alignment between different circuits can be more fiddly, depending on how much of a perfectionist you are. Sometimes, they work immediately, but the wires don't always align perfectly with each other. Generally the problem is that the highest gate in each row is different (here, the LHS is missing an $X$ gate on the second row)
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \gate{X} & \ctrl{1} & \qw \\
+& \qw & \targ{} & \qw
+\end{quantikz}
+\begin{quantikz}=\end{quantikz}\begin{quantikz}
+& \ctrl{1} & \gate{X} & \qw \\
+& \targ{} & \gate{X} & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \gate{X} & \ctrl{1} & \qw \\
+& \qw & \targ{} & \qw
+\end{quantikz}
+=\begin{quantikz}
+& \ctrl{1} & \gate{X} & \qw \\
+& \targ{} & \gate{X} & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+\noindent Ensuring an even spacing between rows, as described in Sec.\ \ref{sec:spacing}, can help (but is not always appropriate). Often the easiest is to fudge it using the \verb!\ghost! command which will add a 0-width gate of the height corresponding to its argument. So, having identified the problem with the above circuit, we can replace it with:
+\begin{Code}
+$$
+\begin{quantikz}
+& \gate{X} & \ctrl{1} & \qw \\
+& \ghost{X}\qw & \targ{} & \qw
+\end{quantikz}
+=\begin{quantikz}
+& \ctrl{1} & \gate{X} & \qw \\
+& \targ{} & \gate{X} & \qw
+\end{quantikz}
+$$
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \gate{X} & \ctrl{1} & \qw \\
+& \ghost{X}\qw & \targ{} & \qw
+\end{quantikz}
+=\begin{quantikz}
+& \ctrl{1} & \gate{X} & \qw \\
+& \targ{} & \gate{X} & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+If you cannot identify the offending gate, and particularly if the operation is not a standard \verb!\gate! command, you might be better off combining the two circuits in a single circuit with no wires joining the two parts. The spacing works better if your circuit has an odd number of wires, otherwise you have to add an extra row in the middle, and then change the spacing of that row with its neighbours.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \qw & \ctrl{2} & \qw&&& \ctrl{2} & \gate{Z} & \qw \\[-0.3cm]
+&&&&=&\\[-0.3cm]
+& \gate{Z} & \targ{} & \qw&&& \targ{} & \gate{Z} & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \qw & \ctrl{2} & \qw&&& \ctrl{2} & \gate{Z} & \qw \\[-0.3cm]
+&&&&=&\\[-0.3cm]
+& \gate{Z} & \targ{} & \qw&&& \targ{} & \gate{Z} & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+\subsubsection{Perfecting Vertical Alignment}
+
+If you want total control over vertical alignment between several different circuits, the trick is to use the \verb!baseline! key. All the baselines of different items are placed on the same level. This is particularly helpful if you give certain wires in the circuit a name, and that will let you place the baseline directly on a level with that wire.
+
+To name a wire as `name', place an \verb!\alias{name}! command in any cell which is either empty, or contains a \verb!\qw!, \verb!\cw! or \verb!\push! \emph{only}, and place it before that command\footnote{Alternatively, for any node that accepts tikz styling parameters directly as an option, passing the option \texttt{alias=name} should do.}. That lets you align circuit identities such as
+\begin{Code}
+$$
+\begin{quantikz}[baseline=(W.base)]
+\lstick{\ket{0}} & \qw & \ctrl{1} & \qw \\
+& \gate{H} & \targ{} & \alias{W} \qw
+\end{quantikz}
+\equiv
+\begin{quantikz}[baseline=(W.base)]
+& \gate{H} & \gate{X} & \alias{W} \qw
+\end{quantikz}
+$$
+\tcblower
+\begin{lstlisting}
+$$
+\begin{quantikz}[baseline=(W.base)]
+\lstick{\ket{0}} & \qw & \ctrl{1} & \qw \\
+& \gate{H} & \targ{} & \alias{W} \qw
+\end{quantikz}
+\equiv\begin{quantikz}[baseline=(W.base)]
+& \gate{H} & \gate{X} & \alias{W} \qw
+\end{quantikz}
+$$
+\end{lstlisting}
+\end{Code}
+This has aligned the bottom wire of the first circuit with the wire in the second circuit, making the correspondence more obvious. However, the $\equiv$ sign is now in the wrong place, with its baseline placed at the same point as the baseline of the circuits. We can fix this with a vertical shift of the two diagrams. We demonstrate two different ways of achieving the same effect (the only important feature is that both diagrams have the same shift).
+\begin{Code}
+$$
+\begin{quantikz}[baseline={($(W.base)+0.3*(0,1cm)$)}]
+\lstick{\ket{0}} & \qw & \ctrl{1} & \qw \\
+& \gate{H} & \targ{} & \alias{W} \qw
+\end{quantikz}
+\equiv\begin{quantikz}[baseline={([yshift=0.3cm]new.base)}]
+& \gate{H} & \gate{X} & \alias{new} \qw
+\end{quantikz}
+$$
+\tcblower
+\begin{lstlisting}
+$$
+\begin{quantikz}[baseline={($(W.base)+0.3*(0,1cm)$)}]
+\lstick{\ket{0}} & \qw & \ctrl{1} & \qw \\
+& \gate{H} & \targ{} & \alias{W} \qw
+\end{quantikz}
+\equiv\begin{quantikz}[baseline={([yshift=0.3cm]new.base)}]
+& \gate{H} & \gate{X} & \alias{new} \qw
+\end{quantikz}
+$$
+\end{lstlisting}
+\end{Code}
+
+If you have an even number if wires, you might choose to calculate the centre of the circuit from \verb!current bounding box.center!, or you could perform a calculation to average the position of two wires. This calculation can then be adjusted to take into account the desire to vertically align on the centre of an equals sign rather than the baseline (which is below the bottom of the equals)
+
+\begin{Code}
+$$
+\begin{quantikz}[baseline={($(W.base)!.5!(W2.base) - height("$\vcenter{}$")*(0,1pt)$)}]
+& \gate{X} & \ctrl{1} & \alias{W} \qw \\
+& \ghost{X}\qw & \targ{} & \alias{W2} \qw
+\end{quantikz}
+=\begin{quantikz}[baseline={($(W.base)!.5!(W2.base) - height("$\vcenter{}$")*(0,1pt)$)}]
+& \ctrl{1} & \gate{X} & \qw \\
+& \targ{} & \gate{X} & \qw
+\end{quantikz}
+$$
+\tcblower
+\begin{lstlisting}
+$$
+\begin{quantikz}[baseline={($(W.base)!.5!(W2.base) - height("$\vcenter{}$")*(0,1pt)$)}]
+& \gate{X} & \ctrl{1} & \alias{W} \qw \\
+& \ghost{X}\qw & \targ{} & \alias{W2} \qw
+\end{quantikz}
+=\begin{quantikz}[baseline={($(W.base)!.5!(W2.base) - height("$\vcenter{}$")*(0,1pt)$)}]
+& \ctrl{1} & \gate{X} & \qw \\
+& \targ{} & \gate{X} & \qw
+\end{quantikz}
+$$
+\end{lstlisting}
+\end{Code}
+
+For more details on the possible syntax here, see the \verb!calc! library in tikz.
+
+\subsection{Scaling}
+
+When we altered the spacing, that left all the gate elements, text etc.\ the same size, and just altered the spacing between them. If you want to override the standard size of a circuit (gate elements, text and spacing), you can make it a node inside a \verb!tikzpicture!:
+\begin{Code}
+\begin{center}
+\begin{tikzpicture}
+\node[scale=1.5] {
+\begin{quantikz}
+& \gate{H} & \phase{\beta} & \gate{H} & \qw
+\end{quantikz}
+};
+\end{tikzpicture}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{tikzpicture}
+\node[scale=1.5] {
+\begin{quantikz}
+& \gate{H} & \phase{\beta} & \gate{H} & \qw
+\end{quantikz}
+};
+\end{tikzpicture}
+\end{lstlisting}
+\end{Code}
+It's also possible to rescale to a fixed width, so long as you declare the \verb!adjustbox! package in the document preamble.
+\begin{Code}
+\begin{center}
+\begin{adjustbox}{width=0.8\textwidth}
+\begin{quantikz}
+& \gate{H} & \phase{\beta} & \gate{H} & \qw
+\end{quantikz}
+\end{adjustbox}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{adjustbox}{width=0.8\textwidth}
+\begin{quantikz}
+& \gate{H} & \phase{\beta} & \gate{H} & \qw
+\end{quantikz}
+\end{adjustbox}
+\end{lstlisting}
+\end{Code}
+
+
+\section{Typesetting}
+
+\subsection{Global Styling}
+
+Global properties that affect all circuit elements of a given type can be affected through \verb!tikzset!.
+\begin{Code}
+\begin{center}
+\tikzset{
+ operator/.append style={fill=red!20},
+ my label/.append style={above right,xshift=0.3cm},
+ phase label/.append style={label position=above}
+}
+\begin{quantikz}
+& \gate{H} & \phase{\beta} & \gate{H} & \qw & \meter{$\ket{\pm}$}
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\tikzset{
+ operator/.append style={fill=red!20},
+ my label/.append style={above right,xshift=0.3cm},
+ phase label/.append style={label position=above}
+}
+\begin{quantikz}
+& \gate{H} & \phase{\beta} & \gate{H} & \qw & \meter{$\ket{\pm}$}
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+The global styles are:
+\begin{center}
+\begin{tabular}{c|c}
+Style Name & Affected Command(s) \\
+\hline
+operator & \verb!\gate! \\
+meter & \verb!\meter! \\
+slice & \verb!\slice! \\
+wave & \verb!\wave! \\
+leftinternal & \verb!\gateinput! \\
+rightinternal & \verb!\gateoutput! \\
+dm & left braces (\verb!\gateoutput!,\verb!\lstick!) \\
+dd & right braces (\verb!\gateinput!,\verb!\rstick!) \\
+phase & \verb!\phase!, \verb!\control! \\
+ophase & \verb!\ophase!, \verb!\ocontrol! \\
+circlewc & \verb!\targ! \\
+crossx2 & \verb!\swap!,\verb!\targX! \\
+my label & measurement bases in \verb!\meter! \\
+phase label & phases in \verb!\phase! \\
+gg label & main gate label in \verb!\gate! \\
+group label & label in \verb!\gategroup!
+\end{tabular}
+\end{center}
+
+There are two keys that change styles globally: `thin lines' to make the lines thin, more in keeping with what QCircuit produced
+\begin{Code}
+\begin{center}
+\begin{quantikz}[thin lines]
+& \ctrl{1} & \qw & \ctrl{1} & \qw & \qw \\
+& \targ{} & \gate{R_z(-\theta/2)} & \targ{} & \gate{R_z(\theta/2)} & \meter{}
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}[thin lines]
+& \ctrl{1} & \qw & \ctrl{1} & \qw & \qw \\
+& \targ{} & \gate{R_z(-\theta/2)} & \targ{}
+ & \gate{R_z(\theta/2)} & \meter{}
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+\noindent and `transparent', should you want the background of all the gates to be transparent:
+\begin{Code}
+\begin{center}
+\begin{quantikz}[transparent]
+& \ctrl{1} & \qw & \ctrl{1} & \qw & \qw \\
+& \targ{} & \gate{R_z(-\theta/2)} & \targ{} & \gate{R_z(\theta/2)} & \meter{}
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}[transparent]
+& \ctrl{1} & \qw & \ctrl{1} & \qw & \qw \\
+& \targ{} & \gate{R_z(-\theta/2)} & \targ{}
+ & \gate{R_z(\theta/2)} & \meter{}
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+One place where this might be useful is as a ``pass-through'' on a gate, such as
+\begin{Code}
+\begin{center}
+\begin{quantikz}[transparent]
+& \gate[2]{J_{12}} & \gate[3,label style={yshift=0.2cm}]{J_{13}} & \qw & \qw \\
+& & \linethrough &\gate[2]{J_{23}} & \qw \\
+& \qw &&& \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}[transparent]
+& \gate[2]{J_{12}} & \gate[3,label style={yshift=0.2cm}]{J_{13}} & \qw & \qw \\
+& & \linethrough &\gate[2]{J_{23}} & \qw \\
+& \qw &&& \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+While the \verb!\linethrough! would normally be hidden behind the gate, making the gate transparent leaves the line visible. Then one just has to move the $J_{13}$ label (see next section).
+
+\subsection{Per-Gate Styling}
+
+Individual gates can be modified using optional arguments of the calling function.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \gate[style={fill=red!20},label style=cyan]{H} & \phase[green,label position=above]{\beta} & \gate{H} & \qw & \meter{$\ket{\pm}$}
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \gate[style={fill=red!20},label style=cyan]{H}
+ & \phase[green,label position=above]{\beta}
+ & \gate{H} & \qw & \meter{$\ket{\pm}$}
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+The specific syntax varies a little depending on the type of gate
+\begin{center}
+\begin{tabular}{p{0.4\textwidth}|p{0.4\textwidth}}
+gates that don't accept formatting parameters & \verb!\qw!,\verb!\vqw!,\verb!\qwbundle!,\verb!\cw!,\verb!\vcw!,\verb!\cwbend!,\verb!\push! \\
+\hline
+gates that accept tikz node formatting keys directly in optional argument & \verb!\phase!, \verb!\control!, \verb!\ocontrol!, \verb!\targ!, \verb!\targX!, \verb!\meter!, \verb!\meterD!, \verb!\measure!, \verb!\measuretab!, \verb!\wave! \\
+\hline
+gates that accept node formatting keys as \verb!label style! key in optional argument & \verb!\gate!, \verb!\slice!, \verb!\lstick!, \verb!\rstick!, \verb!\gategroup!, \verb!\gateinput!, \verb!\gateoutput!
+\end{tabular}
+\end{center}
+Those that accept the \verb!label style! key also accept a second key for formatting other elements of the display
+\begin{center}
+\begin{tabular}{c|cc}
+\verb!\gate!,\verb!\gategroup! & \verb!style! & styles the box \\
+\verb!\slice! & \verb!style! & styles the line\\
+\verb!\lstick!,\verb!\rstick!,\verb!\gateinput!,\verb!\gateoutput! & \verb!braces! & styles the brace
+\end{tabular}
+\end{center}
+If you want to input several styling parameters with one of these keys, just group them together in a set of curly braces, \{\}. Typical styling parameters include \verb!draw=! specifying line colour, \verb!fill=!, specifying fill colour, \verb!inner xsep=! and \verb!inner ysep=! specifying horizontal and vertical margins respectively, \verb!xshift=! and \verb!yshift=! for adjusting horizontal and vertical positioning. Beyond that, the \href{http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf}{tikz manual} is your friend!
+
+This styling is really quite flexible, as we can override the default shapes with anything that we want:
+\begin{Code}
+\begin{center}
+\tikzset{
+ group-1-5/.append style={starburst,fill=yellow,draw=red,line width=2pt,inner ysep=-15pt}
+}
+\begin{quantikz}[row sep=0.3cm,column sep=0.3cm]%
+& \gate{H} & \ctrl{2}& \qw & \gate[3,style={starburst,fill=yellow,draw=red,line width=2pt,inner xsep=-4pt,inner ysep=-5pt},label style=cyan]{\text{noise}} & \ctrl{3} & \qw & \qw & \qw\\
+\lstick{$\ket{0}$} & \qw & \targ{} & \qw & \qw & \qw & \ctrl{3} & \qw & \qw \\
+\lstick{$\ket{0}$} & \qw & \targ{}& \qw & \qw & \qw & \qw & \ctrl{2} & \qw\\
+&&&&\lstick{$\ket{0}$} & \targ{} & \targ{} & \qw & \meter{} \\
+&&&&\lstick{$\ket{0}$} & \qw & \targ{} & \targ{} & \meter{}
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}[row sep=0.3cm,column sep=0.3cm]%
+& \gate{H} & \ctrl{2}& \qw &
+ \gate[3,style={starburst,fill=yellow,draw=red,line width=2pt,inner xsep=-4pt,inner ysep=-5pt},
+ label style=cyan]{\text{noise}} & \ctrl{3} & \qw & \qw& \qw\\
+\lstick{$\ket{0}$} & \qw & \targ{} & \qw & \qw & \qw & \ctrl{3} & \qw & \qw \\
+\lstick{$\ket{0}$} & \qw & \targ{}& \qw & \qw & \qw & \qw & \ctrl{2} & \qw\\
+&&&&\lstick{$\ket{0}$} & \targ{} & \targ{} & \qw & \meter{} \\
+&&&&\lstick{$\ket{0}$} & \qw & \targ{} & \targ{} & \meter{}
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+% We can also supplement with standard tikz commands by using the `execute at end picture' key. The cells of the matrix contain nodes called \verb!\tikzcdmatrixname-i-j!, where i is the row number and j is the column number. Thus,
+% \begin{Code}
+% \begin{center}
+% \begin{quantikz}[row sep=0.3cm,column sep=0.3cm,execute at end picture={
+% \node [fit=(\tikzcdmatrixname-1-6)(\tikzcdmatrixname-4-6)(\tikzcdmatrixname-5-9),draw,dashed,inner sep=4pt,label={[yshift=0.3cm]above:syndrome extraction}] {};
+% }]
+% & \gate{H} & \ctrl{2}& \qw & \gate[3,style={starburst,fill=yellow,draw=red,line width=2pt,inner xsep=-4pt,inner ysep=-5pt}]{\text{noise}} & \ctrl{3} & \qw & \qw& \qw\\
+% \lstick{$\ket{0}$} & \qw & \targ{} & \qw & \qw & \qw & \ctrl{3} & \qw & \qw \\
+% \lstick{$\ket{0}$} & \qw & \targ{}& \qw & \qw & \qw & \qw & \ctrl{2} & \qw\\
+% &&&&\lstick{$\ket{0}$} & \targ{} & \targ{} & \qw & \meter{} \\
+% &&&&\lstick{$\ket{0}$} & \qw & \targ{} & \targ{} & \meter{}
+% \end{quantikz}
+% \end{center}
+% \tcblower
+% \begin{lstlisting}
+% \begin{quantikz}[row sep=0.3cm,column sep=0.3cm,execute at end picture={
+% \node [fit=(\tikzcdmatrixname-1-6)(\tikzcdmatrixname-4-6)(\tikzcdmatrixname-5-9),draw,dashed,inner sep=4pt,label={[yshift=0.3cm]above:syndrome extraction}] {};
+% }]
+% & \gate{H} & \ctrl{2}& \qw & \gate[3,style={starburst,fill=yellow,draw=red,line width=2pt,inner xsep=-4pt,inner ysep=-5pt}]{\text{noise}} & \ctrl{3} & \qw & \qw& \qw\\
+% \lstick{$\ket{0}$} & \qw & \targ{} & \qw & \qw & \qw & \ctrl{3} & \qw & \qw \\
+% \lstick{$\ket{0}$} & \qw & \targ{}& \qw & \qw & \qw & \qw & \ctrl{2} & \qw\\
+% &&&&\lstick{$\ket{0}$} & \targ{} & \targ{} & \qw & \meter{} \\
+% &&&&\lstick{$\ket{0}$} & \qw & \targ{} & \targ{} & \meter{}
+% \end{quantikz}
+% \end{lstlisting}
+% \end{Code}
+
+\subsection{Boxing/Highlighting Parts of a Circuit}\label{sec:boxing}
+
+It is often useful to highlight parts of a circuit. We do this with the \verb!\gategroup! command. The optional parameters \verb!wires! (again, the default) and \verb!steps! specify the number of rows and columns that the group spans respectively. The mandatory argument is the label for the box (although this can be empty). The top-left corner of the box coincides with the cell in which the command is placed.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \gate{H} & \ctrl{1} & \gate{H}\gategroup[wires=2,steps=3,style={inner sep=6pt}]{reversed c-{\sc not}} & \ctrl{1} & \gate{H} & \ctrl{1} & \qw & \qw \\
+& \qw & \targ{} & \gate{H} & \targ{} & \gate{H} & \targ{} & \gate{H} & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \gate{H} & \ctrl{1} & \gate{H}\gategroup[wires=2,steps=3,style={inner sep=6pt}]{reversed c-{\sc not}} & \ctrl{1} & \gate{H} & \ctrl{1} & \qw & \qw \\
+& \qw & \targ{} & \gate{H} & \targ{} & \gate{H} & \targ{} & \gate{H} & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+By default, this box is drawn on top of the circuit itself. If you want it to be behind (for example, should you want it to have a background colour), then use the \verb!background! option.
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \gate{H} & \ctrl{1}\gategroup[2,steps=3,style={dashed,rounded corners,fill=blue!20, inner xsep=2pt},background]{{\sc swap}} & \targ{} & \ctrl{1} & \qw & \qw \\
+& \qw & \targ{} & \ctrl{-1} & \targ{} & \gate{H} & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \gate{H} & \ctrl{1}\gategroup[2,steps=3,style={dashed,rounded corners,fill=blue!20, inner xsep=2pt},background]{{\sc swap}} & \targ{} & \ctrl{1} & \qw & \qw \\
+& \qw & \targ{} & \ctrl{-1} & \targ{} & \gate{H} & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+The \verb!label style! key can be used to tune the label's properties, including positioning. For example,
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \gate{H} & \ctrl{1}\gategroup[2,steps=3,style={dashed,rounded corners,fill=blue!20, inner xsep=2pt},background,label style={label position=below,anchor=north,yshift=-0.2cm}]{{\sc swap}} & \targ{} & \ctrl{1} & \qw & \qw \\
+& \qw & \targ{} & \ctrl{-1} & \targ{} & \gate{H} & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \gate{H} & \ctrl{1}\gategroup[2,steps=3,style={dashed,rounded corners,fill=blue!20, inner xsep=2pt},background,label style={label position=below,anchor=north,yshift=-0.2cm}]{{\sc swap}} & \targ{} & \ctrl{1} & \qw & \qw \\
+& \qw & \targ{} & \ctrl{-1} & \targ{} & \gate{H} & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+Note that it is often good to use \verb!anchor=mid! for label anchors because if you have multiple labels, this will help get them horizontally aligned. It just means you have to use some \verb!yshift! to move the label off the border around the gategroup.
+
+
+At this point, we mention an extra option for the gate command. The \verb!swap! keyword turns the gate into a variant of a {\sc swap} gate which explicitly shows the wires (the \verb!wires! setting is fixed to 2, overriding any value you might supply).
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \gate{H} & \gate[swap]{} & \qw & \qw \\
+& \qw & & \gate{H} & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \gate{H} & \gate[swap]{} & \qw & \qw \\
+& \qw & & \gate{H} & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+%\noindent Here the \texttt{fullwidth} command is helpful for getting the symmetry of the swap gate correct in terms of how much goes above the top wire, and how much below the bottom wire.
+\section{Otherwise Undocumented Features}
+A wave for separating rows. Do we really need this? Perhaps not, but it's fun!
+\begin{Code}
+\begin{center}
+\begin{quantikz}
+& \gate{H} & \ctrl{3} & \ \ldots\ \qw & \qw & \gate{H} & \qw \\
+\wave&&&&&&\\
+& \gate{H} & \qw & \ \ldots\ \qw & \ctrl{1} & \gate{H} & \qw \\
+& \qw & \gate{U} & \ \ldots\ \qw & \gate{U^k} & \qw & \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}
+& \gate{H} & \ctrl{3} & \ \ldots\ \qw & \qw & \gate{H} & \qw \\
+\wave&&&&&&\\
+& \gate{H} & \qw & \ \ldots\ \qw & \ctrl{1} & \gate{H} & \qw \\
+& \qw & \gate{U} & \ \ldots\ \qw & \gate{U^k} & \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+
+\section{Converting from QCircuit}
+
+I've updated all of my existing teaching materials from QCircuit to Quantikz with very little trouble. There are a few standard replacements:
+\begin{center}
+\begin{tabular}{c|c}
+QCircuit notation & Quantikz notation \\
+\hline
+\verb!\QCircuit @C=n @R=m {#}! & \verb!\begin{quantikz}[row sep=m,col sep=n]#\end{quantikz}! \\
+\verb!\multigate{n}! & \verb!\gate[n+1]! \\
+\verb!\targ! & \verb!\targ{}! \\
+\verb!\control! & \verb!\control{}! \\
+\verb!\meter! & \verb!\meter{}! \\
+\verb!\measureD! & \verb!\meterD{}! \\
+\end{tabular}
+\end{center}
+Updating the \verb!\gategroup! command requires a little more care since the first two arguments have to be removed, and the command placed in the correct cell, at which point \verb!\gategroup{i}{j}{k}{l}{m}! becomes \verb!\gategroup[wires=k+1-i,steps=l+1-j]!. My primary use of gategroup was to achieve the effect now achieved with \verb!\lstick[k+1-i]!.
+
+It should not be necessary to use \verb!\ghost! commands in the way they were used in QCircuit. The \verb!\cghost! and \verb!\nghost! commands have been replaced by option keys for the gate command, \verb!cwires! and \verb!nwires! respectively.
+
+\section{Troubleshooting}\label{sec:trouble}
+\begin{itemize}
+\item Have you checked that all commands that need them are followed by an empty argument, \{\}? Things like \verb!meter!, \verb!\control! (basically, those that can accept an optional styling parameter) look like they don't take any parameters, but they have to be followed by the pair of braces or you'll get very odd effects.
+\item If you get a whole bunch of unexpected text in one of your cells instead of a gate, make sure that the gate command is the first command in the cell, and that other commands (such as \verb!\qwbundle!) appear after.
+\item If you're getting errors about cells not being found (and especially if you're doing any slicing), check that your last row doesn't end with \textbackslash\textbackslash, and make sure that your last row contains as many cells (even if they're empty) as there are columns in the circuit.
+\item If you are trying to typeset your circuit inside some sort of tabular or align environment and are getting an error ``single ampersand used with wrong catcode'', trying adding the \verb![ampersand replacement=\&]! option to tikzcd, and instead of separating every cell by \&, use \textbackslash\&. This can also be useful if you want to insert a normal matrix as a gate
+\begin{Code}
+\begin{center}
+\begin{quantikz}[ampersand replacement=\&]
+\lstick{$\ket{0}$} \& \gate{\left(\begin{array}{cc} \alpha & \beta \\ \beta & -\alpha \end{array}\right)} \& \ctrl{1} \& \gate{U_1} \& \qw \\
+\lstick{$\ket{0}$} \& \qw \& \targ{} \& \gate{U_2} \& \qw
+\end{quantikz}
+\end{center}
+\tcblower
+\begin{lstlisting}
+\begin{quantikz}[ampersand replacement=\&]
+\lstick{$\ket{0}$} \& \gate{\left(\begin{array}{cc} \alpha & \beta \\ \beta & -\alpha \end{array}\right)} \& \ctrl{1} \& \gate{U_1} \& \qw \\
+\lstick{$\ket{0}$} \& \qw \& \targ{} \& \gate{U_2} \& \qw
+\end{quantikz}
+\end{lstlisting}
+\end{Code}
+Beamer is particularly annoying with doing this. It probably helps to issue a global command
+\begin{lstlisting}
+\tikzcdset{
+ every matrix/.style={ampersand replacement=\&}
+}
+\end{lstlisting}
+Beamer is particularly annoying with doing this. It probably helps to issue a global command
+\begin{lstlisting}
+\tikzcdset{
+ every matrix/.style={ampersand replacement=\&}
+}
+\end{lstlisting}
+somewhere in your document preamble. The tikzcd manual suggests another possible strategy, but I haven't had much success with it.
+\item If you have a \verb!\cwbend! in the bottom right cell of the matrix, sometimes you get an error (I have no understanding of why). Add an extra \& after, and all seems to be well.
+\item If you're using transparency, and the width of gates seems to be greater than you expected, it may be worthwhile removing the .aux file and recompiling. If your tex editor isn't good at resetting the .aux file, the system may be remembering older widths.
+\item The code provides definitions for \verb!\bra!, \verb!\ket!, \verb!\proj!, \verb!\braket!. If you don't like them, just define your own versions \emph{before} you load the quantikz library.
+\end{itemize}
+
+For any bug reports (please make sure you've checked the above list first!) or feature requests, please contact alastair.kay@rhul.ac.uk.
+
+\section{Citation}
+
+If you found this package useful, please consider citing the arXiv version of this document, arXiv:1809.03842.
+
+
+\end{document} \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/quantikz/tikzlibraryquantikz.code.tex b/Master/texmf-dist/tex/latex/quantikz/tikzlibraryquantikz.code.tex
index 7d6a96319a4..f2c15ced5be 100644
--- a/Master/texmf-dist/tex/latex/quantikz/tikzlibraryquantikz.code.tex
+++ b/Master/texmf-dist/tex/latex/quantikz/tikzlibraryquantikz.code.tex
@@ -1,9 +1,22 @@
-%This is the quantikz library for typesetting quantum circuits using LaTeX/Tikz. version 0.9.1
-%Written by Alastair Kay, 2018. Published under a CC-BY-4.0 licence
-% Please email me with any bug reports or feature requests.
-%If you find this library useful, please cite its usage in your work,using the DOI: 10.17637/rh.7000520.
+%This is the quantikz library for typesetting quantum circuits using LaTeX/Tikz. version 0.9.4
+% Written by Alastair Kay, 2018. Published under a CC-BY-4.0 licence
+% Please email me (alastair.kay@rhul.ac.uk) with any bug reports or feature requests.
+% If you find this library useful, please cite its usage in your work, using arXiv:1809.03842, and possibly the DOI: 10.17637/rh.7000520.
% Usage is at your own risk.
+%version 0.9.4:
+% added nwires and cwires options to gate command to simulate qcircuit's nphantom and cphantom
+% vertical text options for slice labels.
+% replaced macro for measuring width and height for greater reliability. disable auto spacing now unnecessary as things like \sqrt{} work in the gate label.
+% investigated possibility of high labels (multi-line labels, particularly for a multi-qubit gate). key disable auto height introduced.
+% now provides a quantikz environment, which is theoretically compatible with tikz' external library (entirely untested). Can still use tikzcd environment otherwise.
+% removed a tikzcd customisation fixing the baseline for one row circuits as this was messing with any manual attempts to adjust the baseline.
+%version 0.9.3:
+% adjusted spacing of gate operation between in-circuit and overlay so that transparency looks better
+% Other gate spacing adjustments. multi-qubit gates in particular should look better. 'disable auto spacing' can switch this off, particularly for use with things like \sqrt{} in the multi-qubit gate label, which will throw a weird error.
+% gate command now takes two further optional parameters: minimum width and minimum height for each cell.
+% some consolidation of styling commands
+% global keys 'transparent' and 'thin lines' added. 'thin lines' gives a look more similar to the original QCircuit.
%version 0.9.2:
% made 'wires' the default key, so [wires=2] now becomes [2]
% added 'slice title', 'slices style', 'slices label style' key to control titles of slices under 'slice all'
@@ -17,14 +30,19 @@
%version 0.9.0:
%original release.
+\ProvidesPackage{quantikz}[2019/03/18 typeset quantum circuit diagrams]
% Package(s) to include
-\RequirePackage{xargs,ifthen,xstring,xparse,etoolbox}
+\RequirePackage{xargs,ifthen,xstring,xparse,etoolbox,mathtools}
+\RequirePackage{environ} %in an attempt to help with compatibility with the external library of tikz.
\RequirePackage{tikz}
-%\RequirePackage{pgffor,pgfmath}
\usetikzlibrary{cd,decorations.pathreplacing,calc,positioning,fit,shapes.symbols,decorations.pathmorphing,shapes.misc,backgrounds,decorations.markings}
-\makeatletter
+\newlength{\myl}
+\newlength{\myh}
+\newlength{\myd}
+
+%\makeatletter
\newcounter{aaa}
\tikzset{
apply/.style args={#1 except on segments #2}{postaction={
@@ -58,37 +76,123 @@
},
},
}
+%test if item is in list of item. Probably better ways to do this, but I could get this version to work.
+\newcommand*{\IfInList}[2]{%
+ \gdef\memory{0}
+ \edef\arg{#1}
+ \foreach \q in #2 {%
+ \ifthenelse{\q=\arg}{%
+ \gdef\memory{1}
+ }{}
+ }
+ \ifthenelse{\memory=1} {%
+ \expandafter\@firstoftwo
+ }{%
+ \expandafter\@secondoftwo
+ }
+}
+%define the quantikz environment. I need this to facilitate the external library
+\NewEnviron{quantikz}[1][]{%
+ \def\@temp{\tikzcd@[#1]\BODY}%
+ \expandafter\@temp\endtikzcd
+}
+\def\temp{&} \catcode`&=\active \let&=\temp
+
+%commands for putting in text vertically
+\protected\def\vvv#1{\leavevmode\bgroup\vbox\bgroup\xvvv#1\relax}
+
+\def\xvvv{\afterassignment\xxvvv\let\tmp= }
+
+\def\xxvvv{%
+% \ifx\tmp\@sptoken\egroup\ \vbox\bgroup\let\next\xvvv
+% \else
+\ifx\tmp\relax\egroup\egroup\let\next\relax
+ \else
+\hbox to 1.1em{\hfill\tmp\hfill}% centred
+\let\next\xvvv\fi%\fi
+\next}
+%end of commands for putting text vertically
\long\def\ifnodedefined#1#2#3{%
\@ifundefined{pgf@sh@ns@#1}{#3}{#2}%
}
+%I don't think this is used any more
+% \newcommand\getwidth[1]{
+% \pgfkeys{minimum width=0pt}%
+% \pgfkeys{/quantikz,#1}
+% \pgfkeysgetvalue{/quantikz/minimum width}{\minwidth}
+% \minwidth
+% }
%the main gate command
-\newcommand\gate[2][]{%optional parameter contains styling info. compulsory is gate text.
- \def\toswap{0}
- \edef\options{row=\the\pgfmatrixcurrentrow,col=\the\pgfmatrixcurrentcolumn,#1}
- \pgfkeys{/quantikz,wires=1,style=,label style=,braces=}
+\DeclareExpandableDocumentCommand{\gate}{O{}O{1.5pt}O{1.5pt}m}{%optional parameter contains styling info. compulsory is gate text.
+ |[inner sep=4pt,minimum width=#2,minimum height=#3]|
+ \edef\n{\the\pgfmatrixcurrentrow} %the row
+ \edef\m{\the\pgfmatrixcurrentcolumn} %the column
+ %resent macros that are going to be set by the options
+ \edef\options{row=\n,col=\m,#1}
+ \def\toswap{0}%
+ \def\DisableMinSize{0}%
+ \pgfkeys{/quantikz,wires=1,style=,label style=,braces=}%
+ %import options passed as parameters
\pgfkeys{/quantikz,#1}%
\pgfkeysgetvalue{/quantikz/wires}{\quantwires}
\pgfkeysgetvalue{/quantikz/style}{\a}
\pgfkeysgetvalue{/quantikz/label style}{\b}
- \edef\n{\the\pgfmatrixcurrentrow}
- \edef\m{\the\pgfmatrixcurrentcolumn}
- \ifthenelse{\toswap=1}{\def\quantwires{2}\phantom{wide}}{\phantom{#2}}
+ \pgfkeysgetvalue{/quantikz/cwires}{\mylist}
+ \pgfkeysgetvalue{/quantikz/nwires}{\nowires}
+ \ifthenelse{\toswap=1}{%if it's a swap gate...
+ \def\quantwires{2}
+ \phantom{wide}
+ \settowidth{\myl}{$wide$}
+ \settoheight{\myh}{$wide$}
+ \settodepth{\myd}{$wide$}
+ }{%not a swap gate
+ \settowidth{\myl}{$#4$}
+ \ifthenelse{\DisableMinSize=1}{%disable automatic size detection. Use $U$ instead.
+ \phantom{U}
+ \settoheight{\myh}{$U$}
+ \settodepth{\myd}{$U$}
+ }{%automatically get width and height of label
+ \phantom{#4}
+ \settoheight{\myh}{$#4$}
+ \settodepth{\myd}{$#4$}
+ }
+ }
+%
+ \IfInList{1}{\mylist}{\cw}{\IfInList{1}{\nowires}{}{\qw}}%do we need classical, no wire, or quantum wire?
\edef\k{\the\numexpr\n+\quantwires-1\relax}
- \foreach \i in {\n,...,\k} {
- \edef\from{\i-\m}
- \edef\to{\i-\the\numexpr\m-1\relax}
- \expandafter\expandafter\expandafter\vqwexplicit\expandafter\expandafter\expandafter{\expandafter\from\expandafter}\expandafter{\to}
+ \edef\mn{\the\numexpr\m-1\relax}
+ \ifthenelse{\quantwires=1}{}{%more than 1 wire on gate. iterate through each wire
+ \foreach \i in {\the\numexpr\n+1\relax,...,\k} {
+ \edef\newcom{\noexpand\vcwhexplicit{\i-\m}{\i-\mn}}
+ \edef\newcomb{\noexpand\vqwexplicit{\i-\m}{\i-\mn}}
+ \edef\val{\the\numexpr\i+1-\n\relax}
+ \IfInList{\val}{\mylist}{\newcom}{\IfInList{\val}{\nowires}{}{\newcomb}}%do we need classical, no wire, or quantum wire?
+ %apply auto width to the cell, and make sure we unset the setting so that it doesn't apply to later circuits.
+ \globaldefs=1
+ \edef\dotikzset{\noexpand\tikzset{row \i\space column \m/.append style={minimum width={max(\the\myl+8pt,#2)}}}}
+ \dotikzset
+ \edef\undotikzset{\noexpand\tikzset{row \i\space column \m/.style={}}}
+ \expandafter\pgfutil@g@addto@macro\expandafter\tikzcd@atendglobals\expandafter{\undotikzset}
+ }
+ %apply auto height to last row only. unsetting already handled above.
+ \globaldefs=1
+ \edef\dotikzset{\noexpand\tikzset{row \k\space column \m/.append style={minimum height={max(\the\myh+\the\myd+8pt,#3)}}}}
+ \dotikzset
+
}
+ %call deferred gate command.
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\pgfutil@g@addto@macro\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\tikzcd@atendsavedpaths\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter{%
- \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\gate@end\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter\a\expandafter\expandafter\expandafter}\expandafter\expandafter\expandafter{\expandafter\b\expandafter}\expandafter{\options}{#2}
+ \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\gate@end\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter\a\expandafter\expandafter\expandafter}\expandafter\expandafter\expandafter{\expandafter\b\expandafter}\expandafter{\options}{#4}
}
}
-%deferred gate command
+
+%deferred gate command. draws a box around all included cells. this is not part of the matrix, but comes afterwards.
\newcommand{\gate@end}[4]{
\pgfkeys{/quantikz,wires=1}
\def\toswap{0}
+ \def\DisableMinSize{0}
\pgfkeys{/quantikz,#3}%
\pgfkeysgetvalue{/quantikz/wires}{\quantwires}
\pgfkeysgetvalue{/quantikz/row}{\row}
@@ -101,15 +205,20 @@
}{}
}
\ifthenelse{\toswap=1}{
- \node (group\tikzcdmatrixname-\row-\col) [fit=\LoopGG,operator,inner xsep=3pt,inner ysep=5pt,#1] {\hphantom{wide}};
- \draw [thick] (group\tikzcdmatrixname-\row-\col.west|-\tikzcdmatrixname-\row-\col.center) to[out=0,in=180] (group\tikzcdmatrixname-\row-\col.east|-\tikzcdmatrixname-\the\numexpr\row+1\relax-\col.center);
+ \node (group\tikzcdmatrixname-\row-\col) [fit=\LoopGG,operator,inner sep=0pt,#1] {\hphantom{Wide}};
+ \draw [thickness] (group\tikzcdmatrixname-\row-\col.west|-\tikzcdmatrixname-\row-\col.center) to[out=0,in=180] (group\tikzcdmatrixname-\row-\col.east|-\tikzcdmatrixname-\the\numexpr\row+1\relax-\col.center);
\draw [line width=3pt,white,shorten >=0.9pt,shorten <=0.9pt] (group\tikzcdmatrixname-\row-\col.east|-\tikzcdmatrixname-\row-\col.center) to[out=180,in=0] (group\tikzcdmatrixname-\row-\col.west|-\tikzcdmatrixname-\the\numexpr\row+1\relax-\col.center);
- \draw [thick] (group\tikzcdmatrixname-\row-\col.east|-\tikzcdmatrixname-\row-\col.center) to[out=180,in=0] (group\tikzcdmatrixname-\row-\col.west|-\tikzcdmatrixname-\the\numexpr\row+1\relax-\col.center);
+ \draw [thickness] (group\tikzcdmatrixname-\row-\col.east|-\tikzcdmatrixname-\row-\col.center) to[out=180,in=0] (group\tikzcdmatrixname-\row-\col.west|-\tikzcdmatrixname-\the\numexpr\row+1\relax-\col.center);
}{
- \node (group\tikzcdmatrixname-\row-\col) [fit=\LoopGG,operator,inner xsep=3pt,inner ysep=5pt,label={[gg label,#2]$#4$},#1] {\hphantom{$#4$}};
+ \node (group\tikzcdmatrixname-\row-\col) [fit=\LoopGG,operator,inner sep=0pt,label={[gg label,#2]$#4$},#1] {\hphantom{$#4$}};
}
}
+%ghost will get height correct if can't be automatically assigned.
+\DeclareExpandableDocumentCommand{\ghost}{O{}O{0pt}O{1.5pt}m}{%optional parameter contains styling info. compulsory is gate text.
+ |[inner ysep=4pt,minimum width=#2,minimum height=#3]| \vphantom{#4}
+}
+
%single slice
\newcommand\slice[2][]{%
@@ -134,11 +243,21 @@
}
%deferred command which will slice everything
\newcommand{\sliceallr}{
+ \edef\sstyle{\pgfkeysvalueof{/tikz/slice style}}
+ \edef\slstyle{\pgfkeysvalueof{/tikz/slice label style}}
\foreach \n in {2,...,\the\numexpr\pgfmatrixcurrentcolumn-1-\pgfkeysvalueof{/tikz/remove end slices}\relax} {
\edef\col{\the\numexpr\n-1\relax}
\edef\title{\pgfkeysvalueof{/tikz/slice titles}}
- \edef\sstyle{\pgfkeysvalueof{/tikz/slice style}}
- \edef\slstyle{\pgfkeysvalueof{/tikz/slice label style}}
+ \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\slice@end\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter\n\expandafter\expandafter\expandafter}\expandafter\expandafter\expandafter{\expandafter\sstyle\expandafter}\expandafter{\slstyle}{\title}
+ }
+}
+%deferred slice command with vertical text
+\newcommand{\sliceallvr}{
+ \edef\sstyle{\pgfkeysvalueof{/tikz/slice style}}
+ \edef\slstyle{\pgfkeysvalueof{/tikz/slice label style}}
+ \foreach \n in {2,...,\the\numexpr\pgfmatrixcurrentcolumn-1-\pgfkeysvalueof{/tikz/remove end slices}\relax} {
+ \edef\col{\the\numexpr\n-1\relax}
+ \edef\title{\vvv{\pgfkeysvalueof{/tikz/slice titles}}}
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\slice@end\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter\n\expandafter\expandafter\expandafter}\expandafter\expandafter\expandafter{\expandafter\sstyle\expandafter}\expandafter{\slstyle}{\title}
}
}
@@ -288,7 +407,7 @@
\node (wave-#1) [fit=(\tikzcdmatrixname-row#1),wave,#2] {};
}
-
+%put a border around a group of gates
\newcommand\gategroup[2][]{%
\pgfkeys{/quantikz,wires=1,style=,label style=,braces=}
\pgfkeys{/quantikz,#1}%
@@ -299,7 +418,7 @@
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\gategroup@end\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter\newoptions\expandafter\expandafter\expandafter}\expandafter\expandafter\expandafter{\expandafter\options\expandafter}\expandafter{\opts}{#2}%
}
}
-
+%deferred gate group command
\newcommand{\gategroup@end}[4]{%options, gate style, text style, text
\pgfkeys{/quantikz,wires=1,style=,label style=,braces=,steps=1}%
\edef\background{0}%
@@ -310,9 +429,9 @@
\pgfkeysgetvalue{/quantikz/steps}{\steps}%
\edef\fit{(\tikzcdmatrixname-col\col.west |- \tikzcdmatrixname-row\row.north)(\tikzcdmatrixname-col\the\numexpr\col+\steps-1\relax.east |- \tikzcdmatrixname-row\the\numexpr\row+\quantwires-1\relax.south)}%
\ifthenelse{\background=1}{%
- \begin{scope}[on background layer]\node (ggroup-\row-\col) [fit=\fit,draw,inner sep=4pt,thick,label={[group label,#3]:#4},#2] {};\end{scope}
+ \begin{scope}[on background layer]\node (ggroup-\row-\col) [fit=\fit,ggroup,label={[group label,#3]:#4},#2] {};\end{scope}
}{%
- \node (ggroup-\row-\col) [fit=\fit,draw,inner sep=4pt, thick,label={[group label,#3]:#4},#2] {};
+ \node (ggroup-\row-\col) [fit=\fit,ggroup,label={[group label,#3]:#4},#2] {};
}
}
@@ -329,23 +448,23 @@
\node [phase,inner sep=2pt] at (\tikzcdmatrixname-#1) {};
}
-
%patch tikzcd to allow for multiple layers of commands
-\patchcmd\tikzcd@{\tikzpicture}{\def\toslice{0}
- \tikzpicture}{}{}
+\patchcmd\tikzcd@{\tikzpicture}{\def\toslice{0}\def\vert{0}
+ \begin{tikzpicture}}{}{}
\patchcmd\tikzcd@
{\global\let\tikzcd@savedpaths\pgfutil@empty}
{\global\let\tikzcd@savedpaths\pgfutil@empty
\global\let\tikzcd@atendsavedpaths\pgfutil@empty
\global\let\tikzcd@atendlabels\pgfutil@empty
\global\let\tikzcd@atendslices\pgfutil@empty
+ \global\let\tikzcd@atendglobals\pgfutil@empty
\pgfutil@g@addto@macro\tikzcd@savedpaths\DivideRowsCols
%\pgfmathsetmacro{\mname}{random(100000)}
- \ifthenelse{\toslice=1}{\pgfutil@g@addto@macro\tikzcd@atendslices\sliceallr}{}
+ \ifthenelse{\toslice=1}{\ifthenelse{\vert=0}{\pgfutil@g@addto@macro\tikzcd@atendslices\sliceallr}{\pgfutil@g@addto@macro\tikzcd@atendslices\sliceallvr}}{}
}{}{}
%this patching works on modern systems, but I believe is incompatible with the old version that arXiv is running
-%\patchcmd\endtikzcd{\tikzcd@savedpaths}{\tikzcd@savedpaths\tikzcd@atendsavedpaths\tikzcd@atendlabels\tikzcd@atendslices}{}{}
+%\patchcmd\endtikzcd{\tikzcd@savedpaths}{\tikzcd@savedpaths\tikzcd@atendsavedpaths\tikzcd@atendlabels\tikzcd@atendslices{\globaldefs=1\tikzcd@atendglobals}}{}{}
%instead, completely redefine the function
\def\endtikzcd{%
@@ -363,14 +482,14 @@
\def\errmessage##1{\tikzcd@errmessage{##1^^J...^^Jl.\tikzcd@lineno\space%
I think the culprit is a tikzcd arrow in cell \tikzcd@currentrow-\tikzcd@currentcolumn}}%
\tikzcd@before@paths@hook%
- \tikzcd@savedpaths\tikzcd@atendsavedpaths\tikzcd@atendlabels\tikzcd@atendslices%I just added stuff here instead
+ \tikzcd@savedpaths\tikzcd@atendsavedpaths\tikzcd@atendlabels\tikzcd@atendslices{\globaldefs=1\tikzcd@atendglobals}%I just added stuff here instead
\endgroup%
- \endtikzpicture%
+ \end{tikzpicture}%
\ifnum0=`{}\fi}
%end patching
-\makeatother
+%\makeatother
%this command runs after we've finished the matrix, and makes unified cells for each row and each column. This allows much nicer alignment of large boxes.
\newcommand{\DivideRowsCols}{
@@ -402,30 +521,31 @@
%initialise all the pgfkeys for key=value parametre passing in macro options
-\pgfkeys{/tikz/slice all/.code={\def\toslice{1}},/tikz/remove end slices/.initial=0,/tikz/slice titles/.initial={\col},/tikz/slice style/.initial={},/tikz/slice label style/.initial={}}
+\pgfkeys{/tikz/slice all/.code={\def\toslice{1}},/tikz/remove end slices/.initial=0,/tikz/slice titles/.initial={\col},/tikz/slice style/.initial={},/tikz/slice label style/.initial={},/tikz/thin lines/.code={\resetstyles},/tikz/transparent/.code={\maketransparent},/tikz/vertical slice labels/.code={\def\vert{1}}}
\pgfkeys{/quantikz/.is family,/quantikz,%
.unknown/.style={%
/quantikz/wires=\pgfkeyscurrentname
},%
wires/.initial=1,%
-style/.initial={},label style/.initial={},braces/.initial={},background/.code={\def\background{1}},alternate/.code={\def\helper{1}},row/.initial=1,col/.initial=1,steps/.initial=1,Strike Width/.initial=0.08cm,Strike Height/.initial=0.12cm,swap/.code={\def\toswap{1}}}
-%\pgfkeys{/quantikz/.unknown/.style={/tikz}}
-%\pgfkeys{/tikz/background/.style={},/tikz/wires/.style={}}
+style/.initial={},label style/.initial={},braces/.initial={},background/.code={\def\background{1}},alternate/.code={\def\helper{1}},row/.initial=1,col/.initial=1,steps/.initial=1,Strike Width/.initial=0.08cm,Strike Height/.initial=0.12cm,swap/.code={\def\toswap{1}},disable auto height/.code={\def\DisableMinSize{1}},cwires/.initial={-1},nwires/.initial={-1}}
-%Define some useful commands
-\providecommand{\ket}[1]{\ensuremath{\left | #1 \right\rangle}}
-\providecommand{\bra}[1]{\ensuremath{\left \langle #1 \right |}}
-\providecommand{\proj}[1]{\ket{#1}\bra{#1}}
+%my standard Dirac notation commands. can be overridden by user.
+\providecommand{\ket}[1]{\ensuremath{\left|#1\right\rangle}}
+\providecommand{\bra}[1]{\ensuremath{\left\langle#1\right |}}
+\providecommand{\proj}[1]{\ensuremath{\ket{#1}\!\bra{#1}}}
+\providecommand{\braket}[2]{\ensuremath{\left\langle#1\middle|#2\right\rangle}}
%single qubit operations
-\newcommand{\phantomgate}[1]{|[linecont,thick, inner ysep=3pt]| \phantom{#1} \qw}
-\newcommand{\hphantomgate}[1]{|[linecont,minimum size=1.5em,thick]| \hphantom{#1} \qw}
+\newcommand{\phantomgate}[1]{|[linecont,thickness, inner ysep=3pt]| \phantom{#1} \qw}
+\newcommand{\hphantomgate}[1]{|[linecont,minimum size=1.5em,thickness]| \hphantom{#1} \qw}
\newcommand{\push}[1]{#1 \qw}
-\DeclareExpandableDocumentCommand{\phase}{O{}m}{|[phase,label={[phase label]#2},#1]| {} \qw}
+\newcommand{\alias}[1]{|[alias=#1]|}
+\DeclareExpandableDocumentCommand{\phase}{O{}m}{|[phase,#1,label={[phase label,#1]#2}]| {} \qw}
\DeclareExpandableDocumentCommand{\control}{O{}m}{|[phase,#1]| {} \qw}
\DeclareExpandableDocumentCommand{\ocontrol}{O{}m}{|[ophase,#1]| {} \qw}
\DeclareExpandableDocumentCommand{\targ}{O{}m}{|[circlewc,#1]| {} \qw}
\DeclareExpandableDocumentCommand{\targX}{O{}m}{|[crossx2,#1]| {} \qw}
+\newcommand{\linethrough}{|[linecont, inner ysep=3pt]| }
%measuring
\DeclareExpandableDocumentCommand{\meter}{O{}{m}}{|[meter,label={[my label]#2},#1]| {} \qw}
@@ -458,64 +578,75 @@ style/.initial={},label style/.initial={},braces/.initial={},background/.code={\
}
%quantum wire, absolute positioning
\newcommand{\vqwexplicit}[2]{
- \arrow[from=#1,to=#2,dash,thick] {}
+ \arrow[from=#1,to=#2,arrows] {}
}
+%classical vertical wire, absolute positioning
\newcommand{\vcwexplicit}[2]{
- \arrow[from=#1,to=#2,dash,thick,xshift=0.05cm] {}\arrow[from=#1,to=#2,dash,thick,xshift=-0.05cm] {}
+ \arrow[from=#1,to=#2,arrows,xshift=0.05cm] {}\arrow[from=#1,to=#2,arrows,xshift=-0.05cm] {}
+}
+%classical horizontal wire, absolute positioning
+\newcommand{\vcwhexplicit}[2]{
+ \arrow[from=#1,to=#2,arrows,yshift=0.05cm] {}\arrow[from=#1,to=#2,arrows,yshift=-0.05cm] {}
}
%quantum wire, absolute positioning, going to centres of cell, not edge.
\newcommand{\vqwexplicitcenter}[2]{
- \arrow[from=#1,to=#2,dash,thick,start anchor=center,end anchor=center] {}
+ \arrow[from=#1,to=#2,arrows,start anchor=center,end anchor=center] {}
}
%horizontal wires
-\newcommand{\qw}{\ifthenelse{\the\pgfmatrixcurrentcolumn>1}{\arrow[dash,thick]{l}}{}}
-\newcommand{\cw}{\ifthenelse{\the\pgfmatrixcurrentcolumn>1}{\arrow[dash,thick,yshift=0.05cm]{l}\arrow[dash,thick,yshift=-0.05cm]{l}}{}}
+\newcommand{\qw}{\ifthenelse{\the\pgfmatrixcurrentcolumn>1}{\arrow[arrows]{l}}{}}
+\newcommand{\cw}{\ifthenelse{\the\pgfmatrixcurrentcolumn>1}{\arrow[arrows,yshift=0.05cm]{l}\arrow[arrows,yshift=-0.05cm]{l}}{}}
%define the strike distance for strike-through on qwbundle.
%\newcommand*{\StrikeDistance}{0.1cm}%
%a bundle of horizontal quantum wires
-\newcommand{\qwbundle}[1][]{\ifthenelse{\the\pgfmatrixcurrentcolumn>1}{
+\newcommand{\qwbundle}[2][]{\ifthenelse{\the\pgfmatrixcurrentcolumn>1}{
\def\helper{0}
\pgfset{/quantikz,#1}
\ifthenelse{\helper=1}{
- \arrow[dash,thick,yshift=0.1cm]{l}\arrow[dash,thick]{l}\arrow[dash,thick,yshift=-0.1cm]{l}
+ \arrow[arrows,yshift=0.1cm]{l}\arrow[arrows]{l}\arrow[arrows,yshift=-0.1cm]{l}
}{
- \arrow[phantom,strike arrow]{l}
+ \arrow[phantom,strike arrow]{l}[xshift=\pgfkeysvalueof{/quantikz/Strike Width}, yshift=\pgfkeysvalueof{/quantikz/Strike Height},anchor=south west,inner sep=0pt]{\scriptstyle #2}
}}{}}
%configure some of the style properties.
-\tikzcdset{row sep/normal=0.5cm,column sep/normal=0.5cm,thick,nodes in empty cells,every cell/.style={
+\tikzcdset{row sep/normal=0.5cm,column sep/normal=0.5cm,thick,nodes in empty cells,
+ every cell/.style={
anchor=center,minimum size=0pt,inner sep=0pt,outer sep=0pt,thick
- }
+ },
+ arrows/.style={dash,thick},
+ 1-row diagram/.style={}
}
\tikzset{
- operator/.style={draw,fill=white,minimum size=1.5em, inner xsep=2pt,thick,align=center},
+ thickness/.style={thick},
+ operator/.style={draw,fill=white,minimum size=1.5em, inner sep=2pt,thickness,align=center},
+ ggroup/.style={draw,minimum size=1.5em,thickness,align=center,inner sep=4pt},
leftinternal/.style={anchor=mid west,font=\scriptsize,inner sep=4pt,align=center},
rightinternal/.style={anchor=mid east,font=\scriptsize,inner sep=4pt,align=center},
wave/.style={inner sep=-3pt,tape,fill=white,apply={draw=black} except on segments {5,6,1,2,9}},
phase/.style={fill,shape=circle,minimum size=4pt},
- phase label/.style={label distance=2mm,label position=45,anchor=mid},
+ phase label/.style={label distance=2mm,anchor=mid,label position=45},
ophase/.style={fill=white,draw=black,shape=circle,minimum size=4pt},
+ internal/.style={thickness,black},
line/.style={path picture={
-\draw[thick,black](path picture bounding box.west) -- (path picture bounding box.east);
+\draw[internal](path picture bounding box.west) -- (path picture bounding box.east);
}},
linecont/.style={circle,line},
cross/.style={path picture={
-\draw[thick,black](path picture bounding box.north) -- (path picture bounding box.south) (path picture bounding box.west) -- (path picture bounding box.east);
+\draw[internal](path picture bounding box.north) -- (path picture bounding box.south) (path picture bounding box.west) -- (path picture bounding box.east);
}},
circlewc/.style={draw,circle,cross,minimum width=4pt,inner sep=3pt},
crossx/.style={path picture={
-\draw[thick,black,inner sep=0pt]
+\draw[internal,inner sep=0pt]
(path picture bounding box.south east) -- (path picture bounding box.north west) (path picture bounding box.south west) -- (path picture bounding box.north east) (path picture bounding box.west) -- (path picture bounding box.east);
}},
crossx2/.style={circle,crossx,minimum size=1em},
- dd/.style={decoration={brace},decorate,thick},
- dm/.style={decoration={brace,mirror},decorate,thick},
- slice/.style={thick,red,dash pattern=on 5pt off 3pt,align=center},
- meter/.style={draw,fill=white,minimum width=2em,minimum height=1.5em, rectangle, font=\vphantom{A}, line width=.8,
+ dd/.style={decoration={brace},decorate,thickness},
+ dm/.style={decoration={brace,mirror},decorate,thickness},
+ slice/.style={thickness,red,dash pattern=on 5pt off 3pt,align=center},
+ meter/.style={draw,fill=white,minimum width=2em,minimum height=1.5em, rectangle, font=\vphantom{A}, thickness,
path picture={\draw[black] ([shift={(.1,.24)}]path picture bounding box.south west) to[bend left=50] ([shift={(-.1,.24)}]path picture bounding box.south east);\draw[black,-{Latex[scale=0.6]}] ([shift={(0,.1)}]path picture bounding box.south) -- ([shift={(.3,-.1)}]path picture bounding box.north);}},
measuretab/.style={draw,signal,signal to=west,inner sep=4pt,fill=white},
meterD/.style={draw,rounded rectangle,rounded rectangle left arc=none,inner sep=4pt,fill=white},
@@ -525,10 +656,34 @@ style/.initial={},label style/.initial={},braces/.initial={},background/.code={\
group label/.style={label position=above,yshift=0.2cm,anchor=mid},
strike arrow/.style={
decoration={markings, mark=at position 0.5 with {
- \draw [black, thick,-]
+ \draw [internal,-]
++ (-\pgfkeysvalueof{/quantikz/Strike Width},-\pgfkeysvalueof{/quantikz/Strike Height} )
-- ( \pgfkeysvalueof{/quantikz/Strike Width}, \pgfkeysvalueof{/quantikz/Strike Height});} %can I use pgfkeys and do some maths here?
},
postaction={decorate},
}
+}
+
+\def\resetstyles{
+\tikzcdset{thin,every cell/.append style={thin},arrows/.append style={thin}
+ }
+\tikzset{
+ thickness/.style={thin},
+ %operator/.append style={thin},
+ %internal/.append style={thin},
+ %dd/.append style={thin},
+ %dm/.append style={thin},
+ %slice/.append style={thin},
+ meter/.append style={thin},
+ phase/.append style={minimum size=3pt},
+ ophase/.append style={minimum size=3pt},
+ %circlewc/.append style={minimum size=3pt,inner sep=2pt}
+}
+}
+
+\def\maketransparent{
+\tikzset{
+ operator/.append style={fill opacity=0},
+ meter/.append style={fill opacity=0}
+}
} \ No newline at end of file