% BEGIN_FOLD Attributes
\yquant@langhelper@declare@attr{%
   value/.store in=\yquant@lang@attr@value,%
   after/.code={%
      \yquant@register@get@ids{#1}%
      \let\yquant@lang@attr@after=\yquant@register@get@ids@list%
   },%
   type/.store in=\yquant@lang@attr@type,%
   ancilla/.code={%
      \undef\yquant@lang@attr@input%
      \undef\yquant@lang@attr@output%
   },%
   in/.code={%
      \let\yquant@lang@attr@input=\relax%
      \undef\yquant@lang@attr@output%
   },%
   in/.default=\regidx,%
   out/.code={%
      \undef\yquant@lang@attr@input%
      \let\yquant@lang@attr@output=\relax%
   },%
   out/.default=\regidx,%
   inout/.code={%
      \let\yquant@lang@attr@input=\relax%
      \let\yquant@lang@attr@output=\relax%
   }%
   inout/.default=\regidx,%
}
\yquant@langhelper@declare@attr@global{%
   name/.store in=\yquant@lang@attr@name%
}

\protected\def\yquant@lang@reset@attrs{%
   \undef\yquant@lang@attr@value%
   \undef\yquant@lang@attr@after%
   \undef\yquant@lang@attr@type%
   \yquant@lang@reset@attrs@inputoutput%
   \let\yquant@lang@attr@name=\empty%
}

\protected\def\yquant@lang@reset@attrs@inputoutput{%
   \undef\yquant@lang@attr@input%
   \undef\yquant@lang@attr@output%
}

\protected\def\yquant@lang@reset@attrs@inputoutput@subcircuit{%
   \let\yquant@lang@attr@input=\relax%
   \let\yquant@lang@attr@output=\relax%
}
% END_FOLD

% BEGIN_FOLD Declaration of registers
\yquant@langhelper@declare@command@uncontrolled{nobit}\yquant@lang@@nobit
\yquant@langhelper@setup@attrs{nobit}{}{ancilla,out}
\def\yquant@lang@@nobit#1{%
   \let\yquant@lang@create@type=\yquant@register@type@none%
   \def\yquant@lang@create@style{initial}% there is no separate style, just duplicate
   \ifdefined\yquant@lang@attr@value%
      \PackageError{yquant.sty}{Placeholder initialization must not have value}%
                   {You must not provide a description for an invisible register.}
   \else%
      \let\yquant@lang@attr@value=\empty%
   \fi%
   \yquant@lang@create@parse@name#1[;%
}

\yquant@langhelper@declare@command@uncontrolled{qubit}\yquant@lang@@qubit
\yquant@langhelper@setup@attrs{qubit}{}{after,value,ancilla,in,out,inout}
\def\yquant@lang@@qubit#1{%
   \let\yquant@lang@create@type=\yquant@register@type@q%
   \def\yquant@lang@create@style{qubit}%
   \unless\ifdefined\yquant@lang@attr@value%
      \let\yquant@lang@attr@value=\yquant@config@register@default@name%
   \fi%
   \yquant@lang@create@parse@name#1[;%
}

\yquant@langhelper@declare@command@uncontrolled{cbit}\yquant@lang@@cbit
\yquant@langhelper@setup@attrs{cbit}{}{after,value,ancilla,in,out,inout}
\def\yquant@lang@@cbit#1{%
   \let\yquant@lang@create@type=\yquant@register@type@c%
   \def\yquant@lang@create@style{qubit}%
   \unless\ifdefined\yquant@lang@attr@value%
      \let\yquant@lang@attr@value=\yquant@config@register@default@name%
   \fi%
   \yquant@lang@create@parse@name#1[;%
}

