summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/yquant
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2020-03-24 20:57:29 +0000
committerKarl Berry <karl@freefriends.org>2020-03-24 20:57:29 +0000
commit2788d9fb9b228a993b9396b91c9fcd4845635b64 (patch)
tree134367b5ecbcd84d94aa0946a6aa94be11b92027 /Master/texmf-dist/tex/latex/yquant
parent5de4049c3701b77b230e19cd22c0f1b0e3ac762e (diff)
yquant (24mar20)
git-svn-id: svn://tug.org/texlive/trunk@54527 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/yquant')
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex476
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-config.tex140
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-draw.tex422
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-env.tex261
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-lang.tex559
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-langhelper.tex315
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-registers.tex532
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-shapes.tex614
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-tools.tex265
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant.sty40
10 files changed, 3624 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex b/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex
new file mode 100644
index 00000000000..993455cbebb
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex
@@ -0,0 +1,476 @@
+% BEGIN_FOLD Drawing wires
+% extends the wire of register #1. Assumes a node called yquantbox is set up, and it is a node with appropriate projections.
+\protected\def\yquant@circuit@extendwire#1{%
+ \begingroup%
+ \edef\wiretype{\yquant@register@get@type{#1}}%
+ \dimdef\wireypos{\yquant@register@get@y{#1}}%
+ \tikzset{/yquant/every wire}%
+ \unless\ifnum\wiretype=\yquant@register@type@none{%
+ \csname yquant@circuit@extendwire@\wiretype\endcsname{#1}%
+ }\fi%
+ % 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}%
+ \@tempdima=\pgf@x%
+ \pgfpointshapexproj{yquantbox}%
+ {\pgfqpoint{\@tempdima}
+ {\dimexpr\wireypos+2\pgflinewidth\relax}}%
+ \edef\tmp{{(\the\pgf@x,\the\pgf@y)}}%
+ % For multi-qubit registers, the east anchor is not necessarily accurate.
+ \pgfpointshapexproj{yquantbox}{\pgfqpoint{\@tempdima}{\wireypos}}%
+ \edef\tmp{\tmp{(\the\pgf@x,\the\pgf@y)}}%
+ \pgfpointshapexproj{yquantbox}
+ {\pgfqpoint{\@tempdima}%
+ {\dimexpr\wireypos-2\pgflinewidth\relax}}%
+ \yquant@register@set@lastwire{#1}{\tmp{(\the\pgf@x,\the\pgf@y)}}%
+ \endgroup%
+}
+
+% finishes the wire of register #1 until x position \yquant@env@end@xpos
+\protected\def\yquant@circuit@endwire#1{%
+ \begingroup%
+ \edef\wiretype{\yquant@register@get@type{#1}}%
+ \unless\ifnum\wiretype=\yquant@register@type@none\relax%
+ % we don't have a yquantbox node but still want to extend the line; so just install a dummy projection
+ \let\pgfpointshapexproj=\yquant@circuit@endwire@xproj%
+ \dimdef\wireypos{\yquant@register@get@y{#1}}%
+ \tikzset{/yquant/every wire}%
+ \csname yquant@circuit@extendwire@\wiretype\endcsname{#1}%
+ \fi%
+ \endgroup%
+}
+
+\protected\def\yquant@circuit@endwire@xproj#1#2{%
+ \pgf@process{%
+ #2%
+ \pgf@x=\yquant@env@end@xpos%
+ }%
+}
+
+\def\yquant@circuit@extendwire@@extract(#1,#2){%
+ #1%
+}
+
+% a bit faster than nested \@firstoftwo/\@secondoftwo
+% note \@thirdofthree is defined in the latex kernel already.
+\long\def\@firstofthree#1#2#3{#1}%
+\long\def\@secondofthree#1#2#3{#2}%
+
+% quantum wire
+\protected\csdef{yquant@circuit@extendwire@1}#1{%
+ \edef\tmp{\yquant@register@get@lastwire{#1}}%
+ \edef\tmp{\expandafter\@secondofthree\tmp}%
+ \edef\lastx{\expandafter\yquant@circuit@extendwire@@extract\tmp}%
+ \pgfpointshapexproj{yquantbox}{\pgfqpoint{\lastx}{\wireypos}}%
+ \ifdim\lastx<\pgf@x%
+ \edef\cmd{%
+ \noexpand\path [/yquant/every wire, /yquant/every qubit wire]
+ \tmp -- (\the\pgf@x,\the\pgf@y);%
+ }%
+ \cmd%
+ \fi%
+}
+
+% classical wire
+\protected\csdef{yquant@circuit@extendwire@2}#1{%
+ \edef\tmp{\yquant@register@get@lastwire{#1}}%
+ \edef\tmpa{\expandafter\@firstofthree\tmp}%
+ \edef\lastxa{\expandafter\yquant@circuit@extendwire@@extract\tmpa}%
+ \edef\tmpb{\expandafter\@thirdofthree\tmp}%
+ \edef\lastxb{\expandafter\yquant@circuit@extendwire@@extract\tmpb}%
+ \let\cmd=\empty%
+ \pgfpointshapexproj{yquantbox}{\pgfqpoint{\lastxa}%
+ {\dimexpr\wireypos+2\pgflinewidth\relax}}%
+ \ifdim\lastxa<\pgf@x%
+ \edef\cmd{%
+ \tmpa -- (\the\pgf@x,\the\pgf@y)%
+ }%
+ \fi%
+ \pgfpointshapexproj{yquantbox}{\pgfqpoint{\lastxb}%
+ {\dimexpr\wireypos-2\pgflinewidth\relax}}%
+ \ifdim\lastxb<\pgf@x%
+ \eappto\cmd{%
+ \tmpb -- (\the\pgf@x,\the\pgf@y)%
+ }%
+ \fi%
+ \unless\ifx\cmd\empty%
+ \edef\cmd{\noexpand\path [/yquant/every wire, /yquant/every cbit wire] \cmd;}%
+ \cmd%
+ \fi%
+}
+
+% quantum-bundle
+\protected\csdef{yquant@circuit@extendwire@3}#1{%
+ \edef\tmp{\yquant@register@get@lastwire{#1}}%
+ \edef\tmpa{\expandafter\@firstofthree\tmp}%
+ \edef\lastxa{\expandafter\yquant@circuit@extendwire@@extract\tmpa}%
+ \edef\tmpb{\expandafter\@secondofthree\tmp}%
+ \edef\lastxb{\expandafter\yquant@circuit@extendwire@@extract\tmpb}%
+ \edef\tmpc{\expandafter\@thirdofthree\tmp}%
+ \edef\lastxc{\expandafter\yquant@circuit@extendwire@@extract\tmpc}%
+ \let\cmd=\empty%
+ \pgfpointshapexproj{yquantbox}{\pgfqpoint{\lastxa}%
+ {\dimexpr\wireypos+2\pgflinewidth\relax}}%
+ \ifdim\lastxa<\pgf@x%
+ \edef\cmd{%
+ \tmpa -- (\the\pgf@x,\the\pgf@y)%
+ }%
+ \fi%
+ \pgfpointshapexproj{yquantbox}{\pgfqpoint{\lastxb}{\wireypos}}%
+ \ifdim\lastxb<\pgf@x%
+ \eappto\cmd{%
+ \tmpb -- (\the\pgf@x,\the\pgf@y)%
+ }%
+ \fi%
+ \pgfpointshapexproj{yquantbox}{\pgfqpoint{\lastxc}%
+ {\dimexpr\wireypos-2\pgflinewidth\relax}}%
+ \ifdim\lastxc<\pgf@x%
+ \eappto\cmd{%
+ \tmpc -- (\the\pgf@x,\the\pgf@y)%
+ }%
+ \fi%
+ \unless\ifx\cmd\empty%
+ \edef\cmd{\noexpand\path [/yquant/every wire, /yquant/every qubits wire] \cmd;}%
+ \cmd%
+ \fi%
+}
+% END_FOLD
+
+% BEGIN_FOLD Drawing control lines
+% populates a drawing macro with the current control line with style #1 at position #2. Assumes a node called yquantbox is set up, and it is a node with appropriate projections. At the first call, \yquant@circuit@extendcontrolline@cmd must be \let to \empty and \yquant@circuit@extendcontrolline@prev to \relax.
+\protected\def\yquant@circuit@extendcontrolline#1#2{%
+ \begingroup%
+ \tikzset{/yquant/every control line}%
+ \expandafter%
+ \endgroup%
+ \expandafter\@tempdima\the\pgflinewidth%
+ \ifcase#1%
+ % no control (or to a discarded target, which we don't do)
+ \or%
+ % qubit
+ \unless\ifx\yquant@circuit@extendcontrolline@prev\relax%
+ \pgfpointanchor{yquantbox}{north}%
+ \pgfpointshapeyproj{yquantbox}{\pgf@x=#2\relax}%
+ \eappto\yquant@circuit@extendcontrolline@cmd{%
+ \expandafter\@secondofthree\yquant@circuit@extendcontrolline@prev%
+ -- (\the\pgf@x,\the\pgf@y)%
+ }%
+ \fi%
+ \yquant@circuit@extendcontrolline@store{#2}%
+ \or%
+ % cbit
+ \unless\ifx\yquant@circuit@extendcontrolline@prev\relax%
+ \pgfpointanchor{yquantbox}{north}%
+ \pgfpointshapeyproj{yquantbox}%
+ {\pgf@x=\dimexpr#2-2\@tempdima\relax}%
+ \eappto\yquant@circuit@extendcontrolline@cmd{%
+ \expandafter\@firstofthree\yquant@circuit@extendcontrolline@prev%
+ -- (\the\pgf@x,\the\pgf@y)%
+ }%
+ \pgfpointshapeyproj{yquantbox}%
+ {\pgf@x=\dimexpr#2+2\@tempdima\relax}%
+ \eappto\yquant@circuit@extendcontrolline@cmd{%
+ \expandafter\@thirdofthree\yquant@circuit@extendcontrolline@prev%
+ -- (\the\pgf@x,\the\pgf@y)%
+ }%
+ \fi%
+ \yquant@circuit@extendcontrolline@store{#2}%
+ \or%
+ % quantum-bundle (very unusual, but perhaps for transversal operations?)
+ \unless\ifx\yquant@circuit@extendcontrolline@prev\relax%
+ \pgfpointanchor{yquantbox}{north}%
+ \pgfpointshapeyproj{yquantbox}%
+ {\pgf@x=\dimexpr#2-2\@tempdima\relax}%
+ \eappto\yquant@circuit@extendcontrolline@cmd{%
+ \expandafter\@firstofthree\yquant@circuit@extendcontrolline@prev%
+ -- (\the\pgf@x,\the\pgf@y)%
+ }%
+ \pgfpointshapeyproj{yquantbox}%
+ {\pgf@x=\dimexpr#2\relax}%
+ \eappto\yquant@circuit@extendcontrolline@cmd{%
+ \expandafter\@secondofthree\yquant@circuit@extendcontrolline@prev%
+ -- (\the\pgf@x,\the\pgf@y)%
+ }%
+ \pgfpointshapeyproj{yquantbox}%
+ {\pgf@x=\dimexpr#2+2\@tempdima\relax}%
+ \eappto\yquant@circuit@extendcontrolline@cmd{%
+ \expandafter\@thirdofthree\yquant@circuit@extendcontrolline@prev%
+ -- (\the\pgf@x,\the\pgf@y)%
+ }%
+ \fi%
+ \yquant@circuit@extendcontrolline@store{#2}%
+ \else%
+ \PackageError{yquant.sty}{Invalid control line type `\the#1'}%
+ {yquant encountered an internal error.}%
+ \fi%
+}
+
+\protected\def\yquant@circuit@extendcontrolline@store#1{%
+ \pgfpointanchor{yquantbox}{south}%
+ \pgfpointshapeyproj{yquantbox}%
+ {\pgf@x=\dimexpr#1-2\@tempdima\relax}%
+ \edef\yquant@circuit@extendcontrolline@prev{{(\the\pgf@x,\the\pgf@y)}}%
+ \pgfpointshapeyproj{yquantbox}%
+ {\pgf@x=#1\relax}%
+ \eappto\yquant@circuit@extendcontrolline@prev{{(\the\pgf@x,\the\pgf@y)}}%
+ \pgfpointshapeyproj{yquantbox}%
+ {\pgf@x=\dimexpr#1+2\@tempdima\relax}%
+ \eappto\yquant@circuit@extendcontrolline@prev{{(\the\pgf@x,\the\pgf@y)}}%
+}
+% END_FOLD
+
+\newif\ifyquant@circuit@operator@hasControls%
+% sets up the relevant variables associated with an operator
+% #1: positive controls
+% #2: negative controls
+% #3: targets
+\protected\def\yquant@circuit@operator#1#2#3{%
+ % convert all names to indices
+ % targets
+ \yquant@register@get@ids{#3}%
+ \let\yquant@circuit@operator@targets=\yquant@register@get@ids@list%
+ \let\yquant@circuit@operator@mintarget=\yquant@register@get@ids@min%
+ \let\yquant@circuit@operator@maxtarget=\yquant@register@get@ids@max%
+ \let\yquant@circuit@operator@numtarget=\yquant@register@get@ids@count%
+ % For the targets, multi-qubit registers might have been allowed, but certainly not for
+ % the controls!
+ \yquant@register@get@allowmultifalse%
+ % positive controls
+ \yquant@register@get@ids{#1}%
+ \let\yquant@circuit@operator@pctrls=\yquant@register@get@ids@list%
+ \let\yquant@circuit@operator@minpctrl=\yquant@register@get@ids@min%
+ \let\yquant@circuit@operator@maxpctrl=\yquant@register@get@ids@max%
+ \let\yquant@circuit@operator@numpctrl=\yquant@register@get@ids@count%
+ \ifnum\yquant@register@get@ids@count>0 %
+ \yquant@circuit@operator@hasControlstrue%
+ \fi%
+ % negative controls
+ \yquant@register@get@ids{#2}%
+ \let\yquant@circuit@operator@nctrls=\yquant@register@get@ids@list%
+ \let\yquant@circuit@operator@minnctrl=\yquant@register@get@ids@min%
+ \let\yquant@circuit@operator@maxnctrl=\yquant@register@get@ids@max%
+ \let\yquant@circuit@operator@numnctrl=\yquant@register@get@ids@count%
+ \ifnum\yquant@register@get@ids@count>0 %
+ \yquant@circuit@operator@hasControlstrue%
+ \fi%
+ % determine the qubits spanned
+ \yquant@min\yquant@circuit@operator@minctrl%
+ \yquant@circuit@operator@mintarget%
+ \yquant@circuit@operator@minpctrl%
+ \yquant@circuit@operator@minnctrl%
+ \relax%
+ \yquant@max\yquant@circuit@operator@maxctrl%
+ \yquant@circuit@operator@maxtarget%
+ \yquant@circuit@operator@maxpctrl%
+ \yquant@circuit@operator@maxnctrl%
+ \relax%
+ % obtain the required minimal x position
+ \yquant@register@get@maxxrange%
+ \yquant@circuit@operator@x%
+ \yquant@circuit@operator@minctrl%
+ \yquant@circuit@operator@maxctrl%
+ \dimdef\yquant@circuit@operator@x{%
+ \yquant@circuit@operator@x+\yquant@config@operator@sep%
+ }%
+}
+
+% BEGIN_FOLD Subcircuit-related
+% Does all necessary calculations for inserting a sub-circuit
+% #1: subcircuit code (should start with \begin{yquant})
+%\newbox\yquant@circuit@subcircuit@box
+%\protected\long\def\yquant@circuit@subcircuit#1{%
+% % We need to place the inner circuit at the correct position; but for this, we need
+% % its extent. For this, we first place it within a box. But this box is then
+% % integrated seamlessly, in particular, named nodes must be re-placed. We use a lot of
+% % inspiration from pgf's matrix capabilities.
+% % First, we anticipate the macro that is used by our subcircuit to store the node
+% % names.
+% \edef\yquant@circuit@subcircuit@nodelist{yquant@env\the\numexpr\yquant@env+1\relax @circuit@subcircuit@nodelist}%
+% \global\cslet\yquant@circuit@subcircuit@nodelist\empty%
+% \pgfinterruptboundingbox%
+% % we make sure there are no conflicts by prefixing any named nodes in any case.
+% \ifx\yquant@lang@attr@name\empty%
+% \pgfkeys{/tikz/name prefix/.expanded={sub\yquant@prefix-}}%
+% \else%
+% \pgfkeys{/tikz/name prefix/.expanded={\pgfkeysvalueof{/tikz/name prefix}\yquant@lang@attr@name-}}%
+% \fi%
+% \let\pgf@nodecallback=\yquant@circuit@subcircuit@nodecallback%
+% \pgftransformreset%
+% \global\setbox\yquant@circuit@subcircuit@box=\hbox{{%
+% % bypass 'overlay' option
+% \pgf@relevantforpicturesizetrue%
+% \pgfsys@beginpicture%
+% #1%
+% \pgfsys@endpicture%
+% \ifdim\pgf@picmaxx=-16000pt %
+% \global\pgf@picmaxx=0pt %
+% \global\pgf@picminx=0pt %
+% \global\pgf@picmaxy=0pt %
+% \global\pgf@picminy=0pt %
+% \fi%
+% }}%
+% \wd\yquant@circuit@subcircuit@box=0pt %
+% \global\setbox\yquant@circuit@subcircuit@box=\hbox{{%
+% \hskip-\pgf@picminx%
+% \unhbox\yquant@circuit@subcircuit@box%
+% \hskip\pgf@picmaxx%
+% }}%
+% \ht\yquant@circuit@subcircuit@box=\pgf@picmaxy%
+% \dp\yquant@circuit@subcircuit@box=-\pgf@picminy%
+% % We need to remember the offset for the coordinate shifts
+% \dimgdef\yquant@circuit@subcircuit@shiftx{-\pgf@picminx}%
+% \endpgfinterruptboundingbox%
+% \ifx\yquant@lang@attr@name\empty%
+% % However, if the outer node was not named, no access to the inner nodes is desired,
+% % so we delete all nodes again.
+% \def\do##1{%
+% \csgundef{pgf@sh@ns@##1}%
+% \csgundef{pgf@sh@np@##1}%
+% \csgundef{pgf@sh@nt@##1}%
+% \csgundef{pgf@sh@pi@##1}%
+% \csgundef{pgf@sh@ma@##1}%
+% }%
+% \dolistcsloop\yquant@circuit@subcircuit@nodelist%
+% \global\cslet\yquant@circuit@subcircuit@nodelist\empty%
+% \else%
+% % But now access is desired, and probably we are deeply nested. Append the sublist to ours, so that our parent can re-map them again.
+% \ifx\pgf@nodecallback\yquant@circuit@subcircuit@nodecallback%
+% \csxappto{\yquant@prefix circuit@subcircuit@nodelist}%
+% {\csname\yquant@circuit@subcircuit@nodelist\endcsname}%
+% \fi%
+% \fi%
+%}
+%
+%\def\yquant@circuit@subcircuit@nodecallback#1{%
+% \listcsxadd{\yquant@prefix circuit@subcircuit@nodelist}{#1}%
+%}
+
+%\protected\def\yquant@circuit@subcircuit@shiftnodes#1{%
+% \expandafter\unless\expandafter\ifx\csname\yquant@circuit@subcircuit@nodelist\endcsname\empty{%
+% \pgftransformreset%
+% \pgf@process{\pgfpointanchor{#1}{text}}%
+% \edef\yquant@circuit@subcircuit@offset{%
+% \noexpand\pgfqpoint{\the\dimexpr\pgf@x+\yquant@circuit@subcircuit@shiftx\relax}%
+% {\the\dimexpr\pgf@y\relax}%
+% }%
+% \def\do##1{%
+% \pgf@shift@node{##1}\yquant@circuit@subcircuit@offset%
+% }%
+% \dolistcsloop\yquant@circuit@subcircuit@nodelist%
+% }\fi%
+%}
+% END_FOLD
+
+% BEGIN_FOLD Helpers for operator callbacks
+% turn a wire into a different type
+\def\yquant@circuit@settype#1{%
+ \yquant@register@set@type{#1}\yquant@circuit@settype@to%
+}
+
+% performs an alignment of all registers specified in the argument; that is, the next operation on any of the listed registers will be after the maximum position of all of them
+% #1: arbitrary register list
+\protected\def\yquant@circuit@align#1{%
+ \begingroup%
+ \yquant@register@get@maxxlist\x{#1}%
+ \def\do##1{%
+ \yquant@register@set@x{##1}\x%
+ }%
+ \dolistloop{#1}%
+ \endgroup%
+}
+
+% introduces a horizontal skip (= invisible operator of given width) among the registers; that is, those registers are first aligned, then skipped by the given amount.
+% #1: arbitrary register list
+% #2: skip width
+\protected\def\yquant@circuit@hspace#1#2{%
+ \begingroup%
+ \yquant@register@get@maxxlist\x{#1}%
+ \dimdef\x{\x+#2}%
+ \def\do##1{%
+ \yquant@register@set@x{##1}\x%
+ }%
+ \dolistloop{#1}%
+ \endgroup%
+}
+
+% sets the type of a list of registers
+% #1: arbitrary register list
+% #2: new type
+\protected\def\yquant@circuit@settypes#1#2{%
+ \begingroup%
+ \let\tmp=\empty%
+ \def\do##1{%
+ % We do not extend the wire: a register that is discarded somewhere does not make
+ % sense, only right after some application (which is supposed to already have
+ % extended the wire appropriately).
+ \appto\tmp{\yquant@register@set@type{##1}#2}%
+ }%
+ \dolistloop{#1}%
+ \csxappto{\yquant@prefix draw}{\tmp}%
+ \endgroup%
+}
+
+% sets the output of wires
+% #1: arbitrary register list
+\protected\def\yquant@circuit@output#1{%
+ \csxappto{\yquant@prefix outputs}%
+ {\noexpand\yquant@circuit@output@do%
+ {\noexpand#1}% there is nothing to expand - except the first token, which might be \yquant@register@multi, and we need to preserve this.
+ {\yquant@attrs@remaining}%
+ {\unexpanded\expandafter{\yquant@lang@attr@value}}%
+ }%
+}
+
+\protected\long\def\yquant@circuit@output@do#1#2#3{%
+ % this must only be called at the end of an environment, where \yquant@env@end@xpos is
+ % set up properly!
+ \def\do##1{%
+ \ifyquant@firsttoken\yquant@register@multi{##1}{%
+ \csxappto{\yquant@prefix draw}%
+ {\noexpand\yquant@circuit@output@do@multi%
+ \yquant@circuit@output@do@multi@@extract##1{\unexpanded{#3}}}%
+ }{%
+ \csgappto{\yquant@prefix draw}%
+ {\yquant@circuit@output@do@single{##1}{#3}}%
+ }%
+ }%
+ % \dolistloop will carry out one \expandafter on the argument; but this expansion step
+ % is already done. If #1 starts with \yquant@register@multi, this will be expanded once
+ % despite \protected, so insert some expand-to-nothing token first.
+ \csgappto{\yquant@prefix draw}{%
+ \yquant@circuit@output@group{#2}%
+ }
+ \dolistloop{\empty#1}%
+ \csgappto{\yquant@prefix draw}{%
+ \yquant@circuit@output@endgroup%
+ }%
+}
+
+\def\yquant@circuit@output@do@multi@@extract#1#2#3#4#5{%
+ {#2}{#3}%
+}
+
+\protected\long\def\yquant@circuit@output@group#1{%
+ \begingroup%
+ \def\idx{0}%
+ \yquant@set{#1}%
+}
+
+\let\yquant@circuit@output@endgroup=\endgroup%
+
+\long\def\yquant@circuit@output@do@single#1#2{%
+ \path
+ (\yquant@env@end@xpos, \yquant@register@get@y{#1})
+ node[/yquant/every output,
+ /yquant/every \ifcase\yquant@register@get@type{#1} qubit\or cbit\or qubits\fi\space output] {#2};
+ \numdef\idx{\idx+1}%
+}
+
+\long\def\yquant@circuit@output@do@multi#1#2#3{%
+ \path[/yquant/every multi output]
+ (\yquant@env@end@xpos, \yquant@register@get@y{#1}) --
+ (\yquant@env@end@xpos, \yquant@register@get@y{#2})
+ node {#3};%
+ \numdef\idx{\idx+1}%
+}
+% END_FOLD \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-config.tex b/Master/texmf-dist/tex/latex/yquant/yquant-config.tex
new file mode 100644
index 00000000000..2aa1158b05b
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-config.tex
@@ -0,0 +1,140 @@
+\usetikzlibrary{decorations.pathreplacing}
+\pgfdeclaremetadecoration{tikz@internal}{pre}{
+ \state{pre}[width=\pgfkeysvalueof{/pgf/decoration/pre length}+\pgfkeysvalueof{/pgf/decoration/post length}, next state=main]{
+ \appto\tikz@dec@shift{\pgftransformxshift{-\pgfkeysvalueof{/pgf/decoration/post length}}}
+ \tikz@dec@trans
+ \decoration{\pgfkeysvalueof{/pgf/decoration/pre}}
+ }
+ \state{main}[width=\pgfmetadecoratedremainingdistance, next state=final]{
+ \tikz@dec@trans
+ \decoration{\tikz@decoration@name}
+ }
+ \state{final}{
+ \tikz@dec@trans
+ \decoration{\pgfkeysvalueof{/pgf/decoration/post}}
+ }
+}
+\pgfqkeys{/yquant}{
+ every circuit/.style={},
+ % register settings
+ register/default name/.store in=%
+ \yquant@config@register@default@name,
+ register/minimum height/.code=%
+ {\dimdef\yquant@config@register@minimum@height{#1}},
+ register/separation/.code=%
+ {\dimdef\yquant@config@register@sep{#1}},
+ % register label style
+ every label/.style=%
+ {shape=yquant-text, anchor=circuit, align=right},
+ every initial label/.style=%
+ {anchor=east},
+ every qubit label/.style=%
+ {},
+ every cbit label/.style=%
+ {},
+ every qubits label/.style=%
+ {},
+ every multi label/.style=%
+ {shift={(-.075, 0)}, draw, decoration={brace, mirror, pre=moveto, pre length=-1mm, post=moveto, post length=-1mm}, decorate,
+ every node/.append style={shape=yquant-text, anchor=east, align=right, midway, shift={(-.025, 0)}}},
+ % output label styles
+ every output/.style=%
+ {shape=yquant-text, anchor=west, align=left},
+ every qubit output/.style=%
+ {},
+ every cbit output/.style=%
+ {},
+ every qubits output/.style=%
+ {},
+ every multi output/.style=%
+ {shift={(.075, 0)}, draw, decoration={brace, pre=moveto, pre length=-1mm, post=moveto, post length=-1mm}, decorate,
+ every node/.append style={shape=yquant-text, anchor=west, align=left, midway, shift={(.025, 0)}}},
+ % wire style
+ every wire/.style=%
+ {draw},
+ every qubit wire/.style=%
+ {},
+ every cbit wire/.style=%
+ {},
+ every qubits wire/.style=%
+ {},
+ % operator settings
+ operator/separation/.code=%
+ {\dimdef\yquant@config@operator@sep{#1}},
+ operator/minimum width/.code=%
+ {\dimdef\yquant@config@operator@minimum@width{#1}},
+ % operator style: control
+ every control line/.style=%
+ {draw},
+ every control/.style=%
+ {shape=yquant-circle, anchor=circuit, radius=.5mm},
+ every positive control/.style=%
+ {fill=black},
+ every negative control/.style=%
+ {draw},
+ % operator style: main part
+ every operator/.style=%
+ {anchor=circuit},
+ % overwriting all styles
+ this operator/.style=%
+ {},
+ this control/.style=%
+ {},
+ operator style/.style=%
+ {/yquant/this operator/.append style={#1}},
+ control style/.style=%
+ {/yquant/every control line/.append style={#1},
+ /yquant/this control/.append style={#1}},
+ style/.style=%
+ {/yquant/this operator/.append style={#1},
+ /yquant/every control line/.append style={#1},
+ /yquant/this control/.append style={#1}},
+ % different operator appearances
+ operators/every box/.style=%
+ {shape=yquant-rectangle, draw, align=center, inner xsep=1mm, x radius=2mm, y radius=2.47mm},
+ operators/every h/.style=%
+ {/yquant/operators/every box},
+ operators/every pauli/.style=%
+ {/yquant/operators/every box},
+ operators/every x/.style=%
+ {/yquant/operators/every pauli},
+ operators/every y/.style=%
+ {/yquant/operators/every pauli},
+ operators/every z/.style=%
+ {/yquant/operators/every pauli},
+% operators/every subcircuit/.style=%
+% {/yquant/operators/every box, inner ysep=0pt},
+ operators/every phase/.style=%
+ {shape=yquant-circle, radius=.5mm, fill},
+ operators/every zz/.style=%
+ % y radius must be twice as large as x radius (= two circles). And there is no
+ % possiblity to distort the circle to an ellipse; x radius is always the defining
+ % property!
+ {shape=yquant-zz, x radius=.5mm, y radius=1mm, fill, draw},
+ operators/every xx/.style=%
+ % same as zz
+ {shape=yquant-xx, x radius=.75mm, y radius=1.5mm, draw},
+ operators/every slash/.style=%
+ {shape=yquant-slash, x radius=.5mm, y radius=.7mm, draw},
+ operators/every swap/.style=%
+ {shape=yquant-swap, x radius=.75mm, y radius=1.5mm, draw},
+ operators/every not/.style=%
+ {shape=yquant-oplus, radius=1.3mm, draw},
+ operators/every measure/.style=%
+ {shape=yquant-measure, x radius=4mm, y radius=2.5mm, draw},
+ operators/every measure meter/.style=%
+ {draw, -{Latex[length=2.5pt]}},
+ operators/every dmeter/.style=%
+ {shape=yquant-dmeter, x radius=2mm, y radius=2mm, draw},
+ operators/every barrier/.style=%
+ {shape=yquant-barrier, dashed, draw},
+ operators/multi operator line/.is if=\yquant@config@multi@line,
+}
+
+\def\yquant@config@register@default@name{\regidx}
+\def\yquant@config@register@minimum@height{3mm}
+\def\yquant@config@register@sep{1mm}
+\def\yquant@config@operator@sep{1mm}
+\def\yquant@config@operator@minimum@width{5mm}
+\newif\ifyquant@config@multi@line
+\yquant@config@multi@linetrue \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-draw.tex b/Master/texmf-dist/tex/latex/yquant/yquant-draw.tex
new file mode 100644
index 00000000000..baaac6ac0d2
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-draw.tex
@@ -0,0 +1,422 @@
+% BEGIN_FOLD Actual drawing at shipout
+\newcount\yquant@draw@@currentcontroltype%
+
+\protected\def\yquant@draw@group#1#2#3#4#5{%
+ \begingroup%
+ \def\yquant@draw@@x{#1}%
+ \ifx F#2%
+ \yquant@draw@@currentcontroltype=0 %
+ \else%
+ \yquant@draw@@currentcontroltype=\yquant@register@get@type{#2}\relax%
+ \fi%
+ \let\yquant@circuit@extendcontrolline@cmd=\empty%
+ \let\yquant@circuit@extendcontrolline@prev=\relax%
+ \yquant@langhelper@list@attrs%
+ % If the quotes library is loaded, activate it. (else, this is by default \relax)
+ \tikz@enable@node@quotes%
+ \yquant@set{#3}%
+ \def\yquant@draw@@style{#4}%
+ \def\yquant@draw@@content{#5}%
+ \def\yquant@draw@@idx@content{0}%
+ \def\yquant@draw@@idx@pcontrol{0}%
+ \def\yquant@draw@@idx@ncontrol{0}%
+}
+
+\protected\def\yquant@draw@endgroup#1#2#3{%
+ \unless\ifx F#1%
+ \yquant@draw@cline%
+ \fi%
+ \ifcase#3\relax%
+ \or%
+ \yquant@draw@alias@ctrl{#2}n%
+ \or%
+ \yquant@draw@alias@ctrl{#2}p%
+ \or%
+ \yquant@draw@alias@ctrl{#2}p%
+ \yquant@draw@alias@ctrl{#2}n%
+ \or%
+ \yquant@draw@alias{#2}%
+ \or%
+ \yquant@draw@alias{#2}%
+ \yquant@draw@alias@ctrl{#2}n%
+ \or%
+ \yquant@draw@alias{#2}%
+ \yquant@draw@alias@ctrl{#2}p%
+ \or%
+ \yquant@draw@alias{#2}%
+ \yquant@draw@alias@ctrl{#2}p%
+ \yquant@draw@alias@ctrl{#2}n%
+ \fi%
+ \endgroup%
+}
+
+\protected\long\def\yquant@draw@single#1#2{%
+ \let\idx=\yquant@draw@@idx@content%
+ \edef\cmd{%
+ \noexpand\path (\yquant@draw@@x, \yquant@register@get@y{#1})%
+ node[/yquant/every operator, \yquant@draw@@style, /yquant/this operator,%
+ name prefix=, name suffix=, name=yquantbox]%
+ {\unexpanded\expandafter{\yquant@draw@@content}};%
+ }%
+ \cmd%
+ \ifpgfpointshapexproj{yquantbox}%
+ \yquant@circuit@extendwire{#1}%
+ \fi%
+ \yquant@circuit@extendcontrolline\yquant@draw@@currentcontroltype\yquant@draw@@x%
+ % check for empty name parameter
+ \if\relax\detokenize{#2}\relax%
+ \else%
+ \pgfnodealias{\tikz@pp@name{#2}}{yquantbox}%
+ \fi%
+ \numdef\yquant@draw@@idx@content{\yquant@draw@@idx@content+1}%
+}
+
+\protected\long\def\yquant@draw@multi#1#2#3#4#5{%
+ \let\idx=\yquant@draw@@idx@content%
+ % We need to somehow extract the y radius
+ \edef\cmd{%
+ \noexpand\path (\yquant@draw@@x, \the\dimexpr.5\dimexpr%
+ \yquant@register@get@y{#1}+\yquant@register@get@y{#2}\relax%
+ \relax)%
+ node[/yquant/every operator, \yquant@draw@@style, /yquant/this operator,%
+ y radius/.expanded=\the\dimexpr.5\dimexpr\yquant@register@get@ydist{#1}{#2}\relax\relax+%
+ .5*\noexpand\pgfkeysvalueof{/tikz/y radius},%
+ name prefix=, name suffix=, name=yquantbox]%
+ {\unexpanded\expandafter{\yquant@draw@@content}};
+ }%
+ \cmd%
+ \ifpgfpointshapexproj{yquantbox}%
+ \let\do=\yquant@circuit@extendwire%
+ \dolistloop{#4}%
+ \fi%
+ \yquant@circuit@extendcontrolline\yquant@draw@@currentcontroltype\yquant@draw@@x%
+ % check for empty name parameter
+ \if\relax\detokenize{#5}\relax%
+ \else%
+ \pgfnodealias{\tikz@pp@name{#5}}{yquantbox}%
+ \fi%
+ \numdef\yquant@draw@@idx@content{\yquant@draw@@idx@content+1}%
+}
+
+\protected\long\def\yquant@draw@multiinit#1#2#3#4#5{%
+ \let\idx=\yquant@draw@@idx@content%
+ % We need to somehow extract the y radius
+ \edef\cmd{%
+ \noexpand\path[/yquant/every operator, \yquant@draw@@style,%
+ /yquant/every multi label, /yquant/this operator]%
+ (\yquant@draw@@x, \yquant@register@get@y{#1}) --%
+ (\yquant@draw@@x, \yquant@register@get@y{#2})%
+ node[name prefix=, name suffix=, name=yquantbox]%
+ {\unexpanded\expandafter{\yquant@draw@@content}};
+ }%
+ \cmd%
+ % no wire extension (we are still at the initial position), no control line (init doesn't allow for those, so just save the no-op)
+ % check for empty name parameter
+ \if\relax\detokenize{#5}\relax%
+ \else%
+ \pgfnodealias{\tikz@pp@name{#5}}{yquantbox}%
+ \fi%
+ \numdef\yquant@draw@@idx@content{\yquant@draw@@idx@content+1}%
+}
+
+\protected\def\yquant@draw@control#1#2#3{%
+ \edef\cmd{%
+ \noexpand\path (\yquant@draw@@x, \yquant@register@get@y{#2})%
+ node[/yquant/every control, /yquant/every #1 control, /yquant/this control,%
+ name prefix=, name suffix=, name=yquantbox]%
+ {};%
+ }%
+ \cmd%
+ \ifpgfpointshapexproj{yquantbox}%
+ \yquant@circuit@extendwire{#2}%
+ \fi%
+ \yquant@draw@@currentcontroltype=\yquant@register@get@type{#2}\relax%
+ \yquant@circuit@extendcontrolline\yquant@draw@@currentcontroltype\yquant@draw@@x%
+ % check for empty name parameter
+ \if\relax\detokenize{#3}\relax%
+ \else%
+ \pgfnodealias{\tikz@pp@name{#3}}{yquantbox}%
+ \fi%
+}
+
+\protected\def\yquant@draw@pcontrol#1#2{%
+ \let\idx=\yquant@draw@@idx@pcontrol%
+ \yquant@draw@control{positive}{#1}{#2}%
+ \numdef\yquant@draw@@idx@pcontrol{\yquant@draw@@idx@pcontrol+1}%
+}
+
+\protected\def\yquant@draw@ncontrol#1#2{%
+ \let\idx=\yquant@draw@@idx@ncontrol%
+ \yquant@draw@control{negative}{#1}{#2}%
+ \numdef\yquant@draw@@idx@ncontrol{\yquant@draw@@idx@ncontrol+1}%
+}
+
+\protected\def\yquant@draw@cline{%
+ \edef\cmd{%
+ \noexpand\path[/yquant/every control line]%
+ \yquant@circuit@extendcontrolline@cmd;
+ }%
+ \cmd%
+}
+
+\protected\def\yquant@draw@alias#1{%
+ \pgfnodealias{\tikz@pp@name{#1}}{\tikz@pp@name{#1-0}}%
+}
+
+\protected\def\yquant@draw@alias@ctrl#1#2{%
+ \pgfnodealias{\tikz@pp@name{#1-#2}}{\tikz@pp@name{#1-#20}}%
+}
+% END_FOLD
+
+% BEGIN_FOLD Preparation of drawing a generic shape
+% Most drawing operations will be realized through nodes
+\let\yquant@draw@callback@box=\@gobble
+\let\yquant@draw@callback@wire=\@gobble
+
+\def\yquant@draw@sort#1#2{%
+ \yquant@draw@sort@aux#1\relax#2\relax%
+ \expandafter\@firstoftwo%
+ \else%
+ \expandafter\@secondoftwo%
+ \fi%
+}
+
+\def\yquant@draw@sort@aux#1#2#3\relax#4#5#6\relax{%
+ \unless\ifnum#2>#5\relax%
+}
+
+% generic shape of an operator
+% #1: value
+% #2: tikz options that select the correct shape
+% #3: positive controls
+% #4: negative controls
+% #5: targets
+\protected\long\def\yquant@draw#1#2#3#4#5{%
+ % setup the required macros
+ \yquant@circuit@operator{#3}{#4}{#5}%
+ \yquant@draw@{#1}{#2}%
+}
+
+\protected\long\def\yquant@draw@#1#2{%
+ \yquant@sort@clear%
+ \def\idx{0}%
+ \dimen2=\yquant@config@operator@minimum@width%
+ % BEGIN_FOLD register
+ \def\do##1{%
+ \ifx\yquant@lang@attr@name\empty%
+ \let\nodename=\empty%
+ \else%
+ \edef\nodename{\yquant@lang@attr@name-\idx}%
+ \fi%
+ \ifyquant@firsttoken\yquant@register@multi{##1}{%
+ \yquant@draw@@multi{#1}{#2}{##1}%
+ }{%
+ \yquant@draw@@single{#1}{#2}{##1}%
+ }%
+ \expandafter%
+ \endpgfinterruptboundingbox%
+ \expandafter\dimen\expandafter0\expandafter=%
+ \the\dimexpr\pgf@picmaxx-\pgf@picminx\relax\relax%
+ \ifdim\dimen0>\dimen2 %
+ \dimen2=\dimen0 %
+ \fi%
+ \numdef\idx{\idx+1}%
+ % TODO
+% \yquant@draw@callback@box\nodename%
+ }%
+ \dolistloop\yquant@circuit@operator@targets%
+ % END_FOLD
+ % BEGIN_FOLD controls
+ \ifyquant@circuit@operator@hasControls%
+ \def\do##1{%
+ \ifx\yquant@lang@attr@name\empty%
+ \let\nodename=\empty%
+ \else%
+ \edef\nodename{\yquant@lang@attr@name-\yquant@draw@controlprefix\idx}%
+ \fi%
+ \yquant@sort@eadd{%
+ \expandafter\noexpand\csname yquant@draw@\yquant@draw@controlprefix control\endcsname%
+ {##1}% register index
+ {\nodename}%
+ }%
+ \unless\ifdefined\yquant@draw@controltype%
+ \edef\yquant@draw@controltype{##1}%
+ \fi%
+ \numdef\idx{\idx+1}%
+ }
+ \def\yquant@draw@controlprefix{p}%
+ \def\idx{0}%
+ \dolistloop\yquant@circuit@operator@pctrls%
+ \def\yquant@draw@controlprefix{n}%
+ \def\idx{0}%
+ \dolistloop\yquant@circuit@operator@nctrls%
+ \unless\ifdefined\yquant@draw@controltype%
+ \PackageError{yquant.sty}{Assertion failure}%
+ {Internal inconsistency in yquant: Controlled action detected, but no controls were found.}%
+ \fi%
+ \fi%
+ % END_FOLD
+ % We now know the dimensions of all the registers (though we didn't bother with the height of the control knobs [if present], we just assume they are too small to change this).
+ \protected\def\idx{}%
+ \protected@edef\yquant@draw@append{%
+ \noexpand\yquant@draw@group%
+ {\the\dimexpr\yquant@circuit@operator@x+.5\dimen2\relax}% mid x position
+ \ifyquant@circuit@operator@hasControls%
+ \yquant@draw@controltype%
+ \else%
+ F%
+ \fi% if-switch whether controls are present
+ {\yquant@attrs@remaining}% custom style
+ {#2}% operator style
+ {#1}%
+ }%
+ \yquant@sort\yquant@draw@sort%
+ \advance \dimen2 by \yquant@circuit@operator@x\relax%
+ % BEGIN_FOLD shipout
+ \ifyquant@circuit@operator@hasControls%
+ % If we draw a control line, all intermediate registers are affected in their position so that the line is never crossed.
+ \yquant@for \yquant@i := \yquant@circuit@operator@minctrl to \yquant@circuit@operator@maxctrl {%
+ \yquant@register@set@x\yquant@i{\the\dimen2}%
+ }%
+ \fi%
+ \def\do##1{%
+ \appto\yquant@draw@append{##1}%
+ \yquant@draw@finalize@ctrl##1%
+ }%
+ \yquant@sort@dolistloop%
+ \csxappto{\yquant@prefix draw}{%
+ \unexpanded\expandafter{\yquant@draw@append}%
+ \noexpand\yquant@draw@endgroup%
+ \ifyquant@circuit@operator@hasControls%
+ T%
+ \else%
+ F%
+ \fi%
+ \ifx\yquant@lang@attr@name\empty%
+ {}0%
+ \else%
+ {\yquant@lang@attr@name}%
+ \ifnum\yquant@circuit@operator@numtarget=1 %
+ \ifnum\yquant@circuit@operator@numpctrl=1 %
+ \ifnum\yquant@circuit@operator@numnctrl=1 %
+ 7%
+ \else%
+ 6%
+ \fi%
+ \else%
+ \ifnum\yquant@circuit@operator@numnctrl=1 %
+ 5%
+ \else%
+ 4%
+ \fi%
+ \fi%
+ \else%
+ \ifnum\yquant@circuit@operator@numpctrl=1 %
+ \ifnum\yquant@circuit@operator@numnctrl=1 %
+ 3%
+ \else%
+ 2%
+ \fi%
+ \else%
+ \ifnum\yquant@circuit@operator@numnctrl=1 %
+ 1%
+ \else%
+ 0%
+ \fi%
+ \fi%
+ \fi%
+ \fi%
+ }%
+ % END_FOLD
+}
+
+\protected\def\yquant@draw@@single#1#2#3{%
+ \yquant@sort@eadd{%
+ \yquant@draw@single%
+ {#3}% register index
+ {\nodename}%
+ }%
+ % determine the actual dimensions by a virtual draw command
+ \pgfinterruptboundingbox%
+ \yquant@env@virtualize@path%
+ \path%
+ (0pt, 0pt)
+ node[/yquant/every operator, #2, /yquant/this operator,%
+ name prefix=, name suffix=, name=] {#1};%
+ \yquant@register@update@height{#3}{%
+ \the\dimexpr\pgf@picmaxy-\pgf@picminy\relax%
+ }%
+}
+
+\protected\def\yquant@draw@@multi#1#2#3{%
+ \yquant@sort@eadd{%
+ \yquant@draw@multi%
+ #3%
+ {\nodename}%
+ }%
+ % Determining the actual height is a problem - where to store its value? We just assume that there is always enough space for such a control, since it anyway already spans multiple registers. (TODO?)
+ \pgfinterruptboundingbox%
+ \yquant@env@virtualize@path%
+ % Here, we just set a dummy height, as we don't know the actual height yet. As the width of most/all shapes should not depend on their height, it does not matter.
+ \path%
+ (0pt, 0pt)
+ node[/yquant/every operator, #2, /yquant/this operator, y radius=1cm,%
+ name prefix=, name suffix=0, name=] {#1};
+}
+
+\protected\def\yquant@draw@@multiinit#1#2#3{%
+ \yquant@sort@eadd{%
+ \yquant@draw@multiinit%
+ #3%
+ {\nodename}%
+ }%
+ % Determining the actual height is a problem - where to store its value? We just assume that there is always enough space for such a control, since it anyway already spans multiple registers. (TODO?)
+ \pgfinterruptboundingbox%
+ \yquant@env@virtualize@path%
+ % Here, we just set a dummy height, as we don't know the actual height yet. As the width of most/all shapes should not depend on their height, it does not matter.
+ \path%
+ (0pt, 0pt)
+ node[/yquant/every operator, #2, /yquant/every multi label, y radius=1cm,%
+ name prefix=, name suffix=0, name=] {#1};
+}
+
+\def\yquant@draw@finalize@ctrl#1{%
+ \ifx\yquant@draw@multi#1%
+ \expandafter\yquant@draw@finalize@ctrl@multi%
+ \else%
+ \ifx\yquant@draw@multiinit#1%
+ \expandafter\expandafter\expandafter\yquant@draw@finalize@ctrl@multi%
+ \else%
+ \expandafter\expandafter\expandafter\yquant@draw@finalize@ctrl@single%
+ \fi%
+ \fi%
+}
+
+\protected\def\yquant@draw@finalize@ctrl@single#1#2{%
+ \unless\ifyquant@circuit@operator@hasControls%
+ \yquant@register@set@x#1{\the\dimen2}%
+ \fi%
+ \eappto\yquant@draw@append{%
+ \yquant@draw@callback@wire{#1}%
+ }%
+}
+
+\protected\def\yquant@draw@finalize@ctrl@multi#1#2#3#4#5{%
+ \unless\ifyquant@circuit@operator@hasControls{%
+ % \yquant@for uses \loop...\repeat and hence redefines \body, which would destroy an outer loop.
+ % if we did not draw a control line, the x position has not yet been set. A multi-qubit register might visually extend over multiple registers that are not even part, hence we update them all.
+ \yquant@for \yquant@i := #1 to #2 {%
+ \yquant@register@set@x\yquant@i{\the\dimen2}%
+ }%
+ }\fi%
+ % this is called from a do loop itself, so preserve \do (but do not enter grouping)
+ \let\yquant@draw@update@x@multi@@olddo=\do%
+ \def\do##1{%
+ \eappto\yquant@draw@append{%
+ \yquant@draw@callback@wire{##1}%
+ }%
+ }%
+ \dolistloop{#4}%
+ \let\do=\yquant@draw@update@x@multi@@olddo%
+}
+% END_FOLD \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-env.tex b/Master/texmf-dist/tex/latex/yquant/yquant-env.tex
new file mode 100644
index 00000000000..9ba97f5915d
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-env.tex
@@ -0,0 +1,261 @@
+\newif\ifyquant@env@lazy
+
+\protected\def\yquant@envunstar{%
+ \yquant@env@lazyfalse%
+ \yquant@env@begin%
+}
+
+\protected\def\yquant@envstar{%
+ \yquant@env@lazytrue%
+ \yquant@env@begin%
+}
+
+\protected\def\yquant@env@begin{%
+ % We check for an optional argument, but if it is in a new line, we don't take it - it
+ % might well be the square brace of an argument. Temporary change newlines to ordinary
+ % characters.
+ \catcode`\^^M=12 %
+ \yquant@futurenonspacelet\yquant@env@begin@next\yquant@env@begin@checkarg%
+}
+
+{\catcode`\^^M=12 \global\let\yquant@env@linebreak=^^M}
+
+\protected\def\yquant@env@begin@checkarg{%
+ \catcode`\^^M=5 %
+ \ifx\yquant@env@begin@next[%
+ \expandafter\yquant@env@begin@arg%
+ \else%
+ \ifx\yquant@env@begin@next\yquant@env@linebreak%
+ % In this case we don't really want to inject the wrong-catcode linebreak back,
+ % which would produce an error.
+ \afterassignment\yquant@env@begin@noarg%
+ \expandafter\expandafter\expandafter\let%
+ \expandafter\expandafter\expandafter\@eattoken%
+ % since ^^M is an ordinary character, no need for "= ".
+ \else%
+ \expandafter\expandafter\expandafter\yquant@env@begin@noarg%
+ \fi%
+ \fi%
+}
+
+\def\yquant@env@begin@noarg{%
+ \yquant@env@begin@arg[]%
+}
+
+\long\protected\def\yquant@env@begin@arg[#1]{%
+ \begingroup%
+ \advance\yquant@env by 1 %
+ \edef\yquant@prefix{yquant@env\the\yquant@env @}%
+ \let\yquant=\yquant@env@scan%
+ \yquant@lang@reset@attrs%
+ \csgdef{\yquant@prefix registers}{0}%
+% \csgdef{\yquant@prefix lasty}{0pt}%
+ \global\cslet{\yquant@prefix draw}\relax%
+ \global\cslet{\yquant@prefix outputs}\relax%
+ \csxdef{\yquant@prefix cleanup}{%
+ \expandafter\noexpand\csname\yquant@prefix registers\endcsname%
+ \expandafter\noexpand\csname\yquant@prefix draw\endcsname%
+ \expandafter\noexpand\csname\yquant@prefix outputs\endcsname%
+ \expandafter\noexpand\csname\yquant@prefix cleanup\endcsname%
+ }%
+ \ifnum\yquant@env=1 %
+ \yquant@env@substikz%
+ \fi%
+ \scope[{/yquant/.cd, every circuit, #1}]%
+}
+\newif\ifyquantdebug
+\protected\def\yquant@env@end{%
+ \letcs\yquant@env@end@registers{\yquant@prefix registers}%
+ \ifnum\yquant@env@end@registers>0 %
+ % draw all wires
+ \yquant@register@get@maxxrange\yquant@env@end@xpos{1}{\yquant@env@end@registers}%
+ % to have a symmetric situation, we extend again one separation at the end
+ \csxappto{\yquant@prefix draw}{%
+ \def\noexpand\yquant@env@end@xpos{%
+ \the\dimexpr\yquant@env@end@xpos+\yquant@config@operator@sep\relax%
+ }%
+ }
+ % also calculate the true y positions
+ \dimen0=0pt %
+ \dimen2=0pt %
+ \dimen4=\yquant@config@register@sep %
+ \yquant@for \i := 1 to \yquant@env@end@registers {%
+ % add a final wire
+ \csxappto{\yquant@prefix draw}{%
+ \yquant@circuit@endwire{\i}%
+ }%
+ % we do not care if the wire is present for the y position
+ \dimen2=.5\dimexpr\yquant@register@get@height\i\relax%
+ \advance\dimen0 by \dimen2\relax%
+ % top-to-bottom means negative coordinates in pgf
+ \yquant@register@set@y\i{-\the\dimen0}%
+ \advance\dimen0 by \dimen2\relax%
+ \advance\dimen0 by \dimen4\relax%
+ }%
+ \csname\yquant@prefix outputs\endcsname%
+ \fi%
+ \endscope%
+ % Now we actually carry out the tikz commands which were previously stored in the draw command. But before this, we get rid of all \yquant@env@scan calls and also restore the scope command, since this would add itself once again. And get@y needs to expand.
+ \let\path=\tikz@command@path%
+ \let\tikz@lib@scope@check=\yquant@env@substikz@scopecheck%
+ \let\tikz@scope@opt=\yquant@env@substikz@scope%
+ \let\endtikz@scope@env=\yquant@env@substikz@endscope%
+ \let\endscope=\endtikz@scope@env%
+ \let\stopscope=\endscope%
+ \yquant@register@get@y@@expandable%
+ \ifyquantdebug%
+ \csshow{\yquant@prefix draw}%
+ \fi%
+ \csname\yquant@prefix draw\endcsname%
+ \expandafter\expandafter\expandafter\yquant@cleanup\csname\yquant@prefix cleanup\endcsname|%
+ \endgroup%
+}
+
+\tikzaddtikzonlycommandshortcutlet\yquant\yquant@envunstar
+\expandafter\tikzaddtikzonlycommandshortcutlet\csname yquant*\endcsname\yquant@envstar
+\tikzaddtikzonlycommandshortcutlet\endyquant\yquant@env@end
+\expandafter\tikzaddtikzonlycommandshortcutlet\csname endyquant*\endcsname\yquant@env@end
+
+\protected\def\yquantset{%
+ \pgfqkeys{/yquant}%
+}
+\let\yquant@set=\yquantset%
+
+% private yquant-language related helpers
+% In order to allow nested environments and also grouping (without the need to smuggle definitions out of the groups whenever necessary), we count the number of nested environments.
+\newcount\yquant@env
+
+\def\yquant@env@substikz@finish{%
+ % Rendering pipeline
+ \endgroup%
+ \global\pgflinewidth=\tikzscope@linewidth\relax%
+ \tikz@path@do@at@end%
+}
+
+% first undoes the substikz commands, next turns the \path command into a virtual one that does not produce any output.
+\protected\def\yquant@env@virtualize@path{%
+ \yquant@register@get@y@@expandable%
+ \let\path=\tikz@command@path%
+ \let\tikz@finish=\yquant@env@substikz@finish%
+ \let\tikz@lib@scope@check=\yquant@env@substikz@scopecheck%
+}
+
+% substitute the tikz commands (defined in \tikz@installcommands) so that they can be arbitrarily interleaved with yquant code. We patch \path, \scope, \endscope, \stopscope, their internal complements, and also patch \yquantset.
+\protected\def\yquant@env@substikz{%
+ % \tikz@path@do@at@end is called after a path. Hence, it is an ideal candidate to re-invoke \yquant@env@scan. However, it is by default defined to be \tikz@lib@scope@check, and we need this definition for the scopes library to work correctly. But since \tikz@lib@scope@check is also called after a scope and the end of a scope, this is even better. Yet, we need to check whether the scopes library is present or not.
+ \let\yquant@env@substikz@scopecheck=\tikz@lib@scope@check%
+ \ifx\tikz@lib@scope@check\pgfutil@empty%
+ % no, it is not. This is simple.
+ \let\tikz@lib@scope@check=\yquant@env@scan%
+ \else%
+ % yes, it is. Call it after the special behavior is done.
+ \patchcmd\tikz@lib@scope@check{{}}{\yquant@env@scan}\relax{%
+ \PackageWarning{yquant.sty}{Patching \string\tikz@lib@scope@check\space failed; you must invoke \string\yquant\space manually after every tikz command to switch back to yquant code.}%
+ }
+ \fi%
+ % We not only need to re-invoke yquant after the tikz command, but we must also make sure that the tikz command is not actually drawn now, but at the end. However, what happens if some macros are used within the command? Here, we choose to expand the macros to the values they have _now_, but protected (which should prevent bad things for formatting commands). If you find this to be an issue, please report.
+ \def\path##1;{%
+ \protected@csxappto{\yquant@prefix draw}{%
+ \noexpand\path##1;%
+ }%
+ \yquant%
+ }%
+ % no need for \scoped, because it internally calls \scope.
+ % We need to hack into \scope, but this is a bit tricky due to its argument handling. In order to get all optional arguments, including the possible animations library, correct, we change \tikz@scope@opt.
+ \let\yquant@env@substikz@scope=\tikz@scope@opt%
+ \def\tikz@scope@opt[##1]{%
+ \protected@csxappto{\yquant@prefix draw}{%
+ \noexpand\tikz@scope@env[{##1}]%
+ }%
+ \yquant@env@substikz@scope[{##1}]%
+ }%
+ \let\yquant@env@substikz@endscope=\endtikz@scope@env%
+ \def\endtikz@scope@env{%
+ \csgappto{\yquant@prefix draw}{%
+ \yquant@env@substikz@endscope%
+ }%
+ \yquant@env@substikz@endscope%
+ }%
+ \let\endscope=\endtikz@scope@env%
+ \let\stopscope=\endscope%
+ % We define \yquantset as a pgfkeys-like macro. Anything else would deteriorate performance badly, as \pgfkeys, \pgfqkeys, or \tikzset are used a lot internally.
+ \protected\def\yquantset##1{%
+ \protected@csxappto{\yquant@prefix draw}{%
+ \noexpand\pgfqkeys{/yquant}{##1}%
+ }%
+ \pgfqkeys{/yquant}{##1}%
+ \yquant@env@scan%
+ }%
+}
+
+% Scan until the next non-space token is found and execute it as a csname
+\def\yquant@env@scan{%
+ \begingroup%
+ \yquant@env@contscan%
+}
+
+\protected\def\yquant@env@contscan{%
+ \yquant@futurenonspacelet\yquant@env@nextchar\yquant@env@check%
+}
+
+\def\yquant@env@rescan{%
+ \endgroup%
+ \yquant@env@scan%
+}
+
+\protected\def\yquant@env@check{%
+ \let\next=\relax%
+ % Here we assume standard catcodes for A and [, but our language specification also requires this implicitly.
+ \ifx\yquant@env@nextchar[%
+ \let\next=\yquant@langhelper@check@attrs%
+ \else%
+ \ifcat\noexpand\yquant@env@nextchar A% letter
+ \let\next=\yquant@langhelper@check@name%
+ \else%
+ \ifcat\noexpand\yquant@env@nextchar\bgroup%
+ \endgroup%
+ \let\next=\yquant@env@opengroup%
+ \else%
+ \ifcat\noexpand\yquant@env@nextchar\egroup%
+ \endgroup%
+ \let\next=\yquant@env@closegroup%
+ \else%
+ \ifx\yquant@env@nextchar\par%
+ \let\next=\yquant@env@gobblepar%
+ \else%
+ \ifcat\noexpand\yquant@env@nextchar\relax%
+ \endgroup%
+ \let\next=\relax%
+ \else%
+ \PackageError{yquant.sty}%
+ {Invalid yquant syntax: `\meaning\yquant@env@nextchar'}%
+ {Adhere to the specs!}%
+ \fi%
+ \fi%
+ \fi%
+ \fi%
+ \fi%
+ \fi%
+ \next%
+}
+
+\protected\def\yquant@env@opengroup{%
+ \afterassignment\yquant@env@opengroup@aux%
+ \let\@eattoken= %
+}
+
+\def\yquant@env@opengroup@aux{%
+ \bgroup%
+ \csgappto{\yquant@prefix draw}{\begingroup}%
+ \yquant@env@scan%
+}
+
+\def\yquant@env@closegroup{%
+ \csgappto{\yquant@prefix draw}{\endgroup}%
+ \aftergroup\yquant@env@scan%
+}
+
+\def\yquant@env@gobblepar{%
+ \afterassignment\yquant@env@contscan%
+ \let\@eattoken= %
+} \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-lang.tex b/Master/texmf-dist/tex/latex/yquant/yquant-lang.tex
new file mode 100644
index 00000000000..b88503beb1a
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-lang.tex
@@ -0,0 +1,559 @@
+% 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
+}
+\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%
+ \let\yquant@lang@attr@name=\empty%
+}
+% END_FOLD
+
+% BEGIN_FOLD Declaration of registers
+\yquant@langhelper@declare@command@uncontrolled{nobit}\yquant@lang@@nobit
+\yquant@langhelper@setup@attrs{nobit}{}{}
+\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}
+\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{qubit}{}{after,value}
+\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{qubit}{}{after,value}
+\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;{%
+ \if\relax\detokenize{#2}\relax%
+ \yquant@lang@create@do#1[1][;%
+ \else%
+ \yquant@lang@create@do#1[#2;%
+ \fi%
+}
+
+\protected\def\yquant@lang@create@do#1[#2]#3[;{%
+ % parse length
+ \if\relax\detokenize{#3}\relax%
+ \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
+ \else%
+ \PackageError{yquant.sty}{Invalid register name}%
+ {Register names must not contain `[' apart from register length indication.}%
+ \fi%
+ \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%
+ \else%
+ \def\yquant@lang@create@x{0pt}%
+ \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 {%
+ \yquant@register@define%
+ \yquant@lang@create@type%
+ \yquant@lang@create@x%
+ \reg\idx%
+ % First determine the actual height by a virtual draw command
+ \pgfinterruptboundingbox%
+ \yquant@env@virtualize@path%
+ \path%
+ (\yquant@lang@create@x, 0pt)
+ node[/yquant/every label, /yquant/every initial label,%
+ /yquant/every \yquant@lang@create@style\space label]
+ {\trim@spaces{\yquant@lang@attr@value}};%
+ \expandafter\yquant@register@update@height%
+ \csname\yquant@prefix registers\endcsname%
+ {\the\dimexpr\pgf@picmaxy-\pgf@picminy\relax}%
+ \endpgfinterruptboundingbox%
+ % Prepare to shipout
+ \protected@csxappto{\yquant@prefix draw}{%
+ \yquant@lang@create@draw{\csname\yquant@prefix registers\endcsname}%
+ {\yquant@lang@create@x}%
+ {\yquant@lang@create@style}%
+ {\yquant@lang@attr@value}%
+ {\yquant@lang@create@name}%
+ }%
+ }%
+ \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@draw#1#2#3#4#5{%
+ \begingroup%
+ \dimdef\wireypos{\yquant@register@get@y{#1}}%
+ \if\relax\detokenize{#4}\relax%
+ % 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]
+ (#2, \wireypos)%
+ coordinate[name prefix=, name suffix=, name=yquantbox];
+ \else%
+ \path
+ (#2, \wireypos)%
+ node[/yquant/every label, /yquant/every initial label,%
+ /yquant/every #3 label, name prefix=, name suffix=, name=yquantbox]%
+ {#4};%
+ \fi%
+ % 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}%
+ % Every label shape should implement the projection anchor, else we just guess the values, but this might be inaccurate for non-rectangular shapes
+ \ifpgfpointshapexproj{yquantbox}%
+ \@tempdima=\pgf@x%
+ \pgfpointshapexproj{yquantbox}%
+ {\pgfqpoint{\@tempdima}
+ {\dimexpr\wireypos+2\pgflinewidth\relax}}%
+ \edef\tmp{{(\the\pgf@x,\the\pgf@y)}}%
+ % This projection should normally not be necessary, as the east anchor _should_ be accurate - but who knows?
+ \pgfpointshapexproj{yquantbox}{\pgfqpoint{\@tempdima}{\wireypos}}%
+ \edef\tmp{\tmp{(\the\pgf@x,\the\pgf@y)}}%
+ \pgfpointshapexproj{yquantbox}
+ {\pgfqpoint{\@tempdima}%
+ {\dimexpr\wireypos-2\pgflinewidth\relax}}%
+ \yquant@register@set@lastwire{#1}{\tmp{(\the\pgf@x,\the\pgf@y)}}%
+ \else%
+ % Just guess the values.
+ \yquant@register@set@lastwire{#1}{%
+ {(\the\pgf@x,\the\dimexpr\wireypos+2\pgflinewidth\relax)}%
+ {(\the\pgf@x,\wireypos)}%
+ {(\the\pgf@x,\the\dimexpr\wireypos-2\pgflinewidth\relax)}%
+ }%
+ \fi%
+ \if\relax\detokenize{#5}\relax%
+ \else%
+ \pgfnodealias{\tikz@pp@name{#5}}{yquantbox}%
+ \fi%
+ \endgroup%
+}
+% 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
+\yquant@langhelper@declare@command{h}\yquant@lang@@h
+\yquant@langhelper@setup@attrs{h}{}{}
+\def\yquant@lang@@h{%
+ \yquant@draw%
+ {$H$}%
+ {/yquant/operators/every h}%
+}
+
+% Pauli X (or NOT)
+\yquant@langhelper@declare@command{x}\yquant@lang@@x
+\yquant@langhelper@setup@attrs{x}{}{}
+\def\yquant@lang@@x{%
+ \yquant@draw%
+ {$X$}%
+ {/yquant/operators/every x}%
+}
+
+% Pauli Y
+\yquant@langhelper@declare@command{y}\yquant@lang@@y
+\yquant@langhelper@setup@attrs{y}{}{}
+\def\yquant@lang@@y{%
+ \yquant@draw%
+ {$Y$}%
+ {/yquant/operators/every y}%
+}
+
+% Pauli Z
+\yquant@langhelper@declare@command{z}\yquant@lang@@z
+\yquant@langhelper@setup@attrs{z}{}{}
+\def\yquant@lang@@z{%
+ \yquant@draw%
+ {$Z$}%
+ {/yquant/operators/every z}%
+}
+
+% sub-circuit: This is a nested circuit.
+%\yquant@langhelper@declare@command{subcircuit}\yquant@lang@@subcircuit
+%\yquant@langhelper@setup@attrs{subcircuit}{}{shift}
+%\protected\def\yquant@lang@@subcircuit#1#2#3{%
+% % First we restore access to the yquant environment (which was a shorthand to
+% % re-starting the parser within the environment, conveniently forbidding nesting).
+% \let\yquant=\yquant@envunstar%
+% \cslet{yquant*}\yquant@envstar%
+% % Then determine the actual subcircuit content.
+% \yquant@circuit@subcircuit\yquant@lang@attr@value%
+% % Now the subcircuit is stored in \yquant@circuit@subcircuit@box. However, note that
+% % it may contain named nodes (whose names are stored in
+% % \csname\yquant@prefix circuit@subcircuit@nodelist\endcsname) that need to be shifted
+% % whenever we actually position the subcircuit.
+%% \let\yquant@draw@callback@box=\yquant@circuit@subcircuit@shiftnodes%
+% \yquant@register@get@allowmultitrue%
+% \yquant@draw%
+% {\copy\yquant@circuit@subcircuit@box}%
+% {/yquant/operators/every subcircuit}
+% {#1}{#2}{#3}%
+% \global\setbox\yquant@circuit@subcircuit@box=\box\voidb@x% memory management
+%}
+% 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#1#2#3{%
+ \yquant@register@get@allowmultitrue%
+ \yquant@circuit@operator{#1}{#2}{#3}%
+ \ifyquant@circuit@operator@hasControls%
+ \yquant@draw@{}{/yquant/operators/every xx, /yquant/operator/multi operator line=false}%
+ \else%
+ \yquant@draw@{}{/yquant/operators/every xx}%
+ \fi%
+}
+
+% 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@allowmultitrue%
+ \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#1#2#3{%
+ \yquant@register@get@allowmultitrue%
+ \yquant@circuit@operator{#1}{#2}{#3}%
+ \ifyquant@circuit@operator@hasControls%
+ \yquant@draw@{}{/yquant/operators/every swap, /yquant/operator/multi operator line=false}%
+ \else%
+ \yquant@draw@{}{/yquant/operators/every swap}%
+ \fi%
+}
+
+% 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%
+ \expandafter\ifstrequal\expandafter{\yquant@lang@attr@type}{qubit}%
+ {\let\yquant@circuit@settype@to=\yquant@register@type@q}%
+ {%
+ \expandafter\ifstrequal\expandafter{\yquant@lang@attr@type}{cbit}%
+ {\let\yquant@circuit@settype@to=\yquant@register@type@c}%
+ {%
+ \expandafter\ifstrequal\expandafter{\yquant@lang@attr@type}{qubits}%
+ {\let\yquant@circuit@settype@to=\yquant@register@type@qs}%
+ {%
+ \PackageError{yquant.sty}{Invalid bit type: `\yquant@lang@attr@type}%
+ {Use one of `qubit', `cbit', or `qubits'.}%
+ }%
+ }%
+ }%
+ \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%
+ \expandafter\ifstrequal\expandafter{\yquant@lang@attr@type}{qubit}%
+ {\let\yquant@circuit@settype@to=\yquant@register@type@q}%
+ {%
+ \expandafter\ifstrequal\expandafter{\yquant@lang@attr@type}{cbit}%
+ {\let\yquant@circuit@settype@to=\yquant@register@type@c}%
+ {%
+ \expandafter\ifstrequal\expandafter{\yquant@lang@attr@type}{qubits}%
+ {\let\yquant@circuit@settype@to=\yquant@register@type@qs}%
+ {%
+ \PackageError{yquant.sty}{Invalid bit type: `\yquant@lang@attr@type}%
+ {Use one of `qubit', `cbit', or `qubits'.}%
+ }%
+ }%
+ }%
+ \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{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}%
+ \yquant@circuit@settypes\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}
+\def\yquant@lang@@init@multi@@extract#1#2#3#4#5{%
+ #5%
+}
+\protected\def\yquant@lang@@init#1{%
+ \yquant@register@get@allowmultitrue%
+ \yquant@register@get@ids{#1}%
+ \ifdefined\yquant@lang@attr@type%
+ \expandafter\ifstrequal\expandafter{\yquant@lang@attr@type}{qubit}%
+ {\let\yquant@circuit@settype@to=\yquant@register@type@q}%
+ {%
+ \expandafter\ifstrequal\expandafter{\yquant@lang@attr@type}{cbit}%
+ {\let\yquant@circuit@settype@to=\yquant@register@type@c}%
+ {%
+ \expandafter\ifstrequal\expandafter{\yquant@lang@attr@type}{qubits}%
+ {\let\yquant@circuit@settype@to=\yquant@register@type@qs}%
+ {%
+ \PackageError{yquant.sty}{Invalid bit type: `\yquant@lang@attr@type}%
+ {Use one of `qubit', `cbit', or `qubits'.}%
+ }%
+ }%
+ }%
+ \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}{%
+ \def\@do####1{%
+ \edef\yquant@circuit@settype@to{\yquant@register@get@type{####1}}%
+ \unless\ifx\yquant@circuit@settype@to\yquant@register@type@none%
+ \expandafter\listbreak%
+ \fi%
+ }%
+ \forlistloop\@do{\yquant@lang@@init@multi@@extract##1}%
+ }{%
+ \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%
+ \ifx\yquant@circuit@settype@to\yquant@register@type@q%
+ \def\yquant@lang@attr@type{qubit}%
+ \else%
+ \ifx\yquant@circuit@settype@to\yquant@register@type@c%
+ \def\yquant@lang@attr@type{cbit}%
+ \else%
+ \def\yquant@lang@attr@type{qubits}%
+ \fi%
+ \fi%
+ \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}%
+ \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{setwire}\yquant@lang@@setwire
+\yquant@langhelper@setup@attrs{setwire}{value}{}
+\protected\def\yquant@lang@@setwire#1{%
+ \yquant@register@get@ids{#1}%
+ \expandafter\ifstrequal\expandafter{\yquant@lang@attr@value}{qubit}%
+ {\let\yquant@circuit@settype@to=\yquant@register@type@q}%
+ {%
+ \expandafter\ifstrequal\expandafter{\yquant@lang@attr@value}{cbit}%
+ {\let\yquant@circuit@settype@to=\yquant@register@type@c}%
+ {%
+ \expandafter\ifstrequal\expandafter{\yquant@lang@attr@value}{qubits}%
+ {\let\yquant@circuit@settype@to=\yquant@register@type@qs}%
+ {%
+ \PackageError{yquant.sty}{Invalid bit type: `\yquant@lang@attr@value}%
+ {Use one of `qubit', `cbit', or `qubits'.}%
+ }%
+ }%
+ }%
+ \yquant@circuit@settypes\yquant@register@get@ids@list\yquant@circuit@settype@to%
+}
+% END_FOLD \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-langhelper.tex b/Master/texmf-dist/tex/latex/yquant/yquant-langhelper.tex
new file mode 100644
index 00000000000..f9a82d1c740
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-langhelper.tex
@@ -0,0 +1,315 @@
+% Parsing attributes
+\let\yquant@langhelper@list@attrs=\empty
+
+\protected\long\def\yquant@langhelper@check@attrs[#1]{%
+ \appto\yquant@langhelper@list@attrs{#1,}%
+ \yquant@env@contscan%
+}
+
+% shorthands for declaring attributes
+\protected\def\yquant@langhelper@declare@attr{%
+ \pgfqkeys{/yquant/all attrs}%
+}
+
+\protected\def\yquant@langhelper@declare@attr@global{%
+ \pgfqkeys{/yquant/global attrs}%
+}
+
+\pgfkeys{%
+ /yquant/attr filter handler/.code={%
+ \let\yquant@langhelper@filter@@name=\pgfkeyscurrentkeyRAW%
+ \let\yquant@langhelper@filter@@value=\pgfkeyscurrentvalue%
+ % the key was filtered out, i.e., it is neither a local nor a global attribute.
+ \pgfkeysinterruptkeyfilter%
+ % execute it in /yquant, if it exists there
+ \pgfqkeys{/yquant}{\yquant@langhelper@filter@@name/.try/.expand once=\yquant@langhelper@filter@@value}%
+ \ifpgfkeyssuccess%
+ \eappto#1{%
+ ,/yquant/\unexpanded\expandafter{\yquant@langhelper@filter@@name}%
+ \unless\ifx\yquant@langhelper@filter@@value\pgfkeysnovalue@text%
+ ={\unexpanded\expandafter{\yquant@langhelper@filter@@value}}%
+ \fi%
+ }%
+ \else%
+ \pgfkeys{/yquant/operator style/.expanded=%
+ {\unexpanded\expandafter{\yquant@langhelper@filter@@name}=%
+ {\unexpanded\expandafter{\yquant@langhelper@filter@@value}}%
+ }%
+ }%
+ \eappto#1{%
+ ,/yquant/operator style={\unexpanded\expandafter{\yquant@langhelper@filter@@name}%
+ \unless\ifx\yquant@langhelper@filter@@value\pgfkeysnovalue@text%
+ ={\unexpanded\expandafter{\yquant@langhelper@filter@@value}}%
+ \fi%
+ }%
+ }%
+ \fi%
+ \endpgfkeysinterruptkeyfilter%
+ },
+ /pgf/key filters/attr filter/.code={%
+ % we need to capture every non-attribute (which means filtering them out).
+ \expandafter\ifyquant@beginswith\expandafter{\pgfkeyscurrentkey}{/yquant/attrs/}{%
+ % the key is in /yquant/attrs. Does it actually exist (but not as a handler, which would define non-existing keys)?
+ \if\pgfkeyscasenumber1%
+ \pgfkeysfiltercontinuetrue%
+ \else%
+ \if\pgfkeyscasenumber2%
+ \pgfkeysfiltercontinuetrue%
+ \else%
+ % 0 or 3 for our case means non-existing - now we need to check whether we can find it in the global attributes.
+ \pgfkeysifassignable{/yquant/global attrs/\pgfkeyscurrentkeyRAW}{%
+ \pgfkeysfiltercontinuetrue%
+ }{%
+ % it is not, so it is not a known attribute for this operator. Filter.
+ \pgfkeysfiltercontinuefalse%
+ }%
+ \fi%
+ \fi%
+ }{%
+ % the key is not in /yquant/attrs. Is it a global attribute (usually, the user should not access this explicitly, but let's be tolerant here)?
+ \expandafter\ifyquant@beginswith\expandafter{\pgfkeyscurrentkey}{/yquant/global attrs/}{%
+ % the key is in /yquant/global attrs. Does it actually exist?
+ \if\pgfkeyscasenumber1%
+ \pgfkeysfiltercontinuetrue%
+ \else%
+ \if\pgfkeyscasenumber2%
+ \pgfkeysfiltercontinuetrue%
+ \else%
+ % no - that's it.
+ \pgfkeysfiltercontinuefalse%
+ \fi%
+ \fi%
+ }{%
+ % the key is no known attribute
+ \pgfkeysfiltercontinuefalse%
+ }%
+ }%
+ },
+ /yquant/attr filter/.style={
+ /pgf/key filters/attr filter/.install key filter,
+ /yquant/attr filter handler/.install key filter handler=\yquant@attrs@remaining%
+ }%
+}
+
+% specifies which attributes can be used for a given command
+% #1: command name
+% #2: comma-separated list of required attrs
+% #3: comma-separated list of optional attrs
+\protected\def\yquant@langhelper@setup@attrs#1#2#3{%
+ \begingroup%
+ \lowercase{\edef\cmd{#1}}%
+ \edef\keyscmd{%
+ \noexpand\pgfkeyslet{/yquant/attrs/\cmd/.unknown/.@cmd}%
+ \yquant@langhelper@setup@attrs@unknown%
+ }%
+ \let\keysset=\relax%
+ \let\keyscheck=\relax%
+ \def\do##1{%
+ \eappto\keyscmd{%
+ \noexpand\pgfkeysdef{/yquant/attrs/\cmd/##1}{%
+ \unexpanded{%
+ \cslet{yquant@langhelper@attrs@req@##1}\relax%
+ \pgfkeysinterruptkeyfilter%
+ \pgfkeys{/yquant/all attrs/##1={####1}}%
+ \endpgfkeysinterruptkeyfilter%
+ }
+ }%
+ }%
+ \eappto\keysset{%
+ \def\expandafter\noexpand\csname yquant@langhelper@attrs@req@##1\endcsname{%
+ \yquant@langhelper@setup@attrs@missing{##1}%
+ }%
+ }%
+ \expandafter\appto\expandafter\keyscheck%
+ \csname yquant@langhelper@attrs@req@##1\endcsname%
+ }%
+ \docsvlist{#2}%
+ \global\cslet{yquant@langhelper@setup@attrs@set@\cmd}\keysset%
+ \global\cslet{yquant@langhelper@setup@attrs@check@\cmd}\keyscheck%
+ \def\do##1{%
+ \eappto\keyscmd{%
+ \noexpand\pgfkeysdef{/yquant/attrs/\cmd/##1}{%
+ \unexpanded{%
+ \pgfkeysinterruptkeyfilter%
+ \pgfkeys{/yquant/all attrs/##1={####1}}%
+ \endpgfkeysinterruptkeyfilter%
+ }%
+ }%
+ }%
+ }%
+ \docsvlist{#3}%
+ \expandafter%
+ \endgroup%
+ \keyscmd%
+}
+
+\protected\def\yquant@langhelper@setup@attrs@unknown#1\pgfeov{%
+ % This is in its essence /.search also={/yquant/global attrs}, but with filtering interrupted
+ \pgfkeysinterruptkeyfilter%
+ \ifpgfkeysaddeddefaultpath%
+ % only process keys for which no full path has been provided:
+ \pgfkeyssuccessfalse%
+ \let\pgfkeys@searchalso@name=\pgfkeyscurrentkeyRAW%
+ % We interrupt the filtering process because we only want to append the very top-level command to the remaining-macro.
+ \unless\ifpgfkeyssuccess%
+ \pgfqkeys{/yquant/global attrs}%
+ {\pgfkeys@searchalso@name={#1}}%
+ \fi%
+ \else%
+ % the /.search also implementation defines this in an unexpanded macro, which is then executed. Any reason?
+ \pgfkeysvalueof{/handlers/.unknown/.@cmd}#1\pgfeov%
+ \fi%
+ \endpgfkeysinterruptkeyfilter%
+}
+
+\protected\def\yquant@langhelper@setup@attrs@missing#1{%
+ \PackageError{yquant.sty}{Required attribute `#1' missing}%
+ {You used a command that requires specifying the attribute `#1'.}%
+}%
+
+% Parsing command itself
+\protected\def\yquant@langhelper@check@name#1 {%
+ \lowercase{\edef\cmd{#1}}%
+ \unless\ifcsname yquant@lang@\cmd\endcsname%
+ \PackageError{yquant.sty}{Unsupported yquant command: `#1'}%
+ {You used a command that is unknown to yquant.}%
+ \fi%
+ % Provide the association with the correct attributes
+ \csname yquant@langhelper@setup@attrs@set@\cmd\endcsname%
+ % For "ordinary" uses of the quotes library (without additional options), it would be better not to load the library now, since then the original text (everything in quotes) is just appended to /yquant/operator style. However, then uses with options will break the pgfkeys parser, as they are invalid. For this reason, we must enable the quotes library already at this state, with the consequence that we store the longer version, i.e., the output of the quotes-parsed expression instead.
+ \tikz@enable@node@quotes%
+ % execute them
+ \let\yquant@attrs@remaining=\empty%
+ \unless\ifx\yquant@langhelper@list@attrs\empty%
+ \edef\yquant@langhelper@list@attrs{%
+ \noexpand\pgfqkeysfiltered%
+ {/yquant/attrs/\cmd}%
+ {\unexpanded\expandafter{\yquant@langhelper@list@attrs}}%
+ }%
+ \pgfkeys{/yquant/attr filter}%
+ \yquant@langhelper@list@attrs%
+ \let\yquant@langhelper@list@attrs=\empty% required for nested environments
+ \fi%
+ % If there was an argument, set it
+ \@ifnextchar\bgroup%
+ \yquant@langhelper@check@name@i%
+ \yquant@langhelper@check@name@ii%
+}
+
+\protected\long\def\yquant@langhelper@check@name@i#1{%
+ \ifdefined\yquant@lang@attr@value%
+ \PackageWarning{yquant.sty}{Node content given explicitly and as an attribute. Using the explicit value.}%
+ \fi%
+ \def\yquant@lang@attr@value{#1}%
+ \let\yquant@langhelper@attrs@req@value=\relax%
+ \yquant@langhelper@check@name@ii%
+}
+
+\protected\def\yquant@langhelper@check@name@ii{%
+ % Check all necessary attributes were given.
+ \csname yquant@langhelper@setup@attrs@check@\cmd\endcsname%
+ % Finally execute the command
+ \csname yquant@lang@\cmd\endcsname%
+}
+
+% Defining commands that accept registers and take an optional value
+% #1: name of the argument
+% #2: command that is to be called with three parameters: the indices of the positive and negative controls and registers, all as named lists
+\protected\def\yquant@langhelper@declare@command#1#2{%
+ \begingroup%
+ \lowercase{\edef\cmd{#1}}%
+ \long\protected\csgdef{yquant@lang@\cmd}{%
+ \let\cmd=#2%
+ \yquant@langhelper@declare@command@@parse%
+ }%
+ \endgroup%
+}
+
+% Defining commands that accept registers and take an additional value
+% #1: name of the argument
+% #2: command that is to be called with three parameters: the indices of the positive and negative controls and registers, all as named lists
+\protected\def\yquant@langhelper@declare@command@uncontrolled#1#2{%
+ \begingroup%
+ \lowercase{\edef\cmd{#1}}%
+ \long\protected\csgdef{yquant@lang@\cmd}{%
+ \def\cmd{\yquant@langhelper@declare@command@@uncontrolled{#2}}%
+ \yquant@langhelper@declare@command@@parse%
+ }%
+ \endgroup%
+}
+
+\long\def\yquant@langhelper@declare@command@@parse#1;{%
+ \yquant@langhelper@declare@command@@extract@nctrl#1~;%
+ \yquant@env@rescan%
+}
+
+\def\yquant@langhelper@declare@command@@extract@nctrl#1~#2;{%
+ \if\relax\detokenize{#2}\relax%
+ \yquant@langhelper@declare@command@@extract@pctrl#1|~~;%
+ \else%
+ \yquant@langhelper@declare@command@@extract@pctrl#1|~#2;%
+ \fi%
+}
+
+\def\yquant@langhelper@declare@command@@extract@pctrl#1|#2~#3~;{%
+ \if\relax\detokenize{#2}\relax%
+ \yquant@langhelper@declare@command@@exec#1||~#3;%
+ \else%
+ \yquant@langhelper@declare@command@@exec#1|#2~#3;%
+ \fi%
+}
+
+\protected\def\yquant@langhelper@declare@command@@exec#1|#2|~#3;{%
+ \edef\params{%
+ {\trim@spaces{#2}}%
+ {\trim@spaces{#3}}%
+ {\trim@spaces{#1}}%
+ }%
+ \expandafter\cmd\params%
+}
+
+\protected\def\yquant@langhelper@declare@command@@uncontrolled#1#2#3{%
+ \ifstrempty{#2}\relax{%
+ \PackageError{yquant.sty}{Positive controls are not allowed for this command}{}%
+ }%
+ \ifstrempty{#3}\relax{%
+ \PackageError{yquant.sty}{Negative controls are not allowed for this command}{}%
+ }%
+ #1%
+}
+
+% shorthands for validation of property values
+% #1: a macro that will contain the sanitized value
+% #2: a TeX register type: most likely \count, \dimen
+% #3: a string to be checked
+% This macro is not expandable.
+\protected\def\yquant@langhelper@validate#1#2#3{%
+ \begingroup%
+ \afterassignment\yquant@langhelper@validate@i%
+ #2 255=#3\relax\yquant@end%
+ \unless\ifvalid%
+ \PackageError{yquant.sty}{Invalid property value: `#3'}%
+ {The value must be assignable to a \protect#2 register.}%
+ \fi%
+ \expandafter%
+ \endgroup%
+ \expandafter\def\expandafter#1\expandafter{\the#2 255}%
+}
+
+\def\yquant@langhelper@validate@relax{\relax}
+\protected\def\yquant@langhelper@validate@i#1\relax#2\yquant@end{%
+ % if the valid value was not user-delimited by \relax, #1 and #2 are empty
+ % if the valid value was user-delimited by \relax, #1 is empty and #2 is \relax
+ \let\ifvalid=\iffalse%
+ \if\relax\detokenize{#1}\relax%
+ \def\tmp{#2}%
+ \ifx\empty\tmp%
+ \csletcs{ifvalid}{iftrue}%
+ \else%
+ \ifx\yquant@langhelper@validate@relax\tmp%
+ \csletcs{ifvalid}{iftrue}%
+ \fi%
+ \fi%
+ \fi%
+ % eat the rest (which should be empty anyway)
+} \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-registers.tex b/Master/texmf-dist/tex/latex/yquant/yquant-registers.tex
new file mode 100644
index 00000000000..7f640fe4996
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-registers.tex
@@ -0,0 +1,532 @@
+\def\yquant@register@type@none{0}
+\def\yquant@register@type@q{1}
+\def\yquant@register@type@c{2}
+\def\yquant@register@type@qs{3}
+
+% Internally, we store the register information in a single macro. Indeed, this is almost always faster than using multiple macros (at least in the way implemented here), apart from changing a single type of information, which is almost as fast.
+% BEGIN_FOLD Constructor: create single register and cleanup environment
+
+% #1: type
+% #2: x position
+% #3: name
+% #4: index
+\protected\def\yquant@register@define#1#2#3#4{%
+ \csnumgdef{\yquant@prefix registers}%
+ {\csname\yquant@prefix registers\endcsname+1}%
+ \csxdef{\yquant@prefix register@\csname\yquant@prefix registers\endcsname}{%
+ {#1}% type
+ {#2}% x pos
+ {\yquant@config@register@minimum@height}% height; at the end, the y position
+ {}% wire start positions
+ }%
+ \global\csletcs{\yquant@prefix registername@#3[#4]}{\yquant@prefix registers}%
+ \csxdef{\yquant@prefix registerhigh@\reg}{#4}%
+ \yquant@cleanup@csadd{\yquant@prefix register@\csname\yquant@prefix registers\endcsname}%
+ \yquant@cleanup@csadd{\yquant@prefix registername@#3[#4]}%
+ \ifnum0=#4\relax%
+ \yquant@cleanup@csadd{\yquant@prefix registerhigh@\reg}%
+ \fi%
+}
+% END_FOLD
+
+% BEGIN_FOLD Converter: convert a register name to its id
+% store the number corresponding to register #2 into #1
+\protected\def\yquant@register@get@id#1#2{%
+ \ifcsname\yquant@prefix registername@#2\endcsname%
+ \letcs#1{\yquant@prefix registername@#2}%
+ \else%
+ \yquant@register@get@id@lazycreate{#2}%
+ \letcs#1{\yquant@prefix registers}%
+ \fi%
+}
+
+% same as before, but resolves to the _index_ of the last register
+\protected\def\yquant@register@get@id@high#1#2{%
+ \ifcsname\yquant@prefix registerhigh@#2\endcsname%
+ \letcs#1{\yquant@prefix registerhigh@#2}%
+ \else%
+ \yquant@register@get@id@lazycreate{#2}%
+ \letcs#1{\yquant@prefix registers}%
+ \fi%
+}
+
+% In the lazy mode, we create all unknown registers on-the-fly.
+\def\yquant@register@get@id@lazycreate#1{%
+ \ifyquant@env@lazy%
+ % In principle, we could just call \yquant@lang@@qubit. However, if access to a vector register is desired and a _part_ of this does already exist (though not the requested index), we only create the missing registers.
+ \yquant@register@get@id@lazycreate@parse#1[;
+ \else%
+ \PackageError{yquant.sty}{Register `#1' unknown}%
+ {You referred to an unknown register.
+ Declare registers first using `qubit' and friends.}%
+ \fi%
+}
+
+\def\yquant@register@get@id@lazycreate@parse#1[#2;{%
+ \if\relax\detokenize{#2}\relax%
+ \yquant@register@get@id@lazycreate@do#1[0][;%
+ \else%
+ \yquant@register@get@id@lazycreate@do#1[#2;%
+ \fi%
+}
+
+\protected\def\yquant@register@get@id@lazycreate@do#1[#2]#3[;{%
+ % parse length
+ \if\relax\detokenize{#3}\relax%
+ \yquant@langhelper@validate\len\count{#2}%
+ \numdef\len{\len+1}%
+ \else%
+ \PackageError{yquant.sty}{Invalid register name}%
+ {Register names must not contain `[' apart from register length indication.}%
+ \fi%
+ \edef\reg{\trim@spaces{#1}}%
+ % Was this register already defined?
+ \ifcsname\yquant@prefix registerhigh@\reg\endcsname%
+ \numdef\idx{\csname\yquant@prefix registerhigh@\reg\endcsname+1}%
+ \unless\ifnum\idx<\len\relax%
+ \PackageError{yquant.sty}{Internal inconsistency detected}%
+ {Tried to create a register on-the-fly that already existed.}%
+ \fi%
+ \else%
+ \def\idx{0}%
+ \fi%
+ \begingroup%
+ % pre-set y position
+ \yquant@for \idx := \idx to \numexpr \len -1\relax {%
+ \yquant@register@define%
+ \yquant@register@type@q%
+ {0pt}%
+ \reg\idx
+ % Prepare to shipout
+ \csxappto{\yquant@prefix draw}{%
+ \yquant@lang@create@draw{\csname\yquant@prefix registers\endcsname}%
+ {0pt}%
+ {qubit}%
+ {}%
+ {}%
+ }%
+ }%
+ \endgroup%
+}
+
+\newif\ifyquant@register@get@allowmulti
+% converts names to indices
+% #1: comma-separated string of names or ranges
+% range format: startname-endname
+% Both startname and endname may be omitted, denoting the very first and last
+% register, respectively
+% If \ifyquant@register@get@allowmulti is set to true, multi-qubit registers are
+% allowed, which are surrounded by parentheses. They may not appear in ranges.
+% \yquant@register@get@ids@list, \yquant@register@get@ids@min, \yquant@register@get@ids@max and \yquant@register@get@ids@count will be set appropriately
+\begingroup%
+\catcode`[=\active%
+\catcode`(=\active%
+\protected\gdef\yquant@register@get@ids#1{%
+ \begingroup%
+ \let\yquant@register@get@ids@list=\empty%
+ \count0=2147483647 % minimal id
+ \count2=0 % maximal id
+ \count4=0 % number of total registers
+ \ifblank{#1}{}{%
+ \let\ifinmulti=\iffalse%
+ \let\do=\yquant@register@get@ids@outerlist%
+ \begingroup%
+ \catcode`[=\active%
+ \catcode`(=\active%
+ \def[##1]{\yquant@register@get@ids@@index{##1}}%
+ \def(##1){\yquant@register@get@ids@@multi{##1}}%
+ \edef\yquant@register@get@ids@retokenized{\scantokens{#1\noexpand}}%
+ \expandafter%
+ \endgroup%
+ \expandafter\docsvlist\expandafter{\yquant@register@get@ids@retokenized}%
+ }%
+ \global\let\yquant@register@get@ids@list=\yquant@register@get@ids@list%
+ \xdef\yquant@register@get@ids@min{\the\count0}%
+ \xdef\yquant@register@get@ids@max{\the\count2}%
+ \xdef\yquant@register@get@ids@count{\the\count4}%
+ \endgroup%
+}
+\endgroup
+
+\protected\def\yquant@register@get@ids@@index{}
+\protected\def\yquant@register@get@ids@@multi{}
+
+\def\yquant@register@get@ids@outerlist#1{%
+ \ifyquant@firsttoken\yquant@register@get@ids@@multi{#1}{%
+ \unless\ifyquant@register@get@allowmulti%
+ \PackageError{yquant.sty}{Multi-register gate not allowed}%
+ {The selected gate can only be used in a single-register context.}%
+ \fi%
+ \yquant@register@get@ids@multi#1\yquant@sep%
+ }{%
+ \yquant@register@get@ids@checkrange#1-\yquant@sep%
+ }%
+}
+
+\protected\def\yquant@register@get@ids@multi\yquant@register@get@ids@@multi#1\yquant@sep{%
+ \begingroup%
+ \let\yquant@register@get@ids@list=\empty%
+ \count0=2147483647 % minimal id
+ \count2=0 % maximal id
+ \count4=0 % number of total registers
+ \let\ifinmulti=\iftrue%
+ \let\do=\yquant@register@get@ids@multilist%
+ \docsvlist{#1}%
+ \edef\process{%
+ \endgroup%
+ \noexpand\listadd\noexpand\yquant@register@get@ids@list{%
+ \noexpand\yquant@register@multi%
+ {\the\count0}{\the\count2}{\the\count4}%
+ {\yquant@register@get@ids@list}%
+ }%
+ \noexpand\ifnum\count0>\the\count0\space%
+ \count0=\the\count0\space%
+ \noexpand\fi%
+ \noexpand\ifnum\count2<\the\count2\space%
+ \count2=\the\count2\space%
+ \noexpand\fi%
+ \advance\count4 by 1 %
+ }%
+ \process%
+}
+
+\def\yquant@register@get@ids@multilist#1{%
+ \yquant@register@get@ids@checkrange#1-\yquant@sep%
+}
+
+\def\yquant@register@get@ids@checkrange#1-#2\yquant@sep{%
+ \if\relax\detokenize{#2}\relax%
+ % the string does not contain a dash
+ \yquant@register@get@ids@norange{#1}%
+ \else%
+ % this is a range argument
+ \yquant@register@get@ids@range#1-#2\yquant@sep%
+ \fi%
+}
+
+\def\yquant@register@get@ids@norange#1{%
+ % the register is not used within a range, which gives us full freedom with respect to sub-index selections
+ \yquant@register@get@ids@norange@checkindex%
+ #1%
+ \yquant@register@get@ids@@index%
+ \yquant@sep%
+}
+
+\protected\def\yquant@register@get@ids@norange@checkindex#1\yquant@register@get@ids@@index#2\yquant@sep{%
+ \edef\current{\trim@spaces{#1}}%
+ \if\relax\detokenize{#2}\relax%
+ % the string does not contain a sub-index; we add the full register
+ \yquant@register@get@id\first{\current[0]}%
+ \letcs\high{\yquant@prefix registerhigh@\current}%
+ \yquant@register@get@id\last{\current[\high]}%
+ \ifnum\first<\count0 %
+ \count0=\first\relax%
+ \fi%
+ \ifnum\last>\count2 %
+ \count2=\last\relax%
+ \fi%
+ \advance\count4 by \numexpr\high+1\relax%
+ \yquant@for \i := 0 to \high {%
+ \yquant@register@get@id\idx{\current[\i]}%
+ \listeadd\yquant@register@get@ids@list{\idx}%
+ }%
+ \else%
+ \yquant@register@get@ids@norange@index#2%
+ \fi%
+}
+
+\protected\def\yquant@register@get@ids@norange@index#1\yquant@register@get@ids@@index{%
+ \let\olddo=\do%
+ % the string contains sub-indices; since we are not in a range, multi-indices may still be allowed
+ \ifinmulti%
+ \let\do=\yquant@register@get@ids@subindex@nomulti%
+ \else%
+ \let\do=\yquant@register@get@ids@subindex@allowmulti%
+ \fi%
+ \docsvlist{#1}%
+ \let\do=\olddo%
+}
+
+\def\yquant@register@get@ids@subindex@nomulti#1{%
+ \yquant@register@get@ids@subindex@checkrange#1-\yquant@sep%
+}
+
+\def\yquant@register@get@ids@subindex@allowmulti#1{%
+ \ifyquant@firsttoken\yquant@register@get@ids@@multi{#1}{%
+ \unless\ifyquant@register@get@allowmulti%
+ \PackageError{yquant.sty}{Multi-register gate not allowed}%
+ {The selected gate can only be used in a single-register context.}%
+ \fi%
+ \yquant@register@get@ids@subindex@multi#1\yquant@sep%
+ }{%
+ \yquant@register@get@ids@subindex@checkrange#1-\yquant@sep%
+ }%
+}
+
+\protected\def\yquant@register@get@ids@subindex@multi\yquant@register@get@ids@@multi#1\yquant@sep{%
+ \begingroup%
+ \let\yquant@register@get@ids@list=\empty%
+ \count0=2147483647 % minimal id
+ \count2=0 % maximal id
+ \count4=0 % number of total registers
+ \let\ifinmulti=\iftrue%
+ \let\do=\yquant@register@get@ids@subindex@nomulti%
+ \docsvlist{#1}%
+ \edef\process{%
+ \endgroup%
+ \noexpand\listadd\noexpand\yquant@register@get@ids@list{%
+ \noexpand\yquant@register@multi%
+ {\the\count0}{\the\count2}{\the\count4}%
+ {\yquant@register@get@ids@list}%
+ }%
+ \noexpand\ifnum\count0>\the\count0\space%
+ \count0=\the\count0\space%
+ \noexpand\fi%
+ \noexpand\ifnum\count2<\the\count2\space%
+ \count2=\the\count2\space%
+ \noexpand\fi%
+ \advance\count4 by 1 %
+ }%
+ \process%
+}
+
+\def\yquant@register@get@ids@subindex@checkrange#1-#2\yquant@sep{%
+ \if\relax\detokenize{#2}\relax%
+ % the string does not contain a dash, this is a single sub-item
+ \yquant@register@get@ids@subindex@norange{\trim@spaces{#1}}%
+ \else%
+ % this is a range argument
+ \yquant@register@get@ids@subindex@range#1-#2\yquant@sep%
+ \fi%
+}
+
+\protected\def\yquant@register@get@ids@subindex@norange#1{%
+ \yquant@register@get@id\idx{\current[#1]}%
+ \ifnum\idx<\count0 %
+ \count0=\idx\relax%
+ \fi%
+ \ifnum\idx>\count2 %
+ \count2=\idx\relax%
+ \fi%
+ \advance\count4 by 1\relax%
+ \listeadd\yquant@register@get@ids@list{\idx}%
+}
+
+\protected\def\yquant@register@get@ids@subindex@range#1-#2-\yquant@sep{%
+ \ifblank{#1}{%
+ \def\first{0}%
+ }{%
+ \yquant@langhelper@validate\first\count{#1}%
+ }%
+ \ifblank{#2}{%
+ \yquant@register@get@id@high\last\current%
+ }{%
+ \yquant@langhelper@validate\last\count{#2}%
+ }%
+ \yquant@for \i := \first to \last {%
+ \yquant@register@get@ids@subindex@norange\i%
+ }%
+}
+
+\protected\def\yquant@register@get@ids@range#1-#2-\yquant@sep{%
+ % being a range between two registers, those must be uniquely identifiable, i.e. either a single sub-indexed part of a vector register, or no vector specification at all.
+ \ifblank{#1}{%
+ \def\first{1}%
+ }{%
+ \yquant@register@get@ids@range@getfirst#1\yquant@register@get@ids@@index\yquant@sep%
+ }%
+ \ifblank{#2}{%
+ \letcs\last{\yquant@prefix registers}%
+ }{%%
+ \yquant@register@get@ids@range@getlast#2\yquant@register@get@ids@@index\yquant@sep%
+ }%
+ \ifnum\first<\last\relax%
+ \ifnum\first<\count0 %
+ \count0=\first\relax%
+ \fi%
+ \ifnum\last>\count2 %
+ \count2=\last\relax%
+ \fi%
+ \advance\count4 by \numexpr\last-\first+1\relax%
+ \else%
+ \ifnum\last<\count0 %
+ \count0=\last\relax%
+ \fi%
+ \ifnum\first>\count2 %
+ \count2=\first\relax%
+ \fi%
+ \advance\count4 by \numexpr\first-\last+1\relax%
+ \fi%
+ \yquant@for \i := \first to \last {%
+ \listeadd\yquant@register@get@ids@list{\i}%
+ }%
+}
+
+\def\yquant@register@get@ids@range@getfirst#1\yquant@register@get@ids@@index#2\yquant@sep{%
+ \if\relax\detokenize{#2}\relax%
+ \yquant@register@get@id\first{\trim@spaces{#1}[0]}%
+ \else%
+ \yquant@register@get@ids@range@get\first#1\yquant@register@get@ids@@index#2%
+ \fi%
+}
+
+\protected\def\yquant@register@get@ids@range@getlast#1\yquant@register@get@ids@@index#2\yquant@sep{%
+ \if\relax\detokenize{#2}\relax%
+ \yquant@register@get@id@high\last{\trim@spaces{#1}}%
+ \yquant@register@get@id\last{\trim@spaces{#1}[\last]}%
+ \else%
+ \yquant@register@get@ids@range@get\last#1\yquant@register@get@ids@@index#2%
+ \fi%
+}
+
+\def\yquant@register@get@ids@range@get#1#2\yquant@register@get@ids@@index#3\yquant@register@get@ids@@index{%
+ \yquant@register@get@id#1{\trim@spaces{#2}[\trim@spaces{\trim@spaces#3}]}%
+}
+
+\let\yquant@register@multi=\empty%
+% END_FOLD
+
+% BEGIN_FOLD Getters: extract the requested information from the register with given id
+\def\yquant@register@get@type#1{%
+ \expandafter\expandafter\expandafter%
+ \yquant@register@get@type@aux\csname\yquant@prefix register@#1\endcsname%
+}
+
+\def\yquant@register@get@type@aux#1#2#3#4{#1}
+
+\def\yquant@register@get@x#1{%
+ \expandafter\expandafter\expandafter%
+ \yquant@register@get@x@aux\csname\yquant@prefix register@#1\endcsname%
+}
+
+\def\yquant@register@get@x@aux#1#2#3#4{#2}
+
+\def\yquant@register@get@height#1{%
+ \expandafter\expandafter\expandafter%
+ \yquant@register@get@height@aux\csname\yquant@prefix register@#1\endcsname%
+}
+
+\def\yquant@register@get@height@aux#1#2#3#4{#3}
+
+% The y parameter get macros exist in two forms: The protected one is used during the storage to the draw macro; it should never be executed. The env environment then maps them to their proper expandable forms.
+\protected\def\yquant@register@get@@protected{%
+ \PackageError%
+ {yquant.sty}%
+ {Execution of a get-y macro in an illegal context}%
+ {get-y macros may not be called unless the yquant environment ends.}%
+}
+
+\let\yquant@register@get@y=\yquant@register@get@@protected
+\let\yquant@register@y=\yquant@register@get@@protected
+% This plays a similar role: It must never be expanded before the tikz command is invoked (because it does not exist).
+\let\nodepart=\yquant@register@get@@protected
+
+% getting the y position is the same as getting the height parameter, since we will reuse it at the end.
+\let\yquant@register@get@y@unprotected=\yquant@register@get@height
+
+% y distance between two registers.
+\def\yquant@register@get@ydist#1#2{%
+ \expandafter\yquant@abs\expandafter%
+ {\the\dimexpr\yquant@register@get@y{#2}-\yquant@register@get@y{#1}\relax}%
+}
+
+% y position of the current register
+\def\yquant@register@y@unprotected{0pt}%
+
+\protected\def\yquant@register@get@y@@expandable{%
+ \let\yquant@register@get@y=\yquant@register@get@y@unprotected%
+ \let\yquant@register@y=\yquant@register@y@unprotected%
+}
+
+\def\yquant@register@get@lastwire#1{%
+ \expandafter\expandafter\expandafter%
+ \yquant@register@get@lastwire@aux\csname\yquant@prefix register@#1\endcsname%
+}
+
+\def\yquant@register@get@lastwire@aux#1#2#3#4{#4}
+
+% Set #1 to the maximum x value found between #2 and #3
+\protected\def\yquant@register@get@maxxrange#1#2#3{%
+ \begingroup%
+ \dimen0=-16383.99999pt %
+ \yquant@for \yquant@register@get@maxx@i := #2 to #3 {%
+ \dimen2=\yquant@register@get@x{\yquant@register@get@maxx@i}\relax%
+ \ifdim\dimen0<\dimen2 %
+ \dimen0=\dimen2 %
+ \fi%
+ }%
+ \expandafter%
+ \endgroup%
+ \expandafter\def\expandafter#1\expandafter{\the\dimen0}%
+}
+
+% Set #1 to the maximum x value found in the list #2
+\protected\def\yquant@register@get@maxxlist#1#2{%
+ \begingroup%
+ \dimen0=-16383.99999pt %
+ \def\do##1{%
+ \dimen2=\yquant@register@get@x{##1}\relax%
+ \ifdim\dimen0<\dimen2 %
+ \dimen0=\dimen2 %
+ \fi%
+ }%
+ \dolistloop{#2}%
+ \expandafter%
+ \endgroup%
+ \expandafter\def\expandafter#1\expandafter{\the\dimen0}%
+}
+% END_FOLD
+
+% BEGIN_FOLD Setters: change register information
+\protected\long\def\yquant@register@set@@aux#1#2#3{%
+ \long\xdef#1{\expandafter#2#1{#3}}%
+}
+
+\protected\def\yquant@register@set@type#1{%
+ \expandafter\yquant@register@set@@aux%
+ \csname\yquant@prefix register@#1\endcsname\yquant@register@set@type@aux%
+}
+
+\long\def\yquant@register@set@type@aux#1#2#3#4#5{%
+ {#5}{#2}{#3}{#4}%
+}
+
+\protected\def\yquant@register@set@x#1{%
+ \expandafter\yquant@register@set@@aux%
+ \csname\yquant@prefix register@#1\endcsname\yquant@register@set@x@aux%
+}
+
+\long\def\yquant@register@set@x@aux#1#2#3#4#5{%
+ {#1}{#5}{#3}{#4}%
+}
+
+\protected\def\yquant@register@update@height#1#2{%
+ \ifdim#2>\yquant@register@get@height{#1} %
+ \expandafter\yquant@register@set@@aux%
+ \csname\yquant@prefix register@#1\endcsname\yquant@register@set@height@aux{#2}%
+ \fi%
+}
+
+\protected\def\yquant@register@set@y#1{%
+ \expandafter\yquant@register@set@@aux%
+ \csname\yquant@prefix register@#1\endcsname\yquant@register@set@height@aux%
+}
+
+% Set the currently used register
+\protected\def\yquant@register@use#1{%
+ \edef\yquant@register@y{\yquant@register@get@y{#1}}%
+}
+
+\long\def\yquant@register@set@height@aux#1#2#3#4#5{%
+ {#1}{#2}{#5}{#4}%
+}
+
+\protected\def\yquant@register@set@lastwire#1{%
+ \expandafter\yquant@register@set@@aux%
+ \csname\yquant@prefix register@#1\endcsname\yquant@register@set@lastwire@aux%
+}
+
+\long\def\yquant@register@set@lastwire@aux#1#2#3#4#5{%
+ {#1}{#2}{#3}{#5}%
+}
+% END_FOLD \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-shapes.tex b/Master/texmf-dist/tex/latex/yquant/yquant-shapes.tex
new file mode 100644
index 00000000000..0f88ed63450
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-shapes.tex
@@ -0,0 +1,614 @@
+% To draw the wires, we need to determine border angles. However, pgf's approach for this (giving the border point that lies on a line from the center to a desired probe point) is not suitable for this. Instead, we need to give a point that is projected perpendicularly onto the shape.
+\def\pgf@sh@anchorxproj#1{%
+ \csgdef{pgf@anchor@\pgf@sm@shape@name @xproj}##1{\pgf@process{##1}#1}%
+}%
+\def\pgf@sh@inheritanchorxproj[from=#1]{%
+ \global\csletcs{pgf@anchor@\pgf@sm@shape@name @xproj}{pgf@anchor@#1@xproj}%
+}%
+\def\pgf@sh@anchoryproj#1{%
+ \csgdef{pgf@anchor@\pgf@sm@shape@name @yproj}##1{\pgf@process{##1}#1}%
+}%
+\def\pgf@sh@inheritanchoryproj[from=#1]{%
+ \global\csletcs{pgf@anchor@\pgf@sm@shape@name @yproj}{pgf@anchor@#1@yproj}%
+}%
+\patchcmd%
+ \pgfdeclareshape%
+ {\let\anchorborder=\pgf@sh@anchorborder}%
+ {\let\anchorborder=\pgf@sh@anchorborder%
+ \let\anchorxproj=\pgf@sh@anchorxproj%
+ \let\inheritanchorxproj=\pgf@sh@inheritanchorxproj
+ \let\anchoryproj=\pgf@sh@anchoryproj%
+ \let\inheritanchoryproj=\pgf@sh@inheritanchoryproj}%
+ {}%
+ {\PackageError{yquant.sty}%
+ {Failed to patch \string\pgfdeclareshape}%
+ {yquant could not provide a necessary extension to pgf.}}%
+% This is mostly a copy of \pgfpointshapeborder, but we do not perform the center-anchor shift.
+\def\pgfpointshapexproj#1#2{%
+ % Ok, check whether #1 is known!
+ \ifcsname pgf@sh@ns@#1\endcsname%
+ \pgf@process{%
+ \edef\pgfreferencednodename{#1}% for use inside of anchors.
+ % MW install special macros
+ \csname pgf@sh@ma@#1\endcsname% MW
+ % install special coordinates
+ \csname pgf@sh@np@#1\endcsname%
+ \pgf@process{%
+ \pgf@process{\pgfpointtransformed{#2}}%
+ \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
+ \pgftransforminvert%
+ \pgf@pos@transform@glob%
+ \pgf@xa=\pgf@x%
+ \pgf@ya=\pgf@y%
+ \csname pgf@anchor@\csname pgf@sh@ns@#1\endcsname @xproj\endcsname{\pgfqpoint{\pgf@xa}{\pgf@ya}}%
+ \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
+ \pgf@pos@transform@glob%
+ }%
+ % Add inter picture transformation
+ \pgf@shape@interpictureshift{#1}%
+ % Undo current transformation
+ \pgftransforminvert%
+ \pgf@pos@transform@glob%
+ }%
+ \else%
+ \pgferror{No shape named #1 is known}%
+ \pgfpointorigin%
+ \fi%
+}%
+\def\ifpgfpointshapexproj#1{%
+ \pgfutil@ifundefined{pgf@sh@ns@#1}%
+ {\pgferror{No shape named #1 is known}}%
+ {\ifcsname pgf@anchor@\csname pgf@sh@ns@#1\endcsname @xproj\endcsname}%
+}
+\let\pgfpointshapeyproj=\pgfpointshapexproj%
+\patchcmd%
+ \pgfpointshapeyproj%
+ {xproj}{yproj}%
+ {}{\PackageError{yquant.sty}{Failed to provide \string\pgfpointshapeyproj}{}}%
+\def\ifpgfpointshapeyproj#1{%
+ \pgfutil@ifundefined{pgf@sh@ns@#1}%
+ {\pgferror{No shape named #1 is known}}%
+ {\ifcsname pgf@anchor@\csname pgf@sh@ns@#1\endcsname @yproj\endcsname}%
+}
+
+% Calculate the intersection of an ellipse centered at the origin with radii #1 and #2 with a horizontal line at position #3. Result goes to \pgf@xa, and it is the right intersection point.
+\protected\def\yquant@shape@ellipse@xfromy#1#2#3{%
+ \ifdim#3>#2\relax%
+ \global\pgf@xa=0pt %
+ \else%
+ \ifdim-\dimexpr#3\relax>#2\relax%
+ \global\pgf@xa=0pt %
+ \else%
+ \begingroup%
+ % Here, we essentially do #1*sqrt(1-(#3/#2)^2)
+ \dimen2=#2\relax%
+ \dimen3=#3\relax%
+ % if we divide by a dimension, it is internally converted to sp, so we divide by its pt-value and again by 65536. Same for multiplication. etex fuses muldiv to 64bit, so we don't get overflows.
+ % calculate the sqrt; but \pgfmathsqrt@ expects a real number without dimension suffix. It internally does \expandafter\pgfmath@x#1pt\relax, so just gobble the additional pt.
+ % TODO: is there a better way, exploiting perhaps a representation in sp?
+ \pgfmathsqrt@{\the\dimexpr1pt-\dimen3*\dimen3/\dimen2*65536/\dimen2\relax%
+ \@gobbletwo}%
+ \global\pgf@xa=\pgfmathresult\dimexpr#1\relax%
+ \endgroup%
+ \fi%
+ \fi%
+}
+
+\pgfdeclareshape{yquant-text}{%
+ \inheritsavedanchors[from=rectangle]%
+ \foreach \anc in {center, mid, base, north, south, west, mid west, base west, north west, south west, east, mid east, base east, north east, south east} {%
+ \inheritanchor[from=rectangle]{\anc}%
+ }%
+ \global\cslet{pgf@anchor@yquant-text@circuit}\pgf@anchor@rectangle@center%
+ \inheritanchorborder[from=rectangle]%
+ \inheritbackgroundpath[from=rectangle]%
+ \anchorxproj{%
+ \pgf@xa=\pgf@x%
+ \pgf@ya=\pgf@y%
+ % The origin is at the left baseline of the text, i.e. to the left we have the inner + outer xsep, the the right there's the text + inner + outer xsep.
+ \northeast%
+ \pgf@xb=.5\pgf@x%
+ \southwest%
+ \advance \pgf@xb by .5\pgf@x%
+ \ifdim\pgf@xa>\pgf@xb%
+ % to the right
+ \northeast%
+ % else we already called \southwest
+ \fi%
+ \pgf@y=\pgf@ya%
+ }%
+ \anchoryproj{%
+ \pgf@xa=\pgf@x%
+ \pgf@ya=\pgf@y%
+ % The origin is at the left baseline of the text, i.e. to the top we have the text height + inner + outer ysep, the the bottom there's the text depth + inner + outer ysep.
+ \northeast%
+ \pgf@yb=.5\pgf@y%
+ \southwest%
+ \advance \pgf@yb by .5\pgf@y%
+ \ifdim\pgf@ya>\pgf@yb%
+ % to the top
+ \northeast%
+ % else we already called \southwest
+ \fi%
+ \pgf@x=\pgf@xa%
+ }
+}
+
+\pgfdeclareshape{yquant-rectangle}{%
+ % BEGIN_FOLD Saved anchors
+ \saveddimen\xradius{%
+ \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/x radius}}%
+ \ifdim\wd\pgfnodeparttextbox=0pt %
+ \pgf@xa=0pt %
+ \else%
+ \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner xsep}}%
+ \fi%
+ \ifdim\dimexpr.5\wd\pgfnodeparttextbox+\pgf@xa\relax>\pgf@x%
+ \pgf@x=\dimexpr.5\wd\pgfnodeparttextbox+\pgf@xa\relax%
+ \fi%
+ }%
+ \saveddimen\yradius{%
+ \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/y radius}}%
+ \ifdim\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox\relax=0pt %
+ \pgf@xa=0pt %
+ \else%
+ \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner ysep}}%
+ \fi%
+ \@tempdima=\dimexpr.5\ht\pgfnodeparttextbox+.5\dp\pgfnodeparttextbox+\pgf@xa\relax%
+ \ifdim\@tempdima>\pgf@x%
+ \pgf@x=\@tempdima%
+ \fi%
+ }%
+ \savedanchor\stext{%
+ \pgfqpoint%
+ {-.5\wd\pgfnodeparttextbox}%
+ {-\dimexpr.5\ht\pgfnodeparttextbox-.5\dp\pgfnodeparttextbox\relax}%
+ }%
+ % END_FOLD
+ % BEGIN_FOLD Operator anchors
+ \global\cslet{pgf@anchor@yquant-rectangle@center}\pgfpointorigin%
+ \anchor{text}{\stext}%
+ \anchor{north}%
+ {\pgfqpoint{0pt}%
+ {\yradius}}%
+ \anchor{north east}%
+ {\pgfqpoint{\xradius}%
+ {\yradius}}%
+ \anchor{east}%
+ {\pgfqpoint{\xradius}%
+ {0pt}}%
+ \anchor{south east}%
+ {\pgfqpoint{\xradius}%
+ {-\yradius}}%
+ \anchor{south}%
+ {\pgfqpoint{0pt}%
+ {-\yradius}}%
+ \anchor{south west}%
+ {\pgfqpoint{-\xradius}%
+ {-\yradius}}%
+ \anchor{west}%
+ {\pgfqpoint{-\xradius}% \dimexpr not really necessary...
+ {0pt}}%
+ \anchor{north west}%
+ {\pgfqpoint{-\xradius}%
+ {\yradius}}%
+ \anchorborder{%
+ \@tempdima=\pgf@x%
+ \@tempdimb=\pgf@y%
+ \pgfpointborderrectangle{\pgfqpoint{\@tempdima}{\@tempdimb}}%
+ {\pgfqpoint{\xradius}{\yradius}}%
+ }%
+ \anchorxproj{%
+ \ifdim\pgf@x>0pt %
+ % to the right
+ \pgf@x=\xradius\relax%
+ \else%
+ % to the left
+ \pgf@x=-\xradius\relax%
+ \fi%
+ }%
+ \anchoryproj{%
+ \ifdim\pgf@y>0pt %
+ % to the top
+ \pgf@y=\yradius\relax%
+ \else%
+ % to the bottom
+ \pgf@y=-\yradius\relax%
+ \fi%
+ }%
+ % END_FOLD
+ % BEGIN_FOLD Circuit-related anchors
+ \global\csletcs{pgf@anchor@yquant-rectangle@circuit}%
+ {pgf@anchor@yquant-rectangle@center}%
+ % END_FOLD
+ % BEGIN_FOLD Path
+ \backgroundpath{%
+ \pgfpathrectanglecorners%
+ {\pgfqpoint{-\xradius}{\yradius}}%
+ {\pgfqpoint{\xradius}{-\yradius}}%
+ }%
+ % END_FOLD
+}
+
+\pgfdeclareshape{yquant-circle}{%
+ \inheritsavedanchors[from=yquant-rectangle]%
+ \foreach \anc in {center, north, east, south, west, circuit, text} {%
+ \inheritanchor[from=yquant-rectangle]{\anc}%
+ }%
+ \anchor{north east}%
+ {\pgfqpoint{.707107\dimexpr\xradius\relax}%
+ {.707107\dimexpr\yradius\relax}}%
+ \anchor{south east}%
+ {\pgfqpoint{.707107\dimexpr\xradius\relax}%
+ {-.707107\dimexpr\yradius\relax}}%
+ \anchor{south west}%
+ {\pgfqpoint{-.707107\dimexpr\xradius\relax}%
+ {-.707107\dimexpr\yradius\relax}}%
+ \anchor{north west}%
+ {\pgfqpoint{-.707107\dimexpr\xradius\relax}%
+ {.707107\dimexpr\yradius\relax}}%
+ \anchorborder{%
+ \@tempdima=\pgf@x%
+ \@tempdimb=\pgf@y%
+ \pgfpointborderellipse{\pgfqpoint{\@tempdima}{\@tempdimb}}%
+ {\pgfqpoint{.707107\dimexpr\xradius\relax}%
+ {.707107\dimexpr\yradius\relax}}%
+ }%
+ \anchorxproj{%
+ \yquant@shape@ellipse@xfromy\xradius\yradius\pgf@y%
+ \ifdim\pgf@x>0pt %
+ % to the right
+ \pgf@x=\pgf@xa%
+ \else%
+ % to the left
+ \pgf@x=-\pgf@xa%
+ \fi%
+ }%
+ \anchoryproj{%
+ \yquant@shape@ellipse@xfromy\yradius\xradius\pgf@x%
+ \ifdim\pgf@y>0pt %
+ % to the top
+ \pgf@y=\pgf@xa%
+ \else%
+ % to the bottom
+ \pgf@y=-\pgf@xa%
+ \fi%
+ }%
+ \foregroundpath{%
+ \pgfpathellipse{\pgfpointorigin}%
+ {\pgfqpoint{\xradius}{0pt}}%
+ {\pgfqpoint{0pt}{\yradius}}%
+ }%
+}
+
+\pgfdeclareshape{yquant-zz}{%
+ % Here, the radii have a special meaning, we don't put text into the shape
+ \saveddimen\xradius{%
+ \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/x radius}}%
+ }%
+ \saveddimen\yradius{%
+ \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/y radius}}%
+ }%
+ \foreach \anc in {center, north, east, south, west, circuit} {%
+ \inheritanchor[from=yquant-circle]{\anc}%
+ }%
+ \anchor{north east}%
+ {\pgfqpoint{.707107\dimexpr\xradius\relax}%
+ {\dimexpr\yradius-.292893\dimexpr\xradius\relax\relax}}%
+ \anchor{south east}%
+ {\pgfqpoint{.707107\dimexpr\xradius\relax}%
+ {\dimexpr-\yradius+.292893\dimexpr\xradius\relax\relax}}%
+ \anchor{south west}%
+ {\pgfqpoint{-.707107\dimexpr\xradius\relax}%
+ {\dimexpr-\yradius+.292893\dimexpr\xradius\relax\relax}}%
+ \anchor{north west}%
+ {\pgfqpoint{-.707107\dimexpr\xradius\relax}%
+ {\dimexpr\yradius-.292893\dimexpr\xradius\relax\relax}}%
+ % TODO: this is not really the correct border anchor
+ \inheritanchorborder[from=yquant-rectangle]%
+ \anchorxproj{%
+ \ifdim\pgf@y<0pt %
+ \pgf@ya=\dimexpr\pgf@y+\yradius-\xradius\relax%
+ \else%
+ \pgf@ya=\dimexpr\pgf@y-\yradius+\xradius\relax%
+ \fi%
+ \yquant@shape@ellipse@xfromy\xradius\xradius\pgf@ya%
+ \ifdim\pgf@x>0pt %
+ % to the right
+ \pgf@x=\pgf@xa%
+ \else%
+ % to the left
+ \pgf@x=-\pgf@xa%
+ \fi%
+ }%
+ \anchoryproj{%
+ \yquant@shape@ellipse@xfromy\xradius\xradius\pgf@xa%
+ \ifdim\pgf@y>0pt %
+ % to the top
+ \pgf@y=\dimexpr\yradius-\xradius+\pgf@xa\relax%
+ \else%
+ % to the bottom
+ \pgf@y=-\dimexpr\yradius-\xradius+\pgf@xa\relax%
+ \fi%
+ }%
+ \backgroundpath{%
+ \pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
+ \pgfpathlineto{\pgfqpoint{0pt}{-\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
+ \pgfpathcircle{\pgfqpoint{0pt}{\dimexpr\yradius-\xradius\relax}}%
+ {\xradius}%
+ \pgfpathcircle{\pgfqpoint{0pt}{\dimexpr\xradius-\yradius\relax}}%
+ {\xradius}%
+ }%
+}
+
+\pgfdeclareshape{yquant-xx}{%
+ \inheritsavedanchors[from=yquant-zz]%
+ \savedmacro\ifconnector{%
+ \let\ifconnector=\ifyquant@config@multi@line%
+ }%
+ \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
+ \inheritanchor[from=yquant-rectangle]{\anc}%
+ }%
+ % TODO: this is not really the correct border anchor
+ \inheritanchorborder[from=yquant-rectangle]%
+ \inheritanchorxproj[from=yquant-rectangle]%
+ \inheritanchoryproj[from=yquant-rectangle]%
+ % Draw the operator itself
+ \backgroundpath{%
+ \ifconnector%
+ \pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
+ \pgfpathlineto{\pgfqpoint{0pt}{-\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
+ \fi%
+ \pgfpathrectanglecorners%
+ {\pgfqpoint{-\xradius}{\dimexpr\yradius\relax}}%
+ {\pgfqpoint{\xradius}{\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
+ \pgfpathrectanglecorners%
+ {\pgfqpoint{-\xradius}{-\yradius}}%
+ {\pgfqpoint{\xradius}{-\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
+ }%
+}
+
+\pgfdeclareshape{yquant-slash}{%
+ \inheritsavedanchors[from=yquant-zz]%
+ \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
+ \inheritanchor[from=yquant-rectangle]{\anc}%
+ }%
+ \inheritanchorborder[from=yquant-rectangle]%
+ \backgroundpath{%
+ \pgfpathmoveto{\pgfqpoint{\xradius}{\yradius}}%
+ \pgfpathlineto{\pgfqpoint{-\xradius}{-\yradius}}%
+ }%
+}
+
+\pgfdeclareshape{yquant-swap}{%
+ \inheritsavedanchors[from=yquant-xx]%
+ \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
+ \inheritanchor[from=yquant-rectangle]{\anc}%
+ }%
+ \inheritanchorborder[from=yquant-rectangle]%
+ \inheritanchoryproj[from=yquant-rectangle]%
+ \backgroundpath{%
+ % Connector
+ \ifconnector%
+ \pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr\yradius-\xradius\relax}}%
+ \pgfpathlineto{\pgfqpoint{0pt}{-\dimexpr\yradius-\xradius\relax}}%
+ \fi%
+ % Upper cross
+ \pgfpathmoveto{\pgfqpoint{-\xradius}{\yradius}}%
+ \pgfpathlineto{\pgfqpoint{\xradius}%
+ {\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
+ \pgfpathmoveto{\pgfqpoint{\xradius}{\yradius}}%
+ \pgfpathlineto{\pgfqpoint{-\xradius}
+ {\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
+ % Lower cross
+ \pgfpathmoveto{\pgfqpoint{-\xradius}%
+ {-\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
+ \pgfpathlineto{\pgfqpoint{\xradius}{-\yradius}}%
+ \pgfpathmoveto{\pgfqpoint{\xradius}%
+ {-\dimexpr\yradius-2\dimexpr\xradius\relax\relax}}%
+ \pgfpathlineto{\pgfqpoint{-\xradius}{-\yradius}}%
+ }%
+}
+
+\pgfdeclareshape{yquant-oplus}{%
+ \inheritsavedanchors[from=yquant-zz]%
+ \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
+ \inheritanchor[from=yquant-circle]{\anc}%
+ }%
+ \inheritanchorborder[from=yquant-circle]%
+ \inheritanchorxproj[from=yquant-circle]%
+ \inheritanchoryproj[from=yquant-circle]%
+ \backgroundpath{%
+ \pgfpathmoveto{\pgfqpoint{0pt}{\yradius}}%
+ \pgfpathlineto{\pgfqpoint{0pt}{-\yradius}}%
+ \pgfpathmoveto{\pgfqpoint{-\xradius}{0pt}}%
+ \pgfpathlineto{\pgfqpoint{\xradius}{0pt}}%
+ \pgfpathellipse{\pgfpointorigin}%
+ {\pgfqpoint{\xradius}{0pt}}%
+ {\pgfqpoint{0pt}{\yradius}}%
+ }%
+}
+
+\pgfdeclareshape{yquant-measure}{%
+ \saveddimen\xradius{%
+ \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/x radius}}%
+ \ifdim.5\wd\pgfnodeparttextbox>\pgf@x%
+ \pgf@x=.5\wd\pgfnodeparttextbox%
+ \fi%
+ }%
+ \saveddimen\yradius{%
+ \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/y radius}}%
+ \ifdim\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox\relax=0pt %
+ \ifdim\pgf@x<1.25mm %
+ \pgf@x=1.25mm %
+ \fi%
+ \else%
+ % We need the 2.3mm for the meter sign, the height of the text plus a minimum separation of 2pt
+ \pgf@y=.5\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox+2.3mm+4pt\relax%
+ \ifdim\pgf@x<\pgf@y%
+ \pgf@x=\pgf@y%
+ \fi%
+ \fi%
+ }%
+ \savedanchor\stext{%
+ \pgfqpoint%
+ {-.5\wd\pgfnodeparttextbox}%
+ {\dp\pgfnodeparttextbox}%
+ }%
+ \saveddimen\textheight{%
+ \pgf@x=\ht\pgfnodeparttextbox%
+ }
+ \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
+ \inheritanchor[from=yquant-rectangle]{\anc}%
+ }%
+ \anchor{text}{%
+ \stext%
+ \pgf@y=\dimexpr-\yradius+1pt+\pgf@y\relax%
+ }%
+ \inheritanchorborder[from=yquant-rectangle]%
+ \inheritanchorxproj[from=yquant-rectangle]%
+ \inheritanchoryproj[from=yquant-rectangle]%
+ \backgroundpath{%
+ \pgfpathrectanglecorners%
+ {\pgfqpoint{-\xradius}{\yradius}}%
+ {\pgfqpoint{\xradius}{-\yradius}}%
+ }
+ \beforebackgroundpath{%
+ % Make sure the meter does not extend beyond the box (we are in a scope here)
+ \path [clip]
+ (-\xradius, \yradius) rectangle (\xradius, -\yradius);%
+ % The position of the meter symbol depends on the presence of the text. If there is no text, we just vertically center. If there is some text, we shift the symbol upwards from the text until there is no overlap any more.
+ \csname pgf@anchor@yquant-measure@text\endcsname%
+ \advance\pgf@y by \textheight\relax%
+ \ifdim\pgf@y<-1.15mm %
+ \@tempdima=-1.15mm %
+ \else%
+ \@tempdima=\dimexpr\pgf@y+2pt\relax%
+ \fi%
+ \path [/yquant/operators/every measure meter]
+ (-2.25mm, \@tempdima) arc[start angle=160, end angle=20,%
+ x radius=2.25mm, y radius=1.4mm]
+ (0, \@tempdima) -- ++(1.6mm, 2.3mm);
+ }%
+}
+
+\pgfdeclareshape{yquant-dmeter}{%
+ \saveddimen\xradius{%
+ \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/x radius}}%
+ \ifdim\wd\pgfnodeparttextbox=0pt %
+ \pgf@xa=0pt %
+ \else%
+ \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner xsep}+.5mm}%
+ \fi%
+ \ifdim\dimexpr.5\wd\pgfnodeparttextbox+\pgf@xa\relax>\pgf@x%
+ \pgf@x=\dimexpr.5\wd\pgfnodeparttextbox+\pgf@xa\relax%
+ \fi%
+ }%
+ \saveddimen\yradius{%
+ \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/y radius}}%
+ \ifdim\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox\relax=0pt %
+ \pgf@xa=0pt %
+ \else%
+ \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner ysep}}%
+ \fi%
+ \@tempdima=\dimexpr.5\ht\pgfnodeparttextbox+.5\dp\pgfnodeparttextbox+\pgf@xa\relax%
+ \ifdim\@tempdima>\pgf@x%
+ \pgf@x=\@tempdima%
+ \fi%
+ }%
+ \savedanchor\stext{%
+ \pgfqpoint%
+ {-\dimexpr.5\wd\pgfnodeparttextbox+1mm\relax}%
+ {-\dimexpr.5\ht\pgfnodeparttextbox-.5\dp\pgfnodeparttextbox\relax}%
+ }%
+ \foreach \anc in {center, north, south, south west, west, north west, circuit, text} {%
+ \inheritanchor[from=yquant-rectangle]{\anc}%
+ }%
+ \foreach \anc in {north east, east, south east} {%
+ \inheritanchor[from=yquant-circle]{\anc}%
+ }%
+% \anchor{text}{%
+% \stext%
+% \pgf@x=-.5\dimexpr\xradius-\pgf@x\relax%
+% }%
+ \anchorborder{%
+ \@tempdima=\pgf@x%
+ \@tempdimb=\pgf@y%
+ \ifdim\pgf@x>\dimexpr\xradius-3mm\relax%
+ \pgfpointborderellipse{\pgfqpoint{\dimexpr\@tempdima-\xradius+3mm\relax}%
+ {\@tempdimb}}%
+ {\pgfqpoint{3mm}%
+ {.707107\dimexpr\yradius\relax}}%
+ \advance\pgf@x by \dimexpr\xradius-3mm\relax%
+ \else%
+ \pgfpointborderrectangle{\pgfqpoint{\@tempdima}{\@tempdimb}}%
+ {\pgfqpoint{\xradius}{\yradius}}%
+ \fi%
+ }%
+ \anchorxproj{%
+ \ifdim\pgf@x>\dimexpr\xradius-3mm\relax%
+ % to the right
+ \advance\pgf@x by -\dimexpr\xradius-3mm\relax%
+ \yquant@shape@ellipse@xfromy{3mm}\yradius\pgf@y%
+ \pgf@x=\dimexpr\pgf@xa+\xradius-3mm\relax%
+ \else%
+ % to the left
+ \pgf@x=-\xradius\relax%
+ \fi%
+ }%
+ \anchoryproj{%
+ \ifdim\pgf@x>\dimexpr\xradius-3mm\relax%
+ % to the right
+ \advance\pgf@x by -\dimexpr\xradius-3mm\relax%
+ \yquant@shape@ellipse@xfromy\yradius{3mm}\pgf@x%
+ \advance\pgf@x by \dimexpr\xradius-3mm\relax%
+ \ifdim\pgf@y>0pt %
+ % to the top
+ \pgf@y=\pgf@xa%
+ \else%
+ % to the bottom
+ \pgf@y=-\pgf@xa%
+ \fi%
+ \else%
+ % to the left
+ \ifdim\pgf@y>0pt %
+ % to the top
+ \pgf@y=\yradius\relax%
+ \else%
+ \pgf@y=-\yradius\relax%
+ \fi%
+ \fi%
+ }%
+ \backgroundpath{%
+ \pgfpathmoveto{\pgfqpoint{-\xradius}{\yradius}}%
+ \pgfpathlineto{\pgfqpoint{\dimexpr\xradius-3mm\relax}{\yradius}}%
+ \pgfpatharc{90}{-90}{3mm and \yradius}%
+ \pgfpathlineto{\pgfqpoint{-\xradius}{-\yradius}}%
+ \pgfpathclose%
+ }%
+}
+
+\pgfdeclareshape{yquant-barrier}{%
+ % Here, the radii have a special meaning, we don't put text into the shape
+ \saveddimen\xradius{%
+ \pgf@x=.5\pgflinewidth%
+ }%
+ \savedanchor\shorten{%
+ \pgfqpoint\pgf@shorten@end@additional\pgf@shorten@start@additional%
+ }%
+ \saveddimen\yradius{%
+ \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/tikz/y radius}+.5*\yquant@config@register@sep}%
+ }%
+ \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
+ \inheritanchor[from=yquant-rectangle]{\anc}%
+ }%
+ \inheritanchorborder[from=yquant-rectangle]%
+ \backgroundpath{%
+ \pgfsetlinewidth{\xradius}%
+ \shorten%
+ \pgf@xa=\dimexpr\yradius+\pgf@x\relax%
+ \pgf@ya=\dimexpr\yradius+\pgf@y\relax%
+ \pgfpathmoveto{\pgfqpoint{0pt}{\pgf@xa}}%
+ \pgfpathlineto{\pgfqpoint{0pt}{-\pgf@ya}}%
+ }%
+} \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex b/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex
new file mode 100644
index 00000000000..15d3c328aad
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex
@@ -0,0 +1,265 @@
+% from TeXbook, appendix D
+\protected\def\yquant@futurenonspacelet#1{%
+ \def\yquant@futurenonspacelet@cs{#1}%
+ \afterassignment\yquant@futurenonspacelet@i\let\yquant@futurenonspacelet@next= %
+}
+
+\def\yquant@futurenonspacelet@i{%
+ \expandafter\futurelet\yquant@futurenonspacelet@cs\yquant@futurenonspacelet@ii%
+}
+
+\def\yquant@futurenonspacelet@ii{%
+ \expandafter\ifx\yquant@futurenonspacelet@cs\@sptoken%
+ \expandafter\yquant@futurenonspacelet@iii%
+ \else%
+ \expandafter\yquant@futurenonspacelet@next%
+ \fi%
+}
+
+\def\yquant@futurenonspacelet@iii{%
+ \afterassignment\yquant@futurenonspacelet@i%
+ \let\@eattoken= %
+}
+
+% Loop #1 from min(#2, #3) to max(#2, #3), executing #4
+\protected\def\yquant@for #1:=#2to#3#{%
+ \yquant@for@aux#1{#2}{#3}%
+}
+
+\long\def\yquant@for@aux#1#2#3#4{%
+ \ifnum#2<#3\relax%
+ \numdef#1{#2}%
+ % to allow for things like \yquant@for \i := \i to ..., expand the boundaries
+ \expandafter\yquant@for@loop\expandafter#1\expandafter{\the\numexpr#3+1\relax}{#4}%
+ \else%
+ \numdef#1{#3}%
+ \expandafter\yquant@for@loop\expandafter#1\expandafter{\the\numexpr#2+1\relax}{#4}%
+ \fi%
+}
+
+\long\def\yquant@for@loop#1#2#3{%
+ \loop%
+ \ifnum#1<#2\relax%
+ #3%
+ \numdef#1{#1+1}%
+ \repeat%
+}
+
+% Def #1 to be the minimum of #2, ... until \relax
+\protected\def\yquant@min#1{%
+ \def#1{2147483647}%
+ \def\yquant@min@var{#1}%
+ \yquant@min@loop%
+}
+
+\def\yquant@min@loop#1{%
+ \unless\ifx#1\relax\relax%
+ \ifnum#1<\yquant@min@var\relax%
+ \expandafter\edef\yquant@min@var{#1}%
+ \fi%
+ \expandafter\yquant@min@loop%
+ \fi%
+}
+
+% Def #1 to be the maximum of #2, ... until \relax
+\protected\def\yquant@max#1{%
+ \def#1{-2147483647}%
+ \def\yquant@max@var{#1}%
+ \yquant@max@loop%
+}
+
+\def\yquant@max@loop#1{%
+ \unless\ifx#1\relax\relax%
+ \ifnum#1>\yquant@max@var\relax%
+ \expandafter\edef\yquant@max@var{#1}%
+ \fi%
+ \expandafter\yquant@max@loop%
+ \fi%
+}
+
+% Cleanup global tokens after environment
+\protected\def\yquant@cleanup@csadd#1{%
+ \csxappto{\yquant@prefix cleanup}{\expandafter\noexpand\csname#1\endcsname}%
+}
+
+\def\yquant@cleanup#1#2{%
+ \global\undef#1%
+ \unless\ifx|#2%
+ \expandafter\yquant@cleanup\expandafter#2%
+ \fi%
+}
+
+% Executes #3 if #1 (single token!) is equal (\ifx) to the first token of #2, and #4 else.
+\def\ifyquant@firsttoken#1#2{%
+ % First check whether #2 is present at all...
+ \if\relax\detokenize{#2}\relax%
+ \expandafter\@secondoftwo%
+ \else%
+ \ifyquant@firsttoken@aux#1#2\yquant@sep%
+ \fi%
+}
+
+\def\ifyquant@firsttoken@aux#1#2#3\yquant@sep{%
+ \ifx#1#2%
+ \expandafter\expandafter\expandafter\@firstoftwo%
+ \else%
+ \expandafter\expandafter\expandafter\@secondoftwo%
+ \fi%
+}
+
+% Executes #3 if #1 begins with #2, and #4 else - non-expandable
+\protected\def\ifyquant@beginswith#1#2{%
+ \def\ifyquant@beginswith@##1#2##2\yquant@end{%
+ \if\relax\detokenize{##1}\relax%
+ \expandafter\@firstoftwo%
+ \else%
+ \expandafter\@secondoftwo%
+ \fi%
+ }%
+ \ifyquant@beginswith@#1#2\yquant@end%
+}
+
+% absolute value of a dimension
+\def\yquant@abs#1{%
+ \ifdim#1<0pt %
+ \the\dimexpr-\dimexpr#1\relax\relax%
+ \else%
+ #1%
+ \fi%
+}
+
+% Sortlist related macros.
+\newcount\yquant@sort@count
+
+\protected\def\yquant@sort@clear{%
+ % Probably cleanup used macros?
+ \yquant@sort@count=0 %
+}
+
+\protected\def\yquant@sort@eadd#1{%
+ \csedef{yquant@sort@item\the\yquant@sort@count}{#1}%
+ \advance \yquant@sort@count by 1 %
+}
+
+% Perform quicksort on the stored sortlist.
+% #1: compare macro that expands to ##3 if its second argument is strictly larger than its first or to ##4 else
+\protected\def\yquant@sort#1{%
+ \let\yquant@sort@cmp=#1%
+ \expandafter\yquant@sort@aux\expandafter0\expandafter{\the\numexpr\yquant@sort@count-1\relax}%
+}
+
+\protected\def\yquant@sort@aux#1#2{%
+ \ifnum#1<#2\relax%
+ \yquant@sort@divide{#1}{#2}%
+ \edef\cmd{%
+ \noexpand\yquant@sort@aux{#1}{\the\numexpr\count0-1\relax}%
+ \noexpand\yquant@sort@aux{\the\numexpr\count0+1\relax}{#2}%
+ }%
+ \cmd%
+ \fi%
+}
+
+\protected\def\yquant@sort@divide#1#2{%
+ \count0=#1\relax% i
+ \count2=#2\relax% j
+ \advance\count2 by -1 %
+ \letcs\yquant@sort@pivot{yquant@sort@item#2}%
+ \loop%
+ % search an item from the left that is larger or equal to the pivot
+ {% protect the outer loop from finding \repeat
+ \csletcs{next}{iftrue}%
+ \loop%
+ \ifnum\count0<#2\relax%
+ \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\yquant@sort@cmp%
+ \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter{%
+ \expandafter\expandafter\expandafter\yquant@sort@pivot%
+ \expandafter\expandafter\expandafter}%
+ \expandafter\expandafter\expandafter{%
+ \csname yquant@sort@item\the\count0\endcsname%
+ }{%
+ \csletcs{next}{iffalse}%
+ }{%
+ \advance\count0 by 1 %
+ }%
+ \else%
+ \csletcs{next}{iffalse}%
+ \fi%
+ \next%
+ \repeat%
+ \expandafter%
+ }%
+ \expandafter\count\expandafter0\expandafter=\the\count0\relax%
+ % search an item from the right that is small than the pivot
+ {% protect the outer loop from finding \repeat
+ \csletcs{next}{iftrue}%
+ \loop%
+ \ifnum\count2>#1\relax%
+ \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\yquant@sort@cmp%
+ \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter{%
+ \expandafter\expandafter\expandafter\yquant@sort@pivot%
+ \expandafter\expandafter\expandafter}%
+ \expandafter\expandafter\expandafter{%
+ \csname yquant@sort@item\the\count2\endcsname%
+ }{%
+ \advance\count2 by -1 %
+ }{%
+ \csletcs{next}{iffalse}%
+ }%
+ \else%
+ \csletcs{next}{iffalse}%
+ \fi%
+ \next%
+ \repeat%
+ \expandafter
+ }%
+ \expandafter\count\expandafter2\expandafter=\the\count2\relax%
+ \ifnum\count0<\count2 %
+ % swap item i <> item j
+ \letcs\tmp{yquant@sort@item\the\count0}%
+ \csletcs{yquant@sort@item\the\count0}{yquant@sort@item\the\count2}%
+ \cslet{yquant@sort@item\the\count2}\tmp%
+ \fi%
+ \ifnum\count0<\count2 %
+ \repeat%
+ \letcs\tmp{yquant@sort@item\the\count0}%
+ \csletcs{yquant@sort@item\the\count0}{yquant@sort@item#2}%
+ \cslet{yquant@sort@item#2}\tmp%
+}
+
+% Sorts an internal etoolbox list #1 using macro #2
+\protected\def\yquant@sort@list#1#2{%
+ \begingroup%
+ \yquant@sort@count=0 %
+ \def\do##1{%
+ \csdef{yquant@sort@item\the\yquant@sort@count}{##1}%
+ \advance\yquant@sort@count by 1 %
+ }%
+ \dolistloop#1%
+ \yquant@sort#2%
+ \let#1=\empty%
+ \count0=0 %
+ \loop%
+ \ifnum\count0<\yquant@sort@count%
+ \expandafter\expandafter\expandafter\listadd%
+ \expandafter\expandafter\expandafter#1%
+ \expandafter\expandafter\expandafter{%
+ \csname yquant@sort@item\the\count0\endcsname%
+ }%
+ \advance\count0 by 1 %
+ \repeat%
+ \expandafter%
+ \endgroup%
+ \expandafter\def\expandafter#1\expandafter{#1}%
+}
+
+\protected\def\yquant@sort@dolistloop{%
+ \count0=0 %
+ \loop%
+ \ifnum\count0<\yquant@sort@count%
+ \expandafter\expandafter\expandafter\do%
+ \expandafter\expandafter\expandafter{%
+ \csname yquant@sort@item\the\count0\endcsname%
+ }
+ \advance\count0 by 1 %
+ \repeat%
+} \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant.sty b/Master/texmf-dist/tex/latex/yquant/yquant.sty
new file mode 100644
index 00000000000..25c0873b70e
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/yquant/yquant.sty
@@ -0,0 +1,40 @@
+% yquant.sty
+% Typesetting quantum circuits using a flow-oriented language
+%
+% Copyright 2019-2020 Benjamin Desef
+%
+% This work may be distributed and/or modified under the conditions of the LaTeX Project
+% Public License, either version 1.3 of this license or (at your option) any later
+% version.
+% The latest version of this license is in
+% http://www.latex-project.org/lppl.txt
+% and version 1.3 or later is part of all distributions of LaTeX version 2005/12/01 or
+% later.
+%
+% This work has the LPPL maintenance status `maintained'.
+%
+% The Current Maintainer of this work is Benjamin Desef.
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{yquant}[2020/03/22 v0.1.1 Yet another quantum circuit library for LaTeX]
+
+\RequirePackage{etoolbox}[2018/02/11]
+\RequirePackage{tikz}[2015/08/29]
+\RequirePackage{trimspaces}[2009/09/17]
+\usetikzlibrary{arrows.meta}
+
+\input yquant-config.tex
+\input yquant-tools.tex
+\input yquant-registers.tex
+\input yquant-env.tex
+\input yquant-langhelper.tex
+\input yquant-circuit.tex
+\input yquant-draw.tex
+\input yquant-shapes.tex
+\input yquant-lang.tex
+
+% usually, \\ is robust; but when using \centering, it is \let to \@centercr, which is not robust (probably because this happens only when not protecting). Fix this, so that \\ does not require \protect if a centered circuit is drawn.
+\robustify\@centercr
+
+\endinput
+%%
+%% End of file `yquant.sty'. \ No newline at end of file