% !TeX spellcheck = en_US
\documentclass{scrartcl}

\title{yquant.sty package documentation}
\subtitle{Typesetting quantum circuits in a human-readable language}
\author{Benjamin Desef}

% BEGIN_FOLD Packages
\RequirePackage{fontspec}
\setmainfont{XCharter}[Scale=.98]
\RequirePackage[osf, semibold]{sourcesanspro}
\usepackage{mathtools}
\RequirePackage[math-style=ISO, bold-style=ISO, sans-style=italic]{unicode-math}

\usepackage{xcolor}
\definecolor{darkblue}{RGB}{5, 10, 122}
\usepackage[english]{babel}
\usepackage[colorlinks, linkcolor=darkblue, bookmarksdepth=paragraph]{hyperref}
\usepackage[compat=newest]{yquant}
\usepackage{braket,hyphenat,microtype,hologo,minted,import,ragged2e,booktabs}
\usetikzlibrary{quotes,fit,shapes.symbols,backgrounds,quantikz}
\useyquantlanguage{qasm,groups}
\usepackage{amsmath,adjustbox,cleveref}
\usepackage[framemethod=tikz]{mdframed}
% END_FOLD

\makeatletter

\long\def\compat#1{\texorpdfstring{\leavevmode\makenote{#1}\penalty10000 }{}}

% BEGIN_FOLD Minted configuration
\definecolor{boxGrayBody}{gray}{.94}
\definecolor{boxRedHead} {RGB} {178, 34,  34}
\definecolor{boxRedBody} {RGB} {255, 255, 192}
\definecolor{boxBlueHead}{RGB} {118, 152, 199}
\definecolor{boxBlueBody}{RGB} {242, 247, 255}
\definecolor{mintgreen}  {RGB} {11,  97,  11}
\setminted{frame=none, linenos=false, fontsize=\footnotesize, breaklines, bgcolor=boxGrayBody}
\setmintedinline{bgcolor={}, fontsize=}

\newmintinline[yquant]{text}{}
\newmintinline[tex]{tex}{}
\newmintinline[ebnf]{ebnf}{}
% END_FOLD

% BEGIN_FOLD Block environments (options, code examples, ...)
\def\unskipOpt{\vskip-5mm }
\ifdefined\minted@inline@iii
   % < v2.7
   \let\unpatched@minted@inline@iii=\minted@inline@iii%
   \def\patched@minted@inline@iii#1{%
      \unpatched@minted@inline@iii{#1}%
      \par%
      \endgroup\vskip-\parskip%
      \noindent\ignorespaces%
   }
   \def\patch@mintinline{%
      \let\minted@inline@iii=\patched@minted@inline@iii%
   }
\else
   % v2.7
   \let\unpatched@RobustMintInlineProcess@ii=\RobustMintInlineProcess@ii
   \def\patched@RobustMintInlineProcess@ii#1{%
      \unpatched@RobustMintInlineProcess@ii{#1}%
      \par%
      \endgroup\vskip-\parskip%
      \noindent\ignorespaces%
   }
   \def\patch@mintinline{%
      \let\RobustMintInlineProcess@ii=\patched@RobustMintInlineProcess@ii%
   }