\yquant@langhelper@declare@command@uncontrolled{qubits}\yquant@lang@@qubits
\yquant@langhelper@setup@attrs{qubits}{}{after,value,ancilla,in,out,inout}
\def\yquant@lang@@qubits#1{%
   \let\yquant@lang@create@type=\yquant@register@type@qs%
   \def\yquant@lang@create@style{qubits}%
   \unless\ifdefined\yquant@lang@attr@value%
      \let\yquant@lang@attr@value=\yquant@config@register@default@name%
   \fi%
   \yquant@lang@create@parse@name#1[;%
}

\def\yquant@lang@create@parse@name#1[#2;{%
   \ifstrempty{#2}{%
      \yquant@lang@create@do#1[1][;%
   }{%
      \yquant@lang@create@do#1[#2;%
   }%
}

\protected\def\yquant@lang@create@do#1[#2]#3[;{%
   % parse length
   \ifstrempty{#3}{%
      \yquant@langhelper@validate\len\count{#2}%
      \ifnum\len<1 %
         \PackageError{yquant.sty}{Invalid register length}%
                      {Valid register lengths are integers greater or equal to one.}%
      \fi%
   }{%
      \PackageError{yquant.sty}{Invalid register name}%
         {Register names must not contain `[' apart from register length indication.}%
   }%
   \edef\reg{\trim@spaces{#1}}%
   % we allow for scattering, so check whether the register already exists
   \ifcsname\yquant@prefix registerhigh@\reg\endcsname%
      \ifyquant@firsttoken+{#2}{%
         \numdef\idx{\csname\yquant@prefix registerhigh@\reg\endcsname+1}%
         \numdef\len{\len+\idx}%
      }{%
         \PackageError{yquant.sty}{Duplicate registers}%
            {Register `\reg' was already defined. Use `\reg[+#2]' with explicit plus symbol to indicate that you want to enlarge the register on purpose.}%
      }%
   \else%
      \def\idx{0}%
   \fi%
   % define text macros
   \ifnum\len=1 %
      \let\regidx=\reg%
   \else%
      \def\regidx{\reg[\idx]}%
   \fi%
   % determine x position
   \ifdefined\yquant@lang@attr@after%
      \yquant@register@get@maxxlist\yquant@lang@create@x\yquant@lang@attr@after%
      \ifdefined\yquant@lang@attr@input%
         \PackageError{yquant.sty}{An input register cannot be created with `after` attribute}{}%
      \fi%
   \else%
      \let\yquant@lang@create@x=\yquant@env@create@x%
   \fi%
   \begingroup%
      \ifx\yquant@lang@attr@name\empty%
         \let\yquant@lang@create@name=\empty%
      \else%
         \def\yquant@lang@create@name{\yquant@lang@attr@name-\idx}%
      \fi%
      % pre-set y position
      \yquant@for \idx := \idx to \numexpr \len -1\relax {%
         \ifdefined\yquant@lang@attr@input%
            \expandafter\yquant@list@gdequeue\csname \yquant@prefix parameters\endcsname\outermap%
            \ifx\outermap\empty%
               \PackageError{yquant.sty}{Invalid subcircuit parameter count}%
                            {No outer register available for input register `\reg[\idx]`.}%
            \fi%
            \csxappto{\yquant@prefix draw}{%
               \yquant@lang@create@check@input{\outermap}{\yquant@lang@create@type}%
                                              {\reg[\idx]}%
            }%
            \unless\ifdefined\yquant@lang@attr@output%
               \listcsxadd{\yquant@prefix inonly}%
                          {\the\numexpr\csname\yquant@prefix registers\endcsname+1\relax}%
            \fi%
            \yquant@register@alias%
               \yquant@lang@create@type%
               \yquant@lang@create@x%
               \reg\idx\outermap%
         \else%
            \ifdefined\yquant@lang@attr@output%
               \expandafter\yquant@list@gdequeue\csname\yquant@prefix parameters\endcsname\outermap%
               \ifx\outermap\empty%
                  \PackageError{yquant.sty}{Invalid subcircuit parameter count}%
                               {No outer register available for output register `\reg`.}%
               \fi%
               \csxappto{\yquant@prefix draw}{%
                  \yquant@lang@create@check@output{\outermap}{\reg[\idx]}%
               }%
               \yquant@register@alias%
                  \yquant@lang@create@type%
                  \yquant@lang@create@x%
                  \reg\idx\outermap%
            \else%
               \yquant@register@define%
                  \yquant@lang@create@type%
                  \yquant@lang@create@x%
                  \reg\idx%
            \fi%
         \fi%
         % First determine the actual height by a virtual draw command
         \protected@edef\trimmedvalue{\trim@spaces{\yquant@lang@attr@value}}%
         \unless\ifx\empty\trimmedvalue%
            \pgfinterruptboundingbox%
               \yquant@env@virtualize@path%
               \edef\cmd{%
                  \noexpand\path%
                     (\yquant@lang@create@x, 0pt)%
                     node[/yquant/every label, /yquant/every initial label,%
                          /yquant/every \yquant@lang@create@style\space label%
                          \ifdefined\yquant@lang@attr@input, /yquant/every input label\fi]%
                     {\unexpanded\expandafter{\trimmedvalue}};%
               }%
               \cmd%
               \ifdim\pgf@picminx<\csname\yquant@prefix xmin\endcsname%
                  \csxdef{\yquant@prefix xmin}{\the\pgf@picminx}%
               \fi%
               \expandafter\yquant@register@update@height%
                  \csname\yquant@prefix registers\endcsname%
                  {\the\pgf@picmaxy}%
               \expandafter\yquant@register@update@depth%
                  \csname\yquant@prefix registers\endcsname%
                  {\the\dimexpr-\pgf@picminy\relax}%
            \endpgfinterruptboundingbox%
         \fi%
         % Prepare to shipout
         \csxappto{\yquant@prefix draw}{%
            \yquant@lang@create@draw{\csname\yquant@prefix registers\endcsname}%
                                    {\yquant@lang@create@x}%
                                    {\yquant@lang@create@style}%
                                    \ifdefined\yquant@lang@attr@input1\else0\fi%
                                    {\unexpanded\expandafter{\trimmedvalue}}%
                                    {\yquant@lang@create@name}%
            \unless\ifdefined\yquant@lang@attr@input%
               \ifdefined\yquant@lang@attr@output%
                  \yquant@circuit@flushwire%
                     {\csname\yquant@prefix registers\endcsname}%
                  \yquant@register@set@type%
                     {\csname\yquant@prefix registers\endcsname}%
                     \yquant@lang@create@type%
               \fi%
            \fi%
         }%
      }%
      \unless\ifx\yquant@lang@attr@name\empty%
         \ifnum\len=1 %
            \csxappto{\yquant@prefix draw}%
                     {\yquant@draw@alias{\yquant@lang@attr@name}}%
         \fi%
      \fi%
   \endgroup%
}

\protected\def\yquant@lang@create@check@input#1#2#3{%
   \begingroup%
      \let\yquant@prefix=\yquant@parent%
      \unless\if#2\yquant@register@get@type{#1}%
         \PackageError{yquant.sty}{Subcircuit expects wire of type `\yquant@register@type@tostring{#2}', but got `\yquant@register@type@tostring{\yquant@register@get@type{#1}}'}%
                      {Outer and inner wire types must match for input wire `\detokenize{#3}`.}%
      \fi%
   \endgroup%
}

\protected\def\yquant@lang@create@check@output#1#2{%
   \begingroup%
      \let\yquant@prefix=\yquant@parent%
      \unless\if\yquant@register@type@none\yquant@register@get@type{#1}%
         \PackageError{yquant.sty}%
                      {Subcircuit expects discarded wire, got `\yquant@register@type@tostring{\yquant@register@get@type{#1}}'}%
                      {Outer wire must be discarded before being acceptable for output-only register `\detokenize{#2}`.}%
      \fi%
   \endgroup%
}

\protected\def\yquant@lang@create@draw#1#2#3#4#5#6{%
   \begingroup%
      \dimdef\wireypos{\yquant@register@get@y{#1}}%
      \ifcsname\yquant@prefix xshift\endcsname%
         \dimdef\createxpos{#2+\csname\yquant@prefix xshift\endcsname}%
      \else%
         \dimdef\createxpos{#2}%
      \fi%
      \ifstrempty{#5}{%
         % For empty labels, we still put the node at the appropriate position as it may needs to be referenced, but we will not let it effect the bounding box (so that the left end is not shifted), and we don't need an inner separation, so that the label is truely just a coordinate.
         \path[overlay]%
            (\createxpos, \wireypos)%
            coordinate[name prefix=, name suffix=, name=yquantbox];%
         \let\pgfshapeclippathhorzresult=\empty%
      }{%
         \edef\cmd{%
            \noexpand\path%
               (\createxpos, \wireypos)%
               node[/yquant/every label, /yquant/every initial label,%
                    /yquant/every #3 label\ifx1#4, /yquant/every input label\fi,%
                    name prefix=, name suffix=, name=yquantbox]%
                   {\unexpanded{#5}};%
            \ifcsname\yquant@prefix registermap@#1\endcsname%
               \pgfshapeclippath{yquantbox}%
                                {/yquant/every label, /yquant/every initial label,%
                                 /yquant/every #3 label\ifx1#4, /yquant/every input label\fi}%
            \fi%
         }%
         \cmd%
      }%
      \ifcsname\yquant@prefix registermap@#1\endcsname%
         % if this is an alias, the creation is just an extension
         \if\yquant@register@type@none\yquant@register@get@type{#1}%
            \ifstrequal{#3}{initial}{%
               \yquant@circuit@extendwire{#1}{east}%
            }{%
               % however, our inner wire is present, while the outer wire was discarded.
               \tikzset{/yquant/every wire}%
               \pgfpointanchor{yquantbox}{east}%
               \yquant@register@set@lastwire{#1}{%
                  {\the\pgf@x}{\the\pgf@x}{}%
                  {\unexpanded\expandafter{\pgfshapeclippathhorzresult}}%
               }%
            }%
         \else%
            \yquant@circuit@extendwire{#1}{east}%
         \fi%
      \else%
         % set the wire style to have the correct \pgflinewidth available (we don't allow individual line widths for different types of wires)
         \tikzset{/yquant/every wire}%
         \pgfpointanchor{yquantbox}{east}%
         \yquant@register@set@lastwire{#1}{{\the\pgf@x}{\the\pgf@x}{}{}}%
      \fi%
      \ifstrempty{#6}\relax{%
         \pgfnodealias{\tikz@pp@name{#6}}{yquantbox}%
      }%
   \endgroup%
}
% END_FOLD

% BEGIN_FOLD Define own gates
\def\yquantdefinegate#1{%
   \ifcsname yquant@lang@#1\endcsname%
      \PackageError{yquant.sty}{Gate redefined}%
                   {The gate `#1' already exists. Use \string\yquantredefinegate\space if you really want to redefine it.}%
   \fi%
   \@ifnextchar[{\yquantdefinegate@i{#1}}%
                {\yquantdefinegate@i{#1}[/yquant/operators/every custom gate]}%
}

% while this command is provided to redefine gates, we do not clear the attributes that were once assigned to the previous one, so gate redefinition is discouraged!
\def\yquantredefinegate#1{%
   \unless\ifcsname yquant@lang@#1\endcsname%
      \PackageError{yquant.sty}{Unknown gate redefined}%
                   {The gate `#1' is unknown and cannot be redefined. Use \string\yquantdefinegate\space to define it.}%
   \fi%
   \@ifnextchar[{\yquantdefinegate@i{#1}}%
                {\yquantdefinegate@i{#1}[/yquant/operators/every custom gate]}%
}

\protected\long\def\yquantdefinegate@i#1[#2]#3{%
   \pgfkeys{/yquant/operators/every #1/.style={#2}}%
   \protected@edef\yquantdefinegate@do{%
      \yquant@langhelper@declare@command%
         {#1}%
         \expandafter\noexpand\csname yquant@lang@@#1\endcsname%
      % This does not clear the attributes for redefines, but makes at least sure nothing is marked as required that should not be.
      \yquant@langhelper@setup@attrs{#1}{}{}%
      % Now define the gate's content as a macro
      \def\expandafter\noexpand\csname yquant@lang@@@#1\endcsname{%
         #3%
      }%
      % And provide the implementation
      \protected\def\expandafter\noexpand\csname yquant@lang@@#1\endcsname####1####2####3{%
         \yquant@register@get@multiaslist%
         \yquant@circuit@operator{####1}{####2}{####3}%
         \let\noexpand\yquant@lang@attr@value=\expandafter\noexpand\csname yquant@lang@@@#1\endcsname%
         \yquant@draw@@subcircuit{/yquant/operators/every #1}%
      }%
   }%
   \yquantdefinegate@do%
}

\def\yquantdefinebox#1{%
   \ifcsname yquant@lang@#1\endcsname%
      \PackageError{yquant.sty}{Gate redefined}%
                   {The gate `#1' already exists. Use \string\yquantredefinebox\space if you really want to redefine it.}%
   \fi%
   \@ifnextchar[{\yquantdefinebox@i{#1}}%
                {\yquantdefinebox@i{#1}[/yquant/operators/every box]}%
}

\def\yquantredefinebox#1{%
   \unless\ifcsname yquant@lang@#1\endcsname%
      \PackageError{yquant.sty}{Unknown gate redefined}%
                   {The gate `#1' is unknown and cannot be redefined. Use \string\yquantdefinebox\space to define it.}%
   \fi%
   \yquantdefinebox@i{#1}%
   \@ifnextchar[{\yquantdefinebox@i{#1}}%
                {\yquantdefinebox@i{#1}[/yquant/operators/every box]}%
}

\protected\long\def\yquantdefinebox@i#1[#2]#3{%
   \pgfkeys{/yquant/operators/every #1/.style={#2}}%
   \protected@edef\yquantdefinebox@do{%
      \yquant@langhelper@declare@command%
         {#1}%
         \expandafter\noexpand\csname yquant@lang@@#1\endcsname%
      \yquant@langhelper@setup@attrs{#1}{}{}%
      \def\expandafter\noexpand\csname yquant@lang@@#1\endcsname{%
         \yquant@draw%
            {#3}%
            {/yquant/operators/every #1}%
      }%
   }%
   \yquantdefinebox@do%
}
% END_FOLD

% BEGIN_FOLD Box registers
% all-purpose box with arbitrary text
\yquant@langhelper@declare@command{box}\yquant@lang@@box
\yquant@langhelper@setup@attrs{box}{value}{}
\def\yquant@lang@@box{%
   \yquant@register@get@allowmultitrue%
   \expandafter\yquant@draw%
      \expandafter{\yquant@lang@attr@value}%
      {/yquant/operators/every box}%
}

% Hadamard
\yquantdefinebox{h}{$H$}

% Pauli X (or NOT)
\yquantdefinebox{x}[/yquant/operators/every pauli]{$X$}

% Pauli Y
\yquantdefinebox{y}[/yquant/operators/every pauli]{$Y$}

% Pauli Z
\yquantdefinebox{z}[/yquant/operators/every pauli]{$Z$}

% sub-circuit: This is a nested circuit.
\yquant@langhelper@declare@command{subcircuit}\yquant@lang@@subcircuit
\yquant@langhelper@setup@attrs{subcircuit}{value}{}
\protected\def\yquant@lang@@subcircuit#1#2#3{%
   \yquant@register@get@multiaslist%
   \yquant@circuit@operator{#1}{#2}{#3}%
   \yquant@draw@@subcircuit{/yquant/operators/every subcircuit}%
}
% END_FOLD

% BEGIN_FOLD other geometric shapes
% phase
\yquant@langhelper@declare@command{phase}\yquant@lang@@phase
\yquant@langhelper@setup@attrs{phase}{value}{}%
\def\yquant@lang@@phase{%
   \edef\cmd{%
      \noexpand\yquant@draw%
         {}%
         {/yquant/operators/every phase, label={\unexpanded\expandafter{\yquant@lang@attr@value}}}%
   }%
   \cmd%
}

% two-qubit controlled x (symmetric notation)
\yquant@langhelper@declare@command{xx}\yquant@lang@@xx
\yquant@langhelper@setup@attrs{xx}{}{}
\def\yquant@lang@@xx{%
   \yquant@register@get@multiassingle%
   \yquant@draw%
      {}%
      {/yquant/operators/every xx}%
}

% two-qubit controlled phase (symmetric notation)
\yquant@langhelper@declare@command@uncontrolled{zz}\yquant@lang@@zz
\yquant@langhelper@setup@attrs{zz}{}{}
\def\yquant@lang@@zz{%
   \yquant@register@get@multiassingle%
   \yquant@draw%
      {}%
      {/yquant/operators/every zz}%
      {}{}%
}

% slash (pseudo-operator, alternative indication for a bundle)
\yquant@langhelper@declare@command@uncontrolled{slash}\yquant@lang@@slash
\yquant@langhelper@setup@attrs{slash}{}{}
\protected\def\yquant@lang@@slash#1{%
   % temporarily squeeze most into the separation
   \pgfkeys{%
      /yquant/operator/minimum width=0pt,%
      /yquant/operator/separation=.5\dimexpr\yquant@config@operator@sep-\pgflinewidth\relax%
   }%
   \def\yquant@draw@callback@wire##1{%
      \yquant@register@set@x%
         {##1}%
         {\the\dimexpr\yquant@register@get@x{##1}-\yquant@config@operator@sep-\pgflinewidth\relax}%
   }
   \yquant@draw%
      {}%
      {/yquant/operators/every slash}%
      {}{}{#1}%
}

% swap
\yquant@langhelper@declare@command{swap}\yquant@lang@@swap
\yquant@langhelper@setup@attrs{swap}{}{}
\def\yquant@lang@@swap{%
   \yquant@register@get@multiassingle%
   \yquant@draw%
      {}%
      {/yquant/operators/every swap}%
}

% not
\yquant@langhelper@declare@command{not}\yquant@lang@@not
\yquant@langhelper@setup@attrs{not}{}{}
\def\yquant@lang@@not{%
   \yquant@draw%
      {}%
      {/yquant/operators/every not}%
}
% alias to cnot
\let\yquant@lang@cnot=\yquant@lang@not
\yquant@langhelper@setup@attrs{cnot}{}{}

% measure
\yquant@langhelper@declare@command@uncontrolled{measure}\yquant@lang@@measure
\yquant@langhelper@setup@attrs{measure}{}{value,type}
\def\yquant@lang@@measure{%
   \ifdefined\yquant@lang@attr@type%
      \yquant@register@type@fromstring\yquant@lang@attr@type\yquant@circuit@settype@to%
   \else%
      \let\yquant@circuit@settype@to=\yquant@register@type@c%
   \fi%
   \let\yquant@draw@callback@wire=\yquant@circuit@settype%
   \yquant@register@get@allowmultitrue%
   \unless\ifcsname yquant@lang@attr@value\endcsname%
      \let\yquant@lang@attr@value=\empty%
   \fi%
   \expandafter\yquant@draw%
      \expandafter{\yquant@lang@attr@value}%
      {/yquant/operators/every measure}%
      {}{}%
}

% measure (dmeter)
\yquant@langhelper@declare@command@uncontrolled{dmeter}\yquant@lang@@dmeter
\yquant@langhelper@setup@attrs{dmeter}{}{value,type}
\def\yquant@lang@@dmeter{%
   \ifdefined\yquant@lang@attr@type%
      \yquant@register@type@fromstring\yquant@lang@attr@type\yquant@circuit@settype@to%
   \else%
      \let\yquant@circuit@settype@to=\yquant@register@type@c%
   \fi%
   \let\yquant@draw@callback@wire=\yquant@circuit@settype%
   \yquant@register@get@allowmultitrue%
   \unless\ifcsname yquant@lang@attr@value\endcsname%
      \let\yquant@lang@attr@value=\empty%
   \fi%
   \expandafter\yquant@draw%
      \expandafter{\yquant@lang@attr@value}%
      {/yquant/operators/every dmeter}%
      {}{}%
}
% END_FOLD

% BEGIN_FOLD miscellaneous
\yquant@langhelper@declare@command@uncontrolled{barrier}\yquant@lang@@barrier
\yquant@langhelper@setup@attrs{barrier}{}{}
\def\yquant@lang@@barrier{%
   \yquant@register@get@allowmultitrue%
   \yquant@draw%
      {}%
      {/yquant/operators/every barrier}%
      {}{}%
}

\yquant@langhelper@declare@command@uncontrolled{correlate}\yquant@lang@@correlate
\yquant@langhelper@setup@attrs{correlate}{}{}
\def\yquant@lang@@correlate{%
   % do not call \yquant@register@get@multiassingle, we do not want to install a different multi line style!
   \yquant@register@get@allowmultitrue%
   \let\yquant@register@multi@splitparts=\yquant@register@multi@splitparts@sepall%
   \yquant@draw%
      {}%
      {/yquant/operators/every wave}%
      {}{}%
}

\yquant@langhelper@declare@command@uncontrolled{align}\yquant@lang@@align
\yquant@langhelper@setup@attrs{align}{}{}
\def\yquant@lang@@align#1{%
   \yquant@register@get@ids{#1}%
   \yquant@circuit@align\yquant@register@get@ids@list%
}

\yquant@langhelper@declare@command@uncontrolled{hspace}\yquant@lang@@hspace
\yquant@langhelper@setup@attrs{hspace}{value}{}
\def\yquant@lang@@hspace#1{%
   \yquant@langhelper@validate\amount\dimen\yquant@lang@attr@value%
   \yquant@register@get@ids{#1}%
   \yquant@circuit@hspace\yquant@register@get@ids@list\amount%
}

\yquant@langhelper@declare@command@uncontrolled{discard}\yquant@lang@@discard
\yquant@langhelper@setup@attrs{discard}{}{}
\def\yquant@lang@@discard#1{%
   \yquant@register@get@ids{#1}%
   \let\yquant@circuit@settype@to=\yquant@register@type@none%
   \yquant@circuit@actonwires%
      \yquant@circuit@settype%
      \yquant@register@get@ids@list%
      \yquant@register@type@none%
}

\yquant@langhelper@declare@command@uncontrolled{init}\yquant@lang@@init
\yquant@langhelper@setup@attrs{init}{value}{type}
\protected\def\yquant@lang@@init@multi@@extract#1#2#3{%
   \yquant@for \yquant@i := #1 to #2 {%
      \edef\yquant@circuit@settype@to{\yquant@register@get@type\yquant@i}%
      \unless\ifx\yquant@circuit@settype@to\yquant@register@type@none%
         \expandafter\yquant@for@break%
      \fi%
   }%
}

\protected\def\yquant@lang@@init#1{%
   \yquant@register@get@allowmultitrue%
   \yquant@register@get@ids{#1}%
   \ifdefined\yquant@lang@attr@type%
      \yquant@register@type@fromstring\yquant@lang@attr@type\yquant@circuit@settype@to%
   \else%
      % We don't know which type is desired. Scan all target registers and use the first wire that is available as a type.
      \let\yquant@circuit@settype@to=\yquant@register@type@none%
      \def\do##1{%
         \ifyquant@firsttoken\yquant@register@multi{##1}{%
            \let\yquant@register@multi@contiguous=\yquant@lang@@init@multi@@extract%
            \@fifthoffive##1%
            % we should reset multi@contiguous to the original command; but this is really just a placeholder. As long as it is \protected, everything is fine.
         }{%
            \edef\yquant@circuit@settype@to{\yquant@register@get@type{##1}}%
         }%
         \unless\ifx\yquant@circuit@settype@to\yquant@register@type@none%
            \expandafter\listbreak%
         \fi%
      }%
      \dolistloop\yquant@register@get@ids@list%
      \ifx\yquant@circuit@settype@to\yquant@register@type@none%
         % now we don't have a clue; assume it's a qubit
         \let\yquant@circuit@settype@to=\yquant@register@type@q%
      \fi%
      \edef\yquant@lang@attr@type{%
         \yquant@register@type@tostring\yquant@circuit@settype@to%
      }%
   \fi%
   \let\yquant@draw@callback@wire=\yquant@circuit@settype%
   \let\yquant@draw@@multi=\yquant@draw@@multiinit%
   \yquant@circuit@operator{}{}{#1}%
   % special case: if there were no operations at any affected wire before, we will replace the wire description
   \ifdim\yquant@circuit@operator@x=\yquant@config@operator@sep\relax%
      \def\yquant@circuit@operator@x{-.5\dimen2}%
      \let\yquant@draw@finalize@ctrl@single=\yquant@draw@finalize@ctrl@singleinit%
      \let\yquant@draw@finalize@ctrl@multi=\yquant@draw@finalize@ctrl@multiinit%
      \expandafter\yquant@draw@%
         \expandafter{\yquant@lang@attr@value}%
         {/yquant/every label, /yquant/every initial label, /yquant/every \yquant@lang@attr@type\space label}%
   \else%
      \expandafter\yquant@draw@%
         \expandafter{\yquant@lang@attr@value}%
         {/yquant/every label, /yquant/every \yquant@lang@attr@type\space label}%
   \fi%
}

\yquant@langhelper@declare@command@uncontrolled{output}\yquant@lang@@output
\yquant@langhelper@setup@attrs{output}{value}{}
\def\yquant@lang@@output#1{%
   \yquant@register@get@allowmultitrue%
   \yquant@register@get@ids{#1}%
   \expandafter\yquant@circuit@output\expandafter{\yquant@register@get@ids@list}%
}

\yquant@langhelper@declare@command@uncontrolled{settype}\yquant@lang@@settype
\yquant@langhelper@setup@attrs{settype}{value}{}
\protected\def\yquant@lang@@settype#1{%
   \yquant@register@get@ids{#1}%
   \yquant@register@type@fromstring\yquant@lang@attr@value\yquant@circuit@settype@to%
   \yquant@circuit@actonwires%
      \yquant@circuit@settype%
      \yquant@register@get@ids@list%
      {}%
}

\def\yquant@lang@setwire{%
   \PackageWarning{yquant.sty}{`setwire' gate is deprecated as of yquant 0.1.2. Use `settype' instead.}%
   \yquant@lang@settype%
}
\yquant@langhelper@setup@attrs{setwire}{value}{}

\yquant@langhelper@declare@command@uncontrolled{setstyle}\yquant@lang@@setstyle
\yquant@langhelper@setup@attrs{setstyle}{value}{}
\protected\def\yquant@lang@@setstyle#1{%
   \yquant@register@get@ids{#1}%
   \yquant@circuit@actonwires%
      \yquant@circuit@setstyle%
      \yquant@register@get@ids@list%
      {{\yquant@lang@attr@value}}%
}

\yquant@langhelper@declare@command@uncontrolled{addstyle}\yquant@lang@@addstyle
\yquant@langhelper@setup@attrs{addstyle}{value}{}
\protected\def\yquant@lang@@addstyle#1{%
   \yquant@register@get@ids{#1}%
   \yquant@circuit@actonwires%
      \yquant@circuit@addstyle%
      \yquant@register@get@ids@list%
      {{\yquant@lang@attr@value}}%
}
% END_FOLD