\fi
\newenvironment{option*}[3][]{\vskip5mm%
   \noindent\begin{minipage}[t]{\linewidth}%
      \begingroup%
         \patch@mintinline%
         \raggedleft%
         \hspace*{-1cm}%
         \phantomsection\label{style:/#2/#3}%
         \texttt{\ifstrempty{#1}\relax{\compat{#1}}\textcolor{gray}{/#2/}\textcolor{mintgreen}{#3}}\hfill default: %
         \tex}{%
   \end{minipage}}
\newenvironment{option}[1][]{\csname option*\endcsname[{#1}]{yquant}}{\csname endoption*\endcsname}

\newsavebox\codeexamplebox
\newenvironment{codeexample}{%
   \VerbatimEnvironment%
   \let\FVB@VerbatimOut\minted@FVB@VerbatimOut
   \let\FVE@VerbatimOut\minted@FVE@VerbatimOut
   \minted@configlang{tex}%
   \minted@fvset
   \begin{VerbatimOut}[codes={\catcode`\^^I=12},firstline,lastline]{\minted@jobname.pyg}%
}{
   \end{VerbatimOut}%
   \minted@langlinenoson%
   \savebox\codeexamplebox{\input \minted@jobname.pyg}%
   \ifdim\wd\codeexamplebox>\dimexpr.5\linewidth-3mm\relax%
      \wd\codeexamplebox=.5\linewidth% squeeze if necessary
   \else%
      \wd\codeexamplebox=\dimexpr\wd\codeexamplebox+3mm\relax% else give some space
   \fi%
   \noindent\begin{minipage}{\wd\codeexamplebox}%
      \centering%
      \usebox\codeexamplebox%
   \end{minipage}%
   \begin{minipage}{\dimexpr\linewidth-\wd\codeexamplebox\relax}%
      \expandafter\minted@pygmentize\expandafter{\minted@lang}%
   \end{minipage}%
   \minted@langlinenosoff%
   \par%
}

\newenvironment{codeexample*}{%
   \VerbatimEnvironment%
   \let\FVB@VerbatimOut\minted@FVB@VerbatimOut
   \let\FVE@VerbatimOut\minted@FVE@VerbatimOut
   \minted@configlang{tex}%
   \minted@fvset
   \begin{VerbatimOut}[codes={\catcode`\^^I=12},firstline,lastline]{\minted@jobname.pyg}%
}{
   \end{VerbatimOut}%
   \minted@langlinenoson%
   \begin{adjustbox}{center}
      \input \minted@jobname.pyg %
   \end{adjustbox}\nopagebreak
   \expandafter\minted@pygmentize\expandafter{\minted@lang}%
   \minted@langlinenosoff%
   \par%
}

\def\bd@boxextra#1{%
   \node[anchor=north east, overlay] at (current bounding box.north west) {#1\hskip7pt};%
}

\newcommand*\bd@boxintro[5]{%
   \begingroup%
      \setlength{\parskip}{0pt}%
      \setlength{\parindent}{0pt}%
      \edef\tmp{#5}%
      \ifx\tmp\empty%
         \expandafter\@firstoftwo%
      \else%
         \expandafter\@secondoftwo%
      \fi{%
         \begin{mdframed}[style=bdBox, backgroundcolor=#4, linecolor=#2,
                          firstextra=\bd@boxextra{#1}, singleextra=\bd@boxextra{#1}]%
      }{%
         \begin{mdframed}[style=bdBox, backgroundcolor=#4,
                          frametitlefont=\bfseries\sffamily\color{#3},
                          frametitlebackgroundcolor=#2,
                          frametitle={\strut\tmp}, linecolor=#2,
                          firstextra=\bd@boxextra{#1}, singleextra=\bd@boxextra{#1}]%
      }%
      \ignorespaces%
}
\def\bd@boxoutro{%
      \end{mdframed}%
   \endgroup%
}
\iffalse% code folding breaks
   \end{mdframed}
\fi
\mdfdefinestyle{bdBox}{
   skipabove=3pt,
   skipbelow=0pt,
   leftmargin=0pt,
   rightmargin=0pt,
   innerleftmargin=7pt,
   innerrightmargin=7pt,
   innertopmargin=5pt,
   innerbottommargin=5pt,
   splittopskip=17pt,
   frametitlealignment=\raggedright,
   frametitleaboveskip=3pt,
   frametitlebelowskip=1.5pt
}
\newenvironment*{warning}[1][]{%
   \bd@boxintro{\raisebox{\baselineskip-\height-6.5pt}{\includegraphics[width=1cm]{Warning.pdf}}}%
               {boxRedHead}{white}{boxRedBody}{\unexpanded{#1}}%
   \ignorespaces%
}{%
   \bd@boxoutro%
}
\def\example{\@ifnextchar<\example@i{\example@i<>}}
\def\example@i<#1>{\@ifnextchar[{\example@ii<{#1}>}{\example@ii<{#1}>[]}}
\long\def\example@ii<#1>[#2]{%
   \bd@boxintro{\ifstrempty{#1}{}{\ifstrempty{#2}{\compat{#1}}{}}%
                \raisebox{\baselineskip-\height-6.5pt}{%
                   \includegraphics[width=1cm]{Bulb.png}%
               }}{boxBlueHead}{white}{boxBlueBody}%
               {\ifstrempty{#1}{}{\ifstrempty{#2}{}{\unexpanded{\compat{#1}}}}\unexpanded{#2}}%
   \ignorespaces%
}
\let\endexample=\bd@boxoutro
% END_FOLD

\def\TikZ{\textcolor{brown}{Ti\textit kZ}}
\def\pkg#1{\textcolor{brown}{\texttt{#1}}}
\def\gate#1{\hyperref[gate:#1]{\texttt{#1}}}
\def\style#1{\hyperref[style:#1]{\texttt{#1}}}
\def\Yquant{\pkg{yquant}}
\def\ii{{\symup i}}
\def\ee{{\symup e}}
\def\ketbra#1#2{\ket{#1}\!\bra{#2}}

\robustify\bmod % unicode-math makes problems when \bmod is used within a box

\frenchspacing
\RequirePackage{scrlayer-scrpage,scrlayer-notecolumn}
\setcounter{tocdepth}{\subsectiontocdepth}
\KOMAoptions{DIV=8}
\newcommand*{\the@orig@section}{}
\let\the@orig@section=\section
\renewcommand*{\section}{%
   \clearpage%
   \the@orig@section%
}
\addtokomafont{notecolumn.marginpar}{\footnotesize\RaggedRight}
\recalctypearea

\begin{document}
   \maketitle
   \begin{abstract}
      \noindent This manual introduces \Yquant, a \LaTeX\hyp only package that outputs quantum circuits.
      They are entered using a human\hyp readable language that, even from the source code, allows for a fluent understanding of the logic that underlies the circuit.
      \Yquant{} internally builds on \TikZ{} and can be easily combined with arbitrary \LaTeX{} code.
      Almost one hundred pages of examples complement the formal manual.
   \end{abstract}
   \tableofcontents

   \section{Introduction}
      This document outlines the scope and usage of the \Yquant{} package.
      It contains both a reference and a huge number of examples.
      \Yquant{} is a package that makes typesetting quantum circuits easy; the package is available on CTAN.
      This beta version~0.7.3 \emph{should} be stable and interfaces are not very likely to change in an incompatible way in the future.
      \compat{New in 0.4}Sometimes, backwards\hyp incompatible changes are required or advisable, in which case a compatibility setting will allow to revert back to the old behavior (rather, to maximize compatibility, this is an opt\hyp in setting: unless you choose the new behavior, you will get the old one).
      Please do report all issues and desirable additions on \href{https://github.com/projekter/yquant/issues}{GitHub}.

      \subsection{How to read the manual}
         The probably fastest way to start using \Yquant{} is by just scanning through the examples in \cref{sec:examples}.
         A more formal description of the \Yquant{} grammar and its fundamental concepts can be found in \cref{sec:grammar}.
         If your desire is to change the appearance of \Yquant{} elements, use the configuration reference in \cref{sec:config}.
         The full list of all available gates is provided in \cref{sec:gates}.
         Finally, you may find that \Yquant{} \emph{almost} does what you want, but there is some final tweak that you cannot achieve\dots.
         Then, have a look at \cref{sec:tikz} (or \cref{sec:alt}).

      \subsection{Installation}
         The recommended way of installation is through CTAN.
         A direct installation from the Git repository to obtain the latest additions and features is be possible by just cloning it to a path visible to your \TeX{} compiler.
         For example, you may put the source files in the same directory as your document (if you just want to give a try), or you may extract them to \texttt{tex/latex/yquant} in your local \texttt{texmf} (followed by an update of the file name database).
         While the repository may contain new additions, they are not thoroughly tested until they end up on CTAN; features that are not documented in this manual are entirely unreliable.

         \compat{New in 0.4}The CTAN repository reflects the most current version tag on Git; the \href{https://github.com/projekter/yquant/releases}{Releases} section on GitHub additionally provides a single\hyp file version of the main package, which can for example conveniently be included in arXiv submissions.
         Note that the arXiv currently provides \Yquant{}~0.3.2 out\hyp of\hyp the\hyp box.

      \subsection{Purpose of \Yquant, alternatives}\label{sec:alt}
         \Yquant{} is the acronym for ``yet another quantum circuit package.''
         This highlights the fact that nothing that this package provides cannot be achieved by other means.
         In particular, there are at least the following methods to typeset quantum circuits in \TeX.
         \begin{itemize}
            \item Use some external program to draw them and include the output via \tex!\includegraphics!.
            \item Use either \TeX's own drawing capabilities (the \tex!picture! environment) or other drawing packages such as \TikZ{} or \pkg{pstricks}.
            \item Use a package specifically designed to draw quantum circuits (if you feel some other package should be mentioned here, please file an issue):
               \begin{itemize}
                  \item \pkg{qasm} is probably the first of them (in terms of age).
                     It was developed to typeset the circuits found in Nielsen and Chuang's famous \emph{Quantum Computation and Quantum Information} book.
                     \pkg{qasm} consists of a Python~2 script (\texttt{qasm2circ}) that reads a quantum circuit written in a very intuitive language: declare names for your qubits, perform gates on them in each line.
                     \texttt{qasm2circ} converts those circuits into \TeX{} files that internally make use of the \pkg{xy} package to display the output.
                     Consequently, the user is restricted to the set of features that \pkg{qasm} directly offers (which is small).
                     Changes to the output, while possible, will be overwritten if \texttt{qasm2circ} is run again.
                     \pkg{qasm} output often looks sub\hyp optimal do to the fact that, e.g., rectangles are made up of four lines that do not properly connect and give a crumbly general feeling.

                     Note that since version~0.3, \Yquant{} understands \pkg{qasm} syntax, see \cref{sec:foreign:qasm}.

                     Maintenance status: last update of \pkg{qasm} in 2005. Also, \pkg{xy} was last updated in 2013, and the script is not compatible out\hyp of\hyp the\hyp box with Python~3, though an automatic conversion should work.
                  \item \pkg{qcircuit} is probably the most\hyp widely used package.
                     It provides commands that make it much easier to create quantum circuits using the \pkg{xy} package.
                     Its syntax therefore is grid\hyp oriented; inferring what a circuit does or locating a gate in the code can be tough.
                     This is particularly true for multi\hyp qubit gates.
                     Additionally, the \tex!\xymatrix! syntax is also somewhat cryptic.
                     \pkg{qcircuit} provides some flexibility within the limits of \pkg{xy} as to configuring the output.

                     Maintenance status: active (\href{https://github.com/CQuIC/qcircuit}{GitHub}); but remember this is \pkg{xy} based, with last update in 2013.
                  \item \pkg{quantikz} is a relatively recent package that, following the same grid\hyp based approach as \pkg{qcircuit}, instead builds on \TikZ{} as a backend.
                     As a consequence, it provides the full flexibility of customization that \TikZ{} offers, where hardly anything cannot be done.
                     It also reduces burdens of the \pkg{xy} syntax.
                     However, the disadvantages of the grid\hyp based syntax still remain.

                     Maintenance status: last update in 2020; the underlying \TikZ{} is actively maintained again by now.
                  \item \pkg{qpic} follows the approach of \pkg{qasm}: It makes use of an external Python program that reads the quantum circuits in an own language and converts them into \TikZ{} commands.
                     The language \pkg{qpic} follows is much more powerful than \pkg{qasm}'s.
                     The disadvantage that modifications in the output code will not remain after running the Python script again is mitigated by the possibility to define own \TeX{} macros.
                     Being an external program, \pkg{qpic}'s intrinsic set of features (including, e.g., vertically set circuits) are huge.
                     However, the language \pkg{qpic} uses cannot be understood without a detailed study of the manual, it appears to have been designed with the aim to minimize the length of command names.
                     A disadvantage of external programs is that the amount of space gates need is not accessible by the script; hence, manual intervention may be required.

                     Maintenance status: last update in 2020; the underlying \TikZ{} is actively maintained, and the script is compatible with Python~3.
               \end{itemize}
         \end{itemize}

      \subsection{License}
          This work may be distributed and/or modified under the conditions of the \LaTeX{} Project Public License, either version~1.3c of this license or (at your option) any later version.
          The latest version of this license is in
          \begin{center}
             \url{http://www.latex-project.org/lppl.txt}
          \end{center}
          and version~1.3c or later is part of all distributions of LaTeX version 2005/12/01 or later.

   \section{Basic elements of \Yquant}\label{sec:grammar}
      \Yquant, as some of the aforementioned packages, builds on \TikZ.
      Its basic syntax is similar to \pkg{pgfplots}: Start a \tex!tikzpicture! environment (perhaps passing some options); inside, start a \tex!yquant! environment.

      Inside the \tex!yquant! environment, \TeX{} will now understand the \Yquant{} language---so \Yquant{} falls into the same category as \pkg{qasm} and \pkg{qpic}, providing a human\hyp readable language for the specification of the circuit that is not fixed to the actual layout.

      However, \Yquant{} is a \TeX\hyp only package (actually, \hologo{LaTeX2e}, but not \hologo{LaTeX3}) that requires no external script to run---so it also falls into the same category as \pkg{qcircuit} and \pkg{quantikz}.

      Since it runs entirely within \TeX, you can at any time interject \Yquant{} code with arbitrary \TeX{} or \TikZ{} code (though if it is ``too arbitrary,'' you may need to restart the \Yquant{} interpreter).

      \subsection{General usage}
         \begin{minted}[escapeinside=||]{tex}
% preamble: |\compat{Changed in 0.4}|\usepackage[compat=<version>]{yquant}
\begin{tikzpicture}% tikz options possible
   % tikz commands go here
   \begin{yquant}% yquant options possible. Watch the newlines!
      % yquant and tikz commands go here
   \end{yquant}
   % tikz commands go here
\end{tikzpicture}
         \end{minted}

         Note that \Yquant{} depends on \pkg{etoolbox}, \TikZ, \pkg{trimspaces}, and \compat{Changed in 0.4}\pkg{xkeyval}.
         Additionally, it requires a moderately recent version of \hologo{LaTeX2e}, using either \hologo{LuaLaTeX}; or (untested) \hologo{pdfLaTeX} or \hologo{XeLaTeX}.

         \begin{warning}[Optional arguments]
            The optional arguments for the \tex!yquant! environment have to appear \emph{on the same line} as the environment itself.
            If you want to put the arguments into a new line, it is crucial to mask the line break by putting a comment symbol after the environment: \tex!\begin{yquant}%!.
            Without this comment, \Yquant{} will detect your line break (this is one of the few places in \TeX{} where line breaks and spaces are different) and assume that the expression in square brackets instead provides arguments for the following operation! \\
            Finally note that in (non\hyp fragile) \pkg{beamer} frames, this discrimination between spaces and new lines does not work; the optional arguments will always be counted for the environment, not for the gate.
            In this case, you can either declare the frame as fragile or (recommended) introduce a blank line between the environment and the options for the first gate.
         \end{warning}

         \begin{warning}[\compat{New in 0.4}Compatibility mode]
            Sometimes, continued development shows that certain choices of interfaces, configuration, or behavior are less ideal than originally thought.
            In other cases, bugs are detected and fixed.
            Both may lead to a change in the look of circuits developed with a previous version of \Yquant{} or even---though this should rarely, if ever, happen, and should be filed as a bug---prevent compilation in the new version.

            For this reason, \Yquant{} offers a compatibility key that is highly recommended to be specified as a package option.
            This allows certain features that are expected to break old layout or functionality to revert to their previous behavior.
            Every feature affected by the \texttt{compat} key is documented in this manual.
            Once a compatibility version is selected in a document, it cannot be changed any more.
            Compatibility versions will include the major and minor, but not the patch level version number (though not every major or minor version will necessarily introduce new compatibility versions).
            Bugs that clearly violated behavior described in this manual will be fixed without a possibility to revert back.
            Changes that are not supposed to result in a (more than marginally) different result will not be included in the compatibility layer.
            If you find this to be wrong in a particular case, please file a bug report.

            When starting a new document, it is recommended to leave out the compatibility key at first compilation.
            \Yquant{} will then issue a warning from which you can infer the recommended setting, corresponding to the current version.
            You should then pass the appropriate version to the \tex!\usepackage! command.
            For example, this manual corresponds to \tex!\usepackage[compat=0.6]{yquant}!.

            Allowed values for \texttt{compat} are \texttt{newest} (discouraged), which equals \texttt{0.6}, \texttt{0.4}, and \texttt{0.3} (default).
         \end{warning}

      \subsection{Starred vs. unstarred environment}
         You may choose to use either the \tex!yquant! or the \tex!yquant*! environment.
         The former one requires you to define all your registers before you use them (though you may decide to define a register after some operations on \emph{different} registers, but before its first usage).

         The starred form additionally supports the use of undeclared registers: it basically declares a registers upon its first usage.
         This will always be a \texttt{qubit} register; but if you use the corresponding attribute and the first usage is an \gate{init} command, you may overwrite this.

         \compat{New in 0.2}Subcircuits always use the unstarred form.

         \compat{New in 0.1.1}Additionally, if you refer to the index $i$ of a vector register of length $L < i$, this register will automatically be enlarged to $i \coloneq L$.
         It is also possible to convert a scalar register into a vector register in this manner.
         To enlarge a register in the unstarred environment, you must precede the number of registers to be added in the second declaration by a plus sign.
         Note that in this manner, you may even create discontiguous vectors.

         \emph{This might be a good point to proceed to the examples \cref{sec:examples}.}

      \subsection[Formal syntax]{\compat{Enhanced in 0.1.2, 0.1.1}Formal syntax}
         Every \Yquant{} command has the same structure (described here in EBNF syntax):
         \begin{minted}{ebnf}
Command = { Arguments }, ?command?, [ Value ], [ RegisterList ], Controls, ";";
Arguments = "[", ?pgfkeys?, "]";
Value = "{", ?TeX code?, "}";
Controls = [ "|", [ RegisterSingleList ] ], [ "~", [ RegisterSingleList ] ];

RegisterList = (RegisterSingle | RegisterMulti), [ ",", RegisterList ];
RegisterSingleList = RegisterSingle, [ ",", RegisterSingleList ];

RegisterSingle = RegisterSingleNoRange | RegisterRange;
RegisterSingleNoRange = ?name?, [ "[", IndexMultiList, "]" ];
RegisterMulti = "(", ( RegisterMultiNoRange | [ "*" ], RegisterRange ), ")";
RegisterMultiNoRange = [ "*" ], ?name?, [ "[", IndexSingleMainList, "]" ];
RegisterRange = [ RegisterUnique ], "-", [ RegisterUnique ];
RegisterUnique = ?name?, [ "[", ?number?, "]" ];

IndexMultiList = IndexMulti, [ ",", IndexMultiList ];
IndexSingleList = IndexSingle, [ ",", IndexSingleList ];
IndexSingleMainList = [ "*" ], IndexSingle, [ ",", IndexSingleMainList ];
IndexMulti = IndexSingle | ( "(", IndexSingle, ")" );
IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
         \end{minted}
         Note that \Yquant{} is quite tolerant with respect to whitespaces.
         Virtually every comma in the EBNF notation may consist of an arbitrary (including zero) number of whitespaces.
         Not all combinations that can be constructed by this grammar are actually allowed semantically; but it would make the grammar too verbose to spell this out in detail.
         Deviations are noted in this manual.

         Valid values for
         \begingroup%
            % since v2.6 of minted, \PYG is no longer universally defined, so bring it into scope
            \minted@defstyle{\minted@get@opt{style}{default}}%
         \begin{BVerbatim}[commandchars=\\\{\}]
\PYG{n+ni}{?command?}
         \end{BVerbatim}
         \space (case\hyp insensitive) are documented in a \cref{sec:gates}.
         We use
         \begin{BVerbatim}[commandchars=\\\{\}]
\PYG{n+ni}{?pgfkeys?}
         \end{BVerbatim}
         \space to describe any valid content passed to the \tex!\pgfkeys! macro (rather, \tex!\yquantset! is invoked with some subtleties); and by
         \begin{BVerbatim}[commandchars=\\\{\}]
\PYG{n+ni}{?name?}
         \end{BVerbatim}
         \space we denote any valid register name.
         Register names must not contain any of the control literals used before (semicolon, comma, parentheses, square brackets, dash, pipe, tilde, beginning star); and you should avoid using special \TeX{} characters.
         Note that for performance reasons, \Yquant{} does not check whether a register name is valid or not, but expect to either see unintended output or not\hyp so\hyp helpful error messages if you choose an invalid name.
         \begin{BVerbatim}[commandchars=\\\{\}]
\PYG{n+ni}{?number?}
         \end{BVerbatim}
         \space is a decimal integer larger or equal to zero (in the context of register creation, strictly larger; in this context, it may also contain a leading
         \begin{BVerbatim}[commandchars=\\\{\}]
\PYG{l+s+s2}{\PYGZdq{}+\PYGZdq{}}
         \end{BVerbatim}
         ).\endgroup

      \subsection{Registers}\label{sec:registers}
         Every quantum circuit is structured by means of \emph{registers}.
         A register has a \emph{type} that specifies how its wire is drawn, and that may even change during its lifetime.
         At the moment, \Yquant{} supports four types:
         \begin{enumerate}
            \item \gate{qubit} is the most common type, used for a quantum register.
               It corresponds to a single line.
            \item \gate{cbit} is a classical register, which can be either declared from the beginning or arises by using measurements.
               It corresponds to a double line.
            \item \gate{qubits} is a ``quantum bundle,'' i.e., a bunch of quantum registers that are always addressed in a group as a single register.
               Operations between bundles of the same length should be interpreted as transversal.
               It corresponds to a triple line.
               An alternative (and more common) representation is to use the \gate{qubit} type and a \gate{slash} gate at its very beginning.
            \item \gate{nobit} is the most obscure type, corresponding to a non\hyp existing wire.
               Mostly, this register type arises by using the \gate{discard} command.
               However, it can also be directly declared, which on rare occasions might be necessary (its type can then be changed by means of an \gate{init} or \gate{setwire} pseudo\hyp gate).
               If you want to declare a register only at a certain horizontal position in the circuit, consider using the \texttt{after} argument instead.
         \end{enumerate}

         Registers must be declared before they can be used (though in the \tex!yquant*! environment, this declaration may be implicit, creating a \gate{qubit} register).

         Registers can have a vector character, i.e., not only a \emph{name}, but also an \emph{index} (or, in the declaration, a \emph{length}).
         The index (zero\hyp based) or length is specified in square brackets following the name, which closely mimics the OpenQASM language.

         \compat{New in 0.1.1}Vector registers may be non\hyp contiguous: Whenever you create a bunch of registers, it is put at the bottom of the circuit.
         If you later on again create registers of the same name---either implicitly in the \tex!yquant*! environment, or explicitly by preceding the length of the vectors entries to be added by a plus, as in \yquant!qubit a[+3];!---they will be put to what is \emph{now} the bottom of the circuit, even if some other registers are interspersed.

         Registers are referenced---i.e., used in operations---by their name and index.
         If the latter is omitted, all indices of the register are targeted.
         Multiple registers can be referenced by joining their names in a comma\hyp separated list, or by means of a range specifier: give the name of the first (topmost), a dash, and the last (bottom\hyp most) register.
         Both are inclusive.
         In a range specifier, omitting the start name means that the range begins at the first known register; omitting the end name means that the range ends at the last known (at the moment of its use) register.
         Omitting both indicates a range over all known registers.

         \compat{New in 0.1.1}It is also possible to use comma\hyp separated lists and ranges within the indices themselves, so that, e.g., \yquant!a[0, 2, 5-], b[-2]! will target the zeroth and second index of \yquant!a!; the remaining indices of \yquant!a! starting from five; and the first three indices of \yquant!b!.
         However, if you use an \emph{outer} range (i.e., a range between indices of registers with different names), the initial and final register of the range must be unique, i.e., either you omit the index (targeting the first or last register with the given name) or specify a single one.

         \begin{warning}[Ranges and discontiguous registers]
            Assume a configuration in which the vector register \yquant!a! begins with one qubit, then the single register \yquant!b! follows, and after that \yquant!a! is continued with another qubit.

            The range \yquant!a-b! will target \yquant!a[0]! and \yquant!b[0]!, but not \yquant!a[1]!.
            As \yquant!a! is used as the initial register in the range without an explicit index specification, \Yquant{} automatically translates this into \yquant!a[0]!, while \yquant!b!, being used as the final register, is automatically translated into the last register of name \yquant!b! (which here happens to be \yquant!b[0]!).
            Ranges between different register names (outer ranges) are \emph{visual} ranges, i.e., they refer to the top\hyp to\hyp bottom order that is visible.
            Consequently, the register \yquant!a[1]! is left out since it is visually below the others.

            Likewise, the range \yquant!b-a! will target \yquant!b[0]! and \yquant!a[1]!.

            Ranges within indices are \emph{logical} ranges.
            Hence, \yquant!a!, \yquant!a[-]!, \yquant!a[0-]!, \yquant!a[-1]!, and \yquant!a[0-1]! are all equivalent: they all refer to the registers \yquant!a[0]! and \yquant!a[1]!, but never to \yquant!b!, regardless of any visual position.
         \end{warning}

         All that was said so far refers to the operation being carried out on each of the registers \emph{individually}, i.e., producing several copies of the operation.
         This is different from using the operation multiple times on the individual single registers only with regard to the horizontal positioning: if specified as a register list with one operation, all copies of the operation will be aligned at the same horizontal middle axis (for gates with the same width on each register, this is the same as issuing an \gate{align} command before performing the operations individually).
         \begin{warning}
            It is forbidden (in the sense of ``not useful and giving unexpected output,'' but \Yquant{} does not check for this) to list the same register multiple times (explicitly or via ranges) in one operation.
         \end{warning}

         Instead of copies of single\hyp register operations, one might want to carry out a multi\hyp register operation.
         In this case, the desired list of registers (comma separated, range, or both) must be surrounded by parentheses.
         It is possible to mix single- and multi\hyp register operations arbitrarily.
         In an index list, you may also choose to surround only certain indices with parenthesis, provided the whole register is not already a multi\hyp register.
         \begin{warning}
            Note that some gates, such as the \gate{swap} gate, always require (semantically, not grammatically) multi\hyp register operations.
            \compat{Changed in 0.1.2}The number of constituents is not stipulated; while a \gate{swap} gate with more than two targets is no longer well\hyp defined, other registers such as \gate{zz} may still be useful.
            \Yquant{} will prevent you from using a gate in a multi\hyp qubit setting when it may only be used for single registers.
         \end{warning}
         Typically, multi\hyp register operations should only be carried out on adjacent registers---but sometimes, one might want to carry out a multi\hyp qubit operation on a visually discontiguous set of registers (which, due to a particular quantum computer topology, might even be physically feasible).
         \compat{New in 0.1.2}\Yquant{} supports these discontiguous operations explicitly.
         It will draw a \emph{main} part of the gate at the first contiguous slice of registers in the target list---you may select another register for this part by preceding the name or index with a star (which, contrary to the simplified grammar, may only occur \emph{once} in a target specification).
         All other contiguous slices of target registers will be drawn in a \emph{subordinate style} for this gate.
         Finally, all slices will be connected by a single vertical line with the style \style{/yquant/every multi line}.
         \compat{New in 0.2}Subcircuits will always span the full region from the first to the last register specified in a multi\hyp qubit gate.
         This is due to the fact that they may contain arbitrary ancilla registers which may be positioned somewhere in between the parts that actually constitute the subcircuit---surrounding this with a scattered set of connected boxes would look quite unpleasant.
         \clearpage
         \begin{warning}[\compat{Improved in 0.1.2}Discontiguous targets and control lines]
            A control line extends from the very first to the very last affected register in an operation.
            A sub\hyp gate line that is used for discontiguous registers will only span the range of a multi\hyp register.
            This distinction becomes crucial if you want to carry out a \emph{controlled} operation on more than one multi\hyp register, where at least one is discontiguous.
            Without the controls, the separate multi\hyp registers could be identified, since no connecting vertical line extends between them (unless, which you should strictly avoid, they are intertwined).
            However, with the controls, the control line will make it hard (for some gates, impossible) to visually distinguish the connected parts.
            \Yquant{} will kindly provide a warning in this case.
            You may choose to suppress this warning using the boolean key \style{/yquant/operator/multi warning}.
         \end{warning}
         \begin{warning}
            There is no established style for discontiguous gates.
            Note that at the moment, main and subordinate style coincide for all gates except for the \gate{measure} gate with a value.
            In order to still make it possible to visually distinguish discontiguous multi\hyp register gates operating on slices of a single register from just a bunch of single\hyp register gates that are executed in a parallel manner if controls are present, \Yquant's default vertical line style for the former case is a wavy line instead of a straight one.
            Still, the meaning of this should probably be explained.
            Please feel free to submit issues or pull requests with propositions of how default styles or alternative subordinate gate shapes may additionally help to mitigate the problem.
         \end{warning}

      \subsection{Arguments}
         Every command may take one or multiple arguments.
         Those are specified in square brackets that precede the command itself.
         The content of those square brackets is essentially fed to a \tex!\pgfkeys!-like macro.
         The default path is set appropriately such that the arguments of the command can be accessed without path specifiers.
         If the key is not a valid argument for the command or a global argument and it is not given by an absolute path, it is searched for in the \texttt{/yquant} namespace.
         If it cannot be found there, it is passed to \style{/yquant/operator style}.

         Note that commands may have required arguments.
         If a required argument is missing, an error will be issued.

         The \texttt{value} attribute can alternatively be given inside curly brackets after the command name and before the register specification.
         This has the advantage that special characters such as a closing square bracket need not be escaped.
         If both alternatives are present, the value inside curly brackets takes precedence and a warning is issued.

      \subsection{Controls}
         Lots of gates may have controls, i.e., they are only to be executed if some other gate is set or unset.
         The former case is called a \emph{positive control}, the latter one a \emph{negative control}.
         Those are indicated by filled and empty circles on the control registers and a vertical line that joins the registers that belong together.

         The gate specification is followed by the list of target registers.
         By then writing a pipe (``\yquant!|!''), the list of positive controls is introduced; this mimics the mathematical syntax ``conditioned on'' for probabilities or ``given'' for sets.
         If there are no positive controls, the list may be empty or, together with the pipe, omitted.
         Preceded by a tilde (``\yquant!~!''), the list of negative controls then follows; this mimics the syntax of many programming languages that denote logical negation by a tilde.
         If there are no negative controls, the list may be empty or, together with the tilde, omitted.

      \subsection[Importing circuit from files]{\compat{New in 0.2}Importing circuits from files}\label{sec:import}
         \Yquant{} provides a simple way to import circuits that are stored in external files.
         The macro \tex!\yquantimport! can be used in three different contexts:
         \begin{itemize}
            \item Outside of a \TikZ{} picture environment. \\
               Here, \tex!\yquantimport[<options>]{<filename>}! will be equivalent to
               \begin{minted}{tex}
\begin{tikzpicture}
   \begin{yquant}[<options>]
      % the content of <filename> goes here
   \end{yquant}
\end{tikzpicture}
               \end{minted}
               The starred form, \tex!\yquantimport*[<options>]{<filename>}!, instead inserts the starred \Yquant{} environment.
               Note that the options are always \Yquant{} options; if you want to pass \TikZ{} options, you will have to create the picture environment by yourself or change the option path to the correct one (\texttt{/tikz/.cd}).
            \item Inside a \TikZ{} picture environment, but outside of a \Yquant{} environment. \\
               This is the same as before, just that no extra picture environment will be added.
            \item Inside both a \TikZ{} picture environment and a \Yquant{} environment. \\
               The file will be inserted directly into the environment.
               \Yquant's parser is automatically restarted after this.
               The content will always be put in a \TeX{} group; if additional options are provided, \Yquant{} also inserts a \TikZ{} \tex!scope! and executes \tex!\yquantset{<options>}! directly after the scope.
               If \tex!\yquantimport! is used, the content will be read as if the containing environment was an unstarred one; if \tex!\yquantimport*! is used, the content will be read as if the containing environment was a starred one.
         \end{itemize}
         Note that \Yquant{} internally uses plain \TeX's \tex!\import! command (i.e., \tex!\@@import! in \LaTeX).
         However, when the \pkg{import} package is loaded, it uses \\ \tex!\subimport{\yquantimportpath}{<filename>}!, where \tex!\yquantimportpath! defaults to \texttt{./}---so by changing this, files from other folders may be imported which by themselves again include other files, and the relative path resolution will work.

         Note that you may in particular import the content of a \gate{subcircuit}.

      \subsection{Defining own gates}
         \begin{warning}[Scope]
            All gate declarations are always global.
         \end{warning}

         \compat{New in 0.2.1}If you want to define a gate that corresponds to a single \gate{box} gate with a certain pre\hyp defined content, you may use the macro\\
         \tex!\yquantdefinebox{<name>}[<style>]{<content>}!, which is far more efficient than the much more general \tex!\yquantdefinegate! introduced below.
         It only allows for single\hyp register usage; use \compat{New in 0.4}\tex!\yquantdefinemultibox! with the same arguments if you want to allow the gate to be used in a multi\hyp register gate fashion.
         The macros work in the following way:
         \begin{itemize}
            \item They create a new gate with name \texttt{<name>} that can be accessed as all the other build\hyp in gates.
               Note that \texttt{<name>} is case\hyp insensitive and may not contain spaces.
               Special characters are allowed if \TeX{} can cope with them (i.e., no comment signs, no unbalanced braces, no backslashes...).
            \item They create a style \style{/yquant/operators/every <name>} and assign the optional \texttt{<style>} to it.
               If no style is provided, the default style will inherit from \style{/yquant/operators/every rectangular box}\compat{Changed in 0.6}.
               If a \texttt{compat} version before \texttt{0.6} is chosen, \style{/yquant/operators/every box} will instead be the ancestor.
            \item They define \texttt{<content>} to be the value that is written into the box.
               This \texttt{<content>} is expanded in a protected manner at the time of gate declaration.
               You may need to prefix fragile macros by \tex!\protect!.
         \end{itemize}

         \compat{New in 0.2}Sometimes, you may wish to define gates that are more than just a single box---perhaps a succession of multiple gates or even multi\hyp register gates with individual operations on the input registers.
         \Yquant{} provides a simple macro that allows this.
         The macro \tex!\yquantdefinegate{<name>}[<style>]{<content>}! works in the following way:
         \begin{itemize}
            \item It creates a new gate with name \texttt{<name>} that can be accessed as all the other built\hyp in gates.
               Note that \texttt{<name>} is case\hyp insensitive and may not contain spaces.
               Special characters are allowed if \TeX{} can cope with them (i.e., no comment signs, no unbalanced braces, no backslashes...).
            \item It creates a style \style{/yquant/operators/every <name>} and assigns the optional \texttt{<style>} to it.
               If no style is provided, the default style will inherit from \style{/yquant/operators/every custom gate}.
               This will make the gate ``seamless,'' i.e., avoid highlighting the fact that this is a custom gate.
            \item It defines a macro that contains \texttt{<content>} (expanded in a protected manner) and that will be inserted as a subcircuit whenever this gate is invoked.
               This in particular means that if you use \hyperref[sec:import]{\tex!\yquantimport!} within the gate, the file will only be loaded once at the time of declaration.
         \end{itemize}
         When the gate is later drawn, the styles are invoked in the following order---remember custom gates are implemented by means of subcircuits---:
         \begin{enumerate}
            \item \style{/yquant/every operator}
            \item \style{/yquant/operators/every <name>}
            \item \style{/yquant/operators/every subcircuit box}
            \item \style{/yquant/this operator}
            \item \style{/yquant/operators/this subcircuit box}
         \end{enumerate}
         Gates defined in this way can only make use of the default gates or other custom gates.
         They do not accept custom arguments, and it is not possible to declare own, custom shapes in this way (though other predefined shapes may be used).
         If they are used in a multi\hyp qubit manner, they will never be split into contiguous slices (but their content will be, so if you use the default style that turns off the box, the only way to notice this is that intermediate unaffected registers will not be allowed to have gates visually within the rectangle that would bound the custom gate).

         \begin{warning}[Redefining existing gates]
            The above macros will issue an error if the gate already exists.
            You can use \tex!\yquantredefinebox!, \tex!\yquantredefinemultibox! (use the appropriate command for the \emph{new} definition), or \tex!\yquantredefinegate! to overwrite existing gate definitions.
            Note that this will overwrite \emph{any} gate, even the built\hyp in ones.

            Generally, it is discouraged to make use of this possibility.
            For custom gates, if you redefine a gate as a box which was previously a general subcircuit\hyp based gate, the macro that contains the subcircuit will still be held in memory.
            Overwriting built\hyp in gates will not clear the attributes associated to this gate (though required attributes will no longer be required afterwards).
            Again, this is not a problem but prevents \Yquant{} from issuing potentially helpful error message if such a---now meaningless---attribute is used.

            Finally, once a built\hyp in gate is overwritten, it cannot be restored.
            In particular, the register creation pseudo\hyp gates \gate{qubit}, \gate{cbit}, \gate{qubits}, and \gate{nobit} perform some magic that cannot be mimicked with custom gates.
         \end{warning}

         More advanced declaration of custom gates requires the use of backend macros.
         Refer to \texttt{yquant-lang.tex} for this.
         Note that the backend interface changed in version~0.4.
         For the declaration of custom shapes, see \texttt{yquant-shapes.tex} for examples.

      \subsection[The flow of time: horizontal and vertical layout]{\compat{New in 0.7}The flow of time: horizontal and vertical layout}
         By default, quantum circuits are oriented \emph{horizontally}, i.e., time flows from left to right.
         Sometimes, this is problematic when printed on a portrait page layout and a \emph{vertical} layout would be better suited.
         \Yquant{} supports this by simply passing the configuration option \style{/yquant/vertical} to the circuit (this can even be done globally, so that all circuits are rendered vertically).

         The vertical layout is supposed to work exactly as the horizontal layout; however, most testing occurs for horizontal mode only (basically, for every release, the examples in this manual comprise the testsuite).
         Hence, if something weird happens in vertical mode, please file a bug report.

         Most of the internal and exposed nomenclature in \Yquant{} is designed for the horizontal case (names such as ``height'' or ``width'').
         For some of the exposed configuration options, synonyms are provided which are more meaningful in vertical mode or that are more orientation\hyp agnostic.
         These synonyms are merely conveniences, they do not provide any new functionality.
         As a general rule of thumb, everything that was ``atop'' becomes ``left.''

         Some relevant \TikZ{} options refer to a fixed direction, namely \texttt{[x|y] radius} and \texttt{[inner|outer] [x|y]sep}.
         If you think that maybe you want to change the orientation of your circuit at some point, you should never use the original \TikZ{} styles---their meaning would depend on the current orientation.
         Instead, consider using the \Yquant{} alternatives \texttt{[time|space] radius} and \texttt{[inner|outer] [time|space]sep}.

   \section{Configuration}\label{sec:config}
      \Yquant{} uses \pkg{pgfkeys} to control its options, which are located in the path \texttt{/yquant}.
      The following list contains all options and styles that are recognized, apart from gate arguments.
      Those are listed together with their operations.

      \subsection{Circuit layout}\unskipOpt
         \begin{option}[Changed in 0.7, 0.4]{register/minimum height}!1.5mm!
            \Yquant{} automatically determines the height (extent from wire to top boundary; in vertical mode: from wire to left boundary) of a register as the height of the largest operation.
            This might be too small for two reasons:
            \begin{itemize}
               \item if the register is used only with small gates (e.g., only as a control, or as a swap), and it does not have a label (or one containing only x\hyp height letters).
               \item if you manually turned off height calculation or multi\hyp extent calculation for a large gate.
                  \Yquant{} will then not consider the vertical extent of this gate, which might consequently lead to undesirable overlaps.
            \end{itemize}
            This key provides an easy alleviation of the problem by requiring a minimal height for every register.
            As the value of this key is relevant at the time of register declaration, it can also be changed for each register individually.

            Note that in vertical mode, the default of this setting is \tex!2.5mm!.

            Note that this key is affected by the \texttt{compat} setting.
            Before version \texttt{0.4}, there was no \style{/yquant/register/minimum depth} key.
            In this compatibility setting, passing the value $x$ to this key will set both height and depth to $\frac x2$.
            The default for $x$ is then \texttt{3mm}.
         \end{option}

         \begin{option}[Changed in 0.4\\New in 0.4]{register/minimum depth}!1.5mm!
            \emph{see} \style{/yquant/register/minimum height}

            This key allows to specify a minimum depth (extent from wire to bottom boundary; in vertical mode: from wire to right boundary) for a register.

            Note that in vertical mode, the default of this setting is \tex!2.5mm!.

            Note that this key is affected by the \texttt{compat} setting.
            Before version \texttt{0.4}, this key will not be available.
         \end{option}

         \begin{option}[New in 0.7]{register/minimum left}!1.5mm!
            This is a synonym for \style{/yquant/register/minimum height}, as this naming makes more sense for vertical circuits.
         \end{option}

         \begin{option}[New in 0.7]{register/minimum right}!1.5mm!
            This is a synonym for \style{/yquant/register/minimum depth}, as this naming makes more sense for vertical circuits.
         \end{option}

         \begin{option}[New in 0.7]{register/minimum before}!1.5mm!
            This is a synonym for \style{/yquant/register/minimum height}, which provides a naming that makes sense in both horizontal and vertical mode.
         \end{option}

         \begin{option}[New in 0.7]{register/minimum after}!1.5mm!
            This is a synonym for \style{/yquant/register/minimum depth}, which provides a naming that makes sense in both horizontal and vertical mode.
         \end{option}

         \begin{option}{register/separation}!1mm!
            This key controls the amount of vertical space that is inserted between two successive registers.
            Half of this value is also the length that multi\hyp\gate{init} or multi\hyp\gate{output} braces extend beyond the mid position of the register.
         \end{option}

         \begin{option}[Changed in 0.7]{operator/minimum width}!5mm!
            \Yquant{} automatically determines the width (in vertical mode: the vertical extent) of an operator according to its content.
            However, single\hyp letter boxes are among the most common operators, and giving them slightly different widths would result in a very uneven spacing, as \Yquant{} does not use a grid layout but stacks the operators horizontally one after each other.
            Hence, this key provides a minimum width that will be set for every operator.
            This does not imply that the \emph{visual} appearance (i.e., the \texttt{x radius} key) is enlarged, but that operators of a smaller actual width will be centered in a virtual box of the minimum width.

            Note that in vertical mode, the default of this setting is \tex!3mm!.
         \end{option}

         \begin{option}[New in 0.7]{operator/minimum extent}!3mm!
            This is a synonym for \style{/yquant/operator/minimum width}, which provides a naming that makes sense in both horizontal and vertical mode.
         \end{option}

         \begin{option}{operator/separation}!1mm!
            This key controls the amount of horizontal space that is inserted between two successive operators and at the beginning and end of a circuit.
         \end{option}

         \begin{option}[New in 0.1.2]{operator/multi warning}!true!
            If this key is \texttt{true}, a warning is displayed whenever more than a single multi\hyp register gate, where at least one is discontiguous, is employed together with controls.
            Even if a visual distinction between control and multi\hyp qubit line may be possible (depending on the style in use), they will overlap and produce unaesthetic output.
            You may disable this warning globally, on a per\hyp circuit, or even on a per\hyp gate basis.
         \end{option}

         \begin{option}[New in 0.7]{drawing mode}!quality!
            This key determines which drawing pipeline is enabled.
            For more details, see \cref{sec:pipeline}.
            The option should not be changed within a circuit (though only the last value will be relevant).
            Allowed values are \texttt{quality} for the default clipping\hyp based pipeline, and \texttt{size} of the filling\hyp based one.
            Note that choosing \texttt{quality} will set \style{/yquant/default background} to \texttt{none}; choosing \texttt{size} will set it to \texttt{white} (though this can be changed after setting the option).
         \end{option}

         \begin{option}[New in 0.7]{default background}!none!
            This key contains the default color that is used to fill all gates with a nonempty interior.
         \end{option}

         \begin{option}[New in 0.7]{default fill}!fill/.expanded=\pgfkeysvalueof{/yquant/default background}!
            Use this style if you want to apply the default filling to a user\hyp defined gate.
         \end{option}

      \subsection{Register creation}\unskipOpt
         \begin{option}{register/default name}!\regidx!
            The printed name that is used by default if a new register is created explicitly (\gate{qubit}, \gate{cbit}, \gate{qubits}; not used for \gate{nobit} or for implicit declarations) and no value is specified.
            The following macros are available:
            \begin{itemize}
               \item \tex!\reg! contains your name to identify this register.
               \item \tex!\idx! contains the index (zero\hyp based) of the current register within a vector register.
               \item \tex!\regidx! expands to \tex!\reg! if the register is of length one, and to \tex!\reg[\idx]! else.
               \item \tex!\len! contains the length of the current register vector.
            \end{itemize}
         \end{option}

         \begin{option}[New in 0.6]{register/default lazy name}!!
            The printed name that is used by default if a new register is created implicitly (i.e., without using any of \gate{qubit}, \gate{cbit}, \gate{qubits}, or \gate{nobit}, but inside a \texttt{yquant*} environment by just using the register).
            The same macros as with \style{/yquant/register/default name} are available.
            Note that this default setting is not used when the register is created via an \gate{init} gate---its value always overwrites the default.
         \end{option}

         \begin{option}[Changed in 0.7, 0.4]{every label}!shape=yquant-init, anchor=center, align/.expanded=\ifyquanthorz{right}{center}, outer timesep=2pt, /yquant/operator/if multi={draw, decoration={gapped brace, raise=2pt, \ifyquanthorz{mirror}{}}, decorate}!
            This style is installed for every single register name label (i.e., upon creation and when used with the \gate{init} gate).
            The default style allows to use line breaks in the labels.
            The node shape, \texttt{yquant-init}, will generate a path at its right side (in vertical mode: at its bottom side), which is replaced by the \texttt{gapped brace} decoration if the gate is used in a multi\hyp register fashion.
            The decoration is similar to \TikZ's \texttt{brace} decoration, but additionally allows specify the regions in which a line should be drawn by using the \texttt{/tikz/decoration/from to} key, which expects a comma\hyp separated list of dimension ranges, and which is automatically populated by \Yquant.

            Note that if the \texttt{compat} key is below \texttt{0.3}, the multi options are instead read from \style{/yquant/every multi label}.
         \end{option}

         \begin{option}[Changed in 0.7]{every initial label}!anchor/.expanded=\ifyquanthorz{east}{south}, /yquant/internal/autorotate init!
            This style is installed for every single register name label at the left border of the circuit.
            \compat{Changed in 0.4}It is therefore used if a label is specified upon declaration and also for the \gate{init} gate if it happens to be the first gate on an unlabelled register (use a zero\hyp width \gate{hspace} gate before if you want to suppress this).

            \compat{New in 0.7}The automatic rotation will be set up by using the \style{/yquant/vertical} style with an argument; by default, it is empty.
         \end{option}

         \begin{option}{every qubit label}!!
            This style is installed for every single register name label of a register of type \gate{qubit}.
         \end{option}

         \begin{option}{every cbit label}!!
            This style is installed for every single register name label of a register of type \gate{cbit}.
         \end{option}

         \begin{option}{every qubits label}!!
            This style is installed for every single register name label of a register of type \gate{qubits}.
         \end{option}

         \begin{option}[Removed in 0.4\\Changed in 0.1.2]{every multi label}!draw, decoration={gapped brace, mirror, raise=2pt}, decorate!
            This style is installed for every register name label that is attached to a multi\hyp qubit register by means of the \gate{init} gate.

            Note that this key is only available if the \texttt{compat} setting is smaller than \texttt{0.4}.
            In newer versions, this is incorporated in \style{/yquant/every label}.
         \end{option}

         \begin{option}[Removed in 0.4\\New in 0.2]{every input label}!!
            This style is installed for every register name label in a \gate{subcircuit} when the register is an input (or input and output) register.

            Note that this key is only available if the \texttt{compat} setting is smaller than \texttt{0.4}; and in this case, it behaves inconsistently, as it is only applied for labels directly specified during creation, but not for initial \gate{init} gates.
         \end{option}

      \subsection{Register outputs}\unskipOpt
         \begin{option}[Changed in 0.7, 0.4]{every output}!shape=yquant-output, anchor/.expanded=\ifyquanthorz{west}{north}, align/.expanded=\ifyquanthorz{left}{center}, outer timesep=2pt, /yquant/operator/if multi={draw, decoration={gapped brace, raise=2pt, \ifyquanthorz{}{mirror}}, decorate}, /yquant/internal/autorotate output!
            This style is installed for every \gate{output} label at the end of the circuit.
            The default style allows to use line breaks in the labels.

            The node shape, \texttt{yquant-output}, will generate a path at its left side (in vertical mode: at its top side), which is replaced by the \texttt{gapped brace} decoration in the case of multi\hyp register usage.
            See \style{/yquant/every label} for a more detailed explanation.

            \compat{New in 0.7}The automatic rotation will be set up by using the \style{/yquant/vertical} style with an argument; by default, it is empty.
         \end{option}

         \begin{option}{every qubit output}!!
            This style is installed for every \gate{output} label of a register of type \gate{qubit}.
         \end{option}

         \begin{option}{every cbit output}!!
            This style is installed for every \gate{output} label of a register of type \gate{cbit}.
         \end{option}

         \begin{option}{every qubits output}!!
            This style is installed for every \gate{output} label of a register of type \gate{qubits}.
         \end{option}

         \begin{option}[Removed in 0.4\\Changed in 0.1.2]{every multi output}!draw, decoration={gapped brace, raise=2pt}, decorate!
            This style is installed for every \gate{output} label that is attached to a multi\hyp qubit register.

            Note that this key is only available if the \texttt{compat} setting is smaller than \texttt{0.4}.
            In newer versions, this is incorporated into \style{/yquant/every output}.
         \end{option}

      \subsection{General styling}\unskipOpt
         \begin{option}[Changed in 0.4, 0.1.2]{every circuit}!every node/.prefix style={transform shape}!
            Style that is installed for every \tex!yquant! and \tex!yquant*! environment, as if it had been given as an option.
            The style's default path is, as with all other styles, \texttt{/tikz}.
            The style is re\hyp applied for every subcircuit.
            The default style will make all nodes (which in particular means, all gates) respect outer canvas transformations.

            If your \TikZ{} version is before 3.1.6a, this style will additionally contain \tex!every label/.prefix style={transform shape=false}!, which undoes the effect for \texttt{label}s (see \TikZ{} bug \href{https://github.com/pgf-tikz/pgf/issues/843}{\#843}).
            An update is recommended.
         \end{option}

         \begin{option}{every wire}!draw!
            This style is installed whenever a wire is drawn.
         \end{option}

         \begin{option}{every qubit wire}!!
            This style is installed whenever a wire for a register of type \gate{qubit} is drawn.
         \end{option}

         \begin{option}{every cbit wire}!!
            This style is installed whenever a wire for a register of type \gate{cbit} is drawn.
         \end{option}

         \begin{option}{every qubits wire}!!
            This style is installed whenever a wire for a register of type \gate{qubits} is drawn.
         \end{option}

         \begin{option}{every control line}!draw!
            This style is used to draw the vertical control line that connects controlled operations and their controls.
         \end{option}

         \begin{option}{every control}!shape=yquant-circle, anchor=center, radius=.5mm!
            This style is used to draw the node for a control, both positive and negative.
         \end{option}

         \begin{option}{every positive control}!fill=black!
            This style is installed for every positive control (i.e., one that conditions on the register being in state $\ket1$ or $1$).
         \end{option}

         \begin{option}[Changed in 0.7]{every negative control}!draw, /yquant/default fill!
            This style is installed for every negative control (i.e., one that conditions on the register being in state $\ket0$ or $0$).
         \end{option}

         \begin{option}{every operator}!anchor=center!
            This style is installed for every gate (and also pseudo\hyp gates such as the \gate{slash} operator) that acts on one or multiple registers.
         \end{option}

         \begin{option}[New in 0.1.2]{every multi line}!draw, decoration={snake, amplitude=.25mm, segment length=5pt}, decorate!
            This style is used to draw the vertical line that connects discontiguous slices of sub\hyp gates.
         \end{option}

         \begin{option}{this operator}!!
            This style is appended to the current style installed for an operator; it should be used only locally to overwrite any global configuration effect. \\
            \compat{New in 0.7.3}Consider using \style{/tikz/only at} and \style{/tikz/not at} \emph{within this style} if you want to selectively address certain operators when there are multiple.
         \end{option}

         \begin{option}{this control}!!
            This style is appended to the current style installed for a control; it should be used only locally to overwrite any global configuration effect. \\
            \compat{New in 0.7.3}Consider using \style{/tikz/only at} and \style{/tikz/not at} \emph{within this style} if you want to selectively address certain controls when there are multiple.
         \end{option}

         \begin{option}{operator style}!/yquant/this operator/.append style={#1}!
            This is a shorthand that can be used to modify the appearance of the current operator.
         \end{option}

         \begin{option}{control style}!/yquant/every control line/.append style={#1}, /yquant/this control/.append style={#1}!
            This is a shorthand that can be used to modify the appearance of the current control and its associated line.
         \end{option}

         \begin{option}{style}!/yquant/operator style={#1}, /yquant/control style={#1}!
            This is a shorthand that modifies the appearance of both the current operator and any controls or control lines.
         \end{option}

         \begin{option*}[New in 0.7.3]{tikz}{only at}!!
            This is a style which is available within \style{/yquant/this operator} and \style{/yquant/this control}.
            It allows to selectively apply its contents only to a certain part of a multi\hyp partite operator.
            The style expects an even number of parameters.
            The first (third, ...) parameter contains the index of the operator/control where the style should apply.
            This index corresponds to the values that \tex!\idx! can take; i.e., it will be zero for the topmost operator/control (leftmost for vertical circuits) and then increment by one.
            The indices of operators, positive, and negative controls are all independent.
            You may not only give a single index, but instead also a comma\hyp separated list, and you may also use index ranges (where both the first and second part of the range can be omitted, which then means ``from the first'' or ``to the last'').
            The second (fourth, ...) parameter then contains all the styles that should actually be applied.

            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit q[7];
      [operator style={only at={1, 3-}{fill=yellow}
                               {0}{ultra thick}},
       control style={only at={0}{fill=orange}}]
      h q[-2, 4, 5] | q[3, 6];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
         \end{option*}

         \begin{option*}[New in 0.7.3]{tikz}{not at}!!
            See \style{/tikz/not at}; this style does the same, but instead only acts if the current register is \emph{not} the one given in the odd arguments.
         \end{option*}

         \begin{option}[Changed in 0.7.1\\New in 0.1.2]{operator/multi as single}!/yquant/every multi line/.style=/yquant/every control line!
            This style is automatically set for certain gates such as the \gate{swap} or the \gate{zz} gate.
            For those gates, neighboring registers will be treated as discontiguous; and this style will enforce their connecting line to have the style used by control lines.

            \compat{New in 0.7.1}This style actually checks whether control lines are present in the gate and in this case, it is equal to \tex!draw=none!, i.e., it suppresses the multi\hyp register line.
            This is due to the fact that this line would be drawn on top of (a segment of) the control line with an identical style, so that it cannot be seen unless there were some bug in the renderer.
            Note that the check for control lines is embedded into the style (the default value shown here is a simplification); so if you change it, you will overwrite the style for \emph{all} cases, not only when there is no control line.

            The default \style{/yquant/every multi line} is a wavy line; this allows to distinguish discontiguous multi\hyp qubit gates from multiple single\hyp qubit gates when using controls.
            Still, some gates have such an established appearance that---despite being logically misleading---we rather use the same style as for a control line.
         \end{option}

         \begin{option}[New in 0.4]{operator/if multi}!!
            This style can be invoked by other styles with an arguments that contains styles to be executed only if the current gate is used in a multi\hyp register fashion.
            See \style{/yquant/every label} for an example.
         \end{option}

         \begin{option}[New in 0.4]{circuit/seamless}!false!
            The value of this setting determines whether circuits drawn in a \Yquant{} environment in the current group will be drawn in a ``seamless'' state (hence, this style must be set \emph{before} the \Yquant{} environment is started).
            The key \style{/yquant/operator/separation} will control the amount of padding with which a wire starts or ends before the first or after the last gate.
            By turning on the seamless state, this padding is suppressed.
            Using outputs or giving an initial value at the register declaration brings the corresponding padding back.
            Usually, this setting is intended only for subcircuits.
            Direct access is discouraged, as it will persist in subcircuits.
            Only access it via \style{/yquant/operators/subcircuit/seamless}.
         \end{option}

         \begin{option}[New in 0.7]{circuit/orientation}!horizontal!
            This setting allows two possible values, \texttt{horizontal} and \texttt{vertical}.
            It must only be changed before a circuit or at latest with the option arguments to the \tex!yquant! environment, but not within a circuit.

            In the default \texttt{horizontal} mode, time flows from left to right and registers will be created from top to bottom.
            In the alternative \texttt{vertical} mode, time flows from top to bottom and registers will be created from left to right.

            Note that this setting influences the behavior of various macros and styles:
            \begin{center}
               \begin{tabular}{lrr}
                  \toprule
                  Macro/Style & \texttt{horizontal} meaning & \texttt{vertical} meaning \\\midrule
                  \tex!\ifyquanthorz{a}{b}! & \tex!a! & \tex!b! \\
                  \texttt{/tikz/time radius} & \texttt{/tikz/x radius} & \texttt{/tikz/y radius} \\
                  \texttt{/tikz/space radius} & \texttt{/tikz/y radius} & \texttt{/tikz/x radius} \\
                  \texttt{/tikz/inner timesep} & \texttt{/tikz/inner xsep} & \texttt{/tikz/inner ysep} \\
                  \texttt{/tikz/inner spacesep} & \texttt{/tikz/inner ysep} & \texttt{/tikz/inner xsep} \\
                  \texttt{/tikz/outer timesep} & \texttt{/tikz/outer xsep} & \texttt{/tikz/outer ysep} \\
                  \texttt{/tikz/outer spacesep} & \texttt{/tikz/outer ysep} & \texttt{/tikz/outer xsep} \\
                  \bottomrule
               \end{tabular}
            \end{center}
            Additionally, this setting influences the default values of various \Yquant{} styles---note that if a style was once overwritten, the user\hyp supplied value will be never be changed!
            Here, we use the orientation\hyp independent names of the styles, although all their synonyms are equivalent.
            \begin{center}
               \begin{tabular}{lrr}
                  \toprule
                  Style & \texttt{horizontal} def. & \texttt{vertical} def. \\\midrule
                  \style{/yquant/register/minimum before} & \tex!1.5mm! & \tex!2.5mm! \\
                  \style{/yquant/register/minimum after} & \tex!1.5mm! & \tex!2.5mm! \\
                  \style{/yquant/operator/minimum extent} & \tex!5mm! & \tex!3mm! \\
                  \bottomrule
               \end{tabular}
            \end{center}
         \end{option}

         \begin{option}[New in 0.7]{horizontal}!!
            This style is a shorthand that sets \style{/yquant/circuit/orientation} to the \texttt{horizontal} value (which is the default).
         \end{option}

         \begin{option}[New in 0.7]{vertical}!0!
            This style is a shorthand that sets \style{/yquant/circuit/orientation} to the \texttt{vertical} value.
            Additionally, it accepts a parameter which should be an angle value (in degrees) between \tex!-180! and \tex!180!.
            This is a rotation that is automatically applied to the text in every \gate{init} gate at the beginning of a circuit; the inverse rotation is automatically applied to the text in every \gate{output} gate at the end of a circuit.

            Note that the gates themselves are \emph{not} rotated.
            This would be counterproductive for multi\hyp qubit gates that contain braces---those should still be orthogonal to the wire lines.
            In order to achieve this, the macro will use internal \TikZ{} details and exploit that the \texttt{execute at begin node} key is directly followed by the braced content of the node.
            Hence, it will add a corresponding \tex!\adjustbox{rotate=#1}! to this style.
            Therefore, \Yquant{} will raise a warning if the argument is used and the \pkg{adjustbox} package is not loaded, in which case the rotation is just ignored.
         \end{option}

         \begin{option}[New in 0.4]{every post measurement control}!indirect!
            This style determines the default arrangement of measurements that are followed by positive controls.

            The default option \texttt{indirect} will draw the measurement at the position where it is specified.
            Any later use of a control will be at the position of the controlled gate.

            The option \texttt{direct} will defer the measurement.
            If later on, a controlled operation is used where the positive controls contain all of the targets of this measurement \emph{and} no other gate was executed meanwhile on any of the targets of this measurement, then the measurement gate will replace the corresponding positive control knobs (and might inherit \TikZ{} options of the embedding gate); otherwise, it will behave as if the \texttt{indirect} option had been specified.

            Some care must be taken when gates are named that are affected by this option.
            If the embedding gate is named, the positive controls that will be replaced by measurements are no longer available with the ``\texttt{p}''~suffix (but other positive controls will still be numbered as if all were).
            Attach the name to the measurement in order to access it as if it were an ordinary gate; however, note that the name only becomes available after the later embedding gate was called.

            Note that this setting affects all measurements that have a compatible shape; currently, this is only \gate{measure}.
            While there is no technical difficulty in implementing the same behavior for \gate{dmeter}, its particular shape does not really suggest this use.
            However, if you desire to do so, please file a feature request.
         \end{option}

      \subsection{Styles for operators}\unskipOpt
         \begin{option}[Changed in 0.4]{operators/every barrier}!shape=yquant-line, dashed, draw, shorten <= -1mm, shorten >= -1mm!
            This style is installed for every \gate{barrier} pseudo\hyp gate, i.e., the one that is used to explicitly denote a separation between ``before'' and ``after'' within the circuit.

            Note that the \texttt{shorten} keys are only present in the default style if you specify at least the compatibility version \texttt{0.4}.
         \end{option}

         \begin{option}[Changed in 0.6]{operators/every box}!/yquant/operators/every rectangular box!
            This style is installed for every \gate{box} operator.
            Note that with a \texttt{compat} setting strictly smaller than~\texttt{0.6}, the definition of this style was the one that is now \style{/yquant/operators/every rectangular box}, and this style was also the base style from which all box\hyp like gates inherited.
            With a \texttt{compat} setting of at least~\texttt{0.6}, no other gates apart from \gate{box} will use this style directly or indirectly.
         \end{option}

         \begin{option}[Changed in 0.4\\New in 0.2]{operators/every custom gate}!/yquant/operators/subcircuit/seamless!
            This style is by default installed for every user\hyp defined gate.
            User\hyp defined gates are implemented via subcircuits; this style suppresses the box that surrounds the subcircuit and by default suppresses all register names.
            This allows a seamless integration of the gate/subcircuit into the main circuit, without putting particular emphasis to the fact that what was defined as the custom gate indeed belongs together.
            Note that with the \texttt{compat} key set before \texttt{0.4}, this style instead defaults to \tex!/yquant/operators/subcircuit/frameless, /yquant/register/default name=!.
         \end{option}

         \begin{option}[Changed in 0.7]{operators/every dmeter}!shape=yquant-dmeter, time radius=2mm, space radius=2mm, draw, /yquant/default fill!
            This style is installed for every \gate{dmeter} gate.
            The \texttt{yquant-dmeter} shape consists of a rectangle whose right side is replaced by a circle, resembling the letter ``D.''
         \end{option}

         \begin{option}{operators/every h}!/yquant/operators/every rectangular box!
            This style is installed for every \gate{h} (Hadamard) operator.
         \end{option}

         \begin{option}[Changed in 0.7]{operators/every inspect}!shape=yquant-output, align/.expanded=\ifyquanthorz{left}{center}, outer timesep=.3333em, space radius=2.47mm, /yquant/default fill, /yquant/operator/if multi={draw, decoration={gapped brace, raise=2pt, \ifyquanthorz{}{mirror}}, decorate}!
            This style is installed for every \gate{inspect} gate.
            It does not have any shape on its own, apart from multi\hyp register uses, in which it will contain a brace on its left (in vertical mode: on its top).
         \end{option}

         \begin{option}[New in 0.7.2]{operators/every iswap}!shape=yquant-ocross, radius=.75mm, draw!
            This style is installed for every \gate{iswap} gate that interchanges two qubits and conditionally adds phases.
            The \texttt{yquant-iswap} shape is a cross enclosed in a circle.
         \end{option}

         \begin{option}[Changed in 0.7]{operators/every measure}!shape=yquant-measure, x radius=4mm, y radius=2.5mm, draw, /yquant/default fill!
            This style is installed for every \gate{measure} gate.
            The \texttt{yquant-measure} shape is a rectangle that contains a ``meter'' symbol.
            It allows for a text to be put inside (e.g., a basis), which then shifts the meter symbol accordingly.
         \end{option}

         \begin{option}{operators/every measure meter}!draw, -{Latex[length=2.5pt]}!
            This style is applied to the path that resembles the ``meter'' symbol that is drawn by the \texttt{yquant-measure} shape.
            Due to the default style, the \TikZ{} library \pkg{arrows.meta} is automatically loaded with \Yquant.
         \end{option}

         \begin{option}{operators/every not}!shape=yquant-oplus, radius=1.3mm, draw!
            This style is installed for every \gate{not} or \gate{cnot} gate (which are synonyms, and actually do the same as the Pauli~$\sigma_x$ gate).
            The \texttt{yquant-oplus} shape resembles the addition\hyp modulo\hyp two symbol $\oplus$.
         \end{option}

         \begin{option}{operators/every pauli}!/yquant/operators/every rectangular box!
            This style is installed for every Pauli operator, i.e., \gate{x}, \gate{y}, and \gate{z}.
         \end{option}

         \begin{option}{operators/every phase}!shape=yquant-circle, radius=.5mm, fill!
            This style is installed for every \gate{phase} gate $\ketbra00 + \ee^{\ii\phi} \ketbra11$.
         \end{option}

         \begin{option}[Changed in 0.7\\New in 0.6]{operators/every rectangular box}!shape=yquant-rectangle, draw, align=center, inner timesep=1mm, time radius=2mm, space radius=2.47mm, /yquant/default fill!
            This style is not associated to any particular gate, but will be inherited by a lot of gates that have a rectangular box frame with some text.
            This style should not be used with a \texttt{compat} setting strictly smaller than~\texttt{0.6}.
         \end{option}

         \begin{option}{operators/every slash}!shape=yquant-slash, x radius=.5mm, y radius=.7mm, draw!
            This style is installed for every \gate{slash} pseudo\hyp gate, i.e., the one that is used to indicate that a single register line actually denotes multiple registers.
         \end{option}

         \begin{option}[New in 0.2]{operators/every subcircuit}!!
            This style is installed for every \gate{subcircuit}.
            Note that all styles given here will also apply to every element in the subcircuit; in a way, this is an addition to \style{/yquant/every circuit} (which is also again put into effect at the beginning of a subcircuit).
         \end{option}

         \begin{option}[New in 0.2]{operators/every subcircuit box}!/yquant/operators/every rectangular box, fill=none!
            This style is installed for every \gate{subcircuit}.
            Note that in contrast to all other styles such as \style{/yquant/operators/every subcircuit} or \style{/yquant/this operator}, this style is only applied to the ``container'' node of the subcircuit, but not to the elements in the subcircuit themselves.
            Also note that the box style by default contains an \texttt{inner xsep} that will be added as an inside padding.
            This makes sense if your wires have labels so that these labels don't move too closely to the border of the box.
            However, if you do not labelled wires but still want to have a box around the subcircuit, you should consider removing the separation---as it will be added to the initial wire padding given by \style{/yquant/operator/separation}.
         \end{option}

         \begin{option}[New in 0.2]{subcircuit box style}!/yquant/operators/every subcircuit box/.append style={#1}!
            This is a shorthand to append styles to the subcircuit box only.
         \end{option}

         \begin{option}[New in 0.2]{operators/this subcircuit box}!!
            This style is appended to the current style installed for the \gate{subcircuit}, but will not apply to its contents.
            Additionally, this style will be reset to an empty style at the beginning of each subcircuit, so that it really only applies to exactly the subcircuit box it is explicitly specified on, not to nested subcircuit boxes.
         \end{option}

         \begin{option}[New in 0.2]{this subcircuit box style}!/yquant/operators/this subcircuit box/.append style={#1}!
            This is a shorthand to append styles to the current subcircuit box only.
         \end{option}

         \begin{option}[New in 0.4]{operators/subcircuit/frameless}!/yquant/operators/this subcircuit box/.append style={draw=none, inner sep=0pt}!
            This is a shorthand style that removes the frame and additional inner separation for the current subcircuit.
            Note that still, the wire padding given by \style{/yquant/operator/separation} is present within the---now invisible---outer box that contains the subcircuit (use \style{/yquant/operators/subcircuit/seamless} to suppress it).
            Hence, the most prominent application of this key is if the wires before and after the subcircuit are \gate{nobit}s, which provides a clean way to build up circuit equations with perfectly aligned wires (examples can be found in \cref{sec:examples}).
         \end{option}

         \begin{option}[New in 0.5]{operators/subcircuit/name mangling}!prefix or discard!
            This option defines how named nodes within subcircuits are made available to the outer circuit:
            \begin{itemize}
               \item \texttt{prefix or discard} \\
                  If the subcircuit itself has a name $s$ and the inner gate has a name $g$, the outer circuit can refer to the inner gate via the name \texttt{$s$-$g$}.
                  Note that $s$ itself may not only consist of the user\hyp specified name, but may instead already be suffixed by \texttt{-0}, \texttt{-1}, \dots, if the subcircuits were assigned to multiple targets.

                  If the subcircuit itself has no name, works as \texttt{discard}.
               \item \texttt{prefix or transparent} \\
                  If the subcircuit itself has a name, as works as \texttt{prefix or discard}; else, works as \texttt{transparent}.
               \item \texttt{transparent} \\
                  The inner gates are always available in the outer circuit by their original names.
                  Note that this may potentially lead to naming conflicts, which are always resolved by the latest name overwriting all previous declarations without notice.
               \item \texttt{discard} \\
                  The inner gates will not be available in the outer circuit.
            \end{itemize}
            Note that if a new gate is defined via \tex!\yquantdefinegate!---which internally uses subcircuits---the value of this option at the time of declaration is the relevant one, not the one at the time of usage.
            This can be influenced via \style{/yquant/operators/subcircuit/name mangling reset}.
         \end{option}

         \begin{option}[New in 0.5]{operators/subcircuit/name mangling reset}!true!
            The current value of \style{/yquant/operators/subcircuit/name mangling} will be reset at the beginning of a subcircuit to the value it had upon declaration of the subcircuit only if this option is \texttt{true} upon \emph{using} the subcircuit (which typically will only make a difference if the subcircuit was defined via \tex!\yquantdefinegate! at some earlier stage).
            \begin{warning}
               Setting this value to \tex!false! has the potential of breaking the corresponding subcircuit/custom gate, as it may internally reference gates by names that are no longer the correct ones.
               Do not use this property without a very good reason and thorough understanding of what is happening.
            \end{warning}
         \end{option}

         \begin{option}[New in 0.4]{operators/subcircuit/seamless}!/yquant/operators/subcircuit/frameless, /yquant/register/default name=, /yquant/circuit/seamless!
            This option carries out multiple actions that are responsible to let the current subcircuit appear in a ``seamless'' state:
            \begin{itemize}
               \item It calls \style{/yquant/operators/subcircuit/frameless}.
               \item It sets \style{/yquant/circuit/seamless} to \texttt{true}.
               \item It ensures that \style{/yquant/circuit/seamless} is reset within the subcircuit, so that it does not propagate to nested subcircuits.
            \end{itemize}
         \end{option}

         \begin{option}{operators/every swap}!shape=yquant-swap, radius=.75mm, draw!
            This style is installed for every \gate{swap} gate that interchanges two qubits.
            The \texttt{yquant-swap} shape consists of a single cross.
         \end{option}

         \begin{option}[Changed in 0.7\\New in 0.6]{operators/every text}!shape=yquant-rectangle, align=center, inner timesep=1mm, time radius=2mm, space radius=2.47mm, /yquant/default fill!
            This style is installed for every \gate{text} gate.
         \end{option}

         \begin{option}[New in 0.1.2]{operators/every wave}!shape=yquant-circle, radius=.5mm, fill!
            This style is installed for every \gate{correlate} gate.
         \end{option}

         \begin{option}{operators/every x}!/yquant/operators/every pauli!
            This style is installed for every Pauli operator $\sigma_x$, i.e., \gate{x}.
         \end{option}

         \begin{option}[Changed in 0.7]{operators/every xx}!shape=yquant-rectangle, radius=.75mm, draw, /yquant/default fill!
            This style is installed for every \gate{xx} gate in symmetrized notation ($\ketbra{++}{++} + \ketbra{+-}{+-} + \ketbra{-+}{-+} - \ketbra{--}{--}$).
         \end{option}

         \begin{option}{operators/every y}!/yquant/operators/every pauli!
            This style is installed for every Pauli operator $\sigma_y$, i.e., \gate{y}.
         \end{option}

         \begin{option}{operators/every z}!/yquant/operators/every pauli!
            This style is installed for every Pauli operator $\sigma_z$, i.e., \gate{z}.
         \end{option}

         \begin{option}{operators/every zz}!shape=yquant-circle, radius=.5mm, fill!
            This style is installed for every \gate{zz} gate (aka \textsc{CPhase}) in symmetrized notation ($\ketbra{00}{00} + \ketbra{01}{01} + \ketbra{10}{10} - \ketbra{11}{11}$).
         \end{option}

   \section{Doing the impossible}\label{sec:tikz}
      \Yquant{} will almost certainly never be able to do everything an author has in mind.
      Sometimes, there is the need to draw something non\hyp standard, and this cannot be implemented in the \Yquant{} language.
      However, since \Yquant{} is a layer on top of \TikZ, it should be very hard to find something (meaningful) that cannot be done by combining the power of both packages.

      \subsection{Mixing \texorpdfstring{\Yquant}{yquant} and \texorpdfstring{\TikZ}{TikZ} code}
         Before or after any gate, you may interrupt the \Yquant{} instructions to perform arbitrary \TikZ{} path operations.
         After every such operation, \Yquant{} will automatically restart its parser so that you can fluently jump between \Yquant{} and \TikZ{} code.
         You can even interject arbitrary \TeX{} code (or, say, low\hyp level \pkg{pgf} commands); however, then, \Yquant{} is not able to restart its parser.
         For this reason, after the last command in a block of \TeX{} commands, you must issue \tex!\yquant!, which then re\hyp enables the \Yquant{} language.

      \subsection{Accessing gates in \texorpdfstring{\TikZ}{TikZ}}
         The feature to perform arbitrary \TikZ{} operations is powerful in itself, but would be of limited use were there no way to access the elements in the quantum circuit.
         \Yquant{} provides a global attribute \texttt{name} that can be assigned to every gate.
         All quantum operations are in fact \TikZ{} nodes, and the name you give to them then becomes a \TikZ{} name, which you can easily reference to get the coordinates of a particular operator.
         Note that the name you specify is only available if a single register is targeted.
         The name is suffixed by \tex!-\idx!, where \tex!\idx! refers to the (zero\hyp based) index of the operation ordered from top to bottom (i.e., if an operator acts on two qubits and should be named \texttt{op}, the topmost operator will be available as \texttt{op-0} and the second as \texttt{op-1}).
         Multiple slices in a discontiguous multi\hyp register are additionally suffixed by \texttt{-s\textit{<slice index>}}.
         All controls are also named, suffixed by \tex!-p\idx! or \tex!-n\idx! for positive and negative controls (i.e., the topmost positive control of the previous operator will be available as \texttt{op-p0}).
         Counters for target registers, positive, and negative controls are all independent.
         Finally, you can even access names within a subcircuit, provided you give a name to the subcircuit.
         All nodes in the subcircuit will then have the name \texttt{\textit{<subcircuit name>}-\textit{<name specified in the subcircuits>}}.
         Note that here, \texttt{\textit{<subcircuit name>}} is the \emph{full} name of the subcircuit, which includes the \tex!-\idx! suffix, \compat{New in 0.4.1}unless there is only a single target register.
         For nested subcircuits, you will get multiple prefixes.
         \compat{New in 0.5}The prefixing behavior can be influenced by \style{/yquant/operators/subcircuit/name mangling}.

      \subsection{Shapes and the drawing pipeline}\label{sec:pipeline}
         All \Yquant{} shapes have the anchors available you would typically expect from a \TikZ{} shape of the given outline.
         The \texttt{center} anchor will be aligned to the wire.
         \compat{Changed in 0.1.2}In addition to the normal paths implemented by \TikZ{} shapes, the width and height of those fit for \Yquant{} at least twice as large as given by the \texttt{/tikz/x~radius} and \texttt{/tikz/y~radius}; and they must implement clipping paths, a \Yquant{} addition to \TikZ{} shapes.
         Such a path has to provide the ``clipping outline,'' i.e., anything that should not contain register or control lines.
         There may be a difference between horizontal and vertical clipping outlines.
         To understand clipping paths, \Yquant's drawing pipeline needs to be explained.
         \begin{itemize}
            \item In a first run---this is what happens directly at the position where you type the gate command---\Yquant{} will ``virtually'' draw the gates in order to determine their dimensions and calculate register heights.
               The actual drawing commands are written to a macro (this is the cause that some macros must be preceded by \tex!\protect! if used in a gate \texttt{value}---in fact, if multiple registers are targeted in one gate, the style and values required for this gate are only stored once, so that for example \tex!\idx! is a \tex!\protected! macro until the very end).
            \item \compat{New in 0.4}Deferred gates (measurements that may replace future control knobs) are stored temporarily and queried when the next gate is executed or at the end of the circuit.
               The corresponding commands---either re\hyp inserting if they must appear at their original position or substituting the controls---are inserted appropriately.
            \item When \tex!\end{yquant}! is encountered, the vertical positions are determined and the actual drawing commands are executed.
            \item Unless the operation changes the wire type or style, do the following (first two items for every register at which an operator node has to be created).
               \begin{itemize}
                  \item Create the operator node at the appropriate position.
                  \item Call \tex!\pgfshapeclippath! on the newly created node.
                     This will first determine whether the node was stroked; if not, \tex!\pgflinewidth! is set to zero.
                     Then, it will call the horizontal clipping path, which is supposed to create some soft path commands.
                     Those soft path commands are collected in a macro on a per\hyp register basis and the soft path is cleared.
                     The same happens for the vertical clipping path, which is collected in a macro on a per\hyp operation basis.
                  \item If control lines or multi lines are to be drawn, the vertical clipping path commands are now executed and installed as an inverted\footnote{Inverting the clipping means that instead of drawing only \emph{within} the clipping path (which corresponds to the gates), we only draw \emph{outside}. However, as there is no direct support for this, we invert by exploiting the even\hyp odd rule. If you specify a register multiple times, whether as target, control, or mixed, funny effects can be expected, as the clipping region is inverted multiple times. Note that using a register more than once is always an error, but \Yquant{} does not check for it due to the high overhead.} clipping.
                  \item Control lines and multi lines are drawn (in this order) from one to the next \texttt{center} anchor.
                     Due to the clipping commands, this will create a perfect connection with the shape of the gate, but even transparent gates are possible without the lines being visible.
               \end{itemize}
            \item If the operation changes the wire type or style, or if there is no operation left on this register, the following is done.
               \begin{itemize}
                  \item Load the clipping paths accumulated for all the gates acting on this register and install the inverted clipping.
                  \item Draw the wire as one continuous line from where the last wire ended (or the beginning of the circuit) to the center of the last gate, or to the common end position for all wires of the circuit.
                  \item Remove the clipping paths stored so far on this register, apart from the clipping on the last gate (which will be needed again if this was not the end of the circuit).
               \end{itemize}
         \end{itemize}

         \compat{New in 0.7}Note that \Yquant{} also supports a simplified drawing pipeline which does not involve clipping paths.
         It can be enabled by setting the \style{/yquant/drawing mode} option to \texttt{size}.
         The simplified pipeline has the following benefits:
         \begin{itemize}
            \item \TeX{} has to compute a bit less, so the compilation process can be sped up.
            \item PDF readers may render the circuit faster.
            \item The size of the output files is decreased.
            \item Compatibility with very simplistic clients that don't support clipping well is improved (this may be an issue for some PDF to image converters, for example).
            \item Theoretically, you may use any kind of predefined shape in this mode (from \TikZ{} or other packages), since the clipping paths are no longer required.
         \end{itemize}
         However, with it come certain drawbacks:
         \begin{itemize}
            \item Gates are no longer transparent, but filled with some fixed background color, so if transparency is important for you, this just does not work.
            \item \Yquant{} relies on \TikZ's layering capabilities; if you use layers by yourself, you have to pay some attention to do it correctly.
            \item The z\hyp order may not be as you expect it; in particular:
               All the gates will be drawn on the \texttt{main} layer; all the wires on the \texttt{wires} layer, which is behind \texttt{main}; so if you don't use layers by yourself, everything that you draw will overshadow the wires, but not necessarily the gates.
            \item If you were to fill a subcircuit, this would then erase all the internal wires.
               Hence, the box of a subcircuit is drawn on the \texttt{behindwires} layer; but this implies that also the \emph{frame} of the box is drawn behind the wires and that this box is also overshadowed by any of your drawing.
            \item Wires that visually cross gates which are not part of the gate may be displayed differently from the standard pipeline.
         \end{itemize}
         Unless you use \tex!\pgfsetlayers! to add the layers \texttt{wires} and \texttt{behindwires} manually, \Yquant{} will automatically place the \texttt{wires} layer directly before \texttt{main}; then it will place \texttt{behindwires} directly before \texttt{wires}.
         This in particular ensures full compatibility with the \texttt{backgrounds} library: the background layer is still the very first in the layer list.
         In contrast to \pkg{pgfplots}, this automatism should work even if the \Yquant{} environment is placed within groups.

      \subsection{Overwriting the height and depth calculation}
         \Yquant{} automatically takes care of calculating the height and depth of all registers, so that their final vertical positions are chosen without overlap.
         This is almost always advisable, but it has some weaknesses:
         \begin{itemize}
            \item If you specify a multi\hyp register gate, say, extending for three registers and this requires a certain height and depth, where should this be accounted for?
               \compat{New in 0.4}\Yquant{} is able to handle these situations by first determining all heights and depths that can safely be attributed to individual registers.
               After that, it checks for all multi\hyp register gates: Is the space from the top of the first to the bottom of the last register enough to hold the multi\hyp qubit gate?
               If not, it evenly distributes the additional required space to all registers that are visually within the range of this multi\hyp register.

               This will fail to produce good results (hopefully) only in two cases:
               \begin{itemize}
                  \item If you place \texttt{label}s on the gate, those are outside of the gate---and typically, either below or above.
                     Hence, the additional extent stemming from them should \emph{not} be equally distributed among all registers, but either to the height of the first or the depth of the last one.
                     Currently, \Yquant{} is unable to detect this (and, considering the fact that you can place \texttt{label}s at any angle, this is not an easy problem to solve except for special cases).
                  \item If you make use of a discontiguous \gate{init} gate with a large vertical extent, \Yquant{} will correctly allocate space as if the gate's content were placed in the vertical center.
                     However, if there is no way to put the arch of the brace at the middle, as the register at this position is excluded from the gate, the content will be shifted---but only \emph{after} calculating the extent.
                     Hence, the automatically calculated vertical positions will be unsuitable.
               \end{itemize}
            \item Sometimes, there is more space available than \Yquant{} thinks because you already discarded some wire.
               \Yquant{} does not keep track of whether the wires below or above a gate are actually visible at this position---which is not even be known at the time the gate command is issued, as horizontal positions are determined only in the drawing stage.
               Hence, you may choose to draw ``within'' the other, invisible wire.
         \end{itemize}

         \compat{New in 0.4}In these certain special cases, you may want to turn off the automatic calculation for one particular gate.
         Note that you may then, depending on the situation, obtain results with overlapping gates.
         You can use the keys \style{/yquant/register/minimum height} and \style{/yquant/register/minimum depth} when declaring the relevant register to manually specify a larger desired value, but you have to experiment with regard to what this value is.

         The global attribute \texttt{overlay} (conveniently overshadowing \TikZ's \texttt{overlay} key, which should not be used for gates) can take the values
         \begin{itemize}
            \item \texttt{true} (default if no value given, combines \texttt{multi}, \texttt{height}, and \texttt{depth}),
            \item \texttt{multi} (short \texttt{m}),
            \item \texttt{height} (short \texttt{ht}, \texttt{h}), equivalent to \texttt{left} (short \texttt{l}) and \texttt{before} (short \texttt{bef}, \texttt{b}), which sound more meaningful for vertical and generic circuit orientations,
            \item \texttt{depth} (short \texttt{dp}, \texttt{d}), equivalent to \texttt{right} (short \texttt{r}) and \texttt{after} (short \texttt{aft}, \texttt{a}), which sound more meaningful for vertical and generic circuit orientations,
            \item \texttt{single} (short \texttt{s}, combines \texttt{height} and \texttt{depth}), and
            \item \texttt{false} (useless, default if attribute not given).
         \end{itemize}
         It disables the calculation of the selected vertical extent for this particular gate.
         (In fact, \texttt{multi}, \texttt{height}, \texttt{depth}, and \texttt{single} are subkeys that accept boolean values.)

   \section{Reference: Gates and operations}\label{sec:gates}
      This section lists all operations \Yquant{} currently understands.
      It also details all arguments that can be given to customize the operation, apart from \texttt{name} and \compat{New in 0.4}\texttt{overlay}, which are always available.
      Note that the \tex![value=<value>]! attribute can (and should) alternatively be given as a braced expression that follows the name of the register.
      Within \tex!<value>!, unless specified differently, the macro \tex!\idx! is always available and corresponds to the index of the current register in the list of targets.

      \subsection[\texorpdfstring{\yquant{addstyle}}{addstyle}]{\compat{New in 0.1.2}\yquant!addstyle!}\label{gate:addstyle}
         Syntax: \yquant!setstyle <target>;! \\
         This is an invisible pseudo\hyp gate that immediately changes the \TikZ{} style with which the register lines of all target registers are drawn.
         It adds to the styles that are already installed.
         Use \gate{setstyle} to replace styles.
         It may not span multiple registers and does not allow for controls.

         \emph{Possible attributes:}
         \begin{itemize}
            \item \yquant![value=<styles>]! (required) \\
               Denotes the new styles; this should be a string that could be passed to \tex!\tikzset!.
         \end{itemize}

      \subsection{\texorpdfstring{\yquant{align}}{align}}\label{gate:align}
         Syntax: \yquant!align <target>;! \\
         This is an invisible pseudo\hyp gate that enforces all affected registers to share a common horizontal position for their next gate, which is determined by the largest position of all gates involved.
         It may not span multiple registers and does not allow for controls.
         \compat{Changed in 0.4}The gate now always aligns the wires, i.e., if they are discarded directly after this gate, they will still discarded all at the same position.

         \emph{Possible attributes:} none

      \subsection{\texorpdfstring{\yquant{barrier}}{barrier}}\label{gate:barrier}
         Syntax: \yquant!barrier <target>;! \\
         This is a pseudo\hyp gate that denotes some physical barrier that ensures execution with a specific timing; it is basically a visible version of the \hyperref[gate:align]{\yquant!align!} gate, denoted by a vertical line.
         It may span multiple registers, but does not allow for controls.
         The style \style{/yquant/operators/every barrier} is installed.

         \emph{Possible attributes:} none

      \subsection{\texorpdfstring{\yquant{box}}{box}}\label{gate:box}
         Syntax: \yquant!box <target> | <pcontrol> ~ <ncontrol>;! \\
         This is a generic register of a rectangular shape that can be filled with arbitrary content.
         It may span multiple registers and allows for controls.
         The style \style{/yquant/operators/every box} is installed.

         \emph{Possible attributes:}
         \begin{itemize}
            \item \yquant![value=<value>]! \\
               Denotes the content of the box.
         \end{itemize}

      \subsection{\texorpdfstring{\yquant{cbit}}{cbit}}\label{gate:cbit}
         Syntax: \yquant!cbit <name>[<len>];! \\
         Declares a register of type \texttt{cbit}.

         \emph{see \hyperref[gate:qubit]{\yquant!qubit!}}

      \subsection[\texorpdfstring{\yquant{correlate}}{correlate}]{\compat{New in 0.1.2}\yquant!correlate!}\label{gate:correlate}
         Syntax: \yquant!correlate <target>;! \\
         This is a pseudo\hyp gate that indicates a correlation (usually a Bell\hyp state) present between the multi\hyp registers involved.
         This gate should span multiple registers and does not allow for controls.
         The style \style{/yquant/operators/every wave} is installed.

         \emph{Possible attributes:} none

      \subsection{\texorpdfstring{\yquant{cnot}}{cnot}}\label{gate:cnot}
         Syntax: \yquant!cnot <target> | <pcontrol> ~ <ncontrol>;! \\
         This is a synonym for the \gate{not} gate.
         Note that despite its name, controls are not mandatory and also here, the style \style{/yquant/operators/every not} is installed.

      \subsection{\texorpdfstring{\yquant{discard}}{discard}}\label{gate:discard}
         Syntax: \yquant!discard <target>;! \\
         This is an invisible pseudo\hyp gate that changes the type of all target registers to \gate{nobit}, i.e., no line will be drawn for them.
         This has effect already for the outgoing line of the last gate on the target registers.
         The gate may not span multiple registers and does not allow for controls.
         To change a register type on\hyp the\hyp fly into something different from \gate{nobit}, use the \compat{Changed in 0.1.2}\gate{settype} pseudo\hyp gate.

         \emph{Possible attributes:} none

      \subsection{\texorpdfstring{\yquant{dmeter}}{dmeter}}\label{gate:dmeter}
         Syntax: \yquant!dmeter <target>;! \\
         This is a measurement gate, denoted by a ``D'' shape.
         It changes the type of all targets involved.
         It may span multiple registers, but does not allow for controls.
         The style \style{/yquant/operators/every dmeter} is installed.

         \emph{Possible attributes:}
         \begin{itemize}
            \item \yquant![value=<value>]! \\
               Allows to specify a text that will be included inside the gate, possible enlarging its width.
               For outside texts, use \TikZ{} \texttt{label}s instead.
            \item \yquant![type=<qubit|cbit|qubits>]! \\
               Allows to specify the type into which the affected targets are converted.
               Default is \gate{cbit}.
         \end{itemize}

      \subsection{\texorpdfstring{\yquant{h}}{h}}\label{gate:h}
         Syntax: \yquant!h <target> | <pcontrol> ~ <ncontrol>;! \\
         This is a Hadamard gate, $\bigl( \ketbra00 + \ketbra01 + \ketbra10 - \ketbra11 \bigr) \fracslash \sqrt2$, denoted by a rectangle that contains the letter $H$.
         It may not span multiple registers, but allows for controls. \\
         The style \style{/yquant/operators/every h} is installed.

         \emph{Possible attributes:} none

      \subsection{\texorpdfstring{\yquant{hspace}}{hspace}}\label{gate:hspace}
         Syntax: \yquant!hspace <target>;! \\
         This is an invisible pseudo\hyp gate that inserts a certain amount of white space into all target registers.
         It may not span multiple registers and does not allow for controls.
         \compat{Changed in 0.4}The gate now always has an effect, e.g., if the wire is discarded after this gate, it will still be extended by the given amount first.

         \emph{Possible attributes}:
         \begin{itemize}
            \item \yquant![value=<dim>]! (required) \\
               Gives the amount of white space that is to be inserted. Must be a valid (nonnegative) \TeX{} dimension.
         \end{itemize}

      \subsection[\texorpdfstring{\yquant{init}}{init}]{\compat{Changed in 0.4}\yquant!init!}\label{gate:init}
         Syntax: \yquant!init <target>;! \\
         This is a pseudo\hyp gate that (re)initializes a registers to a given state.
         It may span multiple registers, but does not allow for controls.
         The style \style{/yquant/every label} is installed.
         Note that this pseudo\hyp gate, unlike all others, behaves differently if it is the first operation acting on a register: in this case, it does not increment the horizontal position, but uses the space available to the left; and the style \style{/yquant/every initial label} is installed additionally.
         Internally, creating a new register with some printed name is translated into the creation of an unnamed register, followed by application of this gate with the desired text.

         \emph{Possible attributes:}
         \begin{itemize}
            \item \yquant![type=<qubit|cbit|qubits>]! \\
               Allows to specify the type into which the affected target registers are converted.
               Default is the type of the first target register that is different from \gate{nobit}, or \gate{qubit} if they all are \gate{nobit}.
               The style \texttt{/yquant/every <type> label} is installed additionally.
            \item \yquant![value=<value>]! (required) \\
               Denotes the label that is printed to the left of the wire.
         \end{itemize}

      \subsection[\texorpdfstring{\yquant{inspect}}{inspect}]{\compat{New in 0.4}\yquant!inspect!}\label{gate:inspect}
         Syntax: \yquant!inspect <target>;! \\
         This is a pseudo\hyp gate that allows to print the current state of one or multiple registers within a circuit.
         It may span multiple registers, but does not allow for controls.
         The style \style{/yquant/operators/every inspect} is installed.
         Essentially, it is the same as an \gate{output} gate that will be drawn immediately at the current position and not deferred until the end; hence, it also draws braces when used in a multi\hyp register context.
         \compat{New in 0.6}If this is not desired, use the \gate{text} gate instead.

         \emph{Possible attributes:}
         \begin{itemize}
            \item \yquant![value=<value>]! (required) \\
               Denotes the text that is to be printed.
         \end{itemize}

      \subsection[\texorpdfstring{\yquant{iswap}}{iswap}]{\compat{New in 0.7.2}\yquant!iswap!}\label{gate:iswap}
         Syntax: \yquant!iswap <targets> | <pcontrol> ~ <ncontrol>;! \\
         This is the two\hyp qubit i\textsc{swap} gate $\ketbra{00}{00} + \ii\ketbra{01}{10} + \ii\ketbra{10}{01} + \ketbra{11}{11}$ that exchanges two qubits and conditionally adds phases.
         It is denoted by crosses within circles at the affected registers which are connected by a control line.
         It may span multiple registers (in fact, it should always span exactly two registers, though \Yquant{} does not enforce this), and it allows for controls.
         However, refrain from combining \emph{multiple} two\hyp qubit targets \emph{together} with controls.
         The control line will extend from the first to the last of all registers involved in the operation, so that it is impossible to discern visually which registers should actually be swapped.
         Using multiple swaps without controls in one operation is fine, as well as a single controlled swap.
         The style \style{/yquant/operators/every iswap} is installed.

         \emph{Possible attributes:} none

      \subsection[\texorpdfstring{\yquant{measure}}{measure}]{\compat{Changed in 0.4}\yquant!measure!}\label{gate:measure}
         Syntax: \yquant!measure <target>;! \\
         This is a measurement gate, denoted by a rectangle with a meter symbol.
         It changes the type of all targets involved.
         It may span multiple registers, but does not allow for controls.
         The style \style{/yquant/operators/every measure} is installed.
         It may be deferred to be used instead of a control knob for a later gate using the \style{/yquant/every post measurement control} style or the suitable attributes; see the documentation for this style.

         \emph{Possible attributes:}
         \begin{itemize}
            \item \yquant![type=<qubit|cbit|qubits>]! \\
               Allows to specify the type into which the affected targets are converted.
               Default is \gate{cbit}.
            \item \yquant![value=<value>]! \\
               Allows to specify a text that will be included at the bottom of the rectangle (which will shift the meter symbol upwards accordingly).
               For outside texts, use \TikZ{} \texttt{label}s instead.
            \item \yquant![direct control]! \\
               Temporarily sets \style{/yquant/every post measurement control}\tex!=direct! for this particular gate.
            \item \yquant![indirect control]! \\
               Temporarily sets \style{/yquant/every post measurement control}\tex!=indirect! for this particular gate.
         \end{itemize}

      \subsection{\texorpdfstring{\yquant{nobit}}{nobit}}\label{gate:nobit}
         Syntax: \yquant!nobit <name>[<len>];! \\
         Declares a register of type \gate{nobit}.
         The \texttt{<name>} must be a self\hyp chosen name for the register which was not previously used as a register name in this circuit (but names can be re\hyp used in subcircuits).
         Names are case\hyp insensitive.
         The register can be made into a vector register by specifying \texttt{<len>} (default \tex!1!).

         \emph{Possible attributes:}
         \begin{itemize}
            \item \compat{New in 0.2}\yquant![out]! or \yquant![ancilla]! (required in subcircuits) \\
               \emph{see \gate{qubit}}
         \end{itemize}

      \subsection{\texorpdfstring{\yquant{not}}{not}}\label{gate:not}
         Syntax: \yquant!not <target> | <pcontrol> ~ <ncontrol>;! \\
         This is a \textsc{not} gate, $\ketbra01 + \ketbra10$, denoted by the $\oplus$ symbol.
         It may not span multiple registers, but allows for controls.
         Due to its common usage, the synonymous gate \hyperref[gate:cnot]{\yquant!cnot!} is provided.
         The style \style{/yquant/operators/every not} is installed.

         \emph{Possible attributes:} none

      \subsection[\texorpdfstring{\yquant{output}}{output}]{\compat{Changed in 0.4}\yquant!output!}\label{gate:output}
         Syntax: \yquant!output <target>;! \\
         This is a pseudo\hyp gate that allows to write some text at the very end of the register line.
         It may only be specified once per register.
         It may span multiple registers, but does not allow for controls.
         The style \style{/yquant/every output} is installed, and also the style \texttt{/yquant/every <type> output}, where \texttt{<type>} is the type of the affected register (at the time of printout).
         \compat{New in 0.6}Note that while outputs can be named, the name will only become available after the \tex!yquant! environment itself was ended (but of course before the outer \texttt{tikzpicture} was closed).

         \emph{Possible attributes:}
         \begin{itemize}
            \item \yquant![value=<value>]! (required) \\
               Denotes the text that is to be printed.
         \end{itemize}

      \subsection{\texorpdfstring{\yquant{phase}}{phase}}\label{gate:phase}
         Syntax: \yquant!phase <name> | <pcontrol> ~ <ncontrol>;! \\
         This is a phase gate, $\ketbra00 + \ee^{\ii\phi} \ketbra11$, denoted by a filled circle.
         It may not span multiple registers, but allows for controls.
         The style \style{/yquant/operators/every phase} is installed.

         \emph{Possible attributes:}
         \begin{itemize}
            \item \yquant![value=<value>]! (required) \\
               Denotes the angle $\phi$ that is to be printed together with the gate.
               Position and appearance can be influenced by setting the position of \TikZ{} labels, as this is internally used.
               Note that at the moment, it is not possible to change any label options on a gate\hyp type basis, only locally or fully globally (\TikZ{} feature request \href{https://github.com/pgf-tikz/pgf/issues/811}{\#811}).
         \end{itemize}

      \subsection{\texorpdfstring{\yquant{qubit}}{qubit}}\label{gate:qubit}
         Syntax: \yquant!qubit <name>[<len>];! \\
         Declares a register of type \texttt{qubit}.
         The \texttt{<name>} must be a self\hyp chosen name for the register which was not previously used as a register name in this circuit (but names can be re\hyp used in subcircuits).
         Names are case\hyp insensitive.
         The register can be made into a vector register by specifying \texttt{<len>} (default \tex!1!).

         \emph{Possible attributes:}
         \begin{itemize}
            \item \yquant![after=<regname>]! \\
               If given, the register will start not at the left of the circuit but instead at the position at which the last gate in the register \texttt{<regname>} ended.

               This attribute may not be given in combination with \yquant![in]! or \yquant![inout]!.
            \item \compat{New in 0.2}\yquant![in]!, \yquant![out]!, \yquant![inout]!, or \yquant![ancilla]! \\
               Default: \yquant![ancilla]! for top\hyp level circuits (do not change there); \yquant![inout]! for subcircuits.

               Determines how a subcircuit interacts with its parent circuit.

               Registers declared with the \yquant![ancilla]! attribute are available only to the subcircuit; they cannot be connected to an outside wire.

               Registers declared with the \yquant![in]! or \yquant![inout]! attribute will expect an outer wire of the same type to be present and will then be identical with this outer wire.
               Any changes applied to the wire within the subcircuit automatically also happen on the associated outer wire.
               If the attribute is \yquant![in]!, the wire will automatically be discarded at the end of the subcircuit (and hence also in the outer circuit, where it may be re\hyp initialized).
               This is different from applying the \gate{discard} gate in that the wire will still extend until the end of the subcircuit and may thus receive proper \gate{output}s.

               Registers declared with the \yquant![out]! attribute will expect a discarded outer wire to be present, which will be initialized to a \texttt{qubit} at the beginning of the subcircuit, and from then on be identical with the outer wire.
            \item \yquant![value=<value>]! \\
               Denotes the label that is printed to the left of the wire.
               If the value is omitted, the default is used (\style{/yquant/register/default name}, preinitialized to \tex!\regidx!).

               Inside the value, \tex!\reg! expands to \texttt{<name>}, \tex!\len! expands to \texttt{<len>}, \tex!\idx! expands to the current index within the vector register ($0 \leq \text{\tex!\idx!} < \text{\texttt{<len>}}$), and \tex!\regidx! expands to \tex!\reg! if \texttt{<len>} is one, or to \tex!\reg[\idx]! else.
         \end{itemize}

      \subsection{\texorpdfstring{\yquant{qubits}}{qubits}}\label{gate:qubits}
         Syntax: \yquant!qubits <name>[<len>];! \\
         Declares a register of type \texttt{qubits}.

         \emph{see \hyperref[gate:qubit]{\yquant!qubit!}}

      \subsection[\texorpdfstring{\yquant{setstyle}}{setstyle}]{\compat{New in 0.1.2}\yquant!setstyle!}\label{gate:setstyle}
         Syntax: \yquant!setstyle <target>;! \\
         This is an invisible pseudo\hyp gate that immediately changes the \TikZ{} style with which the register lines of all target registers are drawn.
         It replaces all previous styles.
         Use \gate{addstyle} to accumulate styles.
         It may not span multiple registers and does not allow for controls.

         \emph{Possible attributes:}
         \begin{itemize}
            \item \yquant![value=<styles>]! (required) \\
               Denotes the new styles; this should be a string that could be passed to \tex!\tikzset!.
         \end{itemize}

      \subsection[\texorpdfstring{\yquant{settype}}{settype}]{\compat{New in 0.1.2}\yquant!settype!}\label{gate:settype}
         Syntax: \yquant!settype <target>;! \\
         This is an invisible pseudo\hyp gate that immediately changes the type of the targets registers, taking effect with the output line extending from the last drawn gate.
         It may not span multiple registers and does not allow for controls.

         \emph{Possible attributes:}
         \begin{itemize}
            \item \yquant![value=<qubit|cbit|qubits>]! (required) \\
               Denotes the new type that is assigned to all registers.
               To change the type to \gate{nobit}, use the \hyperref[gate:discard]{\yquant!discard!} pseudo\hyp gate instead.
         \end{itemize}

      \subsection[\texorpdfstring{\yquant{setwire}}{setwire}]{\compat{Removed in 0.4\\Deprecated in 0.1.2}\yquant!setwire!}\label{gate:setwire}
         \emph{Use \gate{settype} instead.}

         This gate is only available if a compatibility version before \texttt{0.4} is chosen.

      \subsection[\texorpdfstring{\yquant{slash}}{slash}]{\compat{Changed in 0.4}\yquant!slash!}\label{gate:slash}
         Syntax: \yquant!slash <target>;! \\
         This is a pseudo\hyp gate used to denote that a single line actually represents multiple registers.
         It is drawn as a short slash through the line of the register.
         The style \style{/yquant/operators/every slash} is installed.
         Note that this gate will ignore the \style{/yquant/operator/minimum width} key.
         With a \texttt{compat} key of~0.3 or earlier, the gate was special in that it did not advance the horizontal position on the wire, which allows to use it on only some of the wires without leading to a ragged start of subsequent gates.
         However, as \Yquant's default separation is not large enough to give a pleasant layout when the slash is squeezed in the initial separation, this was dropped as of version~0.4.
         Use the \gate{align} gate after all \gate{slash}es to get a better layout.

         \emph{Possible attributes:} none

      \subsection[\texorpdfstring{\yquant{subcircuit}}{subcircuit}]{\compat{New in 0.2}\yquant!subcircuit!}\label{gate:subcircuit}
         Syntax: \yquant!subcircuit <target>;! \\
         This is a subcircuit gate which inserts independent quantum circuits at the current position within the circuit.
         It may span multiple registers, but is never split into contiguous slices.
         It allows for controls and may change the type of any target involved, depending on the particular subcircuit.
         The style \style{/yquant/operators/every subcircuit} is installed.

         \emph{Possible attributes:}
         \begin{itemize}
            \item \compat{New in 0.4}\yquant!frameless! \\
               This \style{/yquant/operators/subcircuit/frameless} style is activated with this shorthand.
            \item \compat{New in 0.5}\yquant!name mangling! \\
               This shorthand will pass the value of the attribute directly to the configuration key \style{/yquant/operators/subcircuit/name mangling}.
            \item \compat{New in 0.4}\yquant!seamless! \\
               The \style{/yquant/operators/subcircuit/seamless} style is activated with this shorthand (implies \yquant!frameless!).
            \item \yquant!value=<subcircuit>! (required) \\
               Denotes the content of the subcircuit.
               It is specified in the usual syntax of \Yquant.
               Note that, regardless of the outer environment, a subcircuit always implicitly uses the unstarred form, i.e., you must declare every register explicitly before its first usage.
               This is to make sure that the interface of the circuit, i.e., which registers are taken as input and/or output parameters and in which order, is not accidentally mistaken.

               The mapping between input and output registers is trivial for single\hyp qubit uses.
               For multi\hyp qubit uses, it works in the following way---in short, it matches in visual order.
               You declare input and output registers by using the appropriate attributes on the \gate{qubit}, \gate{cbit}, \gate{qubits} (or even \gate{nobit}) gates.
               The list of all non\hyp ancillas, from the topmost to the bottom\hyp most, forms the list of parameter registers of the subcircuit.
               This is exactly the number of registers that must be supplied within one multi\hyp qubit target.
               Also within the multi\hyp qubit target, we sort all registers from the topmost to the bottom\hyp most (in the order as they visually appear, not the order in which they are entered).
               Those two lists of equal length are then mapped $1:1$ to each other.
               Intermixing with ancillas is possible at every position and will lead to a vertical shift of the wires, until all registers, inner and outer, can be displayed flawlessly.

               As subcircuits follow the same rules as ordinary circuits, it is possible to mix them with arbitrary \TeX{} code, and also to access named gates within the subcircuit---but note that named gates in the outer circuit cannot be accessed (at least unless you play with the \texttt{name prefix} key in \TikZ).
               In order to access inner nodes from the outer circuit, the subcircuit itself must be named; the inner nodes are then prefixed by the name of the subcircuit and a dash.

               It is possible to nest subcircuits arbitrarily.
         \end{itemize}

      \subsection{\texorpdfstring{\yquant{swap}}{swap}}\label{gate:swap}
         Syntax: \yquant!swap <targets> | <pcontrol> ~ <ncontrol>;! \\
         This is the two\hyp qubit \textsc{swap} gate $\ketbra{00}{00} + \ketbra{01}{10} + \ketbra{10}{01} + \ketbra{11}{11}$ that exchanges two qubits.
         It is denoted by crosses at the affected registers which are connected by a control line.
         It may span multiple registers (in fact, it should always span exactly two registers, though \Yquant{} does not enforce this), and it allows for controls.
         However, refrain from combining \emph{multiple} two\hyp qubit targets \emph{together} with controls.
         The control line will extend from the first to the last of all registers involved in the operation, so that it is impossible to discern visually which registers should actually be swapped.
         Using multiple swaps without controls in one operation is fine, as well as a single controlled swap.
         The style \style{/yquant/operators/every swap} is installed.

         \emph{Possible attributes:} none

      \subsection[\texorpdfstring{\yquant{text}}{text}]{\compat{New in 0.6}\yquant!text!}\label{gate:text}
         Syntax: \yquant!text <targets> | <pcontrol> ~ <ncontrol>;! \\
         This is a pseudo\hyp gate that allows to write some text within the circuit.
         It may span multiple registers and allows for controls (though the situations in which controls make sense are pretty scarce).
         The style \style{/yquant/operators/every text} is installed.
         Contrary to the \gate{inspect} gate, this gate will not draw curly braces in multi\hyp register use.
         It basically corresponds to a \gate{box} gate with suppressed drawing.

         \emph{Possible attributes:}
         \begin{itemize}
            \item \yquant![value=<value>]! (required) \\
               Denotes the text that is to be printed.
         \end{itemize}

      \subsection{\texorpdfstring{\yquant{x}}{x}}\label{gate:x}
         Syntax: \yquant!x <target> | <pcontrol> ~ <ncontrol>;! \\
         This is a Pauli $\sigma_{\symup x}$ gate $\ketbra01 + \ketbra10$, denoted by a rectangle that contains the letter $X$.
         It may not span multiple registers, but allows for controls. \\
         The style \style{/yquant/operators/every x} is installed.

         \emph{Possible attributes:} none

      \subsection{\texorpdfstring{\yquant{xx}}{xx}}\label{gate:xx}
         Syntax: \yquant!xx <targets>;! \\
         This is a symmetric flip gate, denoted by joined open squares.
         It should span multiple registers and it allows for controls.
         The same warnings as for the \gate{swap} gate apply.
         The style \style{/yquant/operators/every xx} is installed.

         \emph{Possible attributes:} none

      \subsection{\texorpdfstring{\yquant{y}}{y}}\label{gate:y}
         Syntax: \yquant!y <target> | <pcontrol> ~ <ncontrol>;! \\
         This is a Pauli $\sigma_{\symup y}$ gate $-\ii\ketbra01 + \ii\ketbra10$, denoted by a rectangle that contains the letter $Y$.
         It may not span multiple registers, but allows for controls. \\
         The style \style{/yquant/operators/every y} is installed.

         \emph{Possible attributes:} none

      \subsection{\texorpdfstring{\yquant{z}}{z}}\label{gate:z}
         Syntax: \yquant!z <target> | <pcontrol> ~ <ncontrol>;! \\
         This is a Pauli $\sigma_{\symup z}$ gate $\ketbra00 - \ketbra11$, denoted by a rectangle that contains the letter $Z$.
         It may not span multiple registers, but allows for controls. \\
         The style \style{/yquant/operators/every z} is installed.

         \emph{Possible attributes:} none

      \subsection{\texorpdfstring{\yquant{zz}}{zz}}\label{gate:zz}
         Syntax: \yquant!zz <targets>;! \\
         This is a symmetric phase gate, denoted by joined filled circles.
         It should span multiple registers, but does not allow for controls.
         The same warnings as for the \gate{swap} gate apply.
         The style \style{/yquant/operators/every zz} is installed.

         \emph{Possible attributes:} none


   \section{Examples}\label{sec:examples}
      This section will contain lots of examples.
      On the left\hyp hand side, the output is given, while the code to construct the example is on the right.
      All examples that are provided originate from the examples supplied with \pkg{qasm}, \pkg{qcircuit}, and \pkg{quantikz}.
      We will essentially follow their manuals example\hyp by\hyp example, which gives a nice comparison in how to achieve the given feature using these packages and \Yquant{} instead.
      All examples of course require inclusion of the \Yquant{} package with newest compatibility in the preamble, and some also require \pkg{braket}.

      \subsection{\pkg{qasm} documentation}
      \begingroup%
         \yquantset{register/default name=$\ket{\reg_{\idx}}$}%
         The \pkg{qasm} documentation most often names the registers in the way $\ket{\mathrm{register}_{\mathrm{index}}}$.
         This can be achieved by writing
         \begin{minted}{tex}
qubit {$\ket{<name>_{\idx}}$} <name>[<len>];
         \end{minted}
         but if you want to realize this naming scheme for all circuits in your document, it is more convenient to say
         \begin{minted}{tex}
\yquantset{register/default name=$\ket{\reg_{\idx}}$}
         \end{minted}
         in the preamble, as is done here.

         \compat{New in 0.3}Note that \Yquant{} also directly supports the \pkg{qasm} syntax, see \cref{sec:foreign:qasm}.

         \begin{example}[test1 (create an EPR pair)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit q[2];

      h q[0];
      cnot q[1] | q[0];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
         \end{example}

         \clearpage
         \begin{example}<Updated in 0.1.1>[test2 (simple teleportation circuit)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit q[3];

      h q[1];
      cnot q[2] | q[1];
      cnot q[1] | q[0];
      h q[0];
      measure q[0-1];

      z q[2] | q[1];
      x q[2] | q[0];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
         \end{example}

         \begin{example}[test3 (swap circuit)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit q[2];

      cnot q[1] | q[0];
      cnot q[0] | q[1];
      cnot q[1] | q[0];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
         \end{example}

         \clearpage
         \begin{example}<Updated in 0.1.1>[test4 (quantum fourier transform on three qubits)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit j[3];

      h j[0];
      box {$S$} j[0] | j[1];
      box {$T$} j[0] | j[2];
      h j[1];
      box {$S$} j[1] | j[2];
      h j[2];
      swap (j[0, 2]);
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
         \end{example}

         \begin{example}[test5 (demonstrate arbitrary qubit matrix ops)]
            \begin{codeexample}
% \usepackage{amsmath}
\begin{tikzpicture}
   \begin{yquant}
      qubit j[2];

      box {$\begin{bmatrix}
         e^{i \alpha} & 0 \\
         0 & e^{-i \alpha}
      \end{bmatrix}$} j[1] | j[0];
      box {$\begin{bmatrix}
         \cos\theta & -\sin\theta \\
         \sin\theta & \cos\theta
      \end{bmatrix}$} j[0];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
         \end{example}

         \clearpage
         \begin{example}<Updated in 0.1.1>[test6 (demonstrate multiple-qubit controlled single-q-gates)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit j[4];

      cnot j[2] | j[0, 1];
      x j[0];
      box {$U$} j[1] | j[0, 2-3];
      h j[2];
      measure j[3];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
         \end{example}

         \begin{example}<Updated in 0.1.1>[test7 (measurement of operator with correction)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit q[2];

      h q[0];
      box {$U$} q[1] | q[0];
      h q[0];
      measure q[0];
      box {$V$} q[1] | q[0];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
         \end{example}

         \clearpage
         \begin{example}<Updated in 0.4>[test8 (stage in simplification of quantum teleportation)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit {$\ket{q_0} = \ket\psi$} q[1];
      qubit {$\ket{q_{\idx}} = \ket0$} q[+2];

      h q[1];
      cnot q[1] | q[0];
      cnot q[2] | q[1];
      cnot q[1] | q[0];
      h q[0];
      cnot q[2] | q[1];
      z q[0] | q[2];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
            Note that we left out two Hadamards at the end.

            Another way to provide various initial values in a single command is by performing case discrimination on \tex!\idx!, for example in the following manner:

            \begin{minted}{tex}
qubit {$\ket{q_{\idx}} = \Ifcase\idx\relax \ket\psi \Else \ket0 \Fi$} q[3];
            \end{minted}
            In principle, all \TeX{} conditionals that check against \tex!\idx! need to be prefixed by \tex!\protect!.
            If the \texttt{compat} key is at least \texttt{0.4}, \Yquant{} will make the commands \tex!\Ifnum!, \tex!\Ifcase!, \tex!\Or!, \tex!\Else!, \tex!\Fi!, \tex!\Unless! and \tex!\The! available for use within gates; they correspond in a certain way to auto\hyp\tex!\protect!ed versions of the corresponding \TeX{} primitives.
            Most likely, you will never need them inside values if not in the exact combination with \tex!\idx!.
         \end{example}

         \clearpage
         \begin{example}[test9 (two-qubit gate circuit implementation of Toffoli)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit q[3];

      box {$\sqrt X$} q[2] | q[1];
      cnot q[1] | q[0];
      box {$\sqrt X^\dagger$} q[2] | q[1];
      cnot q[1] | q[0];
      box {$\sqrt X$} q[2] | q[0];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
         \end{example}

         \begin{example}<Alternative in 0.1.2\\Updated in 0.1.1>[test10 (multi-qubit gates also demonstrates use of classical bits)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit {$\ket{q_0}$} q;
      cbit {$c_1$} c;
      qubit {$\ket{q_2}$} q[+1];

      h q[0];
      box {$U$} (q[0], c);
      box {$S$} q[1];
      box {$U$} (c, q[1]);
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
            Instead of a discontiguous vector register, we could also have used three scalar registers.
            The labels chosen for \pkg{qasm} do not fit well to the indices \Yquant{} assigns.
            We might also have used a three\hyp register vector and used the \gate{settype} pseudo\hyp gate to immediately change the second register into a classical one, which would give indices matching the labels---but still, the registers would have a common name, which would make this a very unnatural approach.
         \end{example}

         \clearpage
         \begin{example}<Updated in 0.1.1>[test11 (user-defined multi-qubit ops)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit q[3];

      h q[0];
      box {$U_{f(x)}$} (q[0, 1]);
      h q[1];
      box {$U_{f(x, y)}$} (q);
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
            Here we used the fact that a vector register can also be addressed as a whole.
            Instead of \tex!(q)!, we could have also written, e.g., \tex!(q[0]-q[2])! or \tex!(q[0-2])!, or enumerated all sub\hyp registers in a comma\hyp separated list.
         \end{example}

         \begin{example}<Updated in 0.1.1>[test12 (multi-qubit controlled multi-qubit operations)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit q[3];

      h q[0];
      box {$U$} (q[1-2]) | q[0];
      h q[0];
      box {$V$} (q[0-1]) | q[2];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
         \end{example}

         \clearpage
         \begin{example}[test13 (three-qubit phase estimation circuit with QFT and controlled-U)]
            \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant}
      qubit {$\ket{j_{\idx}} = \ket0$} j[3];
      qubit s[2];

      h j;
      box {$U^4$} (s) | j[0];
      box {$U^2$} (s) | j[1];
      box {$U$} (s) | j[2];
      h j[0];
      box {$S$} j[1] | j[0];
      h j[1];
      box {$T$} j[2] | j[0];
      box {$S$} j[2] | j[1];
      h j[2];
      measure j;
   \end{yquant}
\end{tikzpicture}
            \end{codeexample*}
         \end{example}

         \begingroup%
            \mdfapptodefinestyle{bdBox}{%
               leftmargin=-.12\linewidth,
               rightmargin=-.12\linewidth
            }%
            \begin{example}[test14 (three-qubit FT QEC circuit with syndrome measurement)]
               \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant}
      qubit q[3];
      qubit {$\ket{s_{\idx}} = \ket0$} s[2];
      cbit {$c_{\idx} = 0$} c[2];

      h s[0];
      cnot s[1] | s[0];
      cnot s[0] | q[0];
      cnot s[1] | q[1];
      cnot s[1] | s[0];
      h s[0];
      measure s;
      cnot c[0] | s[0];
      cnot c[1] | s[1];
      discard s; % to suppress wires extending until re-initialization

      init {$\ket0$} s;
      h s[0];
      cnot s[1] | s[0];
      cnot s[0] | q[1];
      cnot s[1] | q[2];
      cnot s[1] | s[0];
      h s[0];
      measure s;

      box {Process\\Syndrome} (s, c);
      box {$\symcal R$} (q) | s, c;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample*}
            \end{example}
         \endgroup%

         \clearpage
         \begin{example}<Updated in 0.1.1>[test15 (``D-type'' measurement)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit {$\ket{q_0} = \ket\psi$} q;
      qubit {$\ket{q_1} = \ket+$} q[+1];

      zz (q);
      dmeter {$H Z_\theta$} q[0];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
         \end{example}

         \begin{example}<Updated in 0.4, 0.1.2, 0.1.1>[test16 (example from Nielsen paper on cluster states)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit {$\ket{q_{\idx}} = \ket\psi$} q[2];
      qubit {$\ket{q_2} = \ket\phi$} q[+1];
      qubit {$\ket{q_3} = \ket0$} q[+1];

      zz (q[1], q[2]);
      align q;
      cnot q[3] | q[2];
      slash q[0];
      dmeter q[3];
      align q;
      [solid]
      barrier q[2];
      discard q[2];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
            We needed to include an \gate{align} pseudo\hyp gate to put the slash at the desired position.
            Usually, this would be sufficient to put the \gate{cnot} and the \gate{slash} gate directly under each other, as it is in the \pkg{qasm} example.
            However, the \gate{slash} gate is special in that it does not need horizontal space and is put with only half of the usual operator separation into the circuit (for this reason, it can be put at the beginning of a wire without creating weird shifts with respect to the ``unslashed'' registers---it is put in the initial line that every wire even without an operation has).
            Hence, you should normally only use the \gate{slash} gate as the very first gate in a circuit.
            To get the vertical stopper mark, we abuse a \gate{barrier} on just a single wire and turn it from dashed to solid before \gate{discard}ing.
         \end{example}

         \begin{example}<Updated in 0.1.1>[test17 (example from Nielsen paper on cluster states)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit {$\ket{q_0} = \ket\psi$} q;
      qubit {$\ket{q_{\idx}} = \ket+$} q[+2];
      qubit {$\ket{q_3} = \ket\phi$} q[+1];

      zz q[(0-1), (2-3)];
      zz (q[1-2]);
      dmeter {$H$} q[1-2];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
            This example shows how the multi\hyp qubit delimiter (the parenthesis) can even be used within indices.
         \end{example}

         \begin{example}<Updated in 0.1.2>[test18 (multiple-control bullet op)]
            \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit {$\ket{q_{\idx}} = \ket{\Ifcase\idx\relax \psi \Or + \Or + \Or \phi \Fi}$} q[4];

      zz (q);
      dmeter {$H$} q[1, 2];
   \end{yquant}
\end{tikzpicture}
            \end{codeexample}
            This gate is probably a generalization of \gate{zz}, $\symbb1 - 2 \ketbra{1\dotsm1}{1\dotsm1}$, and indeed since version~0.1.2, we can use \gate{zz} for this purpose.
            This time, we used the case distinction method in the initialization, as already alluded to before.
         \end{example}
      \endgroup

      \clearpage
      \subsection{\pkg{qcircuit} documentation}
      \begingroup%
         \yquantset{operator/separation=2mm}
         For a better orientation, we use the same section headings as the \pkg{qcircuit} manual.
         The manual uses unnamed registers a lot; often, we will use the \tex!yquant*! environment to make things more concise.
         As the \pkg{qcircuit} manual uses a bit larger separation between the operators than \Yquant's default, we globally say\\*\tex!\yquantset{operator/separation=2mm}!.

         \subsubsection{I. Introduction}
            \begin{example}<Updated in 0.5, 0.4, 0.1.1>%
               \begin{codeexample*}
% \useyquantlanguage{groups}
\begin{yquantgroup}
   \registers{
      qubit {} q[3];
   }
   \circuit{
      box {$U$} q[2] | q[0, 1];
   }
   \equals
   \circuit{
      box {$V$} q[2] | q[1];
      cnot q[1] | q[0];
      box {$V^\dagger$} q[2] | q[1];
      cnot q[1] | q[0];
      box {$V$} q[2] | q[0];
   }
\end{yquantgroup}
               \end{codeexample*}
               The best way to realize circuit equalities is with the help of \pkg{groups} language extension, which is documented in \cref{sec:foreign:groups}.
            \end{example}

            \begin{example}<Updated in 0.4>
               \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant}
      qubit {$\ket\psi$} a;
      qubit {$\ket0$} b[2];

      h b[1];
      cnot b[0] | b[1];
      cnot b[0] | a;
      h a;
      align a, b;
      measure a;
      [direct control]
      measure b[0];

      x b[1] | b[0];
      z b[1] | a;

      discard a;
      discard b[0];
      output {$\ket\psi$} b[1];
   \end{yquant}
\end{tikzpicture}
               \end{codeexample*}
               Here, we see how to use a measurement as a direct output for the next controlled operation.
            \end{example}

            \begin{example}<Updated in 0.4>
               \begin{codeexample*}
% \usetikzlibrary{quotes}
\begin{tikzpicture}
   \begin{yquant}
      qubit {} msg[3];
      nobit syndrome[3];

      [this subcircuit box style={dashed, "Syndrome Measurement"}]
      subcircuit {
         qubit {} msg[3];
         [out]
         qubit {$\ket0$} syndrome[3];

         cnot syndrome[0] | msg[0];
         cnot syndrome[0] | msg[1];
         cnot syndrome[1] | msg[1];
         cnot syndrome[1] | msg[2];
         cnot syndrome[2] | msg[0];
         cnot syndrome[2] | msg[2];

         dmeter {$M_{\symbol{\numexpr`a+\idx}}$} syndrome;
      } (msg[-2], syndrome[-2]);

      ["Recovery"]
      box {$\mathcal R$} (msg) | syndrome;
      discard syndrome;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample*}
               The example demonstrates how to put a description next to a gate.
               In general, those descriptions should be realized using the \TikZ{} feature \texttt{label}.
               Using the \TikZ{} library \texttt{quotes}, the label is most easily specified.
               Since the label is not part of the valid arguments and also cannot be found in the \texttt{/yquant} path, it is automatically passed to \style{/yquant/operator style}.

               To enclose a part of the circuit by a rectangle, we use a subcircuit.
               We define the incoming \gate{qubit}s in the outer circuit, they will have the default attribute \texttt{[inout]}; the syndrome registers, which are created only in the subcircuit enter as \gate{nobit}s and consequently have the \texttt{[out]} attribute.
               It is important to note that both the \texttt{dashed} style as well as the \texttt{label} (here with quoted syntax) are specified only inside \style{/yquant/this subcircuit box style}.
               This ensures that they are not also attached to every single gate in the subcircuit.

               Then we see how to apply an operation to multiple registers in parallel while using the \tex!\idx! macro to still give them a different text.
               Since \tex!\idx! gives a numerical index (zero\hyp based), we exploit the ASCII code (actually, this document is compiled in Unicode mode...) to turn this into a letter.

               Note that it could have become necessary to pass the \texttt{overlay} attribute to the recovery gate, as it is a multi\hyp register gate with a \texttt{label}, meaning that \Yquant{} cannot reliably distribute its total vertical extent over its constituent registers.
               However, as the $\symcal R$ together with the label in total were not higher than the three\hyp qubit gate would have been anyway, this was not necessary here.
               In generally, don't use \texttt{overlay} unless necessary; maybe a future version will even be able to handle the more difficult cases better.

               Finally, we will give a similar circuit by using the \TikZ{} interface instead of subcircuits, this time also showing how we can change the shape of the measurement gate to one as in the \pkg{qcircuit} manual:

               \begin{codeexample*}
% \usetikzlibrary{fit, quotes}
\begin{tikzpicture}
   \begin{yquant}
      qubit {} msg[3];
      [name=inits]
      qubit {$\ket0$} syndrome[3];

      [name=scnot0]
      cnot syndrome[0] | msg[0];
      cnot syndrome[0] | msg[1];
      cnot syndrome[1] | msg[1];
      cnot syndrome[1] | msg[2];
      cnot syndrome[2] | msg[0];
      cnot syndrome[2] | msg[2];
      [name=smeas, shape=yquant-rectangle, rounded corners=.45em]
      dmeter {$M_{\symbol{\numexpr`a+\idx}}$} syndrome;
      ["Recovery"]
      box {$\symcal R$} (msg) | syndrome;
      discard syndrome;
   \end{yquant}
   \node[draw, dashed, fit=(inits-2) (scnot0-p0) (smeas-2), "Syndrome Measurement"] {};
\end{tikzpicture}
               \end{codeexample*}
               We name several elements that visually form the enclosing rectangle; then, we use the \TikZ{} library \texttt{fit} to put a node around them all.
               Any gate can be given a custom shape; here, we use a \texttt{yquant-rectangle}, which is the analogue to \TikZ's \texttt{rectangle} and thus supports the standard \texttt{rounded corners} style.
            \end{example}

         \subsubsection{IV. Simple Quantum Circuits}
            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      x q;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
            \end{example}

            \clearpage
            \paragraph{A. Wires and gates}\leavevmode
               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      h a;
      align a, b;
      z a;
      x b;
      h a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}<Updated in 0.1.2>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      box {$U$} a;
      box {$U^\dagger$} b;
      setstyle {->} -;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  \Yquant{} allows to change wire styles by means of the \gate{setstyle} and \gate{addstyle} pseudo\hyp gates.
                  Here, we use the gate on all wires in order to set an arrow style.
                  Note that arrowheads are actually very special in two respects:
                  \begin{itemize}
                     \item \Yquant{} draws continuous wires for as long as possible.
                        In this example, the wire path extends from the very left to the end of the circuit; \compat{Changed in 0.1.2}\Yquant{} does not draw a wire \emph{to} the gate and then a separate one \emph{from} the gate to the next or the end.
                        The only way to force \Yquant{} to draw multiple wires is to change the wire style or type mid\hyp circuit.
                        For example, by saying \yquant!addstyle {} -;!, all wire paths will be separated at the current position, which \emph{in theory} allows to draw arrowsheads on intermediate wires.
                     \item \emph{In practice}, this will not work due to the clipping commands that \Yquant{} installs.
                        Every wire extends from the center of the left to the center of the right gate, and the gate's shape acts as a clipping path.
                        Consequently, though the arrowhead is drawn, it is actually drawn at the center of the gate instead of the \texttt{west} anchor and then clipped away (unless the gate is small, in which case you might still see some fragments of the arrowhead).
                  \end{itemize}
                  Thus, it is currently not possible to use arrowheads on intermediate wires.
                  If you really need to do this (say, for only a single gate), you may experiment with the \TikZ{} \texttt{shorten} keys, which allow you to manually reduce the length of the wire, but the amount of reduction must be hand\hyp computed for every gate.
                  If you need this more often, consider filing a feature request.
               \end{example}

            \paragraph{B. CNOT and other controlled single qubits gates}\leavevmode
               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      cnot a[1] | a[0];
      cnot a[0] | a[1];
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}<Updated in 0.1.1>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      cnot q[2] | q[0];
      cnot q[0] | q[1-3];
      box {$U$} q[0] | q[2];
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

            \paragraph{C. Vertical wires}\leavevmode
               \begin{example}<Updated in 0.4, 0.1.1>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      box {$U_{\The\numexpr\idx+1}$} q[0, 2] | q[1];
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  There is no direct support for this construction, but as with the initialization of a vector registers, \Yquant{} allows to access the macro \tex!\idx! within an operator \texttt{value}.
                  This macro follows the same rules as the name suffix, i.e., it assigns indices (zero\hyp based) to the target registers in top\hyp to\hyp bottom order, regardless of which order was specified in the target list.
                  Since we instead want a one\hyp based subscript, we need to add one.
                  Note that if you want to output \tex!\idx! directly or within an unexpandable expression, you don't need to take any action.
                  However, here, \tex!\the! is expandable; and since \Yquant{} needs to process all its output twice (first in order to determine the vertical spacing, second to actually typeset), you must manually take care that the command is \emph{not} expanded prematurely by saying \tex!\protect\the! instead, for which \Yquant{}, with a \texttt{compat} setting of at least \texttt{0.4}, provides the shorthand \tex!\The!.
                  Had we used the plain \TeX{} \tex!\the! instead, the subscript would have been ``$1$'' for both operators.
               \end{example}

            \paragraph{D. Labeling input and output states}\leavevmode
               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      qubit {$\ket1$} q[2];
      cnot q[0] | q[1];
      output {$\ket\idx$} q;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}<Updated in 0.4, 0.1.1>
                  \begin{codeexample}
% \usetikzlibrary{calc}
\begin{tikzpicture}
   \begin{yquant*}
      {
         \yquantset{every multi label/.style={every node/.style={anchor=east, midway}}}
         init {$\ket{0^k}$} (a[-1]);
      }
      init {$\ket\psi$} (b[-1]);
      [name=cinit]
      qubit {\Ifcase\idx\relax$A$\Or$B$\Fi} c[2];
      \node[anchor=east] at ($(cinit-0.west)!.5!(cinit-1.west)$) {$\ket\psi$};
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Here, three different styles for the initialization of multi\hyp qubit labels are used.
                  The second one (using a curly brace) corresponds to the default.
                  It is overwritten for the first qubit, and to make this modification local, this is done in a group.
                  The third qubit pair uses an overall label and additionally individual labels on the lines.
                  The recommended way to do this starting from version~0.4 is to add the ``special'' label by means of a \TikZ{} command.
               \end{example}

         \subsubsection{V. More Complicated Circuits: Multiple Qubit gates and Beyond}
            \paragraph{A. Multiple qubit gates}\leavevmode
               \begin{example}<Updated in 0.1.1>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      box {$U^\dagger$} (a[-2]);
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}<Updated in 0.4, 0.1.1>
                  \begin{codeexample}
\yquantdefinebox{dots}[inner sep=0pt]{$\dots$}
\begin{tikzpicture}
   \begin{yquant}
      qubit {} a;
      cbit {} b;
      [register/minimum height=0pt, register/minimum depth=0pt]
      nobit ellipsis;
      qubit {} c;

      dots ellipsis;
      box {$U$} (a, b, ellipsis, c);
      dots ellipsis;
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
                  This demonstrates how a register of type \gate{nobit} might even be useful if the register is never used and no subcircuits are involved.
                  Note how we overwrite the default minimum height and depth setting for this register only.
                  Additionally, we for the first time define our own gate, which we call \texttt{dots}.
                  As we define our own style, it does not inherit from \style{/yquant/operators/every box}; hence, we only need to overwrite the \texttt{inner sep} coming from \TikZ's defaults.
               \end{example}

               \clearpage
               \begin{example}<Updated in 0.1.2, 0.1.1>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      box {$\symcal F$} (a[-1]);
      box {$\symcal G$} (a[0, 2]);
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  This demonstrates \Yquant's capabilities of discontiguous multi\hyp qubit gates.
                  \Yquant{} automatically splits multi\hyp qubit gates into slices of directly adjacent wires (which, for the $\symcal G$ case, are the single wires \yquant!a[0]! and as second slice \yquant!a[2]!).
               \end{example}

            \paragraph{B. Measurements and classical bits}\leavevmode
               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      measure a;
      dmeter {$\chi$} b;
      measure {$\ket{\xi_\pm}$} c;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  The ``tab'' and ``measure'' type are not supported yet.
                  Extracting a meter symbol on its own will not be supported.
                  If you are interested in the code, have a look at \texttt{yquant-shapes.tex} and search for the \texttt{yquant-measure} shape.
               \end{example}

               \begin{example}<Updated in 0.4, 0.1.2>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      [shape=yquant-rectangle, rounded corners=.45em, direct control]
      measure {Codebit} a;
      box {$\chi$} b | a;
      discard a;
      measure b;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Rectangles with rounded corners are not a specific style, but since the \texttt{yquant-rectangle} shape internally uses \tex!\pgfpathrectangle!, the ordinary \TikZ{} option can be used (also, an inset specification can control how much the corner is rounded).
               \end{example}

               \clearpage
               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit {$\ket\psi$} q;

      measure {$\ket{\xi_\pm}$} q;
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}<Updated in 0.1.1>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      dmeter {Bell} (a[0, 1]);
      discard a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}<Updated in 0.1.2, 0.1.1>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      measure {$\ket{\xi_\mp}$} (a[-1, 3]);
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Multi\hyp qubit gates (including measurements) on non\hyp adjacent registers are properly supported.
                  As explained in \cref{sec:registers}, there is one main and multiple subordinate gate in such a discontiguous multi\hyp qubit operation (though at the moment, the \gate{measure} gates with text is the only gate that makes this distinction).
                  In our case, the main part contains the measurement symbol and the text, while the subordinate gates only contain the text.
                  By default, \Yquant{} uses the first slice as main part, but you may influence this by preceding what you want to be ``main'' by a star:

                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      measure {$\ket{\xi_\mp}$} (a[-1, *3]);
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

            \clearpage
            \paragraph{C. Non-gate inserts, forcing space, and swap}\leavevmode
               \begin{example}<Updated in 0.6, 0.1.1>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      [name=sw]
      swap (a[0-1]);
      text {$X$} a[1];
      slash b;
      box {$H^{\otimes n}$} b;
      \node[anchor=199] at (sw-0.north) {Defective Circuit};
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Here, the intermediate text was inserted by using a \gate{text} gate; before version~0.6, this would have to be done by a \gate{box} gate with \yquant![draw=none]! attribute.
                  Another way would be to use an \gate{init} command, although this is semantically wrong (probably).
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      qubit {} a;
      [name=ypos]
      qubit {} b[3];

      cnot a | b[0];
      [name=left]
      cnot a | b[1];
      hspace {7mm} -;
      [name=right]
      cnot a | b[2];
   \end{yquant*}
   \path (left |- ypos-0) -- (right |- ypos-1) node[midway] {$\dots$};
\end{tikzpicture}
                  \end{codeexample}
                  Note how the register range \texttt{-} was used to denote all registers.
                  We positioned the dots by first naming the relevant registers, so that the vertical position is at the coordinates \texttt{ypos-0} and \texttt{ypos-1}; and then, we also named the \gate{cnot} gates, so that we are able to discern the horizontal position.
               \end{example}

            \clearpage
            \paragraph{D. Barriers}\leavevmode
               \begin{example}<Updated in 0.1.1>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      x a[0, 1];
      barrier (a);
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}
               Now the \pkg{qcircuit} manual lists three circuits with barriers at different positions.
               They cannot be drawn with \Yquant; however, since neither of them is a valid circuit (no indication whether the control is positive or negative), this is of no concern.

            \paragraph{E. How to control anything}\leavevmode
               \begin{example}<Updated in 0.1.1>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      zz (a[0, 2]);
      cnot a[1] ~ a[0];
      zz (a[2, 3]);
      h a[3] | a[0] ~ a[1];
      measure a[2, 3];
      box {$U$} (a[0, 1]) | a[3] ~ a[2];
      discard a[2, 3];
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Note that it is not possible to draw a control to measurement (the measurement operations are explicitly defined not to accept controls): Either the measurement is performed or not (which transforms the register type), but a measurement conditioned on a quantum state is not possible.
                  In principle, one could think of a measurement conditioned on a classical register (in which case the register type cannot change, as maybe the state stays quantum; the measurement operation then is similar to a complete dephasing).
                  If there is need for this, please file a feature request.
                  But note the relatively common (though unsupported by \Yquant{} at the moment) use of control lines that directly go from the measurement operator to the controlled operation; in this case, the opposite direction would be meant by using the same notation.
               \end{example}

         \subsubsection{VI. Bells and Whistles: Tweaking Your Diagram to Perfection}
            For options how to configure the circuits, refer to \cref{sec:config}.

            \paragraph{A. Spacing}\leavevmode
               \begin{example}<Updated in 0.1.1>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      swap (a[0, 1]);
      box {$T^\dagger$} a[2] | a[1];
      swap (a[0, 1]);
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

            \paragraph{B. Labeling}\leavevmode
               \begin{example}<Updated in 0.6, 0.4>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}[every initial label/.style={anchor=south east, yshift=1mm}, every post measurement control=direct]
      qubit {\rlap{\hskip2mm $a$}} a;
      qubit {\rlap{\hskip2mm $b$}} b;
      nobit out;
      hspace {5mm} -;

      measure b;
      text {$B$} out | b;
      measure a;
      text {$A$} out | a;
      discard -;
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
                  We support measurements with vertical outputs, but only if they replace the positive control of some action.
                  Here, we fake this behavior by introducing an invisible register at the bottom, which will contain the outputs.
                  Note that if we were to give style options to the \gate{text}s, they would also affect the measurements.
                  The reason for this is that internally, the measurement will be nested within the same scope that draws the \gate{text}---so the options given to the \gate{text} will be inherited by the \gate{measure}ment.
                  As an operator style overwrites default styles, this will also apply to the measurements.
                  Hence, to circumvent this, we would need to \emph{revert} the options as attributes to the \gate{measure}ments, even if the reverted option was already included in their native style.

                  Repositioning the initial labels needs some care and manual fine\hyp tuning.
               \end{example}

            \paragraph{C. Grouping}\leavevmode
               \begin{example}<Updated in 0.4, 0.1.1>
                  \begin{codeexample*}
% \usetikzlibrary{fit}
\begin{tikzpicture}
   \begin{yquant*}[register/separation=3mm]
      cnot a[2] | a[0];
      cnot a[2] | a[1];
      [name=left]
      h a[0, 1];
      z a[2];
      cnot a[1] | a[0];
      [name=righttop]
      h a[0];
      [name=rightbot]
      h a[1] | a[2];

      hspace {2mm} -;
   \end{yquant*}
   \node[draw, dashed, fit=(left-0) (left-1) (righttop) (rightbot-0)] {};
\end{tikzpicture}
                  \end{codeexample*}
                  Note that \tex!\begin{yquant*}! must not be followed by a line break (unless masked by \tex!%!) if options follow.
                  Also note that here, we cannot make use of a subcircuit due to the very last control, which would then control an inner gate of said subcircuit---but they are not exposed.
                  \iffalse\end{yquant*}\fi% code folding
               \end{example}
      \endgroup

      \clearpage
      \subsection{\pkg{quantikz} documentation}
      \begingroup
         \yquantset{operator/separation=4mm}%
         Again, our section headings will be the same as in the \pkg{quantikz} manual.
         And since \pkg{quantikz} also has even more space between the gates, we globally say \tex!\yquantset{operator/separation=4mm}!.

         \subsubsection{II. A single wire}
            \begin{example}
               \begin{codeexample*}
\begin{tikzpicture}[label position=north east, every label/.style={inner sep=1pt}]
   \begin{yquant}
      qubit {$\ket0$} a;

      phase {$\alpha$} a;
      h a;
      phase {$\beta$} a;
      h a;
      phase {$\gamma$} a;

      [every output/.append style={align=center}]
      output {Arbitrary\\pure state} a;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample*}
               The captions of \gate{phase} commands are internally implemented using \TikZ{} \texttt{label}s.
               At the moment, it is not possible to change any label options on a gate-type basis, only locally or fully globally (\TikZ{} feature request \href{https://github.com/pgf-tikz/pgf/issues/811}{\#811}).
            \end{example}

            \clearpage
            \paragraph{A. Measurements}\leavevmode
               \begin{example}
                  \begin{codeexample}
% \usetikzlibrary{quotes}
\begin{tikzpicture}
   \begin{yquant*}
      ["$0$"]
      measure a;
      discard a;

      init {} a;
      dmeter {$1$} a;
      discard a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Other measurement shapes are not supported at the moment.
               \end{example}

            \paragraph{B. Wires and arrows}\leavevmode
               \begin{example}<Updated in 0.6, 0.1.2>
                  \begin{codeexample*}
% \usetikzlibrary{quotes}
\begin{tikzpicture}
   \begin{yquant}[operator/separation=1cm, every label/.append style={align=center}]
      qubit {$\ket0$\\initial state} a;

      text {$X$} a;

      ["$0$/$1$", type=qubit]
      measure a;

      addstyle {->} a;
      output {$\ket1$} a;
      \yquantset{operator/separation=5mm}
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample*}
                  This example demonstrates how to instruct the \gate{measure} gate to use a different output type than the standard \gate{cbit}.

                  In general, any macros that are used within a \TikZ{} path or a \Yquant{} operation must not be fragile, or must be preceded with \tex!\protect!.
                  In this example, \tex!\\! is a robust command (at least in newer kernels), so protection is not required.
                  Since it may occur quite frequently that \Yquant{} is used within a \tex!center! environment or in \tex!\centering! mode (in which \tex!\\! is still fragile), \Yquant{} takes care of this (it actually robustifies \tex!\@centercr!, which is the meaning of \tex!\\! in these surroundings---and which is now incorporated into the \LaTeX{} kernel as of June~2021).

                  In order to change the style of an individual wire, we use \gate{addstyle}.
                  To make the final line shorter, we change the operator separation by issuing \tex!\yquantset! at the end.
               \end{example}

               \begin{example}<New in 0.4>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit {$\ket0$} q;
      [name=h]
      h q;
      discard q;
      \path[/yquant/every wire, /yquant/every qubit wire, -Stealth] (h) -| ++(1cm, -.5cm) node[below] {trash};
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
                  Here, we use an ordinary \tex!\path! command to reproduce the ``trash'' line.
                  This time, we chose to use the appropriate styles as \Yquant{} itself would do it instead of just saying \tex!\draw! without the options, which would also have worked.
               \end{example}

               \begin{example}<Updated in 0.4>
                  \begin{codeexample}
% \usetikzlibrary{quotes}
\begin{tikzpicture}
   \begin{yquant*}
      qubit {$\ket0^{\otimes n}$} a;
      ["north east:3" {font=\protect\footnotesize, inner sep=0pt}]
      slash a;
      h a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Again, you see an example of how some commands need to be \tex!\protect!ed when used in \Yquant{} options, and that you can indeed exploit all features of the \texttt{quotes} library.
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubits {$\ket0^{\otimes n}$} a;
      h a;
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

         \subsubsection{III. Multiple Qubits}
            \begin{example}
               \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant}
      qubit {$\ket0$} a;
      qubit {$\ket0$} b;

      h a, b;
      cnot b | a;
      box {$U$} a ~ b;
      zz (a, b);

      [after=a]
      qubit {} c;

      swap (a, c);
      box {$U$} c | a ~ b;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample*}
               This example demonstrates the use of the \texttt{after} argument that instructs the register creation to begin the register only after the current position of another register that already exists.
               Note that this argument will always make the wire begin \emph{at the right end} of the last gate of the referenced register; however, if---as is the case here---this gate is shorter than \style{/yquant/operator/minimum width}, this might not coincide with the visual right end.
            \end{example}

            \clearpage
            \begin{example}<Updated in 0.4, 0.1.2, 0.1.1>
               \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant*}
      [name=c]
      cnot a[0, 2] | a[1];
      [name=m, direct control]
      measure a[1];
      discard a[2];
      box {$U$} a[0] | a[1];
      \path[/yquant/every wire, /yquant/every qubit wire] (c-1) -- (m.center |- c-1);
      discard a[1];
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample*}
               Here, we manually extended the wire on the last register.
               We could instead have performed an \gate{align} gate before the discarding process, then, the wire line would have been extended by \Yquant{}; but since \gate{align} aligns at the \emph{right end} as opposed to the center of the gate, the wire line would have been a bit longer.
               Still, this \TikZ{} wire is inferior to a wire drawn by \Yquant, as it does not use clippings: the connection with the \gate{cnot} gate may not be accurate; in particular, if the wire is of a different color or if you need to draw classical or bundle wires, the connection will become unpleasant.
            \end{example}

            \begin{example}<Updated in 0.1.1>
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      cnot a[1, 2] | a[0];
      measure a[1], a[2];
      box {$U$} a[0] | a[1];
      box {$V$} a[0] | a[2];
      discard a[1]-;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
            \end{example}

            \Yquant{} doesn't offer anything comparable to the new \tex!\ctrlbundle! command; and as the bundle lines are spaced much more tightly in \Yquant, this would not really make sense.

         \clearpage
         \subsubsection{IV. Operating on many Qubits}
            \begin{example}<Updated in 0.1.1>
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      init {$\ket0^{\otimes3}$} (a[-2]);

      box {$U$} (a[1-2]) | a[0];
      measure a[0];
      discard a[0];
      output {$\ket{11}$} (a[1-2]);
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
               Multi\hyp qubits inputs are possible using the \gate{init} command.
               The text assigned to a register declaration is always for an individual register.
            \end{example}

            \begin{example}<Updated in 0.4>
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}[register/minimum height=6mm, register/minimum depth=6mm]
      hspace {7.5mm} a;
      h a;
      hspace {7.5mm} a;
      [x radius=1cm]
      box {$U$} (b, c);
      cnot b | a;
      measure a;
      discard a;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
               \Yquant{} does not use a grid layout: operators are stacked next to each other.
               Therefore, there is no automatic centering of a column, though it could be emulated using hand-crafted \gate{hspace} commands, as was done here (the Hadamard gate uses the \style{/yquant/operator/minimum width}, which is \tex!5mm!, while the large box has a width of \tex!2cm!, so that we need two \tex!7.5mm! spacings at the end, as the \gate{hspace} pseudo\hyp gate only inserts exactly the space you give, but not additional [twice] \style{/yquant/operator/separation}, as would be the case for a hypothetical zero\hyp width gate).
               In fact, we don't even need the second \gate{hspace}, since the two\hyp qubit \gate{cnot} will automatically enforce correct alignment.
            \end{example}

            \begin{example}<Updated in 0.4>
               \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant}[register/separation=3mm, every nobit output/.style={}]
      qubit {} a[4];
      [every inspect/.append style={outer xsep=0pt}, operator/minimum width=0pt, font=\footnotesize, name=sub]
      subcircuit {
         \yquantset{operator/separation=0pt}
         qubit {} x[2];
         qubit {} y;
         discard -;

         inspect {$x$} (x);
         [inner xsep=0pt]
         inspect {$y\vphantom f$} y;

         [shape=yquant-init, decoration={mirror}]
         inspect {\hskip4mm $x$} (x);
         [shape=yquant-init, inner xsep=0pt]
         inspect {$y \oplus f(x)$} y;
      } (a[1-3]) | a[0];
      \node at (sub) {$U$};
      settype {qubit} a;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample*}
               We use quite some tricks to achieve such a layout.
               We use a subcircuit as a container and \gate{inspect} gates to indicate the inputs and output states accurately.
               As those are ordinary gates, we reset \style{/yquant/operator/minimum width}, so that the ``$y$'' indication is not too long.
               Additionally, they are usually meant to be used within a circuit, i.e., they have an additional margin denoted by the \texttt{outer xsep}, which we also remove.
               Then, within the subcircuit, we reset the \style{/yquant/operator/separation}, which would insert additional whitespace at the beginning.
               It is important to do this within the subcircuit and not as an attribute; else, we would also remove the outer lines going into the subcircuit.

               Initial or final \gate{inspect} gates without a brace do not really need the separation between brace tip and text (\texttt{inner xsep}), so we also remove it.
               The output gates should have their braces and separations at the other side, which corresponds to changing their shape from \texttt{yquant-output} to \texttt{yquant-init} and mirroring the decoration (as in \style{/yquant/every label}).
               To get the desired right\hyp alignment, we hand\hyp tailor an \tex!\hskip! that enlarges the upper output label---automatic alignments would not work here: putting the two \gate{inspect}s together with a case distinction on \tex!\idx! would center them; using \gate{output}s would left\hyp align them.

               Finally, we have to deal with the caption of the gate, which should be absolutely centered with respect to the subcircuit and not have any influence on the spacing---so we just insert it retrospectively as an ordinary \TikZ{} node.

               Also note the use of \gate{discard} and \gate{settype} since we needed wires before and after the subcircuit, which must match the inner wires in type, but we actually do not want to have inner wires.
            \end{example}

            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      box {$\sqrt Z$} a;
      box {$X$} b;
      box {$\sqrt{\mathrm{SWAP}}$} (a, b);
      measure a;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
               This time, we did not artificially discard the lines.
            \end{example}

            \begin{example}<Updated in 0.4, 0.1.1>
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit {$c_{\idx}$} c[4];
      box {M\\A\\J} (c[-2]);
      box {M\\A\\J} (c[1-]);
   \end{yquant}
\end{tikzpicture}
               \end{codeexample}
               Notice here that the vertical spacing is uneven.
               \Yquant{} realizes that the minimal vertical spacing will not be enough to account for the multi\hyp qubit boxes.
               However, when it tries to adjust positions accordingly so that the last gate fits, this will of course not change anything for the first wire, which is not contained in the gate.
               After having increased the spacing, \Yquant{} realizes that this already was enough to accomodate for the first gate, so no further action is taken.
               In order to get a more even spacing, just increase \style{/yquant/register/minimum height} and \style{/yquant/register/minimum depth}.
            \end{example}

            \paragraph{A. Different connections}\leavevmode
               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}[register/default name=]
      qubit a;
      cbit b;
      nobit c;
      cbit d;
      qubit e;
      box {$U$} (-);
      settype {qubit} c;
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
                  This example demonstrates the declaration of a non\hyp existing register and the \gate{settype} pseudo\hyp gate that acts as a zero\hyp width, no\hyp content \gate{init} gate.
               \end{example}

         \subsubsection{V. Slicing}
            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit {} a[3];
      h a[0];
      [red, thick, label=step]
      barrier (a);
      cnot a[1] | a[0];
      measure a[0];
      discard a[0];
      cnot a[2] | a[1];
      h a[1];
   \end{yquant}
\end{tikzpicture}
               \end{codeexample}
               There is nothing like a \texttt{slice all} keyword, as \Yquant's underlying layout is not grid\hyp based.
               Changing the style of slice captions simply means providing label options.
               This time, we used the \texttt{label} key instead of the shorter syntax provided by the \texttt{quotes} library, which is of course also possible.
            \end{example}

            \begin{example}
               \begin{codeexample*}
% \usetikzlibrary{quotes}
\begin{tikzpicture}[every label/.style={rotate=40, anchor=south west}]
   \begin{yquant}[operators/every barrier/.append style={blue, thick}]
      qubit {} a[3];
      h a[0];
      ["slice 1"]
      barrier (-);
      cnot a[1] | a[0];
      ["slice 2"]
      barrier (-);
      measure a[0];
      discard a[0];
      cnot a[2] | a[1];
      ["slice 3"]
      barrier (-);
      h a[1];
   \end{yquant}
\end{tikzpicture}
               \end{codeexample*}
            \end{example}

            \begin{example}<Updated in 0.4>
               \begin{codeexample*}
% \usetikzlibrary{quotes}
\begin{tikzpicture}[label distance=4mm]
   \begin{yquant}[operators/every barrier/.append style={red, thick, shorten <= -4mm, shorten >= -4mm}]
      qubit {$\ket0$} a;
      h a;
      ["1"]
      barrier a;
      phase {[label distance=0pt]$\varphi$} a;
      ["2"]
      barrier a;
      h a;
      ["3"]
      barrier a;
      output {$\cos\frac\varphi2 \ket0 - i\sin\frac\varphi2 \ket1$} a;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample*}
               Usually, the \texttt{shorten} keys do not have any effect on \Yquant{} operations, since the latter are all made up of nodes.
               However, the \texttt{yquant-line} shape explicitly takes care of correctly handling them.
               It is the only one that does so.
               Since barriers usually end quite closely to the wires---and the default \texttt{dashed} style may make this worse---the \texttt{shorten}ing may often prove useful.
               Note that if the barriers are enlarged by means of negative \texttt{shorten}ings, this will not affect the bounding box and you must take care of appropriately shifting labels.
               The internal register height calculations might be inconsistent for multi\hyp register barriers with \texttt{shorten}ing: While \Yquant{} takes care of enlarging the registers so that there is enough space for placing the \gate{barrier} with its \emph{original} (single\hyp register) height, it actual height of the registers is only known at the second stage in calculation; but applying \texttt{shorten}ings after this stage would require another iteration of height calculation.
               Hence, multi\hyp register barriers that are enlarged by a lot will probably look bad unless you add manual spacing to the appropriate registers.
               Also note that we used much larger magnitudes in order to achieve a similar appearance as in \pkg{quantikz}.
               To avoid that the large distance also affects the \gate{phase} gate badly, we locally reset the distance; for this, there are two ways.
               The easiest one is to make use of the fact that the value of the \gate{phase} gate is passed directly as \texttt{label} argument, so that we can locally reset the distance.
               The other possibility would be to write
               \begin{minted}[linenos=false, fontsize=\footnotesize, bgcolor=boxGrayBody]{tex}
   {
      \yquantset{/tikz/label distance=0pt}
      phase {$\varphi$} a;
   }
               \end{minted}
               since due to the aforementioned lack of support for a style that sets the options in \TikZ, we must manually use a (grouped) \tex!\yquantset! instruction for this.
               Note that whenever you change a \TikZ{} style in a \Yquant{} environment, use the \tex!\yquantset! macro, \emph{not} \tex!\tikzset! or \tex!\pgfkeys!.
               Not only will the latter two not automatically restart the parser (so that you would have to issue \tex!\yquant! after their use), but \Yquant{} has to process all its content twice in order to properly determine the register height.
               Only \tex!\yquantset! will be properly captured and re\hyp issued at the correct position when the content is actually typeset.
               Had we written \tex!\tikzset{label distance=0pt} \yquant!, no effect at all would have been visible, since this command would only have taken effect in the first (invisible) round when \Yquant{} determines heights.
            \end{example}

            \Yquant{} does not provide a mechanism for vertical labels, but you may of course just insert line breaks at appropriate positions (and set the \texttt{align} property of the labels).

         \subsubsection{VI. Spacing}
            \paragraph{A. Local adjustment}\leavevmode
               \begin{example}<Updated in 0.4>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}[register/default name=]
      [register/minimum depth=2cm]
      qubit a;
      qubit b;
      qubit c;

      h a;
      x b-;
      hspace {2cm} -;
      x a;
      z b-;
      h a;
      z b-;
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
                  The vertical distance between registers is calculated by \Yquant{} automatically based on the height and depth that \Yquant{} find for this particular register---i.e., how much space is required above and below the wire line for all the gates.
                  In order to enlarge these values, reset \style{/yquant/register/minimum height} or \style{/yquant/register/minimum depth} to a different value.
                  It is not possible to artificially \emph{reduce} the calculated heights and depths, as this would result in overlapping gates.
                  However, sometimes it might be required to exclude a certain gate from the calculation; then, use the \texttt{overlay} attribute.
               \end{example}

               \begin{example}
                  \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant*}
      [x radius=1cm]
      x a;
      box {\hbox to 1cm{\hfil$X$\hfil}} a;
      hspace {1cm} a;
      x a;
      discard a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample*}
                  Here, we demonstrate two possibilities to enlarge a box: The first is by specifying its size in terms of the \texttt{x radius} or \texttt{y radius} keys beforehand.
                  Those values serve as minimum sizes and would be extended if the text extended beyond the box.
                  The second option is to just enlarge the text artificially by explicitly putting it into a fixed\hyp width box.
                  Note that in the first case, the \emph{radius} is specified, i.e., the half\hyp width, while in the second case, it is the \emph{total} width (both times modulo the inner separation).
                  Also note that the \style{/yquant/operator/minimum width} style is unsuitable for the given task: it would not change the visual width, only what \Yquant{} assumes its width to be.
               \end{example}

            \clearpage
            \paragraph{B. Global Adjustment}\leavevmode
               \begin{example}
                  \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant*}[operator/separation=1cm]
      h a;
      phase {$\beta$} a;
      h a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample*}
               \end{example}

               \begin{example}<Updated in 0.4, 0.1.1>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}[register/minimum height=0pt, register/minimum depth=0pt]
      x a[0, 2];
      zz (a[0, 1]);
      x a[0];
      h b;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  By default, \Yquant{} will use the height and depth that is required by the individual gates, but at least \style{/yquant/register/minimum height} or, respectively, \style{/yquant/register/minimum depth} (which default to \tex!1.5mm!).
                  Only manually reducing the default height will produce the cramped spacing displayed here.
               \end{example}

            \clearpage
            \paragraph{C. Alignment}\leavevmode
               \begin{example}<Updated in 0.5, 0.4>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      x a[0];
      cnot a[1] | a[0];
   \end{yquant*}
\end{tikzpicture}
$=$
\begin{tikzpicture}
   \begin{yquant*}
      cnot a[1] | a[0];
      x a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Not specifying anything for the vertical alignment will lead to the common \TikZ{} problem: the baseline will be at the bottom, which is particularly bad in this case due to the missing $X$ gate.
                  The keys for minimal register sizes do not help here, since they only affect \Yquant's internal handling, but not the bounding box calculated by \TikZ.
                  The recommended way to draw circuit equations is always with the \pkg{groups} language extension.

                  \begin{codeexample}
% \useyquantlanguage{groups}
\begin{yquantgroup}
   \registers{
      qubit {} q[2];
   }
   \circuit{
      x q[0];
      cnot q[1] | q[0];
   }
   \equals
   \circuit{
      cnot q[1] | q[0];
      x q;
   }
\end{yquantgroup}
                  \end{codeexample}
               \end{example}

               \clearpage
               \begin{example}<Updated in 0.5\\New in 0.4>
                  \begin{codeexample*}
% \useyquantlanguage{groups}
\begin{yquantgroup}
   \registers{
      qubit {} q[2];
   }
   \circuit{
      init {$\ket x$} q[0];
      init {$\ket y$} q[1];

      h q[0];
      cnot q[1] | q[0];
      output {} (-);
   }
   \equals[$\mapsto\quad\ket{\psi_{x, y}}\quad\mapsto$]
   \circuit{
      init {} (q);
      cnot q[1] | q[0];
      h q[0];

      output {$\ket x$} q[0];
      output {$\ket y$} q[1];
   }
\end{yquantgroup}
                  \end{codeexample*}
                  Here, we do not have a circuit equation (i.e., logical statements involving multiple rather independent circuits), but a circuit progression.
                  Since only in one circuit we have a description of the registers, we declare them without an initial text and put their initialization into \gate{init} gates.
                  The mapping in between is done by using the optional argument of the \tex!\equals! macro.
                  In order to obtain the braces at the ends, we use empty \gate{output} and \gate{init} gates.
               \end{example}

               \clearpage
               \subparagraph{1. Perfecting Vertical Alignment}\leavevmode
                  \begin{example}<Updated in 0.5, 0.4>
                     \begin{codeexample*}
% \useyquantlanguage{groups}
\begin{yquantgroup}
   \registers{
      qubit {} q;
      qubit {$\ket0$} q[+1];
   }
   \circuit{
      cnot q[0] | q[1];
      cnot q[1] | q[0];
      cnot q[0] | q[1];
   }
   \equals
   \circuit{
      cnot q[1] | q[0];
      cnot q[0] | q[1];
   }
\end{yquantgroup}
                     \end{codeexample*}
                  \end{example}

            \paragraph{D. Scaling}\leavevmode
               \begin{example}
                  \begin{codeexample*}
\begin{tikzpicture}[scale=1.5]
   \begin{yquant*}
      h a;
      phase {$\beta$} a;
      h a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample*}
                  Here, we first scaled the circuit itself.
                  The default style for \style{/yquant/every circuit} sets the \texttt{transform shape} key for every node (which means any gate), so that those are also scaled.
                  If your \TikZ{} version is at least 3.1.6a, this is all that needs to be done.
                  In earlier versions, there was a bug that required \Yquant{} to reset the \texttt{transform shape} key for \texttt{label}s, which would then require you to scale those manually.
               \end{example}

         \clearpage
         \subsubsection{VII. Typesetting}
            \paragraph{A. Global Styling}\leavevmode
               \begin{example}
                  \begin{codeexample*}
% \usetikzlibrary{quotes}
\begin{tikzpicture}
   \begin{yquant*}[operators/every h/.append style={fill=red!20}]
      h a;
      phase {$\beta$} a;
      h a;
      ["$\ket\pm$" above right]
      measure a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample*}
                  Instead of setting \style{/yquant/operators/every h}, we could also have changed \style{/yquant/operators/every box}.
                  Had we used \style{/yquant/every operator}, then the measurement would also have changed.
                  Again, due to a \TikZ{} limitation, it is not possible to change the position of labels on a per\hyp style basis, only by using \texttt{label} options or a global setting.
               \end{example}

               \begin{example}
                  \begin{codeexample*}
\begin{tikzpicture}[thick]
   \begin{yquant*}[every operator/.prefix style={fill=white}]
      cnot a[1] | a[0];
      box {$R_z(-\theta\fracslash2)$} a[1];
      cnot a[1] | a[0];
      box {$R_z(\theta\fracslash2)$} a[1];
      measure a[1];
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample*}
                  As the ``thin'' style is the default, we present the opposite.
                  By default, all operators are transparent; we changed this by giving all of them a white background color (but as a style \emph{prefix}, so that, e.g., black fillings overwrite this).
                  Contrary to \pkg{quantikz}, this also fills the \gate{cnot}s.
                  If you only want to fill certain operators, you have to selectively target them using their styles.
               \end{example}

               \begin{example}<Updated in 0.1.2, 0.1.1>
                  \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant}[operators/every box/.append style={fill=white}]
      qubit {} j[3];
      box {$J_{12}$} (-j[1]);
      box {$J_{13}$} (j[0, 2]);
      box {$J_{23}$} (j[1]-);
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample*}
                  \Yquant{} properly splits discontiguous multi\hyp qubit operations.
               \end{example}

            \paragraph{B. Per-Gate Styling}\leavevmode
               \begin{example}<Updated in 0.4>
                  \begin{codeexample}
% \usetikzlibrary{quotes}
\begin{tikzpicture}
   \begin{yquant*}
      [fill=red!20, font=\color{cyan}]
      h a;
      [green]
      phase {[green]$\beta$} a;
      ["$\ket\pm$", blue]
      measure a;
      discard a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Note that assigning styles in this way will forward them to \style{/yquant/operator style}, i.e., if you have controls, the style will not apply to them.
                  \style{/yquant/style} is suitable to style both, e.g., \tex|[style={fill=red!20}]|.
               \end{example}

               \begin{example}<Updated in 0.6, 0.4>
                  \begin{codeexample*}
% \usetikzlibrary{shapes.symbols, fit}
\begin{tikzpicture}
   \begin{yquant}
      qubit {} data;
      qubit {$\ket0$} anc1[2];

      h data;
      cnot anc1 | data;
      [after=data]
      qubit {$\ket0$} anc2[2];
      [name=noise]
      text {\phantom{noise}} (data, anc1);
      cnot anc2[0] | data;
      cnot anc2 | anc1[0];
      cnot anc2[1] | anc1[1];
      measure anc2[0];
      [blue] measure anc2[1];
   \end{yquant}
   \node[starburst, cyan, fill=yellow, draw=red, line width=2pt,
         inner xsep=-4pt, inner ysep=-5pt, fit=(noise)] {noise};
\end{tikzpicture}
                  \end{codeexample*}
                  \TikZ{} shapes cannot simply be used with \Yquant.
                  Any \Yquant{} shape must be aware of the keys \texttt{x radius} and \texttt{y radius} that control its width and height.
                  Additionally, \Yquant{} shapes must implement clipping paths.
                  Those objects, which are a \Yquant{} addition to \TikZ{} allow \Yquant{} to properly clip wires and vertical lines to the shape of the gate.
                  \Yquant{} draws its elements sequentially; hence, a wire that comes into an operator will be hidden by anything the operator draws on top of it; but outgoing wires will in turn draw on the operator (modulo clipping).
                  To avoid the issues, we construct an invisible box operator and name it; \emph{outside} of the \tex!yquant! environment, we \texttt{fit} the special \TikZ{} shape on top of it.
               \end{example}

            \paragraph{C. Boxing/Highlighting Parts of a Circuit}\leavevmode
               \begin{example}<Updated in 0.2>
                  \begin{codeexample*}
% \usetikzlibrary{quotes, fit}
\begin{tikzpicture}
   \begin{yquant*}
      h a;
      cnot b | a;
      [name=left]
      h -;
      cnot b | a;
      [name=right]
      h -;
      cnot b|a;
      h b;
   \end{yquant*}
   \node[fit=(left-0) (left-1) (right-0) (right-1),
         draw, inner sep=6pt, "reversed c-\textsc{not}"] {};
\end{tikzpicture}
                  \end{codeexample*}
                  As usual, subcircuits provide a similar experience, but respect the separation:
                  \begin{codeexample*}
% \usetikzlibrary{quotes}
\begin{tikzpicture}
   \begin{yquant*}
      h a;
      cnot b | a;
      [this subcircuit box style={inner ysep=6pt, "reversed c-\textsc{not}"}]
      subcircuit {
         qubit {} x;
         qubit {} y;
         h -;
         cnot y | x;
         h -;
      } (-);
      cnot b | a;
      h b;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample*}
                  Here, we used the key \style{/yquant/this subcircuit box style} to influence only the style of the subcircuit box itself instead of providing global options that apply to every object in the subcircuit (you wouldn't want the label be assigned to every single gate).
               \end{example}

               \begin{example}<Updated in 0.4>
                  \begin{codeexample*}
% \usetikzlibrary{quotes}
\begin{tikzpicture}
   \begin{yquant*}
      h a;
      [this subcircuit box style={draw, dashed, rounded corners, fill=blue!20, inner ysep=10pt, "\textsc{swap}" below}, register/default name=]
      subcircuit {
         qubit a;
         qubit b;
         cnot b | a;
         cnot a | b;
         cnot b | a;
      } (a-b);
      h b;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample*}
                  Since version~0.2, fully enclosing a bunch of operations (with no controls extending to some inner component) is possible by means of \gate{subcircuit}s.
                  Before, this had to be done using named operations and layers.
                  Note that here we used the style \style{/yquant/this subcircuit box style} to assign a styling that only applies to the box containing the subcircuit, but not to the inner gates---which would have happened had we just given the arguments to the subcircuit directly.
               \end{example}

               \Yquant{} does not support the fancy nearest\hyp neighbor swap gate that \pkg{quantikz} has.
               It would however not be very difficult to implement this particular shape and make it available.
               Maybe even a multi\hyp swap gate using the \texttt{knots} library would be possible.

         \clearpage
         \subsubsection{VIII. Otherwise undocumented features}
            \begin{example}<Updated in 0.6, 0.4>
               \begin{codeexample*}
% \usetikzlibrary{quantikz,fit}
\begin{tikzpicture}
   \begin{yquant}[register/default name=]
      qubit a;
      [name=wave, register/minimum height=5mm, register/minimum depth=5mm]
      nobit wave;
      qubit b;
      qubit c;

      h a, b;
      box {$U$} c | a;
      text {$\dots$} a, b-;
      box {$U^k$} c | b;
      h a, b;
   \end{yquant}
   \node[wave, fit=(wave) (current bounding box.east |- wave), inner ysep=.5pt, inner xsep=0pt] {};
\end{tikzpicture}
               \end{codeexample*}
               Here, we included \pkg{quantikz}, which provides the \texttt{wave} shape, then introduced a register that will contain this wave (and enlarged it sufficiently).
               After the circuit is drawn, we \texttt{fit} the wave along.
               Since the name assigned to a register without any text actually is of a \texttt{coordinate} shape, we need to enlarge the height of the wave by providing a slightly increased \texttt{inner ysep}.
               Additionally, \pkg{quantikz} sets a negative \texttt{inner xsep}, which is probably required for its grid layout; but \Yquant{} positions exactly, so we also need to reset this.
            \end{example}

            \Yquant{} does not provide a shape corresponding to the ``creating an ebit'' gate.

         \clearpage
         \subsubsection{X. Troubleshooting}
            \begin{example}<Updated in 0.4>
               \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant}
      qubit {$\ket0$} a[2];
      box {$\begin{pmatrix}
               \alpha & \beta \\
               \beta & -\alpha
            \end{pmatrix}$} a[0];
      cnot a[1] | a[0];
      box {$U_{\The\numexpr\idx+1}$} a;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample*}
            \end{example}
      \endgroup

      \subsection[\texorpdfstring{\pkg{qpic}}{qpic} documentation]{\compat{Added in 0.6}\pkg{qpic} documentation}
      \begingroup
         \yquantset{operator/separation=3mm, register/default name=$\reg$, register/default lazy name=$\reg$}%
         Again, our section headings will be the same as in the \pkg{qpic} manual.
         As the \pkg{qpic} manual uses a bit larger separation between the operators than \Yquant's default, we globally say \tex!\yquantset{operator/separation=3mm, register/default name=$\reg$, register/default lazy name=$\reg$}!, which allows to easily generate all the registers on\hyp the\hyp fly.

         \subsubsection{1 Introduction}
            \begingroup%
               \mdfapptodefinestyle{bdBox}{%
                  leftmargin=-.12\linewidth,
                  rightmargin=-.12\linewidth
               }%
               \begin{example}\label{ex:qupicfirst}
                  \begin{codeexample*}
\def\reversecircuit#1{%
   \begin{tikzpicture}
      \let\high=\empty
      \listeadd\high{#1}
      \def\cnot##1|##2;{%
         \ifinlist{##2}\high{
            \yquant [style=red] cnot a[##1] | a[##2];
            \ifinlist{##1}\high{
               \listremove\high{##1}
               \yquant addstyle {black} a[##1];
            }{
               \listadd\high{##1}
               \yquant addstyle {red} a[##1];
            }
         }{
            \yquant cnot a[##1] | a[##2];
         }
      }
      \def\cnotA{\cnot 0|1; \cnot 2|3; \cnot 4|5; \cnot 6|7;}
      \def\cnotB{\cnot 2|1; \cnot 4|3; \cnot 6|5; \cnot 8|7;}
      \def\cnotC{\cnot 1|0; \cnot 3|2; \cnot 5|4; \cnot 7|6;}
      \def\cnotD{\cnot 1|2; \cnot 3|4; \cnot 5|6; \cnot 7|8;}
      \def\cnotBlock{\cnotA \cnotB barrier (-); \cnotC \cnotD}
      \begin{yquant}[operator/minimum width=0pt, register/minimum height=2mm,
                     register/minimum depth=2mm]
         qubit {\Ifnum\idx=#1\color{red}\Fi$\reg_{\The\numexpr\idx+1}$} a[9];
         addstyle {very thick, red} a[#1];

         \cnotBlock barrier (-);
         \cnotBlock barrier (-);
         \cnotBlock barrier (-);
         \cnotBlock barrier (-);
         \cnotBlock
         output {\protect\xifinlist{\idx}{\high}{\color{red}}\relax
                 $a_{\The\numexpr9-\idx}$} -;
      \end{yquant}
   \end{tikzpicture}%
}
\reversecircuit2
                  \end{codeexample*}
                  This is an extremely interesting example, which could have been implemented in a lot of different manners.
                  We chose an approach where we deferred the logic of coloring the gates entirely to \TeX.
                  Note that we put everything, including the whole \texttt{tikzpicture} itself, in a macro \tex!\reversecircuit!, which we call directly after its definition by saying \tex!\reversecircuit2!.
                  This is of course an overkill in this situation---there is no need for the macro definition.
                  However, note that the macro expects the wire that is to be colored in red as its argument.
                  So by slightly changing the invocation to
                  \begin{minted}{tex}
\foreach \ici in {0, ..., 8} {
   \reversecircuit\ici
   \par\vspace{1cm}
}
                  \end{minted}
                  we are able to render the circuit with all different initial wires one after the other very easily.
                  We do not show the output in the manual to keep it succinct, but just try it out by yourself.

                  We now explain what is done in the macro.

                  We first define an \pkg{etoolbox} list that is stored in \tex!\high!.
                  The idea is that this list holds at any point in time the indices of all the registers that are currently colored in red.
                  Initially, we add the index that was given as a parameter to the macro---in our case, this was \tex!2!.
                  Note we use \tex!\listeadd! instead of \tex!\listadd!, which is important for the invocation via \tex!\foreach!---we want to have the number in the list, not the macro \tex!\ici! that holds the index of the initially colored wire).

                  Next, we do not want to manually do the bookkeeping of this list.
                  All we want to do is to issue the command to put a \gate{cnot} gate on the appropriate registers and \TeX{} should keep track of the correct coloring and register state.
                  For this, we first define a macro \tex!\cnot! that expects the index of the target and the index of the control register.
                  Within this macro, we check whether the register of the control is currently highlighted (\tex!\ifinlist{#2}\high!).
                  If this is not the case, we draw the \gate{cnot} gate without any additional styles (note that since we interrupted the \Yquant{} parser due to the lots of intervening macros, we first have to restart it saying \tex!\yquant!).
                  However, if it is the case that the control register is currently highlighted, we draw the \gate{cnot} gate with the attribute \texttt{[style=red]}---we do not only want to draw the gate itself in red (for which \texttt{[red]} would be sufficient), but also its control line and the control blob, so we use the \style{/yquant/style} shorthand.
                  Note that in the \pkg{qpic} manual, some of the control lines are thicker than others.
                  This could be implemented by adding the argument \tex!every control line/.append style={very thick}!; however, as it is unclear what the thick line should indicate, we did not add this to the example.

                  Then, we have to change the state of the target register appropriately, since the highlighting state will propagate from control to target.
                  If the target register was already highlighted, we have to remove it from the list and we change its line color back to \texttt{black}; if it was not highlighted, we add it to the list and change its line color to \texttt{red}.
                  Note that the use of \gate{addstyle} will keep adding styles, so in the end, the register line style will be a long string \texttt{red,black,red,black,...}; we could do better by saying \gate{setstyle}, which would overwrite the line style.
                  However, since we will initially set the line width of \tex!a[#1]! to \texttt{very thick}---which should be kept throughout the circuit---we would have to take additional care not to lose this setting.
                  Here, we chose the simpler version.

                  After setting the coloring preliminaries, we note that if we slice the circuit at any time, it will have four possible gate configurations (or a \gate{barrier}).
                  We define abbreviations for these in the macros \tex!\cnotA! to \tex!\cnotD!.
                  Since they will always follow in this order, we also define a \tex!\cnotBlock! abbreviation that executes these configurations together with their intermediate \gate{barrier}.
                  We do not include the final barrier, since it is not present in the last block.

                  Now, we start the \tex!yquant! environment.
                  We give some options for a nicer spacing and initialize the registers.
                  In the \pkg{qpic} example, the registers are $1$\hyp indexed, so we use \tex!\The\numexpr\idx+1! to give back the value of the current register index (\tex!\idx!) plus one; we also conditionally color the register name in red if the index coincides with the parameter.
                  Note that here we use \Yquant's shorthand for \tex!\protect\the!, \tex!\protect\ifnum!, and \tex!\protect\fi!, which are \tex!\The!, \tex!\Ifnum!, and \tex!\Fi!, to get the correct expansion behavior.

                  Then, we add the initial style for the \tex!a[#1]! wire.
                  Inserting the gates together with the correct coloring is now extremely simple: we just need to call our \tex!\cnotBlock! command and intersperse it with \gate{barrier}s.
                  At the end, we output all the gates in reverse order, which works similarly to the initialization of the gates, and also conditionally color the reversed register.
                  This coloring could in principle be done similarly to the coloring of the initial label, saying something like \tex!\Ifnum\numexpr8-\idx=#1 \color{red}\Fi!.
                  Here, we chose the ``more honest'' approach to color all the registers that are still present in the coloring list---note the need to \tex!\protect! the \pkg{etoolbox} macro \tex!\xifinlist!.
                  In this way, we could, e.g., terminate the circuit earlier and still get the correct output coloring at this particular point.

                  Note that if there were more that just five blocks, we could also have made use of \TikZ's \tex!\foreach! loop to output all the \tex!\cnotBlock! commands.
                  However, be aware of the fact that \tex!\foreach! puts its content in a group, so the \tex!\high! list assignments would have been local and forgotten in the next iteration.
                  Either they would need to be made globally or some non\hyp grouping loop construct would have to be used (e.g., \tex!\pgfplotsforeachungrouped!).
               \end{example}
            \endgroup

         \clearpage
         \subsubsection{2 Simple Examples}
            \paragraph{2.1 Example 1: Majority}\leavevmode
               \begin{example}
                  \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant*}
      box {\rotatebox{90}{$\operatorname{MAJ}$}} (a, b, c);

      text {$=$} (-);

      cnot b | c;
      cnot a | c;
      cnot c | a, b;

      output {$a \oplus c$} a;
      output {$b \oplus c$} b;
      output {$\operatorname{MAJ}(a, b, c)$} c;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample*}
               \end{example}

            \clearpage
            \paragraph{2.2 Example 2: Quantum Fourier Transform}\leavevmode
               \begin{example}
                  \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant}[operators/every box/.append style={shape=yquant-circle, radius=2.5mm}]
      qubit {$x_2$} x2;
      qubit {$x_1$} x1;
      qubit {$x_0$} x0;

      h x2;
      box {$2$} x2 | x1;
      box {$3$} x2 | x0;
      h x1;
      box {$2$} x1 | x0;
      h x0;

      output {$\frac{1}{\sqrt2} (\ket0 + e^{2\pi i \cdot 0.x_2 x_1 x_0}) \ket1$} x2;
      output {$\frac{1}{\sqrt2} (\ket0 + e^{2\pi i \cdot 0.x_1 x_0}) \ket1$} x1;
      output {$\frac{1}{\sqrt2} (\ket0 + e^{2\pi i \cdot 0.x_0}) \ket1$} x0;
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample*}
                  In this example, we opted to use three distinct registers instead of one vector register, since the reversed indexing would probably have led to more confusion.
                  We globally overwrite the \style{/yquant/operators/every box} style to use a circular shape instead.
                  Note that this would usually be an ellipse, so we explicitly set the radius to a value that exceeds the minimum (half) width.
                  As of version~0.6, the style \style{/yquant/operators/every box} is no longer the base style for other rectangular boxes such as \gate{h} (note this requires a compatibility version of at least \texttt{0.6} or higher).
                  For earlier versions, the change in shape would also affect the Hadamard gate and therefore would have to be reverted using the \style{/yquant/operators/every h} style.
               \end{example}

            \clearpage
            \paragraph{2.3 Example 3: Shor's Algorithm}\leavevmode
            \begingroup%
               \mdfapptodefinestyle{bdBox}{%
                  leftmargin=-.04\linewidth,
                  rightmargin=-.02\linewidth
               }%
               \begin{example}<Updated in 0.7>
                  \begin{codeexample*}
\begin{tikzpicture}
   \def\explain#1#2{%
      \yquant
      [anchor=east, overlay=right] text {#1} explainLeft;
      [anchor=west, overlay=left] text {$\displaystyle#2$} explainRight;
      align -;
   }
   \begin{yquant}[vertical,
                  every control/.append style={radius=1.5mm},
                  operators/every slash/.append style={x radius=3mm, y radius=1.5mm},
                  operators/every box/.append style={y radius=4mm},
                  operators/every measure/.append style={y radius=4mm},
                  operator/minimum extent=1.32cm]
      nobit explainLeft;
      qubit {$\ket{0\dotsm0}$} x; slash x;
      qubit {$\ket{0\dotsm0}$} y; slash y;
      nobit explainRight;
      align -;

      box {$H^{\otimes n}$} x;
      \explain{Quantum Hadamard Transform}
              {\sum_{x = 0}^{2^n -1} \ket x \ket 0}

      box {$a^x \bmod N$} y | x;
      \explain{Exponentiation}
              {\sum_{x = 0}^{2^n -1} \ket x \ket{a^x \bmod N}}

      measure y; output {$y$} y;
      \explain{Measure $y = a^b$}
              {\sum_{j = 0}^{\lfloor\frac{2^n -1}{r}\rfloor} \ket{b + j r} [y]}

      box {QFT} x;
      \explain{Quantum Fourier Transform}
              {\sum_{x = 0}^{2^n -1} \left( \sum_{j = 0}^{\lfloor\frac{2^n -1}{r}\rfloor}
                                            \omega^{x * (b + j r)} \right) \ket x}

      output {$?$} x;
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample*}
                  Once again, this is a very interesting example.
                  The circuit itself is very standard (though it is the first one in vertical mode).
                  In order to output the explanations, we define two invisible wires together with a macro that populates the corresponding \gate{text} gates on those wires.
                  Note that usually, in a vertical layout, all gates would be center\hyp aligned.
                  In order to align the left explanations to the right and the right explanations to the left, we just redefine the \texttt{anchor}s of the gates.
                  However, since \Yquant{} expects the gates to connect at the \texttt{center} anchor and hence equally distributes the required space for the wire to its left and right, this would lead to a very large gap between the explanations and the circuit itself.
                  Here, we don't need \Yquant's wire extent calculations at all---the explanation wires are invisible and at the border of the circuit.
                  Therefore, we just disable the calculations using the \texttt{overlay} attribute.
                  After all the explanations are done, we \gate{align} all registers (if the minimum extent was chosen to be exactly larger or equal to the actual vertical extent of every gate, this would not be necessary; but with two decimals, this is probably not precisely the case).

                  Note that the code example above would work exactly in this way in traditional \LaTeX{} documents; however, this document is set with \pkg{unicode-math}.
                  This leads to a problem when using \tex!\bmod!, which has to be \tex!\protect!ed---or, as we did here, just say \tex!\robustify\bmod! somewhere before its usage and after loading all the packages.
               \end{example}
            \endgroup

            \clearpage
            \paragraph{2.4 Example 4: Teleportation}
               \begin{example}<Updated in 0.7>
                  \begin{codeexample*}
\begin{tikzpicture}
   \newcommand\leftExplain[2][]{
      \yquantsecondpass{
         \draw[decoration={brace, mirror}, decorate, #1]
            let \p1=(leftComments), \p2=(explainTop-0.north), \p3=(explainBottom-0.south) in
            (\x1, \y2) -- (\x1, \y3) node[midway, left=2pt, align=right] {#2};
      }
   }
   \newcommand\rightExplain[2][]{
      \yquantsecondpass{
         \draw[decoration=brace, decorate, #1]
            let \p1=(rightComments), \p2=(explainTop-0.north), \p3=(explainBottom-0.south) in
            (\x1, \y2) -- (\x1, \y3) node[midway, right=2pt, align=left] {#2};
      }
   }
   \begin{yquant}[vertical]
      [name=leftComments] nobit explainLeft;
      qubit {\color{red}$\ket\phi$} q;
      qubit {$\ket0$} q[+2];
      [name=rightComments] nobit explainRight;
      setstyle {red} q[0];

      [name=explainTop]
      h q[1];
      [name=explainBottom]
      cnot q[2] | q[1];
      \rightExplain{Alice and Bob form an\\entangled pair of qubits}
      setstyle {red} q[1];
      setstyle {blue} q[2];
      barrier (q);

      [style=red, operator/separation=0pt, name=explainTop] cnot q[1] | q[0];
      [red] h q[0];
      [red, name=explainBottom] measure q[0, 1];
      \leftExplain[red]{Alice entangles\\and measures}

      [style=blue, name=explainTop] x q[2] | q[1];
      [style=blue, name=explainBottom] z q[2] | q[0];
      discard q[0, 1];
      \rightExplain[blue]{Bob applies gates based on\\Alice's measurements}

      output {\color{blue}$\ket\phi$} q[2];
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample*}
                  This example shows a different way of providing explanations along the circuit, which this time also works for hints encompassing more than a single gate.
                  We define the macros \tex!\leftExplain! and \tex!\rightExplain!, which in the circuit will do the job.
                  They rely on the existent of a couple of named nodes: The node \texttt{leftComments} (or \texttt{rightComments}) is the named node created at the beginning of the circuit when declaring the two invisible wires.
                  They will serve with their horizontal position.
                  Additionally, we require the named gates \texttt{explainTop} and \texttt{explainBottom}, which should correspond to the first and last gate that is supposed to be enclosed in the brace.
                  We then use \TikZ's \texttt{let} functionality in order to extract the required coordinates and draw the nodes.
                  Note that the macros \tex!\p!, \tex!\x!, and \tex!\y! come into existence only when the \tex!\draw! command is executed; hence, just writing the \tex!\draw! call would lead to an error: \Yquant{} would first try to add (using \tex!\protected@edef!) the content of the macro to its output routine for the second pass, then call it in the first pass.
                  We don't need the execution in the first pass---though it would not do harm---but we cannot allow for the expansion at this stage.
                  Hence, we wrap the whole command in \tex!\yquantsecondpass! (which automatically restarts the parser afterwards, so we don't have to do this).
               \end{example}

         \subsubsection{3.1 Wires}
            \paragraph{3.1.1 Wire Declarations}
               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit a;
      qubit b;
      qubit {} c;

      hspace {1cm} -;

      output {$\phi$} a;
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}
                  \begin{codeexample}
\makeatletter
% https://tex.stackexchange.com/a/112212/32357
\DeclareRobustCommand\rvdots{%
   \vbox{%
      \baselineskip4\p@\lineskiplimit\z@%
      \kern-\p@%
      \hbox{.}\hbox{.}\hbox{.}%
   }%
}
\begin{tikzpicture}
   \begin{yquant}[every nobit output/.style={}, register/separation=3mm]
      qubit {$x_1$} x;
      qubit {$\rvdots$} x[+1]; discard x[1];
      qubit {$x_n$} x[+1];

      hspace {1cm} -;

      output {$y_1$} x[0];
      output {$\rvdots$} x[1];
      output {$y_n$} x[2];
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
                  This is one of at least four possible implementations (note we \href{https://tex.stackexchange.com/a/112212/32357}{defined \tex!\rvdots!}, since the native \tex!\vdots! does not appear to be very well\hyp centered).
                  It declares the ``invisible'' register as part of the vector register \yquant!x!.
                  As a consequence, whenever the whole vector register is addressed in operations, the operation is also drawn on the invisible register.
                  For multi\hyp register gates, this may be desired (they just span the whole region), for single\hyp register gates, this is most certainly undesired.
                  Note that \Yquant{} does not allow to declare an \gate{output} gate for invisible registers---usually, this does not make sense.
                  However, this is not enforced as a hard constraint, but rather due to the fact that the style \style{/yquant/every nobit output} does not exist.
                  To prevent an error message, we just define this as an empty style.
                  Also note that, to get a proper vertical spacing, we decided to use the \style{/yquant/register/separation} key---which works well, as there are no other registers.
                  If there were others, it would be better to increase the height and depth of the invisible register.

                  Alternatively, we might declare the invisible register with a completely different name.
                  This would create a discontiguous vector register \yquant!x!, which is probably the better thing to do for single\hyp register gates.
                  However, \Yquant{} may now try to split multi\hyp register gates into contiguous slices---there could be arbitrary registers between discontiguous parts of a vector register, and they should of course not be targeted if they are not in the list of targets of a gate---but here, we would actually want to have this.

                  A third approach mixes \Yquant{} and \TikZ{} code.
                  We declare a vector register with size two, manually increase, say, the depth of the first register, and put a \tex!\node! at the appropriate position by naming the initial labels.
                  In this way, vector usage will never target the ``invisible'' line---since it does not exist; both single\hyp{} and multi\hyp register gates will work appropriately.
                  As a drawback, we need to decide whether we want to enlarge the depth of the first or the height of the second register (or both, splitting in half)---but what if some gates will actually be so large that they would provide enough of height or depth had we just chosen a different way of distribution the space?

                  In order to remediate this, a fourth way using only two registers would be to defer the drawing of the dots to a multi\hyp register \gate{text} gate which receives a \texttt{y~radius} that enforces an appropriate separation.
                  \Yquant{} will then automatically perfectly distribute the vertical extents among height and depth of the involved registers.
                  The drawback with this approach is of course that the dots will be drawn \emph{within} the circuit, not to the left.
                  There is an undocumented option that we can use to shift the gate to the left; but since this only works for initializers, we still need to draw the dots for the outputs manually.
                  A possible implementation could look as follows.

                  \begingroup%
                     \makeatletter%
                     \DeclareRobustCommand\rvdots{%
                        \vbox{%
                           \baselineskip4\p@\lineskiplimit\z@%
                           \kern-\p@%
                           \hbox{.}\hbox{.}\hbox{.}%
                        }%
                     }%
                     \begin{codeexample}
% \rvdots definition from above
\begin{tikzpicture}
   \begin{yquant}
      qubit {$x_1$} x;
      qubit {$x_n$} x[+1];
      [internal/move label, anchor=east, y radius=8mm]
      text {$\rvdots$} (x);

      hspace {1cm} -;

      [name=o1]
      output {$y_1$} x[0];
      [name=o2]
      output {$y_n$} x[1];
   \end{yquant}
   \path (o1.south west) -- (o2.north west) node[midway, /yquant/every output] {$\rvdots$};
\end{tikzpicture}
                     \end{codeexample}
                  \endgroup%
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      [decorate=false, draw=none]
      init {$A$} (q[0, 1]);
      init {$\ket0^{\otimes3}$} (q[2-4]);

      hspace {1cm} -;

      output {$B$} (q[1, 2]);
      output {$\ket0^{\otimes2}$} (q[3, 4]);
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Note that here the $A$ is drawn without the curly braces.
                  There are two simple ways to achieve this: by setting \texttt{draw} to \texttt{none}, the curly brace is suppressed, but still the~$A$ would be drawn at the same position as if the brace were there.
                  We additionally set \texttt{decorate} to \texttt{false} to fully remove any reminiscence of the brace, so that the text is closest to the wires.
                  (Note that just removing the decoration without also removing the drawing would lead to a vertical line that connects all the affected wires---this is how the \texttt{yquant-init} shape looks like in an undecorated fashion.)
               \end{example}

         \subsubsection{3.2 Gates}
            \paragraph{3.2.1 Controlled NOT and controlled \texorpdfstring{$Z$}{Z}}
               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      not a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}[register/default lazy name=$\symbol{\numexpr`a+\idx}$]
      cnot q[1] | q[0];
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Since in \Yquant's notation, \texttt{b} is mentioned before \texttt{a}, it would also be created as the first wire.
                  If we instead resort to vector registers, we can directly specify which position our registers should have.
                  Of course, for longer circuits, an explicit declaration is probably favorable.
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}[register/default lazy name=$\symbol{\numexpr`a+\idx}$]
      cnot q[2] | q[-1];
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      not a;
      zz (b, c);
      cnot c | a ~ b;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

            \paragraph{3.2.2 General Gates}
               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      box {\symbol{\numexpr`A+\idx}} a, b;
      box {$\tau$} (-);
      box {GATE} a | b;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Note that the macro \tex!\idx! is available in any gate, and it gives the index of the current register within the target list.
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}[operators/every box/.append style={shape=yquant-circle}]
      box {$\rho$} a;
      box {$\rho$} b | a;
      box {$\rho$} (-);
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Note that the macro \tex!\idx! is available in any gate, and it gives the index of the current register within the target list.
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}[vertical=-90]
      qubit a; qubit b; qubit c;
      box {$M$} (c, b) | a;
      box {GATE} (-);
      box {$M^{-1}$} (c, b) | a;
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
                  Here, we use the automatic rotation feature that the \style{/yquant/vertical} style provides.
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      [name=fs] box {\Ifnum\idx<1 $f^{-1}$\Else $f$\Fi} (a, b), (c, d);
      [name=g] box {$g$} (b, c) | a;
      [shape=yquant-circle, name=theta] box {$\theta$} d;
   \end{yquant*}
   \draw (fs-0) -- (fs-1) (g) -- (theta);
\end{tikzpicture}
                  \end{codeexample}
                  By putting the two $f$\hyp boxes into a single gate, we ensured that \Yquant{} will center them with respect to each other.
               \end{example}

            \clearpage
            \paragraph{3.2.3 Other predefined Gates}
               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      h a;
      h x;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      z a, b;
      zz (-);
      z a | b;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      zz (a, b), (c, d);
      zz (b, c);
      zz (-b), (c-);
      zz (b, c);
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      swap (a, b);
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}
                  \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant*}[plusctrl/.style={/yquant/every control/.style={/yquant/operators/every not}, /yquant/every positive control/.style={}}]
      [plusctrl] box {$f$} (a, b) | c;
      [plusctrl, shape=yquant-circle] box {$\zeta$} c | d;
      [plusctrl] box {$f$} (a, b) | c;
      cnot b | a;
      cnot c | d;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample*}
                  This very unorthodox\hyp looking style can be achieved by altering the control styles in such a way that it basically looks like a \gate{not} gate.
               \end{example}

         \subsubsection{3.3 Attributes}
            \paragraph{Size Attributes}
               \begin{example}<Changed in 0.7>
                  \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant*}
      [y radius=20pt] box {HIGH} (a, b);
      [x radius=20pt] box {WIDE} (-);
      [time radius=20pt] box {LONG} (-);
      [space radius=20pt] box {BROAD} (-);
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample*}
                  In horizontal mode, \texttt{time radius} is a synonym for \texttt{x radius}, while \texttt{space radius} is a synonym for \texttt{y radius}.
               \end{example}

               \begin{example}<Changed in 0.7>
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}[vertical=45]
      [y radius=20pt] box {HIGH} (a, b);
      [x radius=20pt] box {WIDE} (-);
      [time radius=20pt] box {LONG} (-);
      [space radius=20pt] box {BROAD} (-);
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      [register/minimum depth=10pt]
      qubit a;
      qubit b;
      [register/minimum height=1pt]
      qubit c;

      cnot c | a, b;
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
                  Upon creation, the minimum register sizes can be passed on to \Yquant; note that the \style{/yquant/register/minimum height} extends from the wire line to the top of the space that is allocated for the wire, whereas the corresponding key \style{/yquant/register/minimum depth} extends from the wire line to the bottom.
                  Hence, the values given here are half of \pkg{qpic}'s.
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      [inner sep=0pt, radius=2.5pt]
      box {} a | b;
      [shape=yquant-circle, radius=10pt]
      box {$g$} b | a;
      cnot a | b;
      [operator style={radius=7.5pt}, control style={radius=4pt}]
      cnot a | b;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  To mimick closely \pkg{qpic}'s manual, we used an empty \gate{box} instead of the \gate{xx} gate, which also is a rectangle.
                  Note that the shapes that accept text also have an inner separation, which would interfere with the \texttt{radius} setting.
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      [x radius=12.5pt]
      box {$f$} a;
      [radius=12.pt, shape=yquant-circle]
      box {$f$} a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  Note that when changing to the \texttt{yquant-circle} shape, this will become an ellipse if only one of the radii is modified.
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit {\color{purple}$a$} a;
      setstyle {purple} a;
      qubit b;

      [style=green!50!black]
      cnot a | b;
      setstyle {red} b;
      [orange, control style=blue]
      h a | b;
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}
                  \begin{codeexample}
\yquantdefinebox{circle}[shape=yquant-circle, draw, inner sep=0pt, radius=2mm]{}
\begin{tikzpicture}
   \begin{yquant*}
      [fill=red!50!white] box {$f$} a | b;
      [fill=blue, name=b] circle a;
      [fill=green, name=g] circle b;
      not a;
      [fill=yellow] not b;
   \end{yquant*}
   \draw (b) -- (g);
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      setstyle {dotted} a;
      setstyle {very thick} b;
      [dashed, fill=yellow] box {$G$} (-);
      cnot a | b;
      setstyle {densely dotted} a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}[on/.style={red, very thick}]
   \begin{yquant*}[on/.style={style=red, control style={very thick}}]
      cnot a | b;
      qubit {\color{red}$c$} c;
      setstyle {on} c;
      [on] cnot b | c;
      setstyle {on} b;
      [on] cnot a | b;
      setstyle {on} a;
   \end{yquant*}
\end{tikzpicture}
                  \end{codeexample}
                  This example demonstrates for the first time that new registers can also be declared at any later time in the circuit.
                  Note that we defined two very different styles:
                  \begin{itemize}
                     \item \texttt{/tikz/on} for the \texttt{tikzpicture} \\
                        This is an ordinary \TikZ{} style and hence will be applied whenever it is used in a styling context---for example, when added to the wire styles.
                     \item \texttt{/yquant/on} for the \texttt{yquant*} environment \\
                        This is a style that does not directly apply any styling, but it instead passes options to \style{/yquant/style} (we want to have the gates as well as their controls and control lines in red) as well as to \style{/yquant/control style} (we want to draw the control lines thicker [in principle, this would also affect the controls, but they are filled, not drawn], but we don't want to draw the lines of the \gate{cnot} gates themselves be drawn thicker.).
                        Since attributes for gates will first look in the \texttt{/yquant} namespace, this style is applied when used as an attribute for a gate (but beware that \yquant![style=on]! would call the other style).
                  \end{itemize}
               \end{example}

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}[register/default name=$\reg$]
      cbit a;
      qubit b;
      h b | a;
      discard a;
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \Yquant{} does not offer the variety of shapes that \pkg{qpic} does; please file a feature request if there is a need.

               \begin{example}
                  \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit a;
      qubit b;
      [shape=yquant-circle, radius=1.2mm, inner sep=0pt]
      box {$\cdot$} b | a;
      box {$A$} (-);
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample}
               \end{example}

               \clearpage
               \begin{example}
                  \begin{codeexample*}
% \usepackage[hidelinks]{hyperref}
% \usetikzlibrary{calc}
\makeatletter
\def\tikzHyperNode#1{%
   \ifdefined\tikz@alias%
      \unless\ifyquantmeasuring%
         \pgfqkeysalso{/tikz}{%
            % https://tex.stackexchange.com/a/36111/32357
            alias=sourcenode,
            append after command={
               % we don't need to worry about outer sep, yquant shapes ignore this value
               let \p1=(sourcenode.north west),
                   \p2=(sourcenode.south east),
                   \n1={\x2-\x1},
                   \n2={\y1-\y2} in
               node [inner sep=0pt, outer sep=0pt, anchor=north west, at=(\p1)]
               {#1{\XeTeXLinkBox{\phantom{\rule{\n1}{\n2}}}}}
            }%
         }%
      \fi%
   \fi%
}
\tikzset{
   hyperlink/.code={\tikzHyperNode{\hyperlink{#1}}},
   hyperref/.code={\tikzHyperNode{\hyperref[{#1}]}}
}

\begin{tikzpicture}
   \begin{yquant}
      qubit a;
      qubit b;
      [hyperref=sec:grammar]
      box {SUB} (a-b);
   \end{yquant}
\end{tikzpicture}
                  \end{codeexample*}
                  In principle, adding a hyperlink to any gate works as adding a hyperlink to any \TikZ{} node.
                  We use a standard implementation; because of the way \Yquant{} internally handles styles applied to a gate, we must protect this in the \tex!\ifdefined\tikz@alias! (\Yquant{} executes the options outside of nodes first to set, e.g., line styles appropriately, which leads to an error, as the \texttt{alias} option only works within nodes).
                  We also want to refrain from unnecessarily adding hyperlinks during the initial measurement phase.
                  We then provide two \TikZ{} styles to do the job, depending on whether the link should be created via \tex!\hyperlink! or \tex!\hyperref! and apply it.
                  Note that here, we explicitly created the registers first.
                  Had we used an implicit creation, we would also have applied to hyperref to the register labels!

                  Be aware of the fact that hyperlinks in PDFs will always be rectangular; if your gate shape is different from this, do not expect the shapes to match.
               \end{example}

         \subsubsection{3.4 Measurement and Other Wire Type Changes}
            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      measure a;
      cnot b | a;
      dmeter {$Z$} b;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
            \end{example}

            \Yquant{} does not support the \texttt{tag} shape.

            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      [direct control] measure a;
      cnot b | a;
      dmeter {$Z$} b;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
            \end{example}

            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}[operator/separation=2mm]
      setstyle {-|, shorten >= 3mm} a;
      inspect {$0$} a;
      discard a;

      hspace {1cm} -;

      setstyle {|-, shorten <= 2mm} a;
      init {$1$} a;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
               There are no gates in \Yquant{} that resemble the visual \gate{discard} or reinitialization marker; however, this can be achieved by placing appropriate arrowheads at the wires.
               Still, this is a problematic solution: Every wire in \Yquant{} will extend from the center of one gate to the center of the next gate; protruding parts will be clipped away.
               Hence, the arrowhead will not be visible, as it is below the \gate{inspect} or \gate{init} gate---so we must \texttt{shorten} the wire by an ``appropriate'' amount.
               Additionally, if the circuit were longer, we would want to quickly get rid of this arrowhead style.
               \Yquant{} will try to make the wire lines as long as possible---i.e., in a normal circuit without any changes, the wire will in fact be one continuous line from the left to the right.
               However, whenever something changes at the wire---say, the style or type is changed---\Yquant{} needs to start a new path.
               We don't want the arrowheads to still be installed on this new path, hence we would quickly need to remove them.
            \end{example}

            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit a;
      hspace {5mm} a;
      [after=a] qubit b;
      box {$f$} (a, b);
      inspect {$A$} a;
      [after=a] qubit c;
      discard a;
      box {$g$} (b, c);
      align -;
      init {$a'$} a;
      inspect {$B$} b;
      discard b;
      box {$h$} (-);
      output {$A'$} a;
      output {$C'$} c;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample}
               Here, we create registers with the \texttt{after} attribute at some later point in the circuit.
               Note that logically speaking, the $h$~box should have had the targets \yquant!(a, c)!; however, as \Yquant{} does not know that the middle register was already discarded, it would have drawn two boxes joined by a wiggly line to indicate the discontiguous multi\hyp qubit register.
            \end{example}

         \subsubsection{3.5 Managing Slices}
            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit a; qubit b; qubit c; qubit d;
      zz (a, c);
      h b;
      measure d;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample}
            \end{example}

            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit a; qubit b; qubit c; qubit d;
      zz (a, c);
      h b;
      align -;
      measure d;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample}
            \end{example}

            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit a; qubit b; qubit c; qubit d;
      zz (a, c);
      align -;
      h b;
      measure d;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample}
            \end{example}

            \begin{example}
               \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant}[operators/every barrier/.style={shape=yquant-line, draw, shorten <= -2mm, shorten >= -2mm, decoration={zigzag, segment length=4, amplitude=1pt}, decorate}]
      qubit a; qubit b; qubit c; qubit d;
      zz (a, c);
      h b;
      align -;
      barrier d;
      measure d;
      [red] barrier a, d;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample*}
               Note that a \Yquant{} \gate{barrier} works a bit differently from \pkg{qpic}'s.
               It is basically just an ordinary gate with a dashed line style; by the fact that all registers that are listed in the target list are aligned automatically, the \gate{barrier} usually does its job.
               Hence, we need to \gate{align} before the first \gate{barrier}, as it does not perform an alignment by itself on registers that were not mentioned as targets.

               Here, we also change the default style (which is a dashed line) to the zigzag line that uses \pkg{qpic}'s style.
               Note that \Yquant{} automatically loads the library \texttt{decorations.pathmorphing}, so we don't need to do this.
            \end{example}

            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}[operator/minimum width=0pt, operator/separation=2mm]
      [shape=yquant-circle, radius=1.5ex]
      box {$2$} a | b;
      h a, b, c;
      [style=green!50!black]
      cnot c | a, b;
      [operator/separation=0pt, green!50!black]
      not c;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
               In order to stick two operators directly next to each other, we must set the \style{/yquant/operator/separation} to zero; this is the whitespace that is inserted before an operator.
               However, if the total with of an operator is smaller than \style{/yquant/operator/minimum width}, it is centered in a box of this width (giving a more uniform layout with lots of small gates), which would add additional whitespace both to the right of the Hadamards and to the left of the \gate{cnot}s.
               We just globally suppress this minimum width, which is unproblematic for this particular circuit (we could also locally change it).
            \end{example}

            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}[operator/minimum width=0pt, operator/separation=2mm]
      [shape=yquant-circle, radius=1.5ex]
      box {$2$} a | b;
      h a, b, c;
      [style=red]
      cnot c | a, b;
      [operator/separation=0pt]
      not c;
      cnot c | a, b;
      [operator/separation=0pt, red]
      not c;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
            \end{example}

            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}[operators/every box/.append style={shape=yquant-circle, radius=1.5ex}]
      box {$1$} a;
      not b;
      box {$2$} a;
      align -;
      not b;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
               An instruction like \texttt{MIXGATES} does not exist in \Yquant, as it does not use a grid\hyp based layout; but of course, its behavior can be faked by \gate{align} gates.
            \end{example}

         \clearpage
         \subsubsection{3.6 Reversing and Repeating}
            \begin{example}
               \begin{codeexample*}
\begin{tikzpicture}
   \yquantdefinegate{cnots}{
      qubit a; qubit b; qubit c;
      cnot b | a;
      cnot b | c;
      cnot a | b;
      cnot c | b;
   }
   \begin{yquant*}
      cnots (a, b, c);
      cnots (-);
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample*}
               \Yquant{} does not have a concept of slices and hence can also not automatically repeat gates within a certain slice.
               However, there are multiple ways to achieve the circuits in this section without repeating parts manually.
               Here, we defined a custom gate that contained the content and inserted it two times.
               Another alternative would be to do this using macros, as was illustrated in the \hyperref[ex:qupicfirst]{very first example} of the \pkg{qpic} section.
            \end{example}

            \begin{example}
               \begin{codeexample*}
\begin{tikzpicture}
   \yquantdefinegate{gates}{
      qubit a; qubit b; qubit c;
      [plusctrl] box {$f$} a | b;
      addstyle {dotted} b;
      [plusctrl] box {$g$} (a, b) | c;
      [plusctrl] box {$f$} a | b;
      addstyle {solid} b;
   }
   \begin{yquant*}[plusctrl/.style={/yquant/every control/.style={/yquant/operators/every not}, /yquant/every positive control/.style={}}]
      gates (a, b, c);
      cnot b | c;
      gates (-);
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample*}
               Note that for this sequence, we did basically the same thing as before, as we identified a symmetric slice---so reversing the order does not do anything.

               We will also expand this example and give a very simple (and a bit shortsighted) implementation of a macro that reverses the order of gates.
               Note that this macro basically just splits its content at semicolons and when it is done inputs all the parts in reverse order.
               Hence, it will fail if semicolons appear, e.g., in attributes without enclosing them in braces.
               It also does not correspond exactly to the \texttt{R} instruction from \pkg{qpic}, as it does not \emph{reverse} wire styles (basically \gate{addstyle} would become a hypothetical \gate{subtractstyle} macro), but just inserts them in reverse order.
               Hence, the following example will give a different circuit with respect to the wire style!

               \begin{codeexample*}
\makeatletter
\long\def\reversegates#1{%
   \begingroup%
      \let\reversegates@list=\empty%
      \count0=0 %
      \expandafter\reversegates@i#1;\reversegates@stop%
}
\long\def\reversegates@i#1;#2\reversegates@stop{%
   \ifstrempty{#2}{%
      \yquant@fordown \reversegates@idx := \count0 downto 1 {%
         \expandafter\expandafter\expandafter\yquant%
            \csname reversegates@list@\reversegates@idx\endcsname%
      }%
      \endgroup%
   }{%
      \ifstrequal{#2}{;}{%
         \reversegates@i;\reversegates@stop%
      }{%
         \advance\count0 by 1 %
         \csdef{reversegates@list@\the\count0}{#1;}%
         \reversegates@i#2\reversegates@stop%
      }%
   }
}
\begin{tikzpicture}
   \def\gates{%
      [plusctrl] box {$f$} a | b;
      addstyle {dotted} b;
      [plusctrl] box {$g$} (a, b) | c;
      [plusctrl] box {$f$} a | b;
      addstyle {solid} b;
   }
   \begin{yquant*}[plusctrl/.style={/yquant/every control/.style={/yquant/operators/every not}, /yquant/every positive control/.style={}}]
      \expandafter\yquant\gates
      cnot b | c;
      \reversegates\gates
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample*}
            \end{example}

            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit a; qubit b; qubit c;
      cnot b | a;
      cnot b | c;
      \foreach \i in {1, 2} { \yquant
         cnot a | b;
         cnot c | b;
      }
   \end{yquant}
\end{tikzpicture}
               \end{codeexample}
               Another way to repeat things is to just use appropriate repetition macros (and remember to restart the parser); here, we used \tex!\foreach! from \TikZ, but any other will also do the job.
            \end{example}

         \subsubsection{3.7 Other Circuit Elements}
            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}[operators/every slash/.append style={radius=2mm}]
      slash a;
      [label=10:n] slash a;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
            \end{example}

            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit a; qubit b;
      cnot b | a;
      inspect {\Ifcase\idx$a$\Else$a \oplus b$\Fi} -;
      cnot b | a;
      inspect {$b$} b;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample}
               Here, we achieved the centering of the two \gate{inspect}ed registers by putting them in a single gate instruction with case discrimination.
            \end{example}

            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      swap (a, b);
      text {$=$} (-);
      cnot b | a;
      cnot a | b;
      cnot b | a;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
               This is a very simple equality; for more complicated ones, the \hyperref[sec:foreign:groups]{\texttt{groups}} library is recommended.
            \end{example}

            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant}
      qubit a; qubit b; qubit c; qubit d;
      box {$f$} (a, b);
      inspect {$G$} (a, b);
      init {$F$} (c, d);
      box {$g$} (c, d);
   \end{yquant}
\end{tikzpicture}
               \end{codeexample}
               Note that we first defined all the registers explicitly, and they all use an initializing text.
               Had we directly used the \gate{init} gate on the registers \yquant!(c, d)! as the \emph{first} gate when \emph{neither} of both registers had an initializing text, then the~$F$ would have been placed to the left of the wires.
               Basically, a \gate{qubit} declaration with a value is the same as declaring the register without a value plus another \gate{init} gate that puts the value in place.
               A zero\hyp length \gate{hspace} gate or an \gate{align}ment directly at the beginning would be a way to prevent this shift to the left from happening.
            \end{example}

            \Yquant{} does not support the permutation gate that \pkg{qpic} has.
            It would however not be very difficult to implement this particular shape and make it available.
            Maybe even a multi\hyp swap gate using the \texttt{knots} library would be possible.

         \clearpage
         \subsubsection{3.8 Comments}
            \begin{example}
               \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant}
      qubit a; qubit b;
      \foreach \i in {0, 1, 2} { \yquant
         cnot b | a;
         cnot a | b;
         \ifnum\i<2 \yquant
            [operator/separation=2pt, operator/minimum width=0pt]
            barrier (-);
         \fi
      }
   \end{yquant}
\end{tikzpicture}
               \end{codeexample*}
            \end{example}

            \begin{example}
               \begin{codeexample}
% \usetikzlibrary{quotes}
\begin{tikzpicture}
   \begin{yquant}[operators/every box/.append style={shape=yquant-circle, radius=1.5ex}]
      qubit a;
      [blue, "above" above] box {$1$} a;
      [red, "below" below] box {$2$} a;
      ["both" above, "sides" below] box {$3$} a;
   \end{yquant}
\end{tikzpicture}
               \end{codeexample}
            \end{example}

            \begin{example}
               \begin{codeexample*}
% \usetikzlibrary{calc}
\begin{tikzpicture}
   \begin{yquant}[operators/every box/.append style={shape=yquant-circle, radius=1.5ex}]
      qubit a;
      [name=1] box {$1$} a;
      [name=2] box {$2$} a;
      [name=3] box {$3$} a;
   \end{yquant}
   \draw[decoration=brace, decorate]
      ($(1.north west)+(-.1,.1)$) -- ($(2.north east)+(.1,.1)$)
      node[midway, above=1pt] {above};
   \draw[blue, decoration={brace, mirror}, decorate]
      ($(2.south west)+(-.1,-.1)$) -- ($(3.south east)+(.1,-.1)$)
      node[midway, below=1pt] {below};
\end{tikzpicture}
               \end{codeexample*}
            \end{example}

            \begin{example}
               \begin{codeexample*}
\begin{tikzpicture}
   \begin{yquant*}
      [this subcircuit box style={draw=none, fill=red!40!white}]
      subcircuit {
         qubit {} a; qubit {} b;
         cnot b | a;
         cnot a | b;
      } (a, b);
      [this subcircuit box style={draw, dotted, rounded corners=10pt}]
      subcircuit {
         qubit {} a; qubit {} b;
         cnot b | a;
         cnot a | b;
      } (b, c);
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample*}
            \end{example}

         \clearpage
         \subsubsection{3.9 Macros and \LaTeX{} Code}
            \begin{example}
               \begin{codeexample}
\begin{tikzpicture}[loud/.style={red, very thick}]
   \yquantdefinebox{phase2}[loud, draw, shape=yquant-circle, radius=1.5ex]{$2$}
   \begin{yquant*}
      [style=loud]
      phase2 a | b;
      phase2 b;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
               Note that here, we choose an alternative gate name, as there already is the built\hyp in gate \gate{phase}.
               While we could overwrite it, this is generally a very bad idea.
               Keep in mind that gate declarations are global and also that gates are case insensitive, so changing the capitalization would not help.
               Finally note that when we define a style for a new gate, it only pertains to the \emph{gate} itself.
               It is not possible to change styles external to the gate---such as control lines---within the gate definition itself.
            \end{example}

            \begin{example}
               The following example in the \pkg{qpic} manual requires some additional thoughts.
               It defines a custom gate with a variable number of target registers.
               The \tex!\yquantdefinegate! interface does not officially allow for this, although some low\hyp level hacking can of course be done (a \emph{sorted} \pkg{etoolbox} list is provided in the macro \tex!\yquant@circuit@subcircuit@param!, which holds the internal indices of all currently involved target registers).

               It is of course always possible to write some macros that output the required gate commands.
               Looking at the particular example, it is actually not really necessary to define a gate that has a variable number of targets.
               Rather, in \Yquant, one would define a new gate that just contains the two $\oplus$ symbols next to each other; the control line is drawn separately from the gate anyway.
               This very straightforward description will unfortunately fail, for the following reason:
               When a control line is drawn, \Yquant{} currently always draws it from the \texttt{center} anchor of the current shape upwards or downwards.
               However, for the $\mathord\oplus\!\mathord\oplus$ shape, the control line point should actually be in the middle of the right $\oplus$.
               This is an off\hyp center point, so we need some hacking to convince \Yquant{} to do this.
               The following code is pretty long; we will therefore give parts of the code, followed by an explanation.

               First of all, we define a shape (similar to what is done in \texttt{yquant-shapes.tex}) that holds the two $\oplus$es.
               \begin{codeexample*}
\makeatletter
\pgfdeclareshape{yquant-doubleoplus}{%
   \inheritsavedanchors[from=yquant-slash]%
   \anchor{center}{\pgfqpoint{.5\dimexpr\xradius\relax}{0pt}}%
   \foreach \anc in {north, east, south, west} {
      \inheritanchor[from=yquant-rectangle]{\anc}
   }
   \anchor{north east}{\pgfqpoint{.853553\dimexpr\xradius\relax}
                                 {.707107\dimexpr\yradius\relax}}%
   \anchor{south east}{\pgfqpoint{.853553\dimexpr\xradius\relax}
                                 {-.707107\dimexpr\yradius\relax}}%
   \anchor{south west}{\pgfqpoint{-.853553\dimexpr\xradius\relax}
                                 {-.707107\dimexpr\yradius\relax}}%
   \anchor{north west}{\pgfqpoint{-.853553\dimexpr\xradius\relax}
                                 {.707107\dimexpr\yradius\relax}}%
   % The border anchor is a bit more tricky, we leave it out here
   \backgroundpath{%
      \pgf@relevantforpicturesizefalse%
         \pgfpathmoveto{\pgfqpoint{-.5\dimexpr\xradius\relax}{\yradius}}%
         \pgfpathlineto{\pgfqpoint{-.5\dimexpr\xradius\relax}{-\yradius}}%
         \pgfpathmoveto{\pgfqpoint{.5\dimexpr\xradius\relax}{\yradius}}%
         \pgfpathlineto{\pgfqpoint{.5\dimexpr\xradius\relax}{-\yradius}}%
         \pgfpathmoveto{\pgfqpoint{-\xradius}{0pt}}%
         \pgfpathlineto{\pgfqpoint{\xradius}{0pt}}%
         \pgfpathellipse{\pgfqpoint{-.5\dimexpr\xradius\relax}{0pt}}%
                        {\pgfqpoint{.5\dimexpr\xradius\relax}{0pt}}%
                        {\pgfqpoint{0pt}{\yradius}}%
      \pgf@relevantforpicturesizetrue%
      \pgfpathellipse{\pgfqpoint{.5\dimexpr\xradius\relax}{0pt}}%
                     {\pgfqpoint{.5\dimexpr\xradius\relax}{0pt}}%
                     {\pgfqpoint{0pt}{\yradius}}%
   }%
   \clippath{%
      \pgfpathellipse
         {\pgfqpoint{-.5\dimexpr\xradius}{0pt}}
         {\pgfqpoint{.5\dimexpr\xradius+\pgflinewidth}{0pt}}
         {\pgfqpoint{0pt}{\dimexpr\yradius+.5\pgflinewidth\relax}}%
      \pgfpathellipse
         {\pgfqpoint{.5\dimexpr\xradius\relax}{0pt}}
         {\pgfqpoint{.5\dimexpr\xradius+\pgflinewidth\relax}{0pt}}
         {\pgfqpoint{0pt}{\dimexpr\yradius+.5\pgflinewidth\relax}}%
   }%
}
               \end{codeexample*}
               \input \minted@jobname.pyg % we need to execute all this again without the group
               Nothing special happens in the first few lines (although the \texttt{center} anchor is now off\hyp center): We declare a new shape \texttt{yquant-doubleoplus}, inherit some saved anchors and anchors (for details, see the \TikZ{} manual, section~106.5.3, ``Command for Declaring New Shapes'').
               The \texttt{x~radius} now corresponds to the \emph{diameter} of one of the circles, since we have two circles next to each other.
               We do not define border anchors at the moment; they would require some additional computation, but in lots of scenarios, they are not necessary (as we would also not need most of the anchors, but it is always good to have them).
               The clip path is also not very special, it just contains the shape that is to be clipped away; basically, both circles.
               The background path deserves more attention.
               We draw the two circles and the vertical and horizontal lines; but note that we disable the \pkg{pgf}'s size protocol for all but the right circle.
               Hence, when this shape is used, \TeX{} and \Yquant{} will actually think that it only occupies space for the right circle; the left one will protrude in the margin.
               (Actually, we could wrap this in a test such as \tex!\ifdefined\yquant@prefix! to only discard protocoling within a \tex!yquant! environment, so that the shape is properly usable outside.)

               Next, we must take care of re\hyp inserting this ``lost'' margin whenever the gate is used; and we also define a style that appropriately uses the shape:
               \begin{codeexample*}
\yquantset{
   operators/every noffoli/.style={
      shape=yquant-doubleoplus, x radius=2.6mm, y radius=1.3mm, draw
   },
   internal/noffoli shift/.code={%
      \begingroup%
         \expandafter\tikzset\expandafter{\yquant@draw@@style}%
         \tikzset{/yquant/every operator, /yquant/operators/every noffoli, /yquant/this operator}%
         \edef\cmd{%
            \endgroup
            \dimdef\noexpand\yquant@config@operator@sep{%
               \yquant@config@operator@sep+
               \pgfkeysvalueof{/tikz/x radius}%
            }%
         }%
         \cmd
   }
}
               \end{codeexample*}
               \input \minted@jobname.pyg % we need to execute all this again without the group
               The first style is almost a copy of the \style{/yquant/operators/every not} style, only with the new shape and a doubled \texttt{x~radius}.
               The second style is more complicated: Protected in a group, it first sets all the custom style overwrites that a user may pass to the gate (e.g., the user may wish to overwrite the radii)---those are stored in the internal macro \tex!\yquant@draw@@style!.
               Then, it applies the styles in the order as the gate would do it; note that an attribute such as \yquant![x radius=1cm]! would only add the directive to the \style{/yquant/this operator} style, but not apply it yet, therefore we now execute all the options that were stored previously.
               As the final action that survives the group, we add the current value for the \texttt{x~radius} to the current value of the operator separation---this effectively enacts the proper placement of our gate.

               Having defined those styles, we finally need to declare the gate itself, so that it can be used in a circuit:
               \begin{codeexample*}
\yquant@langhelper@declare@command
   {noffoli}
   {}
   {%
      \appto\yquant@attrs@remaining{,/yquant/internal/noffoli shift}%
      \yquant@prepare
         {}%
         {/yquant/operators/every noffoli}%
   }%
\yquant@langhelper@setup@attrs{noffoli}{}{}
               \end{codeexample*}
               % those were global commands anyway
               We call \tex!\yquant@langhelper@declare@command!, as for every standard gate declaration, with the desired name of the gate (\tex!{noffoli}!), the actions that are to be carried out \emph{before} the targets and controls are parsed (\tex!{}!), and the actions that are to be carried out once the targets and controls are known.
               We append the style that we just defined to the list of attributes, and execute the gate preparation.
               Finally, we also declare the attributes that this gate takes---no required and no optional attributes.

               After all this work, which can be saved in some shared document and used whenever necessary, we can come to the application, which is now very straightforward (however, note that our gate declaration was too simplistic for vertical mode; but an adaptation is not difficult).

               \begin{codeexample}
\begin{tikzpicture}
   \begin{yquant*}
      noffoli a | b, c;
      [style=red] noffoli c | a, b;
      noffoli b | a;
   \end{yquant*}
\end{tikzpicture}
               \end{codeexample}
            \end{example}

            \begin{example}
               \begin{codeexample}
% \usetikzlibrary{backgrounds}
\begin{tikzpicture}
   \begin{yquant}
      qubit a; qubit b;
      [name=cn]
      cnot b | a;
      \draw[fill=blue] (cn) circle[radius=5pt];
      box {FONT} (-);
      [name=cn, fill=boxBlueBody]
      cnot b | a;
      \scoped[on background layer] \draw[fill=red] (cn) circle[radius=5pt];
   \end{yquant}
\end{tikzpicture}
               \end{codeexample}
               There are no special options to mix \TikZ{} code with \Yquant{} code, as this can be done natively at any time.
               To draw at the position of another gate, just name the gate.
               Note that---as was illustrated here---also using the same name multiple times is possible, in this case, the latter use overwrites the former.
               There is no direct equivalent to the \texttt{PRETIKZ} option---the gate has to be drawn first in order to get its position.
               However, \TikZ{} supports layers, so it is easy to draw something behind a gate: just put it on a background layer, e.g., the one provided by the \texttt{backgrounds} library.
               Also note that here, we filled the second \gate{cnot} gate with our background color in order to give the same image as in the \pkg{qpic} manual.
               The circle is not filled by default, hence the red ``outer'' circle would be visible also inside the \gate{cnot} circle.
            \end{example}

            The \texttt{HYPERTARGET} instruction can be directly reproduced in \TeX{} by just putting a \tex!\hypertarget! before the \texttt{tikzpicture}.
      \endgroup

   \section{Foreign language support and extensions}\label{sec:foreign}
      \Yquant{} is built in various modules, so that it is not hard to use the quantum circuit rendering backend, but expose a different language frontend.
      \compat{New in 0.3}\Yquant{} not only understands its own language, but also others.
      \compat{New in 0.5}Although we refer to ``foreign languages,'' additional extension packages of the \Yquant{} language itself are also covered in this section and can be loaded by the same syntax.

      \subsection[groups]{\compat{Updated in 0.7\\New in 0.5}groups}\label{sec:foreign:groups}
         By saying \tex!\useyquantlanguage{groups}! in the preamble after loading \Yquant{} itself, additional support for groups of \Yquant{} circuits is loaded.
         Various circuits in a group share a common set of registers, are appropriately aligned horizontally if on the same line and can also be aligned vertically among multiple lines.
         The main intended use is for circuit equations.

         This extension provides the environment \tex!yquantgroup!.
         You may use this environment within a \tex!tikzpicture!; in this case, all page\hyp break related features are not available.
         You may alternatively use the environment outside of a \tex!tikzpicture!; in this case, it will start and end the pictures appropriately.

         As with \tex!yquant!, the environment accepts optional options that are passed to \tex!\yquantset!; a starred form is available that allows for the lazy creation of registers---but note that \emph{shared} registers must always be created explicitly; only if some circuits in the group have additional registers, the lazy creation applies.

         \subsubsection{General usage}
            \begin{minted}{tex}
% preamble:
% \usepackage[compat=<version>]{yquant}
% \useyquantlanguage{groups}
\begin{tikzpicture}% tikz options possible. This environment may be omitted.
   % tikz commands go here
   \begin{yquantgroup}% yquant(group) options possible.
      \registers{
         % arbitrary shared register declaration go here
      }
      % any of \circuit, \equals, \\, \shiftright
      % if the tikzpicture environment was omitted: also allows
      % \pagebreak, \newpage, \clearpage, \cleardoublepage
      % in most cases, TikZ commands are also allowed
   \end{yquantgroup}
   % tikz commands go here
\end{tikzpicture}
            \end{minted}

         \subsubsection{Special macros}
            \paragraph*{\tex!\registers!}
               The \tex!\registers! macro can and must only be used once in a \tex!yquantgroup! environment.
               It contains the declaration of all the registers that are shared among the various circuits within a group.
               Basically, if you follow the convention in a usual \Yquant{} circuit to first declare all the registers, then use the gates, then you would put the declaration part in the \tex!\registers! macro.
               However, note that it is in principle also possible to mix register declarations with other gates and \TikZ{} commands.

               In case you do not use the \gate{import} gate in any of the circuits within the group and you do not declare own registers, the behavior is very straightforward: basically, the content of \tex!\registers! is copied verbatim at the beginning of each circuit.
               Otherwise, the general rule is: importing a register will ensure that all non\hyp declaration commands that preceded this register declaration are executed; and importing the last register will additionally execute all succeeding commands within \tex!\registers!.

            \paragraph*{\tex!\circuit[<style>]{<content>}!}
               The \tex!\circuit! macro can be thought of as starting a \tex!yquant! (or \tex!yquant*!) environment and using its mandatory argument \tex!<content>! as the content of the circuit; the optional \tex!<style>! is used to apply additional styling options to the circuit.

               This is not entirely accurate: In reality, the content is put into a \gate{subcircuit} and \tex!<style>! is passed as arguments to the subcircuit.

               The default style \style{/yquant/operators/every group circuit} is applied to the circuit.
               This style is configured such that the illusion of working in a top\hyp level \tex!yquant! environment is very convincing: The circuit is frameless by default and uses the transparent name mangling scheme.

               All the registers that were previously defined via \tex!\registers! are automatically available within the circuit, as if their declaration had been copied.
               In fact, \Yquant{} will make a register available the first time it is referenced in some gate; if at the end of a circuit some of the shared registers were not used, they will be imported before exiting the circuit.
               Consequently, if you define own registers just for a single circuit, these will always be at the very top.
               This can be influenced by means of the \gate{import} gate, which is only available in group \tex!\circuit!s.
               This gate allows to import a declared register at an arbitrary position.

            \paragraph*{\tex!\equals*[<content>]!}\label{sec:foreign:groups:equals}
               The \tex!\equals! macro inserts a blank text---internally, a \gate{box}\hyp like gate with the style \style{/yquant/operators/every group equals}---that contains \tex!<content>!.
               If omitted, \tex!<content>! is given by \tex!$=$!.

               The optional star will put a horizontal alignment mark at the position where the box is inserted.
               Similar to the \tex!&! operation in \pkg{amsmath}'s \tex!align! environment or the \tex!\>! in \TeX's native \tex!tabbing!, \Yquant{} will now remember the horizontal position of the box internally and will allow you to directly jump to this position in the next line.
               Note that you may well have multiple alignment marks in a single line, which \Yquant{} internally numbers \texttt{1}, \texttt{2}, \dots.

            \paragraph*{\tex!\\[<separation>]!}
               The \tex!\\! macro inserts a line break (never a page break), so that the next \tex!\circuit! or \tex!\equals! will be put below all circuits that were output before, and it will again start at the same left position as the first circuit.
               The default vertical distance is given by \style{/yquant/group/line separation}, but it may be overwritten by the optional \tex!<separation>! argument, which must be a \TeX{} dimension.

               Note that if you \emph{set} new alignment marks in a new line, this will delete the alignment marks that were previously set.

               If the option \style{/yquant/group/aligned} is passed to the \tex!yquantgroup! environment, the command \tex!\shiftright! is implied after each linebreak.

            \paragraph*{\tex!\shiftright*[<where>]!}
               The \tex!\shiftright! command will put the ``cursor,'' i.e., the horizontal position at which the next \tex!\circuit! or \tex!\equals! will start, at the position specified by \tex!<where>!.
               By default, \tex!<where>! is \tex!1!.
               If the optional star is present, \Yquant{} will additionally put an alignment mark at this position (see the documentation for \hyperref[sec:foreign:groups:equals]{\tex!\equals!}).
               If the option \style{/yquant/group/aligned} is passed to the \tex!yquantgroup! environment, the command \tex!\shiftright! is implied after each linebreak or starred page break.

               The option \tex!<where>! can take various forms:
               \begin{itemize}
                  \item It may be a natural number \texttt{1}, \texttt{2}, \dots, denoting the number of an alignment mark specified in a previous line.
                  \item It may be the number \texttt{0}, denoting the very beginning of the line; this is useful if the \style{/yquant/group/aligned} option is given, but for a specific line, no alignment should be performed.
                  \item It may be a \TeX{} dimension, in which case this dimension is directly added to the cursor (so it is a relative value).
                     This is where passing the optional star makes most sense.
                     If you want to position absolutely, you may first issue \tex!\shiftright[0]! followed by a shift by the dimension that you want.
               \end{itemize}

               \begin{warning}
                  The macro is named \tex!\shiftright!; however, \Yquant{} does not enforce that the actual position is to the right of the current position.
                  You may indeed be able to create overlapping circuits if you shift back to a previous position.
               \end{warning}

            \paragraph*{\tex!\pagebreak*!, \tex!\newpage*!, \tex!\clearpage*!, \tex!\cleardoublepage*!}
               The page breaking commands are available only if the \tex!yquantgroup! was not enclosed in a \tex!tikzpicture!.
               They will end the current picture environment, issue the original page breaking command, and start a new picture.
               Hence, if you want to pass options globally to the picture, you should use the \style{/yquant/preamble} option for the \tex!yquantgroup!; the content of this key will be passed as options for every implicitly started \tex!tikzpicture!.

               Usually, remembering the horizontal alignment marks on a new page does not make much sense.
               For this reason, the commands will delete all alignment; use their starred versions to retain them.
               If the option \style{/yquant/group/aligned} is passed to the \tex!yquantgroup! environment, the command \tex!\shiftright! is implied after the starred version of the page break.

               Typically, you will not want to refer to named gates in a circuit on a different page; remember that if you need this feature, you must pass the \texttt{remember picture} key in the \style{/yquant/preamble} option, as this is a reference to another \tex!tikzpicture!.
               Also don't forget to use the (\TikZ) \texttt{overlay} key on the corresponding path that references the node in order not to mess up with the bounding box (see the \TikZ{} documentation for those two keys).

         \subsubsection{Configuration}
            Loading the \pkg{groups} language extension will define several new configuration keys.

            \begin{option}{group/every group}!!
               Style that is installed for every \tex!yquantgroup! and \tex!yquantgroup*! environment, as if it had been given as an option.
               The style's default path is \texttt{/tikz}.
            \end{option}

            \begin{option}{group/line separation}!5mm!
               This is the default vertical line separation that is inserted whenever a new line is issued in a \tex!yquantgroup!.
            \end{option}

            \begin{option}{group/aligned}!false!
               This boolean flag defines whether \tex!\shiftright! is automatically issued after \tex!\\! and the starred page breaking commands.
            \end{option}

            \begin{option}{preamble}!!
               This style may only be passed to the \tex!yquantgroup! alignment directly as an option; it is not available via \tex!\yquantset! and the like.
               It is only relevant if the \tex!yquantgroup! is not contained in a \tex!tikzpicture!.
               The content of this style will be given as an optional argument to the \tex!tikzpicture!; this is the recommended way to specify \TikZ{} options, as they are automatically preserved among page breaks.
            \end{option}

            \begin{option}{operators/every group circuit}!/yquant/operators/every subcircuit, /yquant/operators/subcircuit/frameless, /yquant/operators/subcircuit/name mangling=transparent!
               This style is installed for the \gate{subcircuit} that implicitly wraps each \tex!\circuit!.
               Note that some magic is carried out to ensure that the name mangling setting only applies to the \emph{direct} content of the \tex!\circuit!; any \gate{subcircuit}s within the \tex!\circuit! will use the default name mangling scheme.
            \end{option}

            \begin{option}[Changed in 0.7]{operators/every group equals}!shape=yquant-rectangle, align=center, anchor/.expanded=\ifyquanthorz{center}{north west}, inner xsep=1mm, x radius=2mm, y radius=2.47mm!
               This style is installed for every \tex!\equals!, which is internally realized similarly to a \gate{box} gate.
            \end{option}

         \subsubsection{Gates and operations}
            No gates or operations may be used directly within the \tex!yquantgroup! environment, but all the usual \Yquant{} gates and operations are available within \tex!\registers! and \tex!\circuit!.
            Additionally, within \tex!\circuit!, the \gate{import} gate is available.

            \paragraph*{\yquant!import!}\label{gate:import}\leavevmode\\
               Syntax: \yquant!import <target>;! \\
               This is a pseudo\hyp gate that makes all the outer registers given in \tex!<target>! available in the current circuit.
               Consequently, the register names that are specified in \tex!<target>!, also ranges, do not refer to the registers in the \emph{current} \tex!\circuit!, but instead to those defined via \tex!\registers!.
               Therefore, it is for example possible to import all outer registers at once using \yquant!import -;!.
               Vector registers can also be imported partially.

               If additional content (\TeX{} commands such as \TikZ{} paths, non\hyp creation gates) is used within \tex!\registers!, everything that comes \emph{before} the declaration of a register will be copied into the \tex!\circuit! when the register is imported; for a vector, this refers to the index zero.
               Additionally, any additional content that comes \emph{after} the declaration of the last register will be copied directly after the last register was imported.

               \begin{warning}[Out-of-order importing]
                  Note that it is principle possible to import registers out\hyp of\hyp order.
                  Since matching outer and inner wires in subcircuits is done in the order in which they appear, this will lead to inner registers with names that do not match their outer registers and is probably highly undesirable.
               \end{warning}

               Usually, this gate will not be needed as \Yquant{} will automatically import an outer register upon its first use.

               \emph{Possible attributes:} none

         \subsubsection[Vertical layout]{\compat{New in 0.7}Vertical layout}
            This library is aware of vertical circuits.
            Note that the layout \emph{between} the circuits will always be the same, irrespective of the actual circuit orientation: Circuit will be set from left to right, and line breaks will always lead to a vertical shift and a reset of the horizontal position.

            That said, the circuits may \emph{internally} be set in vertical mode.
            Every invocation of \tex!\circuit! will then always restart a new \tex!yquant! environment.
            While the content will still be put in a lonely \gate{subcircuit}---to keep consistency in the styling options---no inter\hyp circuit wire alignment will be carried out.

            There is an additional complication regarding the vertical alignment of circuit and equality signs within one ``line.''
            Now, the circuits can very well have a varying height, so vertically centering the circuits with respect to each other would not lead to a satisfying layout.
            We might desire to vertically center the equality sign between its two enclosing circuits.
            However, what if the line contains more than a two circuits and they all have different heights?
            Then, the equality signs would be at different positions.
            For this reason, all \tex!\circuit!s and \tex!\equals! will be aligned at their top.

      \subsection{qasm}\label{sec:foreign:qasm}
         By saying \tex!\useyquantlanguage{qasm}! in the preamble after loading \Yquant{} itself, the parser for \pkg{qasm} (not OpenQASM) is loaded.
         It provides the environment \tex!qasm! as well as the macro \tex!\qasmimport!, which works similarly to \tex!\yquantimport! (but does not accept additional options).

         \subsubsection{Language specification}
            The \pkg{qasm} language is not formally defined, but an overview is provided at \href{https://web.archive.org/web/20050410022847/https://www.media.mit.edu/quanta/qasm2circ/#spec}{the archived website of \texttt{qasm2circ}}.
            The \Yquant{} implementation is designed to be compatible with the original parser, with the following exceptions:
            \begin{itemize}
               \item In \pkg{qasm}, lines could begin in an arbitrary manner; the first whitespace followed by the first valid command were then the instruction.
                  Contrary to this, \Yquant's parser always expects a line to start with a valid gate (preceded by arbitrary whitespaces), a comment, or to be empty.
               \item In \pkg{qasm}, user\hyp defined gates will be drawn in a box unless they contain the text \texttt{\textbackslash dmeter}, and they will be recognized as measurement gates if they contain \texttt{\textbackslash meter} or \texttt{\textbackslash dmeter}.
                  Contrary to this, \Yquant's parser expect the gates to \emph{start} with one of the \emph{macros} \tex!\meter!, \tex!\dmeter!, or \tex!\dmeterwide!.
                  Using these macros \emph{within} the content of a gate does not make sense from the point of view that in \Yquant, gates are nodes with shapes, so either the full gate has a particular shape or it does not, but not only parts of it.
               \item The \texttt{space} gate is supposed to produce a horizontal whitespace without a gate.
                  In \Yquant's implementation, you have to discard the wire if you want to reproduce this behavior; \texttt{space} and \texttt{nop} are equivalent.
            \end{itemize}

            The default \pkg{qasm} style defines several macros that can be used in gates.
            \Yquant{} makes \tex!\m! (matrix; requires \pkg{amsmath}) and \tex!\txt! (switch to text mode) available within the \pkg{qasm} environment.

            Do not expect \Yquant's output to match the one of \pkg{qasm} exactly.
            \Yquant{} is not grid based, so that commands such as \texttt{nop} don't even make sense.
            They are implemented for compatibility reasons and will produce a fixed horizontal space of the operator minimum width plus one separation, which might or might not be accurate.

            Note that whatever you write between \tex!\begin{qasm}! and \tex!\end{qasm}! is essentially treated as verbatim; only where the specification says so (in the definition of a new gate and in the optional third command to the register definition), it is interpreted as \TeX{} markup.
            Consequently, in \pkg{beamer}, any frame containing these environments must be given the \texttt{fragile} option.

         \subsubsection{Configuration}
            Loading the \pkg{qasm} language interpreter will define several new configuration keys.
            For all the gates, it will use the keys defined in \cref{sec:config}, and it additionally provides the following:

            \begin{option}{operators/every s}!/yquant/operators/every box!
               This style is installed for every \texttt{s} operator.
            \end{option}

            \begin{option}{operators/every t}!/yquant/operators/every box!
               This style is installed for every \texttt{t} operator.
            \end{option}

            \begin{option}{operators/every utwo}!/yquant/operators/every box!
               This style is installed for every \texttt{Utwo} operator.
            \end{option}

            \begin{option*}{qasm}{zero}!\qasm@ket0!
               The content of this macro is used as the initialization content whenever the \texttt{zero} gate is invoked.
            \end{option*}

            \begin{option*}{qasm}{register/default qubit name}!\qasm@ket{#1}!
               This macro is invoked with a single parameter (the name of a qubit register) and gives back what is printed as the name of the register (will be in math mode automatically).
            \end{option*}

            \begin{option*}{qasm}{register/default qubit name value}!\qasm@ket{#1} = \qasm@ket{#2}!
               This macro is invoked with two parameters (the name of a qubit register and its initial value) and gives back what is printed as the name of the register (will be in math mode automatically).
            \end{option*}

         \subsubsection{Examples}
            The unaltered \texttt{.qasm} files provided from \href{https://www.media.mit.edu/quanta/qasm2circ/}{the \texttt{qasm2circ} page} were stored in the subfolder \texttt{qasm} relative to this manual's \TeX{} file.
            The following command is then used to print all of them:
            \begin{minted}{tex}
% preamble:
% \usepackage[compat=<version>]{yquant}
% \usepackage{import}
% \useyquantlanguage{qasm}
\def\yquantimportpath{qasm/}
\foreach \circuitno in {1, ..., 18} {
   \paragraph{Circuit \#\circuitno}
      \begin{center}
         \qasmimport{test\circuitno.qasm}
      \end{center}
}
            \end{minted}

            \def\yquantimportpath{qasm/}
            \foreach \circuitno in {1, ..., 18} {
               \paragraph{Circuit \#\circuitno}\leavevmode\nopagebreak\par\nopagebreak
                  \begin{adjustbox}{center}
                     \qasmimport{test\circuitno.qasm}
                  \end{adjustbox}
            }

   \section{Integration with other packages}
      In general, \Yquant{} should not introduce incompatibilities with other packages.
      However, the possibility to mix \Yquant{} code with arbitrary \TeX{} code may lead to certain expectations on how things should work, which may not always be met.
      This is mainly due to the fact that \Yquant{} requires two passes of its content (see \cref{sec:pipeline}), as it has to measure the heights and depths of the individual gates.
      Similar issues can for example also arise in \pkg{amsmath}'s \texttt{align} environment, which also has a measuring and a shipout stage.
      If you run into an incompatibility using a macro from another package (or even plain \TeX), try the following:
      \begin{enumerate}
         \item Using a \TeX{} macro within \Yquant{} code will stop the \Yquant{} parser.
            Hence, all gates following this macro will be ignored.
            Did you remember to issue \tex!\yquant! in order to restart the parser after your macro? \\
            \emph{Symptom:} No errors, but gates are missing
         \item Is the macro robust?
            Modern packages could automatically take care of this by a \tex!\protected! definition, but older ones may not.
            Try to prefix the macro by \tex!\protect!. \\
            \emph{Symptom:} Unexpected error messages
         \item Does the macro depend on other macros defined \emph{within} the circuit?
            The double pass may lead to problems.
            If possible, define your macros outside of the \tex!yquant! environment.
            If this is not possible, make sure the definitions are expandable, then at measurement stage, \Yquant{} will do the expansion, so that you get the correct results. \\
            \emph{Symptom:} Only the latest assignment will show up whenever the macro is used; the vertical spacing (for subcircuits, possibly also the horizontal spacing) may even be screwed.
         \item Does the macro create output, using its own font?
            If the output depends on the current position, this position will be completely wrong.
            This is due to the fact that the macro is executed at the first pass only, where \Yquant{} does not know about any positions at all.
            \compat{New in 0.6}The macro \tex!\yquantsecondpass! will defer its content so that it is executed only at the second pass, where positions are known.
            It will also automatically restart the parser.
            Note that \tex!\yquantsecondpass! will not expand its content.
            If you need expansion, you may use \tex!\yquantesecondpass!, which uses \tex!\protected@edef!. \\
            \emph{Symptom:} Content occurring in the wrong place or missing
         \item Does the macro need to be executed at both passes?
            There may be reasons for this, in particular if you use commands from \pkg{pgf}'s basic or system layer.
            However, all custom macros will only be executed once, at the first pass.
            \compat{New in 0.6}Wrap the macros in \tex!\yquantescape! in order to execute them both times.
            The parser will automatically be restarted afterwards.
            Note that \tex!\yquantescape! will not expand its content.
            You may use \tex!\yquanteescape!, which will first expand its content using \tex!\protected@edef!.
            Note that the content will first be executed, then stored for the second pass. \\
            \emph{Symptom:} Content missing
         \item If all of this did not work and the use case is interesting enough, please file a bug report.
      \end{enumerate}

      \subsection{\texorpdfstring{\TikZ}{TikZ}}
         \Yquant{} is built on top of \TikZ{} an hence integrates well with \TikZ.
         You can use all \tex!\path!-like comands as well as scopes and \Yquant{} will automatically take care of restarting the parser appropriately.
         If it does not, this is very likely a bug, please file a report.

         You should typically not use \tex!\tikzset!, as all changes made by this macro will only be executed in the first pass.
         Instead, use \tex!\yquantset! and change the path appropriately: this macro will first store its argument (using \tex!\protected@edef!) for the second pass and then set the appropriate options also in the first pass.

         Note that low\hyp level \pkg{pgf} functions are not altered by \Yquant; this would be highly inefficient.
         \compat{New in 0.6}If you need to use them, wrap them in \tex!\yquantescape! or \tex!\yquanteescape!.

      \subsection[\texorpdfstring{\pkg{beamer}}{beamer}]{\compat{New in 0.6}\pkg{beamer}}
         \Yquant{} integrates with \pkg{beamer} overlays.
         This means that you can use the overlay commands \tex!\only!, \tex!\alt!, \tex!\temporal!, \tex!\uncover!, \tex!\visible!, and \tex!\invisible! directly in your \Yquant{} code; the parser will automatically be restarted whenever necessary.
         Note that the \texttt{*env} environments (\texttt{onlyenv}, \texttt{altenv}, \texttt{uncoverenv}, \texttt{visibleenv}, and \texttt{invisibleenv}) should \emph{not} be used within \Yquant{} code.

         The macros \tex!\pause! and \tex!\uncover! are also supported to some degree (\tex!\uncover! with braces is fully supported).
         They should work well in simple circuits, but unexpected results can be expected in more complex scenarios.
         If you don't get appropriate results, use the aforementioned macros.

         You may also use \tex!\note! inside \Yquant{} circuits.

         Note that \Yquant{} does not overwrite the definitions of the \pkg{beamer} macros, which implies that you can also use them \emph{within} gates (e.g., for the \texttt{value} of a \gate{box}).
         However, this means that the \Yquant{} parser must be running to detect these macros and take appropriate action.
         Hence, if you interrupted the code via some special macros, make sure to restart the parser even if your next macro is, e.g., \tex!\only!.

         Finally note that \tex!\only!, \tex!\alt!, and \tex!\temporal! are more special than the usual \Yquant\hyp code\hyp interrupting macros.
         They will \emph{not} terminate the group that was opened for the current gate.
         As a consequence, you can also use these macros for arguments.
         Note that whenever you pass arguments to a gate using the \texttt{[<arguments>] <gate> <registers>;} syntax, the value of \texttt{<arguments>} is directly fed to \tex!\pgfkeys!, which \emph{does not} understand \pkg{beamer} macros.
         Hence, you \emph{cannot} use, e.g., \tex!\only! \emph{within} the brackets.
         However, you can wrap the arguments including the brackets as a whole in \tex!\only!---this happens before \Yquant{} relinquishes control to \tex!\pgfkeys! and therefore is executed as expected.
         Since you can also pass multiple arguments to a gate by repeating \texttt{[<arguments>]}, this easily allows to combine arguments with and arguments without overlays.
         \begin{example}[Using overlays for arguments]
            \begin{minted}{tex}
% \documentclass{beamer}
\begin{frame}
   \begin{tikzpicture}
      \begin{yquant}
         qubit a;
         [fill=yellow]
         \alt<2>{[draw=blue]}{[draw=green]}
         \only<3>{[ultra thick]}
         h a;
      \end{yquant}
   \end{tikzpicture}
\end{frame}
            \end{minted}
            The Hadamard gate will always be filled yellow; its line color will be blue on the second frame and green on all other frames.
            On the third frame, its line width is dramatically increased.
         \end{example}

% We have GitHub issues for this
%   \section{Wishlist}
%      This section contains some thoughts on future improvements and features.
%      \begin{itemize}
%         \item Support for more other languages. \\
%            Since version~0.3, \Yquant{} understands \pkg{qasm}.
%            It would be nice if \Yquant{} could also understand \texttt{OpenQASM} correctly.
%            The way \texttt{OpenQASM} treats operations is a bit different from \Yquant{} and also \pkg{qasm}.
%            Some machinery would be required to automatically carry out transversal gates; apart from that everything should be available in \Yquant.
%         \item Vertical layout. \\
%            Sometimes, long quantum circuits on a portrait page can be better represented in a vertical layout.
%            Also if lots of explanations are to be added, this becomes problematic in the horizontal version.
%            In principle, \Yquant's approach could allow for a simple key switch that changes horizontal to vertical.
%            Currently, this is largely unsupported by all quantum circuit packages except for \pkg{qpic}.
%      \end{itemize}

   \section{Changelog}
      \subsection*{2020-03-15: Version 0.1}
         Initial release

      \subsection*{2020-03-22: Version 0.1.1}
         Complete rewrite of the register name parser.
         \Yquant{} now understands comma\hyp separated lists and ranges in indices, and also is far more tolerant with respect to whitespaces. \\
         \Yquant{} now also supports non\hyp contiguous vector registers and allows to add new registers into an already existing vector that is not the last register, and also in the unstarred mode.

      \subsection*{2020-04-11: Version 0.1.2}
         Introduce \gate{setstyle} and \gate{addstyle} pseudo\hyp gates that allow to style individual wires; rename \gate{setwire} to \gate{settype} (the old name is still available and shows a deprecation warning). \\
         Complete rewrite of the way \Yquant{} draws wires; projection anchors are removed in favor of clipping paths.
         This allows perfect connections between gates and wires, even if the (rather rectangular) wire lines meets with nonplanar shapes, while still preserving the possibility of transparent wires. \\
         \Yquant{} now also properly draws non\hyp contiguous multi\hyp qubit operations. \\
         New gate: \gate{correlate}.
         Various bug fixes.

      \subsection*{2020-06-02: Version 0.2}
         Introduce \gate{subcircuit}; required rewriting how \Yquant{} internally positions vertically.
         Provide simple macros to load circuits (or parts) from a file and to declare own custom gates.

      \subsection*{2020-06-07: Version 0.2.1}
         Introduce a macro to declare a lightweight custom gate, which is only a single box with custom content.

      \subsection*{2020-06-13: Version 0.3}
         Introduce support for the \pkg{qasm} language.

      \subsection*{2020-07-11: Version 0.3.1}
         Add legacy support for very old \TikZ{} versions such as the one used on the arXiv.

      \subsection*{2020-08-24: Version 0.3.2}
         Fix \href{https://github.com/projekter/yquant/issues/5}{\#5}: Can't draw circuits with more than 9 qubits.

      \subsection*{2020-10-27: Version 0.3.3}
         Fix \href{https://github.com/projekter/yquant/issues/6}{\#6}: shorten doesn't work for 2-qubit barriers. This fixes a bug in how the \texttt{shorten} keyword worked on \gate{barrier}s, which may require re\hyp assessing your chosen values.

      \subsection*{2021-02-21: Version 0.4-alpha}
         Lots of internal fixes, most notably vertical alignment with subcircuits. \\
         Introduce capability to perform vertical alignment with multi\hyp register gates. \\
         Dramatic changes under the hood regarding horizontal positioning, which is now only determined in the drawing stage; this paves the way for delayed gates, which are planned for 0.4.
         Also changes in the gate declaration interface. \\
         Introduce compatibility layer, so that layout\hyp breaking changes will not become effective unless explicitly requested. \\
         Separate register height into a height and depth key. \\
         Introduce \texttt{overlay} key to disable height caluclation selectively. \\
         Change register style declaration, so that this is now always equivalent to creating an unnamed register followed by an \gate{init} gate with the given text.
         Note: This may be a \textbf{breaking change} that cannot be compatibility\hyp protected---if you used \TeX{} conditionals involving \tex!\idx! for creation labels of registers, you will now need to either \tex!\protect! them all or just capitalize their first letter (which corresponds to auto\hyp\tex!\protect!ed versions for \texttt{compat} at least \texttt{0.4}). \\
         Now use nodes for \gate{init} and \gate{output} gates. \\
         Change behavior of \gate{hspace} and \gate{align}: Now also extend if the wire is discarded afterwards. \\
         Introduce the commands \tex!\Ifnum!, \tex!\Ifcase!, \tex!\Or!, \tex!\Else!, \tex!\Fi!, \tex!\Unless! and \tex!\The! available for use within gates that behave like auto\hyp\tex!\protect!ed versions of their plain \TeX{} equivalents.

      \subsection*{2021-03-27: Version 0.4}
         New gate: \gate{inspect}. Various bug fixes. \\
         Introduce the \texttt{direct control} feature: \gate{measure} gates can now substitute positive controls of future gates.

      \subsection*{2021-07-03: Version 0.4.1}
         Fix \href{https://github.com/projekter/yquant/issues/9}{\#9}: Output bracket misaligned. \\
         Fix \href{https://github.com/projekter/yquant/issues/10}{\#10}: Unable to access node in subcircuit. As of this version, named nodes in subcircuits will also be properly aliased if there is only a single target subcircuit (so that you don't need to use the \texttt{-0} suffix for the subcircuit's name).

      \subsection*{2021-08-17: Version 0.5}
         Improvement: Active outer canvas transformations (\TikZ{} shifts, scalings, rotations) should be supported more nicely (no guarantees!). \\
         Improvement: Custom gates (\tex!\yquantdefinegate!) can now contain \TikZ{} \tex!\path!\hyp like commands without the \tex!\noexpand! prefix. \\
         Improvement: Automatically discard wires \emph{inside} a subcircuit (even if they had the \texttt{out} or \texttt{inout} attribute) if they are discarded directly after the subcircuit \emph{and} they have output gates within the subcircuit (else, the wire would be re\hyp drawn from the output to the border of the subcircuit). \\
         Bugfix: Referencing named gates in nested subcircuits now works without producing an error (worked before, but gave errors). \\
         Bugfix: Properly handle the \texttt{direct control} feature if it was specified, but not used until the end of the (sub)circuit. \\
         Introduce name mangling options for subcircuits. \\
         Implement \href{https://github.com/projekter/yquant/issues/11}{\#11}: Circuit equations. As of this version, the \pkg{groups} language is available that allows to easily implement circuit equations.

      \subsection*{2021-09-04: Version 0.5.1}
         Bugfix: The \gate{xx} gate style was not made available since version~0.4-alpha.

      \subsection*{2021-12-28: Version 0.6}
         Bugfix: Support to set the \style{/yquant/operators/subcircuit/seamless} property outside of \Yquant{} environments. \\
         New: Support for \pkg{beamer}. \\
         New macros: \tex!\yquantsecondpass!, \tex!\yquantesecondpass!, \tex!\yquantescape!, and \tex!\yquanteescape! for more fine\hyp grained control of when to execute macros. \\
         Bugfix: the auto\hyp\tex!\protect!ed versions \tex!\Ifnum! etc. now also work in \gate{output} gates. \\
         New gate: \gate{text}. \\
         Introduce the \style{/yquant/operators/every rectangular box} style as a common ancestor of gates such as \gate{box}, \gate{h}, ... instead of using the \style{/yquant/operators/every box} style for this.
         As a consequence, boxes can now be styled globally without affecting the other gates.
         This new behavior is compatibility\hyp protected. \\
         Bugfix: \gate{output}s can now be named. \\
         Bugfix: Border angles of \texttt{yquant-ellipse} now work properly. \\
         New configuration: \style{/yquant/register/default lazy name}. \\
         Documentation: Replace the wishlist by a section on integration with other packages. \\
         Documentation: Include the examples of \pkg{qpic} in this manual.

      \subsection*{2022-02-05: Version 0.7}
         New: Support for vertical layout. \\
         Various bugfixes. \\
         Internal change of the loading order of the package files. \\
         Fix \href{https://github.com/projekter/yquant/issues/18}{\#18}: Subcircuit boxes don't render in \texttt{groups} environment.
         Now, styles can properly modify the \style{/yquant/operators/this subcircuit box} style without affecting the content of the subcircuit, only the box. \\
         New: Support for a simplified drawing pipeline without clipping paths.

      \subsection*{2022-05-07: Version 0.7.1}
         Fix issues with using handlers for attributes. \\
         Fix \href{https://github.com/projekter/yquant/issues/21}{\#21}: CSWAP scaling problems. Now the clipping of the \gate{swap} and \gate{slash} gate scale appropriately when scaling canvas transformations are in effect (no guarantee with rotations!). Multi-register lines in the same style as control lines (\style{/yquant/operator/multi as single}) will be automatically hidden if control lines are present---they would be drawn on top of each other in the exact same style.

      \subsection*{2022-12-24: Version 0.7.2}
         Fix \href{https://github.com/projekter/yquant/issues/23}{\#23}: Add the \gate{iswap} gate.

      \subsection*{2023-01-21: Version 0.7.3}
         Fix \href{https://github.com/projekter/yquant/issues/24}{\#24}: Clipping in subcircuits can under very special circumstances fail. Change all clipping paths to a most conservative huge rectangle---before, we tried to be economical.
         Also use a more meticulous way of subcircuit position alignment (which will probably consume more resources during compilation, but multiple subcircuits may cancel each other in height and depth calculation if we don't do it). \\
         Address \href{https://github.com/projekter/yquant/issues/25}{\#25}: We now provide the styles \style{/tikz/only at} and \style{/tikz/not at} that allow to easily use styles on an multi\hyp register operator that just affect some parts of their register representation. \\
         Now the size of controls is taken into account when calculating the size of an operation---so extremely large controls will appropriate enlarge the height/depth or horizontal increment.
         This is more useful when putting labels to controls.
%END_FOLD
\end{document}