summaryrefslogtreecommitdiff
path: root/Master/texmf-dist
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2020-04-14 21:06:44 +0000
committerKarl Berry <karl@freefriends.org>2020-04-14 21:06:44 +0000
commitbbe9e3a2874a81d4559603fc57aa37a0f53ae4bb (patch)
tree3b44a4b917247d46f8b79043e2a2774a9e118d3c /Master/texmf-dist
parent70ceb95a32e274762041dec44d43760f70c2dd31 (diff)
yquant (14apr20)
git-svn-id: svn://tug.org/texlive/trunk@54737 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r--Master/texmf-dist/doc/latex/yquant/README.md3
-rw-r--r--Master/texmf-dist/doc/latex/yquant/yquant-doc.pdfbin467903 -> 512339 bytes
-rw-r--r--Master/texmf-dist/doc/latex/yquant/yquant-doc.tex342
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex304
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-config.tex188
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-draw.tex410
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-env.tex8
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-lang.tex151
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-langhelper.tex16
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-registers.tex365
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-shapes.tex610
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-tools.tex41
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant.sty8
13 files changed, 1584 insertions, 862 deletions
diff --git a/Master/texmf-dist/doc/latex/yquant/README.md b/Master/texmf-dist/doc/latex/yquant/README.md
index b7ba3384605..56a8428524a 100644
--- a/Master/texmf-dist/doc/latex/yquant/README.md
+++ b/Master/texmf-dist/doc/latex/yquant/README.md
@@ -7,6 +7,9 @@ It builds on and interacts with TiKZ, which brings an enourmous flexibility for
A detailed reference with lots of examples is provided in the PDF version of this Readme. We will sketch some basic usage.
+## License
+This material is subject to the LaTeX Project Public License 1.3.
+
## Examples
Many more examples and explanations can be found in the [PDF version](https://github.com/projekter/yquant/raw/master/doc/latex/yquant/yquant-doc.pdf) of this Readme.
diff --git a/Master/texmf-dist/doc/latex/yquant/yquant-doc.pdf b/Master/texmf-dist/doc/latex/yquant/yquant-doc.pdf
index 3c129f135fb..16dca0f393a 100644
--- a/Master/texmf-dist/doc/latex/yquant/yquant-doc.pdf
+++ b/Master/texmf-dist/doc/latex/yquant/yquant-doc.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/yquant/yquant-doc.tex b/Master/texmf-dist/doc/latex/yquant/yquant-doc.tex
index 856ac5b6911..64552784306 100644
--- a/Master/texmf-dist/doc/latex/yquant/yquant-doc.tex
+++ b/Master/texmf-dist/doc/latex/yquant/yquant-doc.tex
@@ -117,16 +117,16 @@
\begingroup%
\setlength{\parskip}{0pt}%
\setlength{\parindent}{0pt}%
- \if\relax\detokenize{#5}\relax%
+ \ifstrempty{#5}{%
\begin{mdframed}[style=bdBox, backgroundcolor=#4, linecolor=#2,
firstextra=\bd@boxextra{#1}, singleextra=\bd@boxextra{#1}]%
- \else%
+ }{%
\begin{mdframed}[style=bdBox, backgroundcolor=#4,
frametitlefont=\bfseries\sffamily\color{#3},
frametitlebackgroundcolor=#2,
frametitle={\strut#5}, linecolor=#2,
firstextra=\bd@boxextra{#1}, singleextra=\bd@boxextra{#1}]%
- \fi%
+ }%
\ignorespaces%
}
\def\bd@boxoutro{%
@@ -197,7 +197,7 @@
This document outlines the scope and usage of the \Yquant{} package.
It contains both a reference and a huge number of examples.
\Yquant{} is a package that makes typesetting quantum circuits easy; the package is not yet available on CTAN.
- This alpha version~0.1.1 \emph{should} be stable and interfaces are not very likely to change in an incompatible way in the future.
+ This alpha version~0.1.2 \emph{should} be stable and interfaces are not very likely to change in an incompatible way in the future.
Please do report all issues and desirable additions.
\subsection{How to read the manual}
@@ -256,12 +256,12 @@
\end{itemize}
\subsection{License}
- 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.
+ This work may be distributed and/or modified under the conditions of the \LaTeX{} Project Public License, either version~1.3c of this license or (at your option) any later version.
The latest version of this license is in
\begin{center}
\url{http://www.latex-project.org/lppl.txt}
\end{center}
- and version~1.3 or later is part of all distributions of LaTeX version 2005/12/01 or later.
+ and version~1.3c or later is part of all distributions of LaTeX version 2005/12/01 or later.
\section{Basic elements of \Yquant}\label{sec:grammar}
\Yquant, as some of the aforementioned packages, builds on \TikZ.
@@ -291,7 +291,9 @@
\begin{warning}[Optional arguments]
The optional arguments for the \tex!yquant! environment have to appear \emph{on the same line} as the environment itself.
If you want to put the arguments into a new line, it is crucial to mask the line break by putting a comment symbol after the environment: \tex!\begin{yquant}%!.
- Without this comment, \Yquant{} will detect your line break (this is one of the few places in \TeX{} where line breaks and spaces are different) and assume that the expression in square brackets instead provides arguments for the following operation!
+ Without this comment, \Yquant{} will detect your line break (this is one of the few places in \TeX{} where line breaks and spaces are different) and assume that the expression in square brackets instead provides arguments for the following operation! \\
+ Finally note that in (non\hyp fragile) \texttt{beamer} frames, this discrimination between spaces and new lines does not work; the optional arguments will always be counted for the environment, not for the gate.
+ In this case, you can either declare the frame as fragile or (recommended) introduce a blank line between the environment and the options for the first gate.
\end{warning}
\subsection{Starred vs. unstarred environment}
@@ -321,18 +323,21 @@ RegisterSingleList = RegisterSingle, [ ",", RegisterSingleList ];
RegisterSingle = RegisterSingleNoRange | RegisterRange;
RegisterSingleNoRange = ?name?, [ "[", IndexMultiList, "]" ];
-RegisterMulti = "(", ( RegisterMultiNoRange | RegisterRange ), ")";
-RegisterMultiNoRange = ?name?, [ "[", IndexSingleList, "]" ];
+RegisterMulti = "(", ( RegisterMultiNoRange | [ "*" ], RegisterRange ), ")";
+RegisterMultiNoRange = [ "*" ], ?name?, [ "[", IndexSingleMainList, "]" ];
RegisterRange = [ RegisterUnique ], "-", [ RegisterUnique ];
RegisterUnique = ?name?, [ "[", ?number?, "]" ];
-IndexMultiList = IndexMulti, [ ",", IndexMulti ];
-IndexSingleList = IndexSingle, [ ",", IndexSingle ];
+IndexMultiList = IndexMulti, [ ",", IndexMultiList ];
+IndexSingleList = IndexSingle, [ ",", IndexSingleList ];
+IndexSingleMainList = [ "*" ], IndexSingle, [ ",", IndexSingleMainList ];
IndexMulti = IndexSingle | ( "(", IndexSingle, ")" );
IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
\end{minted}
Note that \Yquant{} is quite tolerant with respect to whitespaces.
Virtually every comma in the EBNF notation may consist of an arbitrary (including zero) number of whitespaces.
+ Not all combinations that can be constructed by this grammar are actually allowed semantically; but it would make the grammar too verbose to spell this out in detail.
+ Deviations are noted in this manual.
Valid values for
\begin{BVerbatim}[commandchars=\\\{\}]
@@ -348,7 +353,7 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
\PYG{n+ni}{?name?}
\end{BVerbatim}
\space we denote any valid register name.
- Register names must not contain any of the control literals used before (semicolon, comma, parentheses, square brackets, dash, pipe, tilde); and you should avoid using special \TeX{} characters.
+ Register names must not contain any of the control literals used before (semicolon, comma, parentheses, square brackets, dash, pipe, tilde, beginning star); and you should avoid using special \TeX{} characters.
Note that for performance reasons, \Yquant{} does not check whether a register name is valid or not, but expect to either see unintended output or not\hyp so\hyp helpful error messages if you choose an invalid name.
\begin{BVerbatim}[commandchars=\\\{\}]
\PYG{n+ni}{?number?}
@@ -359,7 +364,7 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
\end{BVerbatim}
).
- \subsection{Registers}
+ \subsection{Registers}\label{sec:registers}
Every quantum circuit is structured by means of \emph{registers}.
A register has a \emph{type} that specifies how its wire is drawn, and that may even change during its lifetime.
At the moment, \Yquant{} supports four types:
@@ -421,10 +426,30 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
It is possible to mix single- and multi\hyp register operations arbitrarily.
In an index list, you may also choose to surround only certain indices with parenthesis, provided the whole register is not already a multi\hyp register.
\begin{warning}
- Note that some gates, such as the \gate{swap} gate, always require multi\hyp register operations with a fixed number of constituents; others, such as the \gate{slash} pseudo\hyp gate always require single\hyp register operations.
- Again others are completely flexible.
+ Note that some gates, such as the \gate{swap} gate, always require (semantically, not grammatically) multi\hyp register operations.
+ Since version 0.1.2, the number of constituents is no longer fixed; while a \gate{swap} gate with more than two targets is no longer well\hyp defined, other registers such as \gate{zz} may still be useful.
\Yquant{} will prevent you from using a gate in a multi\hyp qubit setting when it may only be used for single registers.
- All other types of validity checks are up to the user.
+ \end{warning}
+ Typically, multi\hyp register operations should only be carried out on adjacent registers---but sometimes, one might want to carry out a multi\hyp qubit operation on a visually discontiguous set of registers (which, due to a particular quantum computer topology, might even be physically feasible).
+ Since version 0.1.2, \Yquant{} supports these discontiguous operations explicitly (before, a single gate was drawn with all intermediate non\hyp affected register lines laying on top).
+ It will draw a \emph{main} part of the gate at the first contiguous slice of registers in the target list---you may select another register for this part by preceding the name or index with a star (which, contrary to the simplified grammar, may only occur \emph{once} in a target specification).
+ All other contiguous slices of target registers will be drawn in a \emph{subordinate style} for this gate.
+ Finally, all slices will be connected by a single vertical line with the style \style{/yquant/every multi line}.
+ \begin{warning}[Discontiguous targets and control lines]
+ A control line extends from the very first to the very last affected register in an operation.
+ A sub\hyp gate line that is used for discontiguous registers will only span the range of a multi\hyp register.
+ This distinction becomes crucial if you want to carry out a \emph{controlled} operation on more than one multi\hyp register, where at least one is discontiguous.
+ Without the controls, the separate multi\hyp registers could be identified, since no connecting vertical line extends between them (unless, which you should strictly avoid, they are intertwined).
+ However, with the controls, the control line will make it hard (for some gates, impossible) to visually distinguish the connected parts.
+ \Yquant{} will kindly provide a warning in this case.
+ You may choose to suppress this warning using the boolean key \style{/yquant/operator/multi warning}.
+ \end{warning}
+ \begin{warning}
+ There is no established style for discontiguous gates.
+ Note that at the moment, main and subordinate style coincide for all gates except for the \gate{measure} gate with a value.
+ In order to still make it possible to visually distinguish discontiguous multi\hyp register gates operating on slices of a single register from just a bunch of single\hyp register gates that are executed in a parallel manner, if controls are present, \Yquant's default vertical line style for the former case is a wavy line instead of a straight one.
+ Still, the meaning of this should probably be explained.
+ Please feel free to submit issues or pull requests with propositions of how default styles or alternative subordinate gate shapes may additionally help to mitigate the problem.
\end{warning}
\subsection{Arguments}
@@ -474,6 +499,7 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
\begin{option}{register/separation}!1mm!
This key controls the amount of vertical space that is inserted between two successive registers.
+ Half of this value is also the length that multi\hyp\gate{init} or multi\hyp\gate{output} braces extend beyond the mid position of the register.
\end{option}
\begin{option}{operator/minimum width}!3mm!
@@ -486,6 +512,12 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
\begin{option}{operator/separation}!1mm!
This key controls the amount of horizontal space that is inserted between two successive operators.
\end{option}
+
+ \begin{option}{operator/multi warning}!true!
+ If this key is \texttt{true}, a warning is displayed whenever more than a single multi\hyp register gate, where at least one is discontiguous, are employed together with controls.
+ Even if a visual distinction between control and multi\hyp qubit line may be possible (depending on the style in use), they will overlap and produce unaesthetic output.
+ You may disable this warning globally, on a per\hyp circuit, or even on a per\hyp gate basis.
+ \end{option}
\subsection{Register creation}\unskipOpt
\begin{option}{register/default name}!\regidx!
@@ -499,7 +531,7 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
\end{itemize}
\end{option}
- \begin{option}{every label}!shape=yquant-text, anchor=circuit, align=right!
+ \begin{option}{every label}!shape=yquant-text, anchor=center, align=right!
This style is installed for every single register name label (i.e., upon creation and when used with the \gate{init} gate).
The default style allows to use line breaks in the labels.
\end{option}
@@ -521,10 +553,12 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
This style is installed for every single register name label of a register of type \gate{qubits}.
\end{option}
- \begin{option}{every multi label}!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)}}!
+ \begin{option}{every multi label}!shift={(-.075, 0)}, draw, decoration={gapped brace, mirror}, decorate, /yquant/gapped brace/apply shift, every node/.append style={shape=yquant-text, anchor=east, align=right, shift={(-.05, 0)}, pos=-1}!
This style is installed for every register name label that is attached to a multi\hyp qubit register by means of the \gate{init} gate.
\Yquant{} additionally inserts a straight line that connects the topmost and the bottom\hyp most register at their left ends.
The default style turns this line into a brace and places the description at the appropriate position.
+ The decoration \texttt{gapped brace} allows to additionally specify the regions in which a line should be drawn by using the \texttt{/tikz/decoration/from to} key, which expects a comma\hyp separated list of dimension ranges, and which is automatically populated by \Yquant.
+ Since it may happen that the arch of the brace needs to be shifted from the value specified in \texttt{/tikz/decoration/aspect} (else, it would be drawn into a gap), the special key \texttt{/yquant/gapped brace/apply shift} is installed, which transforms the \texttt{pos=-1} specification into a position that corresponds to the actual \texttt{aspect} value.
\end{option}
\subsection{Register outputs}\unskipOpt
@@ -545,16 +579,19 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
This style is installed for every \gate{output} label of a register of type \gate{qubits}.
\end{option}
- \begin{option}{every multi output}!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)}}!
+ \begin{option}{every multi output}!shift={(.075, 0)}, draw, decoration={gapped brace}, decorate, /yquant/gapped brace/apply shift, every node/.append style={shape=yquant-text, anchor=west, align=left, shift={(.05, 0)}, pos=-1}!
This style is installed for every \gate{output} label that is attached to a multi\hyp qubit register.
\Yquant{} additionally inserts a straight line that connects the topmost and the bottom\hyp most register at their right ends.
The default style turns this line into a brace and places the description at the appropriate position.
+ See \style{/yquant/every multi label} for a more detailed explanation.
\end{option}
\subsection{General styling}\unskipOpt
- \begin{option}{every circuit}!!
+ \begin{option}{every circuit}!every node/.prefix style={transform shape}, every label/.prefix style={transform shape=false}!
Style that is installed for every \tex!yquant! and \tex!yquant*! environment, as if it had been given as an option.
- The style's default path is \texttt{/yquant}, in contrast to all other styles that operate in the \texttt{/tikz} path by default.
+ Since version 0.1.2, the style's default path is, as with all other styles, \texttt{/tikz}.
+ The default style will make all nodes (which in particular means, all gates) respect outer canvas transformations.
+ Due to \TikZ{} bug \href{https://github.com/pgf-tikz/pgf/issues/843}{\#843}, this must be undone for \texttt{label}s.
\end{option}
\begin{option}{every wire}!draw!
@@ -577,7 +614,7 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
This style is used to draw the vertical control line that connects controlled operations and their controls.
\end{option}
- \begin{option}{every control}!shape=yquant-circle, anchor=circuit, radius=.5mm!
+ \begin{option}{every control}!shape=yquant-circle, anchor=center, radius=.5mm!
This style is used to draw the node for a control, both positive and negative.
\end{option}
@@ -589,10 +626,14 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
This style is installed for every negative control (i.e., one that conditions on the register being in state $\ket0$ or $0$).
\end{option}
- \begin{option}{every operator}!anchor=circuit!
+ \begin{option}{every operator}!anchor=center!
This style is installed for every gate (and also pseudo\hyp gates such as the \gate{slash} operator) that acts on one or multiple registers.
\end{option}
+ \begin{option}{every multi line}!draw, decoration={snake, amplitude=.25mm, segment length=5pt}, decorate!
+ This style is used to draw the vertical line that connects discontiguous slices of sub\hyp gates.
+ \end{option}
+
\begin{option}{this operator}!!
This style is appended to the current style installed for an operator; it should be used only locally to overwrite any global configuration effect.
\end{option}
@@ -612,11 +653,18 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
\begin{option}{style}!/yquant/operator style={#1}, /yquant/control style={#1}!
This is a shorthand that modifies the appearance of both the current operator and any controls or control lines.
\end{option}
+
+ \begin{option}{operator/multi as single}!/yquant/every multi line/.style=/yquant/every control line!
+ This option is automatically set for certain gates such as the \gate{swap} or the \gate{zz} gate.
+ For those gates, neighboring registers will be treated as discontiguous; and this style will enforce their connecting line to have the style used by control lines.
+
+ The default \style{/yquant/every multi line} is a wavy line; this allows to distinguish discontiguous multi\hyp qubit gates from multiple single\hyp qubit gates when using controls.
+ Still, some gates have such an established appearance that---despite being logically misleading---we rather use the same style as for a control line.
+ \end{option}
\subsection{Styles for operators}\unskipOpt
- \begin{option}{operators/every barrier}!shape=yquant-barrier, x radius=\pgflinewidth, dashed, draw!
+ \begin{option}{operators/every barrier}!shape=yquant-line, dashed, draw!
This style is installed for every \gate{barrier} pseudo\hyp gate, i.e., the one that is used to explicitly denote a separation between ``before'' and ``after'' within the circuit.
- The \texttt{yquant-barrier} shape is a vertical line of width \texttt{x radius}.
\end{option}
\begin{option}{operators/every box}!shape=yquant-rectangle, draw, align=center, inner xsep=1mm, x radius=2mm, y radius=2.47mm!
@@ -660,22 +708,21 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
This style is installed for every \gate{slash} pseudo\hyp gate, i.e., the one that is used to indicate that a single register line actually denotes multiple registers.
\end{option}
- \begin{option}{operators/every swap}!shape=yquant-swap, x radius=.75mm, draw!
- This style is installed for every bipartite \gate{swap} gate that interchanges two qubits.
- The \texttt{yquant-swap} shape consists of two crosses that are connected by a middle line.
- The length of the virtual square that contains the crosses is twice the \texttt{x radius} property; the total height (twice \texttt{y radius}) will automatically be set according to the registers involved.
- Hence, this gate must always act on a two\hyp qubit register.
+ \begin{option}{operators/every swap}!shape=yquant-swap, radius=.75mm, draw!
+ This style is installed for every \gate{swap} gate that interchanges two qubits.
+ The \texttt{yquant-swap} shape consists of a single cross.
+ \end{option}
+
+ \begin{option}{operators/every wave}!shape=yquant-circle, radius=.5mm, fill!
+ This style is installed for every \gate{correlate} gate.
\end{option}
\begin{option}{operators/every x}!/yquant/operators/every pauli!
This style is installed for every Pauli operator $\sigma_x$, i.e., \gate{x}.
\end{option}
- \begin{option}{operators/every xx}!shape=yquant-xx, x radius=.75mm, draw!
- This style is installed for every bipartite \gate{xx} gate in symmetrized notation ($\ketbra{++}{++} + \ketbra{+-}{+-} + \ketbra{-+}{-+} - \ketbra{--}{--}$).
- The \texttt{yquant-xx} shape consists of two open squares that are connected by a middle line.
- The length of one side in the square is twice the \texttt{x radius} property; the total height (twice \texttt{y radius}) will automatically be set according to the registers involved.
- Hence, this gate must always act on a two\hyp qubit register.
+ \begin{option}{operators/every xx}!shape=yquant-rectangle, radius=.75mm, draw!
+ This style is installed for every \gate{xx} gate in symmetrized notation ($\ketbra{++}{++} + \ketbra{+-}{+-} + \ketbra{-+}{-+} - \ketbra{--}{--}$).
\end{option}
\begin{option}{operators/every y}!/yquant/operators/every pauli!
@@ -686,11 +733,8 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
This style is installed for every Pauli operator $\sigma_z$, i.e., \gate{z}.
\end{option}
- \begin{option}{operators/every zz}!shape=yquant-zz, x radius=.5mm, fill, draw!
- This style is installed for every bipartite \gate{zz} gate (aka \textsc{CPhase}) in symmetrized notation ($\ketbra{00}{00} + \ketbra{01}{01} + \ketbra{10}{10} - \ketbra{11}{11}$).
- The \texttt{yquant-zz} shape consists of two circles that are connected by a middle line.
- The radius of the circles is controlled via the \texttt{x radius} property; the total height (twice \texttt{y radius}) will automatically be set according to the registers involved.
- Hence, this gate must always act on a two\hyp qubit register.
+ \begin{option}{operators/every zz}!shape=yquant-circle, radius=.5mm, fill!
+ This style is installed for every \gate{zz} gate (aka \textsc{CPhase}) in symmetrized notation ($\ketbra{00}{00} + \ketbra{01}{01} + \ketbra{10}{10} - \ketbra{11}{11}$).
\end{option}
\section{Doing the impossible}\label{sec:tikz}
@@ -708,15 +752,40 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
All quantum operations are in fact \TikZ{} nodes, and the name you give to them then becomes a \TikZ{} name, which you can easily reference to get the coordinates of a particular operator.
Note that the name you specify is only available if a single register is targeted.
The name is suffixed by \tex!-\idx!, where \tex!\idx! refers to the (zero\hyp based) index of the operation ordered from top to bottom (i.e., if an operator acts on two qubits and should be named \texttt{op}, the topmost operator will be available as \texttt{op-0} and the second as \texttt{op-1}).
+ Multiple slices in a discontiguous multi\hyp register are additionally suffixed by \texttt{-s\textit{<slice index>}}.
All controls are also named, suffixed by \tex!-p\idx! or \tex!-n\idx! for positive and negative controls (i.e., the topmost positive control of the previous operator will be available as \texttt{op-p0}).
Counters for target registers, positive, and negative controls are all independent.
All \Yquant{} shapes have the anchors available you would typically expect from a \TikZ{} shape of the given outline.
- Additionally, \Yquant{} shapes will have an anchor \texttt{circuit}; and apart from border anchors, they also implement \emph{projection anchors}.
- As with the former, you will need low\hyp level macros to access these anchors, which are \tex!\pgfpointshapexproj! and \tex!\pgfpointshapeyproj!.
- They will expect the name of the node as first argument and a \pkg{pgf} point as second argument.
- This point will be projected onto the shape in horizontal or vertical direction.
- These special types of anchors are internally used to determine where the intersection of wire and shape is located.
+ Before version~0.1.2, \Yquant{} shapes needed to provide a \texttt{circuit} anchor and projection anchors.
+ These were removed in version~0.1.2 in favor of the common \texttt{center} anchor and clipping paths.
+ The latter is a \Yquant{} extension to \TikZ{} shapes: it is an additional path that must be declared for a given shape.
+ This path has to provide the ``clipping outline,'' i.e., anything that should not contain register or control lines.
+ There may be a difference between horizontal and vertical clipping outlines.
+ To understand clipping paths, \Yquant's drawing pipeline needs to be explained.
+ \begin{itemize}
+ \item In a first run---this is what happens directly at the position where you type the gate command---\Yquant{} will ``virtually'' draw the gates in order to determine their dimensions and calculate register heights.
+ The actual drawing commands are written to a macro (this is the cause that some macros must be preceded by \tex!\protect! if used in a gate \texttt{value}).
+ \item When \tex!\end{yquant}! is encountered, the actual drawing commands are executed.
+ \item Unless the operation changes the wire type or style, do the following (first two items for every register at which an operator node has to be created).
+ \begin{itemize}
+ \item Create the operator node at the appropriate position.
+ \item Call \tex!\pgfshapeclippath! on the newly created node.
+ This will first determine whether the node was stroked; if not, \tex!\pgflinewidth! is set to zero.
+ Then, it will call the horizontal clipping path, which is supposed to create some soft path commands.
+ Those soft path commands are collected in a macro on a per\hyp register basis and the soft path is cleared.
+ The same happens for the vertical clipping path, which is collected in a macro on a per\hyp operation basis.
+ \item If control lines or multi lines are to be drawn, the vertical clipping path commands are now executed and installed as an inverted\footnote{Inverting the clipping has two consequences: First, the region of inversion in vertical direction is given by the width of the operators. The line cannot be wider than the operator. Second, if you specify a register multiple times, whether as target, control, or mixed, funny effects can be expected, as the clipping region is inverted multiple times. Note that using a register more than once is always an error, but \Yquant{} does not check for it due to the high overhead.} clipping path.
+ \item Control lines and multi lines are drawn (in this order) from one to the next \texttt{center} anchor.
+ Due to the clipping commands, this will create a perfect connection with the shape of the gate, but even transparent gates are possible without the lines being visible.
+ \end{itemize}
+ \item If the operation changes the wire type or style, or if there is no operation left on this register, the following is done.
+ \begin{itemize}
+ \item Load the clipping paths accumulated for all the gates acting on this register and install the inverted clipping.
+ \item Draw the wire as one continuous line from where the last wire ended (or the beginning of the circuit) to the center of the last gate, or to the common end position for all wires of the circuit.
+ \item Remove the clipping paths stored so far on this register, apart from the clipping on the last gate (which will be needed again if this was not the end of the circuit).
+ \end{itemize}
+ \end{itemize}
% The current version of \Yquant{} does not implement subcircuits yet.
% However, this is planned in a future version; by naming a subcircuit, all named operations inside should then also become available (prefixed by the subcircuit's name).
@@ -726,6 +795,19 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
It also details all arguments that can be given to customize the operation, apart from \texttt{name}, which is always available.
Note that the \tex![value=<value>]! attribute can (and should) alternatively be given as a braced expression that follows the name of the register.
+ \subsection{\texorpdfstring{\yquant!addstyle!}{addstyle}}\label{gate:addstyle}
+ Syntax: \yquant!setstyle <target>;! \\
+ This is an invisible pseudo\hyp gate that immediately changes the \TikZ{} style with which the register lines of all target registers are drawn.
+ It adds to the styles that are already installed.
+ Use \gate{setstyle} to replace styles.
+ It may not span multiple registers and does not allow for controls.
+
+ \emph{Possible attributes:}
+ \begin{itemize}
+ \item \yquant![value=<styles>]! (required) \\
+ Denotes the new styles; this should be a string that could be passed to \tex!\tikzset!.
+ \end{itemize}
+
\subsection{\texorpdfstring{\yquant!align!}{align}}\label{gate:align}
Syntax: \yquant!align <target>;! \\
This is an invisible pseudo\hyp gate that enforces all affected registers to share a common horizontal position for their next gate, which is determined by the largest position of all gates involved.
@@ -759,6 +841,13 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
\emph{see \hyperref[gate:qubit]{\yquant!qubit!}}
+ \subsection{\texorpdfstring{\yquant!correlate!}{correlate}}\label{gate:correlate}
+ Syntax: \yquant!correlate <target>;! \\
+ This is a pseudo\hyp gate that indicates a correlation (usually a Bell\hyp state) present between the multi\hyp registers involved.
+ This gate should span multiple registers and does not allow for controls.
+
+ \emph{Possible attributes:} none
+
\subsection{\texorpdfstring{\yquant!cnot!}{cnot}}\label{gate:cnot}
Syntax: \yquant!cnot <target> | <pcontrol> ~ <ncontrol>;! \\
This is a synonym for the \gate{not} gate.
@@ -769,7 +858,7 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
This is an invisible pseudo\hyp gate that changes the type of all target registers to \gate{nobit}, i.e., no line will be drawn for them.
This has effect already for the outgoing line of the last visible gate on the target registers.
The gate may not span multiple registers and does not allow for controls.
- To change into a register type on\hyp the\hyp fly into something different from \gate{nobit}, use the \gate{setwire} pseudo\hyp gate.
+ To change into a register type on\hyp the\hyp fly into something different from \gate{nobit}, use the \gate{settype} pseudo\hyp gate.
\emph{Possible attributes:} none
@@ -830,7 +919,6 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
Inside the value, \tex!\idx! expands to the current index within the register list.
\end{itemize}
- \clearpage
\subsection{\texorpdfstring{\yquant!measure!}{measure}}\label{gate:measure}
Syntax: \yquant!measure <target>;! \\
This is a measurement gate, denoted by a rectangle with a meter symbol.
@@ -919,8 +1007,21 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
\emph{see \hyperref[gate:qubit]{\yquant!qubit!}}
- \subsection{\texorpdfstring{\yquant!setwire!}{setwire}}\label{gate:setwire}
- Syntax: \yquant!setwire <target>;! \\
+ \subsection{\texorpdfstring{\yquant!setstyle!}{setstyle}}\label{gate:setstyle}
+ Syntax: \yquant!setstyle <target>;! \\
+ This is an invisible pseudo\hyp gate that immediately changes the \TikZ{} style with which the register lines of all target registers are drawn.
+ It replaces all previous styles.
+ Use \gate{addstyle} to accumulate styles.
+ It may not span multiple registers and does not allow for controls.
+
+ \emph{Possible attributes:}
+ \begin{itemize}
+ \item \yquant![value=<styles>]! (required) \\
+ Denotes the new styles; this should be a string that could be passed to \tex!\tikzset!.
+ \end{itemize}
+
+ \subsection{\texorpdfstring{\yquant!settype!}{settype}}\label{gate:settype}
+ Syntax: \yquant!settype <target>;! \\
This is an invisible pseudo\hyp gate that immediately changes the type of the targets registers, taking effect with the output line extending from the last drawn gate.
It may not span multiple registers and does not allow for controls.
@@ -931,6 +1032,9 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
To change the type to \gate{nobit}, use the \hyperref[gate:discard]{\yquant!discard!} pseudo\hyp gate instead.
\end{itemize}
+ \subsection{\texorpdfstring{\yquant!setwire!}{setwire}}\label{gate:setwire}
+ \emph{Deprecated as of version~0.1.2. Use \gate{settype} instead.}
+
\subsection{\texorpdfstring{\yquant!slash!}{slash}}\label{gate:slash}
Syntax: \yquant!slash <target>;! \\
This is a pseudo\hyp gate used to denote that a single line actually represents multiple registers.
@@ -962,11 +1066,9 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
\subsection{\texorpdfstring{\yquant!xx!}{xx}}\label{gate:xx}
Syntax: \yquant!xx <targets>;! \\
- This is a two\hyp qubit symmetric flip gate, denoted by two joined open squares.
- It may span multiple registers (in fact, it should always span exactly two registers, though \Yquant{} does not enforce this), and it allows for controls.
- However, refrain from combining \emph{multiple} two\hyp qubit targets \emph{together} with controls.
- The control line will extend from the first to the last of all registers involved in the operation, so that it is impossible to discern visually which registers form the two\hyp qubit compounds.
- Using multiple gates without controls in one operation is fine, as well as a single controlled gate.
+ This is a symmetric flip gate, denoted by joined open squares.
+ It should span multiple registers and it allows for controls.
+ The same warnings as for the \gate{swap} gate apply.
The style \style{/yquant/operators/every xx} is installed.
\emph{Possible attributes:} none
@@ -989,8 +1091,9 @@ IndexSingle = ?number? | ( [ ?number? ], "-", [ ?number? ] );
\subsection{\texorpdfstring{\yquant!zz!}{zz}}\label{gate:zz}
Syntax: \yquant!zz <targets>;! \\
- This is a two\hyp qubit symmetric phase gate $\symbb1 - 2\ketbra{11}{11}$, denoted by two joined filled circles.
- It may span multiple registers (in fact, it should always span exactly two registers, though \Yquant{} does not enforce this), but does not allow for controls.
+ This is a symmetric phase gate, denoted by joined filled circles.
+ It should span multiple registers, but does not allow for controls.
+ The same warnings as for the \gate{swap} gate apply.
The style \style{/yquant/operators/every zz} is installed.
\emph{Possible attributes:} none
@@ -1195,8 +1298,8 @@ qubit {$\ket{q_{\idx}} = \ifcase\idx\relax \ket\psi \else \ket0 \fi$} q[3];
\end{tikzpicture}
\end{codeexample}
Instead of a discontigous vector register, we could also have used three scalar registers.
- The labels chosen for \pkg{qasm} do not fit well to the used required by this use.
- We might also have used a three\hyp register vector and used the \gate{setwire} pseudo\hyp gate to immediately change the second register into a classical one, which would give indices matching the labels---but still, the registers would have a common name, which would make this a very unnatural approach.
+ The labels chosen for \pkg{qasm} do not fit well to the indices \Yquant{} assigns.
+ We might also have used a three\hyp register vector and used the \gate{settype} pseudo\hyp gate to immediately change the second register into a classical one, which would give indices matching the labels---but still, the registers would have a common name, which would make this a very unnatural approach.
\end{example}
\begin{example}[test11 (user-defined multi-qubit ops)]
@@ -1328,12 +1431,12 @@ qubit {$\ket{q_{\idx}} = \ifcase\idx\relax \ket\psi \else \ket0 \fi$} q[3];
\end{yquant}
\end{tikzpicture}
\end{codeexample}
- We needed to include an \tex!align! pseudo\hyp gate to put the slash at the desired position.
- Usually, this would be sufficient to put the \tex!cnot! and the \tex!slash! gate directly under each other, as it is in the \pkg{qasm} example.
- However, the \tex!slash! gate is special in that it does not need horizontal space and is put with only half of the usual operator separation into the circuit (for this reason, it can be put at the beginning of a wire without creating weird shifts with respect to the ``unslashed'' registers---it is put in the initial line that every wire even without an operation has).
- Hence, you should normally only use the \tex!slash! gate as the very first gate in a circuit.
+ We needed to include an \gate{align} pseudo\hyp gate to put the slash at the desired position.
+ Usually, this would be sufficient to put the \gate{cnot} and the \gate{slash} gate directly under each other, as it is in the \pkg{qasm} example.
+ However, the \gate{slash} gate is special in that it does not need horizontal space and is put with only half of the usual operator separation into the circuit (for this reason, it can be put at the beginning of a wire without creating weird shifts with respect to the ``unslashed'' registers---it is put in the initial line that every wire even without an operation has).
+ Hence, you should normally only use the \gate{slash} gate as the very first gate in a circuit.
It is not possible to construct the exact same appearance as in the \pkg{qasm} example.
- Note that \tex!discard! currently just drops the wire directly after the last operation.
+ Note that \gate{discard} currently just drops the wire directly after the last operation.
\end{example}
\begin{example}[test17 (example from Nielsen paper on cluster states)]
@@ -1359,14 +1462,12 @@ qubit {$\ket{q_{\idx}} = \ifcase\idx\relax \ket\psi \else \ket0 \fi$} q[3];
\begin{yquant}
qubit {$\ket{q_{\idx}} = \ket{\ifcase\idx\relax \psi \or + \or + \or \phi \fi}$} q[4];
- phase {} | q;
+ zz (q);
dmeter {$H$} q[1, 2];
\end{yquant}
\end{tikzpicture}
\end{codeexample}
- This non\hyp standard gate is something that would have to be defined in an accompanying text; probably it is a generalization of \gate{zz}, $\symbb1 - 2 \ketbra{1\dotsm1}{1\dotsm1}$.
- We implemented it by carrying out a \gate{phase} gate on \emph{no} register (since \gate{phase} requires an argument, we gave an empty one)---indeed, according to the grammar, this is valid syntax with probably no other use case than this---and conditioned it on all others.
- So in principle, we could have used an arbitrary gate, but \gate{phase} was the semantically closest (\gate{zz} does not allow for controls).
+ This gate is probably a generalization of \gate{zz}, $\symbb1 - 2 \ketbra{1\dotsm1}{1\dotsm1}$, and indeed since version~0.1.2, we can use \gate{zz} for this purpose.
This time, we also used the common way to initialize a gate with various identifiers as was done before version~0.1.1, using case distinctions.
\end{example}
\endgroup
@@ -1506,15 +1607,27 @@ $=$
\begin{yquant*}
box {$U$} a;
box {$U^\dagger$} b;
- \yquantset{every wire/.append style={->}}
+ setstyle {->} -;
\end{yquant*}
\end{tikzpicture}
\end{codeexample}
- Though \Yquant{} does not provide any direct mechanism to achieve such wire re\hyp design, changing the wire style at an appropriate position does work.
- Setting the style beforehand would have made every connecting wire (including the initial ones) into arrows.
+ Since version~0.1.2, \Yquant{} allows to change wire styles by means of the \gate{setstyle} and \gate{addstyle} pseudo\hyp gates.
+ Here, we use the gate on all wires in order to set an arrow style.
+ Note that arrowheads are actually very special in two respects:
+ \begin{itemize}
+ \item \Yquant{} draws continuous wires for as long as possible.
+ In this example, the wire path extends from the very left to the end of the circuit; since version 0.1.2, \Yquant{} does not draw a wire \emph{to} the gate and then a separate one \emph{from} the gate to the next or the end.
+ The only way to force \Yquant{} to draw multiple wires is to change the wire style or type mid\hyp circuit.
+ For example, by saying \yquant!addstyle {} -;!, all wire paths will be separated at the current position, which \emph{in theory} allows to draw arrowsheads on intermediate wires.
+ \item \emph{In practice}, this will not work due to the clipping commands that \Yquant{} installs.
+ Every wire extends from the center of the left to the center of the right gate, and the gate's shape acts as a clipping path.
+ Consequently, though the arrowhead is drawn, it is actually drawn at the center of the gate instead of the \texttt{west} anchor and then clipped away (unless the gate is small, in which case you might still see some fragments of the arrowhead).
+ \end{itemize}
+ Thus, it is currently not possible to use arrowheads on intermediate wires.
+ If you really need to do this (say, for only a single gate), you may experiment with the \TikZ{} \texttt{shorten} keys, which allow you to manually reduce the length of the wire, but the amount of reduction must be hand\hyp computed for every gate.
+ If you need this more often, consider filing a feature request.
\end{example}
- \clearpage
\paragraph{B. CNOT and other controlled single qubits gates}\leavevmode
\begin{example}
\begin{codeexample}
@@ -1539,6 +1652,7 @@ $=$
\end{codeexample}
\end{example}
+ \clearpage
\paragraph{C. Vertical wires}\leavevmode
\begin{example}
\begin{codeexample}
@@ -1590,7 +1704,7 @@ $=$
The second one (using a curly brace) corresponds to the default.
It is overwritten for the first qubit, and to make this modification local, this is done in a group.
The third qubit pair uses an overall label and additionally individual labels on the lines.
- This is achieved by some trickery: the individual labels are given as initialization labels on the register; the global label is given as an \tex!init! multi\hyp qubit gate.
+ This is achieved by some trickery: the individual labels are given as initialization labels on the register; the global label is given as an \gate{init} multi\hyp qubit gate.
\end{example}
\clearpage
@@ -1633,13 +1747,12 @@ $=$
\begin{tikzpicture}
\begin{yquant*}
box {$\symcal F$} (a[-1]);
- [name=g]
- box {$\symcal G$} a[0, 2];
- \draw (g-0) -- (g-1);
+ box {$\symcal G$} (a[0, 2]);
\end{yquant*}
\end{tikzpicture}
- \end{codeexample}
- \emph{Note:} The behavior with a line cannot be reproduced without resolving to \TikZ. However, as \pkg{qcircut}'s manual admits, ``such notation may be a bit confusing,'' so probably support will not be added.
+ \end{codeexample}
+ This demonstrates \Yquant's capabilities of discontiguous multi\hyp qubit gates that was added in version~0.1.2.
+ \Yquant{} automatically splits multi\hyp qubit gates into slices of directly adjacent wires (which, for the $\symcal G$ case, are the single wires \yquant!a[0]! and as second slice \yquant!a[2]!).
\end{example}
\paragraph{B. Measurements and classical bits}\leavevmode
@@ -1662,7 +1775,7 @@ $=$
\begin{codeexample}
\begin{tikzpicture}
\begin{yquant*}
- [shape=yquant-circle]
+ [rounded corners]
box {Codebit} a;
box {$\chi$} b | a;
discard a;
@@ -1670,7 +1783,7 @@ $=$
\end{yquant*}
\end{tikzpicture}
\end{codeexample}
- Rectangles with rounded corners are not supported yet.
+ Rectangles with rounded corners are not a specific style, but since the \texttt{yquant-rectangle} shape internally uses \tex!\pgfpathrectangle!, the ordinary \TikZ{} option can be used (also, an inset specification can control how much the corner is rounded).
\end{example}
\clearpage
@@ -1705,8 +1818,18 @@ $=$
\end{yquant*}
\end{tikzpicture}
\end{codeexample}
- Multi\hyp qubit gates (including measurements) on non\hyp adjacent registers are, while being easily written, not supported in terms of a proper visual output.
- Of course, as was done in a previous example, you may instead decide to emulate the behavior by drawing the vertical line manually, using a \gate{box} gate on the last register and also changing the type by means of the \gate{setwire} pseudo\hyp gate (but note that the type was not even changed in the \pkg{qcircuit} documentation)\dots.
+ Multi\hyp qubit gates (including measurements) on non\hyp adjacent registers are properly supported since version~0.1.2.
+ As explained in \cref{sec:registers}, there is one main and multiple subordinate gate in such a discontiguous multi\hyp qubit operation (though at the moment, the \gate{measure} gate with text is the only gate that makes this distinction).
+ In our case, the main part contains the measurement symbol and the text, while the subordinate gates only contain the text.
+ By default, \Yquant{} uses the first slice as main part, but you may influence this by preceding what you want to be ``main'' by a star:
+
+ \begin{codeexample}
+\begin{tikzpicture}
+ \begin{yquant*}
+ measure {$\ket{\xi_\mp}$} (a[-1, *3]);
+ \end{yquant*}
+\end{tikzpicture}
+ \end{codeexample}
\end{example}
\clearpage
@@ -1725,7 +1848,7 @@ $=$
\end{yquant*}
\end{tikzpicture}
\end{codeexample}
- Here, the intermediate text was inserted by using a \tex!box! without drawing.
+ Here, the intermediate text was inserted by using a \gate{box} without drawing.
Another way would be to use an \gate{init} command, although this is semantically wrong (probably).
\end{example}
@@ -1762,10 +1885,9 @@ $=$
\end{yquant*}
\end{tikzpicture}
\end{codeexample}
-
- Now the \pkg{qcircuit} manual lists three circuits with barriers at different positions.
- They cannot be drawn with \Yquant; however, since neither of them is a valid circuit, this is of no concern.
\end{example}
+ Now the \pkg{qcircuit} manual lists three circuits with barriers at different positions.
+ They cannot be drawn with \Yquant; however, since neither of them is a valid circuit, this is of no concern.
\paragraph{E. How to control anything}\leavevmode
\begin{example}
@@ -1785,6 +1907,7 @@ $=$
Note that it is not possible to draw a control to measurement (the measurement operations are explicitly defined not to accept controls): Either the measurement is performed or not (which transforms the register type), but a measurement conditioned on a quantum state is not possible.
In principle, one could think of a measurement conditioned on a classical register (in which case the register type cannot change, as maybe the state stays quantum; the measurement operation then is similar to a complete dephasing).
If there is need for this, please file a feature request.
+ But note the relatively common (though unsupported by \Yquant{} at the moment) use of control lines that directly go from the measurement operator to the controlled operation; in this case, the opposite direction would be meant by using the same notation.
\end{example}
\subsubsection{VI. Bells and Whistles: Tweaking Your Diagram to Perfection}
@@ -1821,7 +1944,7 @@ $=$
\end{yquant}
\end{tikzpicture}
\end{codeexample}
- Measurement with bottom output are not supported (yet).
+ Measurement with vertical output are not supported (yet).
Repositioning the initial labels needs some care and manual fine\hyp tuning.
\end{example}
@@ -1915,8 +2038,9 @@ $=$
["$0$/$1$", type=qubit]
measure a;
- \yquantset{every wire/.append style={->}, operator/separation=5mm}
+ addstyle {->} a;
output {$\ket1$} a;
+ \yquantset{operator/separation=5mm}
\end{yquant}
\end{tikzpicture}
\end{codeexample*}
@@ -1926,9 +2050,8 @@ $=$
In this example, \tex!\\! is a robust command (at least in newer kernels), so protection is not required.
Since it may occur quite frequently that \Yquant{} is used within a \tex!center! environment or in \tex!\centering! mode (in which \tex!\\! is still fragile), \Yquant{} takes care of this (it actually robustifies \tex!\@centercr!, which is the meaning of \tex!\\! in these surroundings).
- In order to change the style of an individual wire, the proper \tex!\yquantset! command must be placed directly before the wire is internally drawn (which happens when the next gate that needs a connecting line is drawn).
- Remember to use grouping so that the changes are local.
- However, the output wires are all drawn together, so it is not possible to individually change the style of a single output wire, only all of them.
+ In order to change the style of an individual wire, we use \gate{addstyle} as of version~0.1.2.
+ To make the final line smaller, we change the operator separation by issuing \tex!\yquantset! at the end.
\end{example}
\begin{example}
@@ -2003,6 +2126,7 @@ $=$
Also, if you discard a gate, this will prevent it from exiting from its last gate.
\Yquant{} will not allow you (apart from manual drawing) to extend the wire to some arbitrary position, then drop it.
But of course, as done here, you can always resort to the full power of \TikZ.
+ Still, this is inferior to a wire drawn by \Yquant, as it does not use clippings: the connection with the \gate{cnot} gate may not be accurate; in particular, if the wire is of a different color or if you need to draw classical or bundle wires, the connection will become unpleasant.
\end{example}
\begin{example}
@@ -2122,11 +2246,11 @@ $=$
cbit d;
qubit e;
box {$U$} (-);
- setwire {qubit} c;
+ settype {qubit} c;
\end{yquant}
\end{tikzpicture}
\end{codeexample}
- This example for the first time demonstrates the declaration of a non\hyp existing register and the \gate{setwire} pseudo\hyp gate that acts as a zero\hyp width, no\hyp content \gate{init} gate.
+ This example for the first time demonstrates the declaration of a non\hyp existing register and the \gate{settype} pseudo\hyp gate that acts as a zero\hyp width, no\hyp content \gate{init} gate.
\end{example}
\clearpage
@@ -2195,7 +2319,7 @@ $=$
\end{tikzpicture}
\end{codeexample*}
Usually, the \texttt{shorten} keys do not have any effect on \Yquant{} operations, since the latter are all made up of nodes.
- However, the \texttt{yquant-barrier} shape explicitly takes care of correctly handling them.
+ However, the \texttt{yquant-line} shape explicitly takes care of correctly handling them.
It is the only one that does so.
Since barriers usually end quite closely to the wires---and the default \texttt{dashed} style may make this worse---the \texttt{shorten}ing may often prove useful.
Note that if the barriers are enlarged by means of negative \texttt{shorten}ings, this will not affect the bounding box or internal register height calculations, and you must take care of appropriately shifting labels.
@@ -2387,7 +2511,7 @@ $=$
\paragraph{D. Scaling}\leavevmode
\begin{example}
\begin{codeexample*}
-\begin{tikzpicture}[scale=1.5, every node/.append style={scale=1.5}]
+\begin{tikzpicture}[scale=1.5, every label/.append style={scale=1.5}]
\begin{yquant*}
h a;
phase {$\beta$} a;
@@ -2396,7 +2520,8 @@ $=$
\end{tikzpicture}
\end{codeexample*}
Here, we first scaled the circuit itself.
- However, since \TikZ{} does not apply scaling to nodes (which means any operation) unless explicitly told so, we need to add the style to those.
+ The default style for \style{/yquant/every circuit} sets the \texttt{transform shape} key for every node (which means any gate), so that those are also scaled.
+ This is explicitly undone for \texttt{label}s due to \TikZ{} bug \href{https://github.com/pgf-tikz/pgf/issues/843}{\#843}, so the scaling must be specified explicitly for the \texttt{label}s.
\end{example}
\subsubsection{VII. Typesetting}
@@ -2448,7 +2573,7 @@ $=$
\end{yquant}
\end{tikzpicture}
\end{codeexample*}
- \Yquant{} will make sure that ``pass\hyp through'' lines are never obscured, even if, as in this case, the backgrounds are explicitly filled.
+ \Yquant{} properly splits discontiguous multi\hyp qubit operations as of version~0.1.2.
\end{example}
\paragraph{B. Per-Gate Styling}\leavevmode
@@ -2495,10 +2620,10 @@ $=$
\end{codeexample*}
\TikZ{} shapes cannot simply be used with \Yquant.
Any \Yquant{} shape must be aware of the keys \texttt{x radius} and \texttt{y radius} that control its width and height.
- Additionally, \Yquant{} shapes must implement the \texttt{circuit} anchor (which can usually be let to the \texttt{center} anchor), and they must implement projection anchors.
- Those objects, which are a \Yquant{} addition to \TikZ{} allow \Yquant{} to determine where precisely the wires at the individual positions are supposed to begin and end.
- \Yquant{} draws its elements sequentially; hence, a wire that comes into an operator will be hidden by anything the operator draws on top of it; but outgoing wires will in turn draw on the operator.
- To avoid the issues, we construct an invisible box operator and name it; \emph{outside} of the \tex!yquant! environment, we \tex!fit! the special \TikZ{} shape on top of it.
+ Additionally, \Yquant{} shapes must implement clipping paths.
+ Those objects, which are a \Yquant{} addition to \TikZ{} allow \Yquant{} to properly clip wires and vertical lines to the shape of the gate.
+ \Yquant{} draws its elements sequentially; hence, a wire that comes into an operator will be hidden by anything the operator draws on top of it; but outgoing wires will in turn draw on the operator (modulo clipping).
+ To avoid the issues, we construct an invisible box operator and name it; \emph{outside} of the \tex!yquant! environment, we \texttt{fit} the special \TikZ{} shape on top of it.
\end{example}
\paragraph{C. Boxing/Highlighting Parts of a Circuit}\leavevmode
@@ -2551,6 +2676,7 @@ $=$
\Yquant{} does not support the fancy nearest\hyp neighbor swap gate that \pkg{quantikz} has.
It would however not be very difficult to implement this particular shape and make it available.
+ Maybe even a multi\hyp swap gate using the \texttt{knots} library would be possible.
\clearpage
\subsubsection{VIII. Otherwise undocumented features}
@@ -2615,14 +2741,6 @@ $=$
Subcircuits will typically be multi\hyp qubit elements that, at least if internal wires are used, may significantly increase the required height for an individual register.
Hence, the internal height calculations must be adapted.
This will be particularly problematic if the subcircuit targets non\hyp adjacent wires.
- \item Better handling of non\hyp adjacent wires. \\
- While this would be a nice feature, an implementation would hard: How should the individual shapes behave for non\hyp adjacent wires?
- Two boxes, connected by a wire, as used in one \pkg{qcircuit} example, is a simplistic design that quickly fails for more complicated or larger shapes.
- \item Styling the wires. \\
- It is currently relatively hard to selectively style wires.
- While individual wire segments can be targeted by changing the appropriate wire styles before the operation that would draw the ingoing wire, it must then be reset and it is cumbersome to do this for all wire segments of a register.
- Additionally, styling the final output wires individually is not possible.
- For this, it would be advantageous to allow a wire style on a per\hyp register basis.
\item Support for other languages. \\
It would be particularly nice to introduce a language mode.
While the \Yquant{} language will always provide the set of everything \Yquant{} can do at the moment, it would be nice if \Yquant{} can automatically detect \texttt{OpenQASM} and parse its content correctly.
@@ -2647,5 +2765,13 @@ $=$
Complete rewrite of the register name parser.
\Yquant{} now understands comma\hyp separated lists and ranges in indices, and also is far more tolerant with respect to whitespaces. \\
\Yquant{} now also supports non\hyp contiguous vector registers and allows to add new registers into an already existing vector that is not the last register, and also in the unstarred mode.
+
+ \subsection{2020-04-11: Version 0.1.2}
+ Introduce \gate{setstyle} and \gate{addstyle} pseudo\hyp gates that allow to style individual wires; rename \gate{setwire} to \gate{settype} (the old name is still available and shows a deprecation warning). \\
+ Complete rewrite of the way \Yquant{} draws wires; projection anchors are removed in favor of clipping paths.
+ This allows perfect connections between gates and wires, even if the (rather rectangular) wire lines meets with nonplanar shapes, while still preserving the possibility of transparent wires. \\
+ \Yquant{} now also properly draws non\hyp contiguous multi\hyp qubit operations. \\
+ New gate: \gate{correlate}.
+ Various bug fixes.
%END_FOLD
\end{document} \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex b/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex
index 993455cbebb..2117e7f4407 100644
--- a/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex
@@ -1,221 +1,145 @@
% 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}%
+\long\def\@firstoffour#1#2#3#4{#1}%
+\long\def\@secondoffour#1#2#3#4{#2}%
+\long\def\@thirdoffour#1#2#3#4{#3}%
+\long\def\@fourthoffour#1#2#3#4{#4}%
+\long\def\@thirdandfourthoffour#1#2#3#4{#3#4}%
-% 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%
+% extends the wire of register #1. Assumes a node called yquantbox is set up, and the \pgfshapeclippathhorzresult was set up appropriately for this node.
+\protected\def\yquant@circuit@extendwire#1{%
+ \begingroup%
+ \pgfpointanchor{yquantbox}{center}%
+ \edef\wirexpos{\the\pgf@x}%
+ \yquant@register@get@typeywire{#1}\wiretype\wireypos\wirelast%
+ \edef\wirexprevpos{\expandafter\@firstoffour\wirelast}%
+ \ifnum\wiretype=\yquant@register@type@none%
+ % the clippings of the previous operator will for sure not be needed, but the type might be turned into an active one, so we need the last clipping.
+ \yquant@register@set@lastwire{#1}{%
+ {\wirexprevpos}{\wirexpos}{}%
+ {\unexpanded\expandafter{\pgfshapeclippathhorzresult}}%
+ }%
+ \else%
+ % append the previous `last' clipping to the old list and insert the new one
+ \yquant@register@set@lastwire{#1}{%
+ {\wirexprevpos}{\wirexpos}%
+ {\unexpanded\expandafter\expandafter\expandafter{%
+ \expandafter\@thirdandfourthoffour\wirelast%
+ }%
+ }
+ {\unexpanded\expandafter{\pgfshapeclippathhorzresult}}%
+ }%
+ \fi%
+ \endgroup%
}
-% 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%
+% finishes the wire of registers 1 to #1 until x position \yquant@env@end@xpos
+\protected\def\yquant@circuit@endwires#1{%
+ \yquant@for \yquant@circuit@endwires@i := 1 to #1 {
+ \yquant@draw@wire\yquant@circuit@endwires@i\yquant@env@end@xpos%
+ }%
}
-% 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)%
+% outputs the wire according to its previous instructions and prepares for a change in the wire style
+\protected\def\yquant@circuit@flushwire#1{%
+ \yquant@draw@wire{#1}{}%
+ \begingroup%
+ \yquant@register@get@lastwire{#1}\wirelast%
+ \yquant@register@set@lastwire{#1}{%
+ {\expandafter\@secondoffour\wirelast}{\expandafter\@secondoffour\wirelast}{}%
+ {\unexpanded\expandafter\expandafter\expandafter{%
+ \expandafter\@fourthoffour\wirelast%
+ }}%
}%
- \fi%
- \unless\ifx\cmd\empty%
- \edef\cmd{\noexpand\path [/yquant/every wire, /yquant/every qubits wire] \cmd;}%
- \cmd%
- \fi%
+ \endgroup%
}
% 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.
+% populates a drawing macro with the current control line with style #1 at position #2. Assumes a node called yquantbox is set up, and the \pgfshapeclippathvertresult was set up appropriately for this node. 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%
+ \eappto\yquant@circuit@extendcontrolline@clip{%
+ \unexpanded\expandafter{\pgfshapeclippathvertresult}%
+ }%
\expandafter\@tempdima\the\pgflinewidth%
\ifcase#1%
% no control (or to a discarded target, which we don't do)
\or%
% qubit
+ \pgfpointanchor{yquantbox}{center}%
\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)%
+ -- (#2,\the\pgf@y)%
}%
\fi%
\yquant@circuit@extendcontrolline@store{#2}%
\or%
% cbit
+ \pgfpointanchor{yquantbox}{center}%
\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{%
+ -- (\the\dimexpr#2-2\@tempdima\relax,\the\pgf@y)%
\expandafter\@thirdofthree\yquant@circuit@extendcontrolline@prev%
- -- (\the\pgf@x,\the\pgf@y)%
+ -- (\the\dimexpr#2+2\@tempdima\relax,\the\pgf@y)%
}%
\fi%
\yquant@circuit@extendcontrolline@store{#2}%
\or%
% quantum-bundle (very unusual, but perhaps for transversal operations?)
+ \pgfpointanchor{yquantbox}{center}%
\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{%
+ -- (\the\dimexpr#2-2\@tempdima\relax,\the\pgf@y)%
\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{%
+ -- (\the\dimexpr#2\relax,\the\pgf@y)%
\expandafter\@thirdofthree\yquant@circuit@extendcontrolline@prev%
- -- (\the\pgf@x,\the\pgf@y)%
+ -- (\the\dimexpr#2+2\@tempdima\relax,\the\pgf@y)%
}%
\fi%
\yquant@circuit@extendcontrolline@store{#2}%
\else%
- \PackageError{yquant.sty}{Invalid control line type `\the#1'}%
+ \PackageError{yquant.sty}{Invalid control line type `#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)}}%
+ \edef\yquant@circuit@extendcontrolline@prev{%
+ {(\the\dimexpr#1-2\@tempdima\relax,\the\pgf@y)}%
+ {(\the\dimexpr#1\relax,\the\pgf@y)}%
+ {(\the\dimexpr#1+2\@tempdima\relax,\the\pgf@y)}%
+ }%
+}
+
+% populates a drawing macro with the multi operation connector at position #2. Assumes a node called yquantbox is set up, and the \pgfshapeclippathvertresult was set up appropriately for this node. At the first call, \yquant@circuit@extendmultiline@cmd must be \let to \empty and \yquant@circuit@extendmultiline@prev to \relax.
+\protected\def\yquant@circuit@extendmultiline#1{%
+ \begingroup%
+ \tikzset{/yquant/every multi line}%
+ \expandafter%
+ \endgroup%
+ \eappto\yquant@circuit@extendmultiline@clip{%
+ \unexpanded\expandafter{\pgfshapeclippathvertresult}%
+ }%
+ \expandafter\@tempdima\the\pgflinewidth%
+ \pgfpointanchor{yquantbox}{center}%
+ \unless\ifx\yquant@circuit@extendmultiline@prev\relax%
+ \eappto\yquant@circuit@extendmultiline@cmd{%
+ \yquant@circuit@extendmultiline@prev -- (#1,\the\pgf@y)%
+ }%
+ \fi%
+ \edef\yquant@circuit@extendmultiline@prev{%
+ (\the\dimexpr#1\relax,\the\pgf@y)%
+ }%
}
% END_FOLD
@@ -364,7 +288,18 @@
% 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%
+ \yquant@circuit@flushwire{#1}%
+ \yquant@register@set@type{#1}{\yquant@circuit@settype@to}%
+}
+
+\protected\long\def\yquant@circuit@setstyle#1#2{%
+ \yquant@circuit@flushwire{#1}%
+ \yquant@register@set@style{#1}{#2}%
+}
+
+\protected\long\def\yquant@circuit@addstyle#1#2{%
+ \yquant@circuit@flushwire{#1}%
+ \yquant@register@set@style{#1}{\yquant@register@get@style{#1},#2}%
}
% 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
@@ -393,19 +328,20 @@
\endgroup%
}
-% sets the type of a list of registers
-% #1: arbitrary register list
-% #2: new type
-\protected\def\yquant@circuit@settypes#1#2{%
+% applies an action to wires a list of registers and causes them to be redrawn
+% #1: action
+% #2: arbitrary register list
+% #3: parameter(s)
+\protected\def\yquant@circuit@actonwires#1#2#3{%
\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}%
+ \appto\tmp{#1{##1}#3}%
}%
- \dolistloop{#1}%
+ \dolistloop{#2}%
\csxappto{\yquant@prefix draw}{\tmp}%
\endgroup%
}
@@ -434,12 +370,12 @@
{\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 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.
\dolistloop{\empty#1}%
\csgappto{\yquant@prefix draw}{%
\yquant@circuit@output@endgroup%
@@ -447,7 +383,7 @@
}
\def\yquant@circuit@output@do@multi@@extract#1#2#3#4#5{%
- {#2}{#3}%
+ {#2}{#3}{#5}%
}
\protected\long\def\yquant@circuit@output@group#1{%
@@ -462,15 +398,27 @@
\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};
+ /yquant/every \ifcase\yquant@register@get@type{#1} nobit\or qubit\or cbit\or qubits\fi\space output] {#2};
\numdef\idx{\idx+1}%
}
-\long\def\yquant@circuit@output@do@multi#1#2#3{%
+\long\def\yquant@circuit@output@do@multi#1#2#3#4{%
+ % extremely similar to \yquant@draw@multiinit
+ \@tempdima=-.5\dimexpr\yquant@config@register@sep\relax%
+ \dimdef\yquant@draw@multiinit@@min{\yquant@register@get@y{#1}-\@tempdima}%
+ \dimdef\yquant@draw@multiinit@@max{\yquant@register@get@y{#2}+\@tempdima}%
+ \dimdef\yquant@draw@multiinit@@total{%
+ \yquant@draw@multiinit@@max-\yquant@draw@multiinit@@min%
+ }%
+ \def\pgfdecorationsegmentaspect{0}%
+ \let\yquant@register@multi@contiguous=\yquant@draw@multiinit@contiguous%
+ \let\pgfdecorationsegmentfromto=\empty%
+ #3%
+ \edef\pgfdecorationsegmentfromto{\expandafter\@gobble\pgfdecorationsegmentfromto}%
\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};%
+ (\yquant@env@end@xpos, \yquant@draw@multiinit@@min) --
+ (\yquant@env@end@xpos, \yquant@draw@multiinit@@max)
+ node {#4};%
\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
index 2aa1158b05b..c1a74fecb46 100644
--- a/Master/texmf-dist/tex/latex/yquant/yquant-config.tex
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-config.tex
@@ -1,4 +1,3 @@
-\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}}}
@@ -15,7 +14,10 @@
}
}
\pgfqkeys{/yquant}{
- every circuit/.style={},
+ every circuit/.style={%
+ every node/.prefix style={transform shape},%
+ every label/.prefix style={transform shape=false}% TODO: no, we don't really want this, but pgf bug #843 requires this if we still want to have `label position` available
+ },
% register settings
register/default name/.store in=%
\yquant@config@register@default@name,
@@ -25,7 +27,7 @@
{\dimdef\yquant@config@register@sep{#1}},
% register label style
every label/.style=%
- {shape=yquant-text, anchor=circuit, align=right},
+ {shape=yquant-text, anchor=center, align=right},
every initial label/.style=%
{anchor=east},
every qubit label/.style=%
@@ -35,8 +37,8 @@
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)}}},
+ {shift={(-.075, 0)}, draw, decoration={gapped brace, mirror}, decorate, /yquant/gapped brace/apply shift,
+ every node/.append style={shape=yquant-text, anchor=east, align=right, shift={(-.05, 0)}, pos=-1}},
% output label styles
every output/.style=%
{shape=yquant-text, anchor=west, align=left},
@@ -47,8 +49,8 @@
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)}}},
+ {shift={(.075, 0)}, draw, decoration={gapped brace}, decorate, /yquant/gapped brace/apply shift,
+ every node/.append style={shape=yquant-text, anchor=west, align=left, shift={(.05, 0)}, pos=-1}},
% wire style
every wire/.style=%
{draw},
@@ -63,18 +65,26 @@
{\dimdef\yquant@config@operator@sep{#1}},
operator/minimum width/.code=%
{\dimdef\yquant@config@operator@minimum@width{#1}},
+ operator/multi warning/.is if=%
+ yquant@config@operator@multi@warn,
% operator style: control
every control line/.style=%
{draw},
every control/.style=%
- {shape=yquant-circle, anchor=circuit, radius=.5mm},
+ {shape=yquant-circle, anchor=center, radius=.5mm},
every positive control/.style=%
{fill=black},
every negative control/.style=%
{draw},
% operator style: main part
every operator/.style=%
- {anchor=circuit},
+ {anchor=center},
+ operator/multi main/.is if=%
+ yquant@config@operator@multi@main,
+ operator/multi as single/.style=%
+ {/yquant/every multi line/.style=/yquant/every control line},
+ every multi line/.style=%
+ {draw, decoration={snake, amplitude=.25mm, segment length=5pt}, decorate},
% overwriting all styles
this operator/.style=%
{},
@@ -107,17 +117,13 @@
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},
+ {shape=yquant-circle, radius=.5mm, fill},
operators/every xx/.style=%
- % same as zz
- {shape=yquant-xx, x radius=.75mm, y radius=1.5mm, draw},
+ {shape=yquant-rectangle, radius=.75mm, 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},
+ {shape=yquant-swap, radius=.75mm, draw},
operators/every not/.style=%
{shape=yquant-oplus, radius=1.3mm, draw},
operators/every measure/.style=%
@@ -127,8 +133,13 @@
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,
+ {shape=yquant-line, dashed, draw},
+ operators/every wave/.style=%
+ {shape=yquant-circle, radius=.5mm, fill},
+ /pgf/decoration/from to/.store in=\pgfdecorationsegmentfromto,
+ gapped brace/apply shift/.code={%
+ \let\tikz@timer@line=\yquant@gappedbrace@timer%
+ },
}
\def\yquant@config@register@default@name{\regidx}
@@ -136,5 +147,142 @@
\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
+\newif\ifyquant@config@operator@multi@main%
+\yquant@config@operator@multi@maintrue
+\newif\ifyquant@config@operator@multi@warn
+\yquant@config@operator@multi@warntrue
+\def\pgfdecorationsegmentfromto{0-1}%
+
+\protected\def\yquant@gappedbrace@extract#1-#2\yquant@sep{%
+ \dimdef\from{#1\pgfdecoratedremainingdistance}%
+ \dimdef\to{#2\pgfdecoratedremainingdistance}%
+}
+% This function is set to replace the transformation that changes the fraction value specified in the node property pos by a computation of the correct value for the gappedbrace decoration. It thus requires \pgfdecorationsegmentfromto to be already set up properly. Only if the special position -1 is given, these transformations are applied; else, the default behavior is reproduced (\tikz@timer@line).
+\protected\def\yquant@gappedbrace@timer{%
+ \ifdim\tikz@time pt=-1pt %
+ % first set \pgfdecoratedremainingdistance appropriately
+ \pgfpointdiff\tikz@timer@start\tikz@timer@end%
+ \pgfmathsqrt@{\dimexpr\pgf@x*\pgf@x/65536+\pgf@y*\pgf@y/65536\relax\@gobbletwo}
+ \pgfdecoratedremainingdistance=\pgfmathresult pt %
+ % now perform the transformation
+ \pgf@xc=\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance%
+ \expandafter\forcsvlist\expandafter\yquant@gappedbrace@shiftloop%
+ \expandafter{\pgfdecorationsegmentfromto}%
+ % and finally let us return the desired position, just ignoring \tikz@time...
+ \pgftransformlineattime{\pgfdecorationsegmentaspect}{\tikz@timer@start}{\tikz@timer@end}%
+ \else%
+ \pgftransformlineattime{\tikz@time}{\tikz@timer@start}{\tikz@timer@end}%
+ \fi%
+}
+\def\yquant@gappedbrace@shiftloop#1{%
+ \yquant@gappedbrace@extract#1\yquant@sep%
+ \unless\ifdim\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance<\from %
+ \unless\ifdim\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance>\to %
+ % be careful about arch positions at the border
+ \ifdim\dimexpr\to-\from\relax<2\pgfdecorationsegmentamplitude %
+ % The arch is larger than the segment. We do not draw a line to it or an end line and place it in the mid of the segment, even if it is too short (this issues one extra \pgfpathmoveto command, but catching this rare case is not worth the effort).
+ \edef\pgfdecorationsegmentaspect{\pgfmath@tonumber{\dimexpr%
+ .5\dimexpr\from+\to\relax*65536/\pgfdecoratedremainingdistance%
+ \relax}}%
+ \else%
+ % The segment is large enough to cover the whole arch. But maybe we are too close at the border?
+ \ifdim\dimexpr\pgf@xc-\pgfdecorationsegmentamplitude\relax<\from %
+ \pgf@xc=\dimexpr\from+\pgfdecorationsegmentamplitude\relax%
+ \fi%
+ \ifdim\dimexpr\pgf@xc+\pgfdecorationsegmentamplitude\relax>\to %
+ \pgf@xc=\dimexpr\to-\pgfdecorationsegmentamplitude\relax%
+ \fi%
+ \edef\pgfdecorationsegmentaspect{\pgfmath@tonumber{\dimexpr%
+ \dimexpr\pgf@xc*65536/\pgfdecoratedremainingdistance%
+ \relax}}%
+ \fi%
+ \expandafter\expandafter\expandafter\listbreak%
+ \fi%
+ \fi%
+}
+\def\yquant@gappedbrace@loop#1{%
+ \yquant@gappedbrace@extract#1\yquant@sep%
+ \unless\ifdim\from=0pt %
+ \pgfpathmoveto{%
+ \pgfqpoint{\from}{.5\pgfdecorationsegmentamplitude}%
+ }%
+ \fi%
+ \unless\ifdim\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance<\from %
+ \unless\ifdim\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance>\to %
+ % be careful about arch positions at the border
+ \ifdim\dimexpr\to-\from\relax<2\pgfdecorationsegmentamplitude %
+ % The arch is larger than the segment. We do not draw a line to it or an end line and place it in the mid of the segment, even if it is too short (this issues one extra \pgfpathmoveto command, but catching this rare case is not worth the effort).
+ \pgfpathmoveto{%
+ \pgfqpoint{\dimexpr.5\dimexpr\from+\to\relax-\pgfdecorationsegmentamplitude\relax}%
+ {.5\pgfdecorationsegmentamplitude}%
+ }%
+ \edef\to{\the\pgfdecoratedremainingdistance}% to prevent the final line, we do not need "to" any more
+ \else%
+ % The segment is large enough to cover the whole arch. But maybe we are too close at the border?
+ \ifdim\dimexpr\pgf@xc-\pgfdecorationsegmentamplitude\relax<\from %
+ \pgf@xc=\dimexpr\from+\pgfdecorationsegmentamplitude\relax%
+ \fi%
+ \ifdim\dimexpr\pgf@xc+\pgfdecorationsegmentamplitude\relax>\to %
+ \pgf@xc=\dimexpr\to-\pgfdecorationsegmentamplitude\relax%
+ \fi%
+ % Both cases can't occur at the same time in this \else clause.
+ \pgfpathlineto{%
+ \pgfqpoint{\dimexpr\pgf@xc-\pgfdecorationsegmentamplitude\relax}%
+ {.5\pgfdecorationsegmentamplitude}%
+ }%
+ \fi%
+ \pgfpathcurveto{%
+ \pgfqpoint{\dimexpr\pgf@xc-.5\pgfdecorationsegmentamplitude\relax}%
+ {.5\pgfdecorationsegmentamplitude}%
+ }{%
+ \pgfqpoint{\dimexpr\pgf@xc-.15\pgfdecorationsegmentamplitude\relax}%
+ {.7\pgfdecorationsegmentamplitude}%
+ }{%
+ \pgfqpoint{\pgf@xc}{\pgfdecorationsegmentamplitude}%
+ }%
+ \pgfpathcurveto{%
+ \pgfqpoint{\dimexpr\pgf@xc+.15\pgfdecorationsegmentamplitude\relax}%
+ {.7\pgfdecorationsegmentamplitude}%
+ }{%
+ \pgfqpoint{\dimexpr\pgf@xc+.5\pgfdecorationsegmentamplitude\relax}%
+ {.5\pgfdecorationsegmentamplitude}%
+ }{%
+ \pgfqpoint{\dimexpr\pgf@xc+\pgfdecorationsegmentamplitude\relax}%
+ {.5\pgfdecorationsegmentamplitude}%
+ }%
+ \fi%
+ \fi%
+ \unless\ifdim\to=\pgfdecoratedremainingdistance %
+ \pgfpathlineto{%
+ \pgfqpoint{\to}{.5\pgfdecorationsegmentamplitude}%
+ }%
+ \fi%
+}
+% This is a variant of the brace in pathreplacing that allows for holes
+\pgfdeclaredecoration{gapped brace}{final}{%
+ \state{final}{%
+ \pgf@xc=\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance%
+ \pgfpathcurveto{%
+ \pgfqpoint{.15\pgfdecorationsegmentamplitude}{.3\pgfdecorationsegmentamplitude}%
+ }{%
+ \pgfqpoint{.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}%
+ }{%
+ \pgfqpoint{\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}%
+ }%
+ \expandafter\forcsvlist\expandafter\yquant@gappedbrace@loop%
+ \expandafter{\pgfdecorationsegmentfromto}%
+ \pgfpathlineto{%
+ \pgfqpoint{\dimexpr\pgfdecoratedremainingdistance-\pgfdecorationsegmentamplitude\relax}%
+ {.5\pgfdecorationsegmentamplitude}%
+ }%
+ \pgfpathcurveto{%
+ \pgfqpoint{\dimexpr\pgfdecoratedremainingdistance-.5\pgfdecorationsegmentamplitude\relax}%
+ {.5\pgfdecorationsegmentamplitude}%
+ }{%
+ \pgfqpoint{\dimexpr\pgfdecoratedremainingdistance-.15\pgfdecorationsegmentamplitude\relax}%
+ {.3\pgfdecorationsegmentamplitude}%
+ }{%
+ \pgfqpoint{\pgfdecoratedremainingdistance}{0pt}%
+ }%
+ }%
+}% \ 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
index baaac6ac0d2..c89eb3ef984 100644
--- a/Master/texmf-dist/tex/latex/yquant/yquant-draw.tex
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-draw.tex
@@ -11,6 +11,8 @@
\fi%
\let\yquant@circuit@extendcontrolline@cmd=\empty%
\let\yquant@circuit@extendcontrolline@prev=\relax%
+ \let\yquant@circuit@extendcontrolline@clip=\empty%
+ \let\yquant@circuit@extendmultiline@total=\empty%
\yquant@langhelper@list@attrs%
% If the quotes library is loaded, activate it. (else, this is by default \relax)
\tikz@enable@node@quotes%
@@ -47,6 +49,7 @@
\yquant@draw@alias@ctrl{#2}p%
\yquant@draw@alias@ctrl{#2}n%
\fi%
+ \yquant@circuit@extendmultiline@total%
\endgroup%
}
@@ -57,86 +60,162 @@
node[/yquant/every operator, \yquant@draw@@style, /yquant/this operator,%
name prefix=, name suffix=, name=yquantbox]%
{\unexpanded\expandafter{\yquant@draw@@content}};%
+ \pgfshapeclippath{yquantbox}%
+ {/yquant/every operator, \yquant@draw@@style,%
+ /yquant/this operator}%
}%
\cmd%
- \ifpgfpointshapexproj{yquantbox}%
- \yquant@circuit@extendwire{#1}%
- \fi%
- \yquant@circuit@extendcontrolline\yquant@draw@@currentcontroltype\yquant@draw@@x%
+ \yquant@circuit@extendwire{#1}%
+ \expandafter\yquant@circuit@extendcontrolline\expandafter%
+ {\the\yquant@draw@@currentcontroltype}\yquant@draw@@x%
% check for empty name parameter
- \if\relax\detokenize{#2}\relax%
- \else%
+ \ifstrempty{#2}\relax{%
\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{%
+\protected\def\yquant@draw@multi#1#2#3#4#5{%
\let\idx=\yquant@draw@@idx@content%
+ \edef\yquant@draw@multi@@name{#5}%
+ \def\yquant@draw@@idx@multipart{0}%
+ \let\yquant@circuit@extendmultiline@cmd=\empty%
+ \let\yquant@circuit@extendmultiline@prev=\relax%
+ \let\yquant@circuit@extendmultiline@clip=\empty%
+ \let\yquant@register@multi@contiguous=\yquant@draw@multi@contiguous%
+ #4%
+ \ifnum\yquant@draw@@idx@multipart>1 %
+ % make sure also the first split part is available via the "-s0" suffix
+ \unless\ifx\yquant@draw@multi@@name\empty%
+ \pgfnodealias{\tikz@pp@name{\yquant@draw@multi@@name-s0}}%
+ {\tikz@pp@name{\yquant@draw@multi@@name}}%
+ \fi%
+ \yquant@draw@mline@prep%
+ \fi%
+ \numdef\yquant@draw@@idx@content{\yquant@draw@@idx@content+1}%
+}
+
+\protected\def\yquant@draw@multi@contiguous#1#2#3{%
% 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,%
+ /yquant/operator/multi main=\ifnum#3=1 true\else false\fi\unless\ifnum#1=#2 ,%
y radius/.expanded=\the\dimexpr.5\dimexpr\yquant@register@get@ydist{#1}{#2}\relax\relax+%
- .5*\noexpand\pgfkeysvalueof{/tikz/y radius},%
+ .5*\noexpand\pgfkeysvalueof{/tikz/y radius}\fi,%
name prefix=, name suffix=, name=yquantbox]%
{\unexpanded\expandafter{\yquant@draw@@content}};
+ \pgfshapeclippath{yquantbox}%
+ {/yquant/every operator, \yquant@draw@@style,%
+ /yquant/this operator}%
}%
\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}%
+ \yquant@for \i := #1 to #2 {%
+ \yquant@circuit@extendwire\i%
+ }%
+ \yquant@circuit@extendmultiline\yquant@draw@@x%
+ \expandafter\yquant@circuit@extendcontrolline\expandafter%
+ {\the\yquant@draw@@currentcontroltype}\yquant@draw@@x%
+ \unless\ifx\yquant@draw@multi@@name\empty%
+ \ifnum\yquant@draw@@idx@multipart=0 %
+ \pgfnodealias{\tikz@pp@name{\yquant@draw@multi@@name}}{yquantbox}%
+ \else%
+ \pgfnodealias{\tikz@pp@name{\yquant@draw@multi@@name-s\yquant@draw@@idx@multipart}}{yquantbox}%
+ \fi%
\fi%
- \numdef\yquant@draw@@idx@content{\yquant@draw@@idx@content+1}%
+ \numdef\yquant@draw@@idx@multipart{\yquant@draw@@idx@multipart+1}%
}
-\protected\long\def\yquant@draw@multiinit#1#2#3#4#5{%
+\protected\def\yquant@draw@multiinit#1#2#3#4#5{%
\let\idx=\yquant@draw@@idx@content%
+ \@tempdima=-.5\dimexpr\yquant@config@register@sep\relax%
+ \dimdef\yquant@draw@multiinit@@min{\yquant@register@get@y{#1}-\@tempdima}%
+ \dimdef\yquant@draw@multiinit@@max{\yquant@register@get@y{#2}+\@tempdima}%
+ \dimdef\yquant@draw@multiinit@@total{%
+ \yquant@draw@multiinit@@max-\yquant@draw@multiinit@@min%
+ }%
+ \def\pgfdecorationsegmentaspect{0}%
+ \let\yquant@register@multi@contiguous=\yquant@draw@multiinit@contiguous%
+ \let\pgfdecorationsegmentfromto=\empty%
+ #4%
+ \edef\pgfdecorationsegmentfromto{\expandafter\@gobble\pgfdecorationsegmentfromto}%
% 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})%
+ (\yquant@draw@@x, \yquant@draw@multiinit@@min) --%
+ (\yquant@draw@@x, \yquant@draw@multiinit@@max)%
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)
+ % 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), no multi line
% check for empty name parameter
- \if\relax\detokenize{#5}\relax%
- \else%
+ \ifstrempty{#5}\relax{%
\pgfnodealias{\tikz@pp@name{#5}}{yquantbox}%
- \fi%
+ }%
\numdef\yquant@draw@@idx@content{\yquant@draw@@idx@content+1}%
}
+\protected\def\yquant@draw@multiinit@contiguous#1#2#3{%
+ \edef\yquant@draw@multiinit@@from{%
+ \pgfmath@tonumber{\dimexpr%
+ \dimexpr\yquant@register@get@y{#1}-\@tempdima-\yquant@draw@multiinit@@min\relax*65536/%
+ \dimexpr\yquant@draw@multiinit@@total\relax%
+ \relax}%
+ }%
+ \edef\yquant@draw@multiinit@@to{%
+ \pgfmath@tonumber{\dimexpr%
+ \dimexpr\yquant@register@get@y{#2}+\@tempdima-\yquant@draw@multiinit@@min\relax*65536/%
+ \dimexpr\yquant@draw@multiinit@@total\relax%
+ \relax}%
+ }%
+ \eappto\pgfdecorationsegmentfromto{,%
+ \yquant@draw@multiinit@@from-\yquant@draw@multiinit@@to%
+ }%
+ % We need to decide where to put the brace arch.
+ \ifdim\yquant@draw@multiinit@@from pt<.5pt %
+ \ifdim\yquant@draw@multiinit@@to pt>.5 pt%
+ % This segment covers the true 1/2 position, take it
+ \def\pgfdecorationsegmentaspect{.5}%
+ \else%
+ % We are not there yet, so the end of this segment is the closest we can get to the mid so far
+ \edef\pgfdecorationsegmentaspect{\yquant@draw@multiinit@@to}%
+ \fi%
+ \else%
+ % We are already beyond the mid...
+ \ifdim\pgfdecorationsegmentaspect pt<.5pt %
+ % ...but we did not find an ideal position yet
+ \ifdim\dimexpr\yquant@draw@multiinit@@from pt-.5pt\relax<%
+ \dimexpr.5pt-\pgfdecorationsegmentaspect pt\relax%
+ % this one is closer to the mid than anything found before
+ \edef\pgfdecorationsegmentaspect{\yquant@draw@multiinit@from}%
+ \fi%
+ \fi%
+ \fi%
+}
+
\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]%
{};%
+ \pgfshapeclippath{yquantbox}%
+ {/yquant/every control, /yquant/every #1 control,%
+ /yquant/this control}%
}%
\cmd%
- \ifpgfpointshapexproj{yquantbox}%
- \yquant@circuit@extendwire{#2}%
- \fi%
+ \yquant@circuit@extendwire{#2}%
\yquant@draw@@currentcontroltype=\yquant@register@get@type{#2}\relax%
- \yquant@circuit@extendcontrolline\yquant@draw@@currentcontroltype\yquant@draw@@x%
+ \expandafter\yquant@circuit@extendcontrolline\expandafter%
+ {\yquant@draw@@currentcontroltype}\yquant@draw@@x%
% check for empty name parameter
- \if\relax\detokenize{#3}\relax%
- \else%
+ \ifstrempty{#3}\relax{%
\pgfnodealias{\tikz@pp@name{#3}}{yquantbox}%
- \fi%
+ }%
}
\protected\def\yquant@draw@pcontrol#1#2{%
@@ -152,11 +231,62 @@
}
\protected\def\yquant@draw@cline{%
- \edef\cmd{%
- \noexpand\path[/yquant/every control line]%
- \yquant@circuit@extendcontrolline@cmd;
+ \pgfscope%
+ % install the clipping
+ \pgfsyssoftpath@setcurrentpath\yquant@circuit@extendcontrolline@clip%
+ % and invert it. It is sufficient to cover the current bounding box, as the wire will be drawn between existing operators.
+ \ifyquantdebug%
+ \pgfsetfillcolor{teal}%
+ \pgfsetfillopacity{.3}%
+ \pgfusepathqfill%
+ \else%
+ \begingroup%
+ \pgftransformreset%
+ \pgfpathrectanglecorners%
+ {\pgfqpoint{\pgf@picminx}{\pgf@picminy}}%
+ {\pgfqpoint{\pgf@picmaxx}{\pgf@picmaxy}}%
+ \pgfseteorule% even-odd to properly invert the clipping
+ \pgfusepathqclip%
+ \endgroup%
+ \fi%
+ \edef\cmd{%
+ \noexpand\path[/yquant/every control line]%
+ \yquant@circuit@extendcontrolline@cmd;
+ }%
+ \cmd%
+ \endpgfscope%
+}
+
+\protected\def\yquant@draw@mline@prep{%
+ \eappto\yquant@circuit@extendmultiline@total{%
+ \yquant@draw@mline%
+ {\unexpanded\expandafter{\yquant@circuit@extendmultiline@clip}}%
+ {\yquant@circuit@extendmultiline@cmd}%
}%
- \cmd%
+}
+
+\protected\def\yquant@draw@mline#1#2{%
+ \pgfscope%
+ % install the clipping
+ \def\pgfsyssoftpath@thepath{#1}%
+ \pgfsyssoftpath@setcurrentpath\pgfsyssoftpath@thepath%
+ % and invert it. It is sufficient to cover the current bounding box, as the wire will be drawn between existing operators.
+ \ifyquantdebug%
+ \pgfsetfillcolor{teal}%
+ \pgfsetfillopacity{.3}%
+ \pgfusepathqfill%
+ \else%
+ \begingroup%
+ \pgftransformreset%
+ \pgfpathrectanglecorners%
+ {\pgfqpoint{\pgf@picminx}{\pgf@picminy}}%
+ {\pgfqpoint{\pgf@picmaxx}{\pgf@picmaxy}}%
+ \pgfseteorule% even-odd to properly invert the clipping
+ \pgfusepathqclip%
+ \endgroup%
+ \fi%
+ \path[/yquant/every multi line] #2;
+ \endpgfscope%
}
\protected\def\yquant@draw@alias#1{%
@@ -166,6 +296,106 @@
\protected\def\yquant@draw@alias@ctrl#1#2{%
\pgfnodealias{\tikz@pp@name{#1-#2}}{\tikz@pp@name{#1-#20}}%
}
+
+\protected\def\yquant@draw@wire#1#2{%
+ \begingroup%
+ \yquant@register@get@typeywire{#1}\wiretype\wireypos\wirelast%
+ \edef\wirexprevpos{\expandafter\@firstoffour\wirelast}%
+ \ifx\yquant@env@end@xpos#2\relax%
+ \let\wirexpos=\yquant@env@end@xpos%
+ \else%
+ \edef\wirexpos{\expandafter\@secondoffour\wirelast}%
+ \fi%
+ \unless\ifnum\wiretype=\yquant@register@type@none%
+ \ifdim\wirexpos>\wirexprevpos %
+ \edef\wirestyle{\noexpand\tikzset{%
+ /yquant/this wire/.style={%
+ /yquant/every wire,%
+ /yquant/every \ifcase\wiretype\relax nobit\or qubit \or cbit \or qubits \fi wire,%
+ \yquant@register@get@style{#1}%
+ }, /yquant/this wire%
+ }}%
+ \wirestyle%
+ % load all clippings
+ \edef\wireclipping{%
+ \unexpanded\expandafter\expandafter\expandafter{%
+ \expandafter\@thirdandfourthoffour\wirelast%
+ }%
+ }%
+ \pgfscope%
+ % install the clipping
+ \pgfsyssoftpath@setcurrentpath\wireclipping%
+ % invert the clipping
+ \ifyquantdebug%
+ \pgfsetfillcolor{orange}%
+ \pgfsetfillopacity{.3}%
+ \pgfusepathqfill%
+ \else%
+ % We need to access the current bounding box as well as other positions in the local coordinate frame. For this, transform the bounding box to the current frame (though this is expensive). Does this capture rotations correctly?
+ \begingroup%
+ \pgftransforminvert%
+ \pgfpointtransformednonlinear{\pgfqpoint{\pgf@picminx}{\pgf@picminy}}
+ \global\@tempdima=\pgf@y%
+ \pgfpointtransformednonlinear{\pgfqpoint{\pgf@picmaxx}{\pgf@picmaxy}}%
+ \global\@tempdimb=\pgf@y%
+ \endgroup%
+ % To avoid rendering artifacts at all zoom levels with all renderers, we need to make the clipping region large. Let's try the current bounding box first.
+ % This may be insufficient if there no or a tiny wire label and only registers of a small height. In this case, take at ten times the line width or at least 1cm, but don't let it affect the bounding box.
+ \ifdim\dimexpr\@tempdimb-\@tempdima\relax<10\pgflinewidth %
+ \@tempdima=\dimexpr\wireypos-5\pgflinewidth\relax%
+ \@tempdimb=\dimexpr\wireypos+5\pgflinewidth\relax%
+ \fi%
+ \ifdim\dimexpr\@tempdimb-\@tempdima\relax<1cm %
+ \@tempdima=\dimexpr\wireypos-5mm\relax%
+ \@tempdimb=\dimexpr\wireypos+5mm\relax%
+ \fi%
+ \pgfinterruptboundingbox%
+ \pgfpathrectanglecorners%
+ {\pgfqpoint{\dimexpr\wirexprevpos-2\pgflinewidth\relax}%
+ {\@tempdima}}%
+ {\pgfqpoint{\dimexpr\wirexpos+2\pgflinewidth\relax}%
+ {\@tempdimb}}%
+ \endpgfinterruptboundingbox%
+ \pgfseteorule% even-odd to properly invert the clipping
+ \pgfusepathqclip%
+ \fi%
+ % the clip inversion is left to the drawing commands (clip two \pgflinewidth more to avoid renderer artifacts)
+ \csname yquant@draw@wire@\wiretype\endcsname{#1}%
+ \endpgfscope%
+ \fi%
+ \fi%
+ \endgroup%
+}
+
+% quantum wire
+\protected\csdef{yquant@draw@wire@\yquant@register@type@q}#1{%
+ \edef\cmd{%
+ \noexpand\path [/yquant/this wire]
+ (\wirexprevpos,\wireypos) -- (\wirexpos,\wireypos);%
+ }%
+ \cmd%
+}
+
+% classical wire
+\protected\csdef{yquant@draw@wire@\yquant@register@type@c}#1{%
+ \edef\cmd{%
+ \noexpand\path [/yquant/this wire]
+ (\wirexprevpos,\wireypos+2\pgflinewidth)--(\wirexpos,\wireypos+2\pgflinewidth)%
+ (\wirexprevpos,\wireypos-2\pgflinewidth)--(\wirexpos,\wireypos-2\pgflinewidth);%
+ }%
+ \cmd%
+}
+
+% quantum-bundle
+\protected\csdef{yquant@draw@wire@\yquant@register@type@qs}#1{%
+ \edef\cmd{%
+ \noexpand\path [/yquant/this wire]
+ (\wirexprevpos,\wireypos+2\pgflinewidth)--(\wirexpos,\wireypos+2\pgflinewidth)%
+ (\wirexprevpos,\wireypos)--(\wirexpos,\wireypos)%
+ (\wirexprevpos,\wireypos-2\pgflinewidth)--(\wirexpos,\wireypos-2\pgflinewidth);%
+ }%
+ \cmd%
+}
% END_FOLD
% BEGIN_FOLD Preparation of drawing a generic shape
@@ -274,7 +504,7 @@
\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.
+ % If we draw a control line, all intermediate registers are affected in their position so that the line is never crossed. If the vertical line is instead caused by a multi register, \yquant@draw@finalize@ctrl will be responsible for advancing only the affected positions.
\yquant@for \yquant@i := \yquant@circuit@operator@minctrl to \yquant@circuit@operator@maxctrl {%
\yquant@register@set@x\yquant@i{\the\dimen2}%
}%
@@ -354,14 +584,39 @@
#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?)
+ % Determining the actual height is a problem - where to store its value? If there are single-register parts, we update the height accordingly; else we just assume that there is always enough space for such a control, since it anyways 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};
+ \def\yquant@draw@@content{#1}%
+ \def\yquant@draw@@style{#2}%
+ \let\yquant@register@multi@contiguous=\yquant@draw@@multi@contiguous%
+ \@fifthoffive#3%
+ \ifdim\pgf@picmaxy=-16000pt %
+ % if there was no single contiguous part before, determine the width now
+ \path%
+ (0pt, 0pt)
+ node[/yquant/every operator, #2, /yquant/this operator,%
+ name prefix=, name suffix=, name=] {#1};
+ \fi%
+}
+
+\protected\def\yquant@draw@@multi@contiguous#1#2#3{%
+ \ifnum#1=#2 %
+ % we only care about single-register parts
+ \global\pgf@picmaxy=-16000pt %
+ \global\pgf@picminy=16000pt %
+ \edef\cmd{%
+ \noexpand\path (0pt, 0pt)%
+ node[/yquant/every operator, \yquant@draw@@style, /yquant/this operator,%
+ /yquant/operator/multi main=\ifnum#3=1 true\else false\fi,
+ name prefix=, name suffix=, name=]%
+ {\unexpanded\expandafter{\yquant@draw@@content}};
+ }%
+ \cmd%
+ \yquant@register@update@height{#1}{%
+ \the\dimexpr\pgf@picmaxy-\pgf@picminy\relax%
+ }%
+ \fi%
}
\protected\def\yquant@draw@@multiinit#1#2#3{%
@@ -373,11 +628,10 @@
% 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};
+ node[/yquant/every operator, #2, /yquant/every multi label,%
+ name prefix=, name suffix=, name=] {#1};
}
\def\yquant@draw@finalize@ctrl#1{%
@@ -401,6 +655,12 @@
}%
}
+\protected\def\yquant@draw@finalize@ctrl@singleinit#1#2{%
+ \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.
@@ -410,13 +670,57 @@
}%
}\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}%
+ \let\yquant@register@multi@contiguous=\yquant@draw@finalize@ctrl@multi@contiguous%
+ \ifyquant@circuit@operator@hasControls%
+ \ifyquant@config@operator@multi@warn%
+ \def\yquant@draw@finalize@ctrl@multi@contiguous@warn{0}%
+ \else%
+ \def\yquant@draw@finalize@ctrl@multi@contiguous@warn{2}%
+ \fi%
+ \else%
+ \def\yquant@draw@finalize@ctrl@multi@contiguous@warn{2}%
+ \fi%
+ \cslet{\yquant@prefix finalize@ctrl@draw@appto}\empty%
+ #4%
+ \eappto\yquant@draw@append{\csname\yquant@prefix finalize@ctrl@draw@appto\endcsname}%
+ \csgundef{\yquant@prefix finalize@ctrl@draw@appto}%
+}
+
+\protected\def\yquant@draw@finalize@ctrl@multiinit#1#2#3#4#5{%
+ % this is called from a do loop itself, so preserve \do (but do not enter grouping)
+ \let\yquant@register@multi@contiguous=\yquant@draw@finalize@ctrl@multi@contiguous%
+ \ifyquant@circuit@operator@hasControls%
+ \ifyquant@config@operator@multi@warn%
+ \def\yquant@draw@finalize@ctrl@multi@contiguous@warn{0}%
+ \else%
+ \def\yquant@draw@finalize@ctrl@multi@contiguous@warn{2}%
+ \fi%
+ \else%
+ \def\yquant@draw@finalize@ctrl@multi@contiguous@warn{2}%
+ \fi%
+ \cslet{\yquant@prefix finalize@ctrl@draw@appto}\empty%
+ #4%
+ \eappto\yquant@draw@append{\csname\yquant@prefix finalize@ctrl@draw@appto\endcsname}%
+ \csgundef{\yquant@prefix finalize@ctrl@draw@appto}%
+}
+
+\protected\def\yquant@draw@finalize@ctrl@multi@contiguous#1#2#3{%
+ \ifnum\yquant@draw@finalize@ctrl@multi@contiguous@warn=1 %
+ \PackageWarning{yquant.sty}{Ambiguous operation: multiple discontiguous multi-register operations in combination with controls make it hard to visually determine on which registers the gates act on.}%
+ % switch the warning off for this group (which is a single operation)
+ \yquant@config@operator@multi@warnfalse%
+ \def\yquant@draw@finalize@ctrl@multi@contiguous@warn{2}%
+ \else%
+ \numdef\yquant@draw@finalize@ctrl@multi@contiguous@warn{%
+ \yquant@draw@finalize@ctrl@multi@contiguous@warn+1%
}%
+ \fi%
+ {% save \body
+ \yquant@for \yquant@i := #1 to #2 {{% let inner loop mess up with macros
+ \csxappto{\yquant@prefix finalize@ctrl@draw@appto}{%
+ \expandafter\yquant@draw@callback@wire\expandafter{\yquant@i}%
+ }%
+ }}%
}%
- \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
index 9ba97f5915d..16c3598af38 100644
--- a/Master/texmf-dist/tex/latex/yquant/yquant-env.tex
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-env.tex
@@ -49,7 +49,6 @@
\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}{%
@@ -61,7 +60,7 @@
\ifnum\yquant@env=1 %
\yquant@env@substikz%
\fi%
- \scope[{/yquant/.cd, every circuit, #1}]%
+ \scope[{/yquant/.cd, #1, /tikz/.cd, /yquant/every circuit}]%
}
\newif\ifyquantdebug
\protected\def\yquant@env@end{%
@@ -74,16 +73,13 @@
\def\noexpand\yquant@env@end@xpos{%
\the\dimexpr\yquant@env@end@xpos+\yquant@config@operator@sep\relax%
}%
+ \yquant@circuit@endwires{\yquant@env@end@registers}%
}
% 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%
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-lang.tex b/Master/texmf-dist/tex/latex/yquant/yquant-lang.tex
index b88503beb1a..b250f788276 100644
--- a/Master/texmf-dist/tex/latex/yquant/yquant-lang.tex
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-lang.tex
@@ -68,25 +68,25 @@
}
\def\yquant@lang@create@parse@name#1[#2;{%
- \if\relax\detokenize{#2}\relax%
+ \ifstrempty{#2}{%
\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%
+ \ifstrempty{#3}{%
\yquant@langhelper@validate\len\count{#2}%
\ifnum\len<1 %
\PackageError{yquant.sty}{Invalid register length}%
{Valid register lengths are integers greater or equal to one.}%
\fi
- \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%
@@ -157,47 +157,25 @@
\protected\def\yquant@lang@create@draw#1#2#3#4#5{%
\begingroup%
\dimdef\wireypos{\yquant@register@get@y{#1}}%
- \if\relax\detokenize{#4}\relax%
+ \ifstrempty{#4}{%
% 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%
+ \yquant@register@set@lastwire{#1}{{\the\pgf@x}{\the\pgf@x}{}{}}%
+ \ifstrempty{#5}\relax{%
\pgfnodealias{\tikz@pp@name{#5}}{yquantbox}%
- \fi%
+ }%
\endgroup%
}
% END_FOLD
@@ -289,21 +267,18 @@
% 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%
+\def\yquant@lang@@xx{%
+ \yquant@register@get@multiassingle%
+ \yquant@draw%
+ {}%
+ {/yquant/operators/every xx}%
}
% two-qubit controlled phase (symmetric notation)
\yquant@langhelper@declare@command@uncontrolled{zz}\yquant@lang@@zz
\yquant@langhelper@setup@attrs{zz}{}{}
\def\yquant@lang@@zz{%
- \yquant@register@get@allowmultitrue%
+ \yquant@register@get@multiassingle%
\yquant@draw%
{}%
{/yquant/operators/every zz}%
@@ -333,14 +308,11 @@
% 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%
+\def\yquant@lang@@swap{%
+ \yquant@register@get@multiassingle%
+ \yquant@draw%
+ {}%
+ {/yquant/operators/every swap}%
}
% not
@@ -433,6 +405,18 @@
{}{}
}
+\yquant@langhelper@declare@command@uncontrolled{correlate}\yquant@lang@@correlate
+\yquant@langhelper@setup@attrs{correlate}{}{}
+\def\yquant@lang@@correlate{%
+ % do not call \yquant@register@get@multiassingle, we do not want to install a different multi line style!
+ \yquant@register@get@allowmultitrue%
+ \let\yquant@register@multi@splitparts=\yquant@register@multi@splitparts@sepall%
+ \yquant@draw%
+ {}%
+ {/yquant/operators/every wave}%
+ {}{}%
+}
+
\yquant@langhelper@declare@command@uncontrolled{align}\yquant@lang@@align
\yquant@langhelper@setup@attrs{align}{}{}
\def\yquant@lang@@align#1{%
@@ -452,14 +436,24 @@
\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%
+ \let\yquant@circuit@settype@to=\yquant@register@type@none%
+ \yquant@circuit@actonwires%
+ \yquant@circuit@settype%
+ \yquant@register@get@ids@list%
+ \yquant@register@type@none%
}
\yquant@langhelper@declare@command@uncontrolled{init}\yquant@lang@@init
\yquant@langhelper@setup@attrs{init}{value}{type}
-\def\yquant@lang@@init@multi@@extract#1#2#3#4#5{%
- #5%
+\protected\def\yquant@lang@@init@multi@@extract#1#2#3{%
+ \yquant@for \yquant@i := #1 to #2 {%
+ \edef\yquant@circuit@settype@to{\yquant@register@get@type\yquant@i}%
+ \unless\ifx\yquant@circuit@settype@to\yquant@register@type@none%
+ \expandafter\yquant@for@break%
+ \fi%
+ }%
}
+\long\def\@fifthoffive#1#2#3#4#5{#5}
\protected\def\yquant@lang@@init#1{%
\yquant@register@get@allowmultitrue%
\yquant@register@get@ids{#1}%
@@ -483,13 +477,9 @@
\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}%
+ \let\yquant@register@multi@contiguous=\yquant@lang@@init@multi@@extract%
+ \@fifthoffive##1%
+ % we should reset multi@contiguous to the original command; but this is really just a placeholder. As long as it is \protected, everything is fine.
}{%
\edef\yquant@circuit@settype@to{\yquant@register@get@type{##1}}%
}%
@@ -518,6 +508,8 @@
% special case: if there were no operations at any affected wire before, we will replace the wire description
\ifdim\yquant@circuit@operator@x=\yquant@config@operator@sep\relax%
\def\yquant@circuit@operator@x{-.5\dimen2}%
+ \let\yquant@draw@finalize@ctrl@single=\yquant@draw@finalize@ctrl@singleinit%
+ \let\yquant@draw@finalize@ctrl@multi=\yquant@draw@finalize@ctrl@multiinit%
\expandafter\yquant@draw@%
\expandafter{\yquant@lang@attr@value}%
{/yquant/every label, /yquant/every initial label, /yquant/every \yquant@lang@attr@type\space label}%
@@ -536,9 +528,9 @@
\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@langhelper@declare@command@uncontrolled{settype}\yquant@lang@@settype
+\yquant@langhelper@setup@attrs{settype}{value}{}
+\protected\def\yquant@lang@@settype#1{%
\yquant@register@get@ids{#1}%
\expandafter\ifstrequal\expandafter{\yquant@lang@attr@value}{qubit}%
{\let\yquant@circuit@settype@to=\yquant@register@type@q}%
@@ -554,6 +546,35 @@
}%
}%
}%
- \yquant@circuit@settypes\yquant@register@get@ids@list\yquant@circuit@settype@to%
+ \yquant@circuit@actonwires%
+ \yquant@circuit@settype%
+ \yquant@register@get@ids@list%
+ {}%
+}
+
+\def\yquant@lang@setwire{%
+ \PackageWarning{yquant.sty}{`setwire' gate is deprecated as of yquant 0.1.2. Use `settype' instead.}%
+ \yquant@lang@settype%
+}
+\yquant@langhelper@setup@attrs{setwire}{value}{}
+
+\yquant@langhelper@declare@command@uncontrolled{setstyle}\yquant@lang@@setstyle
+\yquant@langhelper@setup@attrs{setstyle}{value}{}
+\protected\def\yquant@lang@@setstyle#1{%
+ \yquant@register@get@ids{#1}%
+ \yquant@circuit@actonwires%
+ \yquant@circuit@setstyle%
+ \yquant@register@get@ids@list%
+ {{\yquant@lang@attr@value}}%
+}
+
+\yquant@langhelper@declare@command@uncontrolled{addstyle}\yquant@lang@@addstyle
+\yquant@langhelper@setup@attrs{addstyle}{value}{}
+\protected\def\yquant@lang@@addstyle#1{%
+ \yquant@register@get@ids{#1}%
+ \yquant@circuit@actonwires%
+ \yquant@circuit@addstyle%
+ \yquant@register@get@ids@list%
+ {{\yquant@lang@attr@value}}%
}
% END_FOLD \ 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
index f9a82d1c740..102a8959d90 100644
--- a/Master/texmf-dist/tex/latex/yquant/yquant-langhelper.tex
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-langhelper.tex
@@ -244,19 +244,19 @@
}
\def\yquant@langhelper@declare@command@@extract@nctrl#1~#2;{%
- \if\relax\detokenize{#2}\relax%
+ \ifstrempty{#2}{%
\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%
+ \ifstrempty{#2}{%
\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;{%
@@ -301,7 +301,7 @@
% 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%
+ \ifstrempty{#1}{%
\def\tmp{#2}%
\ifx\empty\tmp%
\csletcs{ifvalid}{iftrue}%
@@ -310,6 +310,6 @@
\csletcs{ifvalid}{iftrue}%
\fi%
\fi%
- \fi%
+ }\relax%
% 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
index 7f640fe4996..18a23662d3b 100644
--- a/Master/texmf-dist/tex/latex/yquant/yquant-registers.tex
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-registers.tex
@@ -17,7 +17,8 @@
{#1}% type
{#2}% x pos
{\yquant@config@register@minimum@height}% height; at the end, the y position
- {}% wire start positions
+ {{0pt}{0pt}{}{}}% wire start positions and clipping
+ {}% wire style
}%
\global\csletcs{\yquant@prefix registername@#3[#4]}{\yquant@prefix registers}%
\csxdef{\yquant@prefix registerhigh@\reg}{#4}%
@@ -63,34 +64,34 @@
}
\def\yquant@register@get@id@lazycreate@parse#1[#2;{%
- \if\relax\detokenize{#2}\relax%
+ \ifstrempty{#2}{%
\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%
+ % parse length
+ \ifstrempty{#3}{%
+ \yquant@langhelper@validate\len\count{#2}%
+ \numdef\len{\len+1}%
+ }{%
+ \PackageError{yquant.sty}{Invalid register name}%
+ {Register names must not contain `[' apart from register length indication.}%
+ }%
+ \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%
% pre-set y position
\yquant@for \idx := \idx to \numexpr \len -1\relax {%
\yquant@register@define%
@@ -129,6 +130,7 @@
\count4=0 % number of total registers
\ifblank{#1}{}{%
\let\ifinmulti=\iffalse%
+ \let\ifallowmain=\iffalse%
\let\do=\yquant@register@get@ids@outerlist%
\begingroup%
\catcode`[=\active%
@@ -169,9 +171,15 @@
\count0=2147483647 % minimal id
\count2=0 % maximal id
\count4=0 % number of total registers
+ \count6=-1 % index of main register
\let\ifinmulti=\iftrue%
+ \let\ifallowmain=\iftrue%
\let\do=\yquant@register@get@ids@multilist%
\docsvlist{#1}%
+ \ifnum\count6=-1 %
+ \count6=\count0 %
+ \fi%
+ \yquant@register@multi@splitparts%
\edef\process{%
\endgroup%
\noexpand\listadd\noexpand\yquant@register@get@ids@list{%
@@ -195,13 +203,13 @@
}
\def\yquant@register@get@ids@checkrange#1-#2\yquant@sep{%
- \if\relax\detokenize{#2}\relax%
+ \ifstrempty{#2}{%
% 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{%
@@ -214,7 +222,30 @@
\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%
+ \ifallowmain%
+ \expandafter\ifyquant@firsttoken\expandafter*\expandafter{\current}{%
+ \edef\current{%
+ \expandafter\expandafter\expandafter\trim@spaces%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@gobble\current%
+ }%
+ }%
+ % catch the minimal index
+ \edef\yquant@register@get@ids@norange@checkindex@setmain{%
+ \count6=\count2%
+ \ifnum\count0<\the\count0 %
+ \count0=\the\count0 %
+ \fi%
+ }%
+ \count0=2147483647 %
+ \csletcs{ifallowmain}{iffalse}%
+ }{
+ \let\yquant@register@get@ids@norange@checkindex@setmain=\relax%
+ }%
+ \else%
+ \let\yquant@register@get@ids@norange@checkindex@setmain=\relax%
+ \fi%
+ \ifstrempty{#2}{%
% 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}%
@@ -230,9 +261,10 @@
\yquant@register@get@id\idx{\current[\i]}%
\listeadd\yquant@register@get@ids@list{\idx}%
}%
- \else%
+ }{%
\yquant@register@get@ids@norange@index#2%
- \fi%
+ }%
+ \yquant@register@get@ids@norange@checkindex@setmain%
}
\protected\def\yquant@register@get@ids@norange@index#1\yquant@register@get@ids@@index{%
@@ -269,9 +301,15 @@
\count0=2147483647 % minimal id
\count2=0 % maximal id
\count4=0 % number of total registers
+ \count6=-1 % index of main register
\let\ifinmulti=\iftrue%
+ \let\ifallowmain=\iftrue%
\let\do=\yquant@register@get@ids@subindex@nomulti%
\docsvlist{#1}%
+ \ifnum\count6=-1 %
+ \count6=\count0 %
+ \fi%
+ \yquant@register@multi@splitparts%
\edef\process{%
\endgroup%
\noexpand\listadd\noexpand\yquant@register@get@ids@list{%
@@ -291,17 +329,29 @@
}
\def\yquant@register@get@ids@subindex@checkrange#1-#2\yquant@sep{%
- \if\relax\detokenize{#2}\relax%
+ \ifstrempty{#2}{%
% the string does not contain a dash, this is a single sub-item
- \yquant@register@get@ids@subindex@norange{\trim@spaces{#1}}%
- \else%
+ \edef\idx{\trim@spaces{#1}}%
+ \expandafter\yquant@register@get@ids@subindex@norange\expandafter{\idx}%
+ }{%
% 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]}%
+ \ifallowmain%%
+ \ifyquant@firsttoken*{#1}{%
+ \edef\idx{\current[\expandafter\trim@spaces\expandafter{\@gobble#1}]}%
+ \expandafter\yquant@register@get@id\expandafter\idx\expandafter{\idx}%
+ \count6=\idx%
+ \csletcs{ifallowmain}{iffalse}%
+ }{
+ \yquant@register@get@id\idx{\current[#1]}%
+ }%
+ \else%
+ \yquant@register@get@id\idx{\current[#1]}%
+ \fi%
\ifnum\idx<\count0 %
\count0=\idx\relax%
\fi%
@@ -313,16 +363,55 @@
}
\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}%
- }%
+ \ifallowmain%
+ \ifyquant@firsttoken*{#1}{%
+ \expandafter\ifblank\expandafter{\@gobble#1}{%
+ \def\first{0}%
+ }{%
+ \expandafter\yquant@langhelper@validate\expandafter\first\expandafter\count\expandafter{\@gobble#1}%
+ }%
+ \yquant@register@get@id\idx{\current[\first]}%
+ \count6=\idx%
+ \csletcs{ifallowmain}{iffalse}%
+ }{%
+ \ifblank{#1}{%
+ \def\first{0}%
+ }{%
+ \yquant@langhelper@validate\first\count{#1}%
+ }%
+ }%
+ \else%
+ \ifblank{#1}{%
+ \def\first{0}%
+ }{%
+ \yquant@langhelper@validate\first\count{#1}%
+ }%
+ \fi%
+ \ifallowmain%
+ % in #1, all initial spaces are gobbled automatically, but not in #2
+ \expandafter\ifyquant@firsttoken\expandafter*\expandafter{\empty#2}{%
+ \expandafter\ifblank\expandafter{\@gobble#2}{%
+ \yquant@register@get@id@high\last\current%
+ }{%
+ \expandafter\yquant@langhelper@validate\expandafter\last\expandafter\count\expandafter{\@gobble#2}%
+ }%
+ \yquant@register@get@id\idx{\current[\last]}%
+ \count6=\idx%
+ \csletcs{ifallowmain}{iffalse}%
+ }{%
+ \ifblank{#2}{%
+ \yquant@register@get@id@high\last\current%
+ }{%
+ \yquant@langhelper@validate\last\count{#2}%
+ }%
+ }%
+ \else%
+ \ifblank{#2}{%
+ \yquant@register@get@id@high\last\current%
+ }{%
+ \yquant@langhelper@validate\last\count{#2}%
+ }%
+ \fi%
\yquant@for \i := \first to \last {%
\yquant@register@get@ids@subindex@norange\i%
}%
@@ -330,14 +419,33 @@
\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%
- }%
+ \ifallowmain%
+ \ifyquant@firsttoken*{#1}{%
+ \expandafter\ifblank\expandafter{\@gobble#1}{%
+ \def\first{1}%
+ }{%
+ \expandafter\yquant@register@get@ids@range@getfirst\@gobble#1\yquant@register@get@ids@@index\yquant@sep%
+ }%
+ \count6=\first%
+ \csletcs{ifallowmain}{iffalse}%
+ }{%
+ \ifblank{#1}{%
+ \def\first{1}%
+ }{%
+ \yquant@register@get@ids@range@getfirst#1\yquant@register@get@ids@@index\yquant@sep%
+ }%
+ }%
+ \else%
+ \ifblank{#1}{%
+ \def\first{1}%
+ }{%
+ \yquant@register@get@ids@range@getfirst#1\yquant@register@get@ids@@index\yquant@sep%
+ }%
+ \fi%
+ % it does not make sense to allow to set the main part on the second half of the range, since a range over registers (not indices) is automatically visual, so this range will be contiguous.
\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%
@@ -363,20 +471,20 @@
}
\def\yquant@register@get@ids@range@getfirst#1\yquant@register@get@ids@@index#2\yquant@sep{%
- \if\relax\detokenize{#2}\relax%
+ \ifstrempty{#2}{%
\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%
+ \ifstrempty{#2}{%
\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{%
@@ -384,6 +492,94 @@
}
\let\yquant@register@multi=\empty%
+\protected\def\yquant@register@multi@contiguous{}%
+
+% splits \yquant@register@get@ids@list into a list of contiguous parts
+\protected\def\yquant@register@multi@splitparts{%
+ \begingroup%
+ \let\registers=\yquant@register@get@ids@list%
+ \yquant@sort@list\registers\yquant@sort@ascending%
+ \let\newlist=\empty%
+ \count2=-1 %
+ \def\do##1{%
+ \ifnum\count2=-1 %
+ \count2=##1 %
+ \count4=\count2 %
+ \else%
+ \advance\count2 by 1 %
+ \ifnum##1>\count2 %
+ % this is a discontiguous change (we disallow duplicate entries)
+ \eappto\newlist{%
+ \yquant@register@multi@contiguous%
+ {\the\count4}{\the\numexpr\count2-1\relax}%
+ {\ifnum\count6<\count2 %
+ \ifnum\count4>\count6 %
+ 0%
+ \else%
+ 1%
+ \fi%
+ \else%
+ 0%
+ \fi}%
+ }%
+ \count2=##1 %
+ \count4=\count2 %
+ \fi%
+ \fi%
+ }%
+ \dolistloop\registers%
+ % we disallow empty lists
+ \eappto\newlist{%
+ \yquant@register@multi@contiguous%
+ {\the\count4}{\the\count2}%
+ {\ifnum\count6>\count2 %
+ 0%
+ \else%
+ \ifnum\count4>\count6 %
+ 0%
+ \else%
+ 1%
+ \fi%
+ \fi}%
+ }%
+ \expandafter%
+ \endgroup%
+ \expandafter\def\expandafter\yquant@register@get@ids@list\expandafter{%
+ \newlist%
+ }%
+}
+
+% splits \yquant@register@get@ids@list into a list of discontiguous parts
+\protected\def\yquant@register@multi@splitparts@sepall{%
+ \begingroup%
+ \let\registers=\yquant@register@get@ids@list%
+ \yquant@sort@list\registers\yquant@sort@ascending%
+ \let\newlist=\empty%
+ \def\do##1{%
+ \eappto\newlist{%
+ \yquant@register@multi@contiguous%
+ {##1}{##1}%
+ {\ifnum##1=\count6 %
+ 1%
+ \else%
+ 0%
+ \fi%
+ }%
+ }%
+ }%
+ \dolistloop\registers%
+ \expandafter%
+ \endgroup%
+ \expandafter\def\expandafter\yquant@register@get@ids@list\expandafter{%
+ \newlist%
+ }%
+}
+
+\protected\def\yquant@register@get@multiassingle{%
+ \yquant@register@get@allowmultitrue%
+ \let\yquant@register@multi@splitparts=\yquant@register@multi@splitparts@sepall%
+ \preto\yquant@attrs@remaining{/yquant/operator/multi as single,}%
+}
% END_FOLD
% BEGIN_FOLD Getters: extract the requested information from the register with given id
@@ -392,21 +588,21 @@
\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@type@aux#1#2#3#4#5{#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@x@aux#1#2#3#4#5{#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}
+\def\yquant@register@get@height@aux#1#2#3#4#5{#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{%
@@ -443,7 +639,27 @@
\yquant@register@get@lastwire@aux\csname\yquant@prefix register@#1\endcsname%
}
-\def\yquant@register@get@lastwire@aux#1#2#3#4{#4}
+\protected\def\yquant@register@get@lastwire@aux#1#2#3#4#5#6{%
+ \def#6{#4}%
+}
+
+\def\yquant@register@get@style#1{%
+ \expandafter\expandafter\expandafter%
+ \yquant@register@get@style@aux\csname\yquant@prefix register@#1\endcsname%
+}
+
+\def\yquant@register@get@style@aux#1#2#3#4#5{#5}
+
+\def\yquant@register@get@typeywire#1{%
+ \expandafter\expandafter\expandafter%
+ \yquant@register@get@typeywire@aux\csname\yquant@prefix register@#1\endcsname%
+}
+
+\protected\def\yquant@register@get@typeywire@aux#1#2#3#4#5#6#7#8{%
+ \def#6{#1}%
+ \def#7{#3}%
+ \def#8{#4}%
+}%
% Set #1 to the maximum x value found between #2 and #3
\protected\def\yquant@register@get@maxxrange#1#2#3{%
@@ -487,8 +703,8 @@
\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}%
+\long\def\yquant@register@set@type@aux#1#2#3#4#5#6{%
+ {#6}\unexpanded{{#2}{#3}{#4}{#5}}%
}
\protected\def\yquant@register@set@x#1{%
@@ -496,8 +712,8 @@
\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}%
+\long\def\yquant@register@set@x@aux#1#2#3#4#5#6{%
+ \unexpanded{{#1}}{#6}\unexpanded{{#3}{#4}{#5}}%
}
\protected\def\yquant@register@update@height#1#2{%
@@ -513,12 +729,8 @@
}
% 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}%
+\long\def\yquant@register@set@height@aux#1#2#3#4#5#6{%
+ \unexpanded{{#1}{#2}}{#6}\unexpanded{{#4}{#5}}%
}
\protected\def\yquant@register@set@lastwire#1{%
@@ -526,7 +738,16 @@
\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}%
+\long\def\yquant@register@set@lastwire@aux#1#2#3#4#5#6{%
+ \unexpanded{{#1}{#2}{#3}}{#6}\unexpanded{{#5}}%
+}
+
+\protected\def\yquant@register@set@style#1{%
+ \expandafter\yquant@register@set@@aux%
+ \csname\yquant@prefix register@#1\endcsname\yquant@register@set@style@aux%
+}
+
+\long\def\yquant@register@set@style@aux#1#2#3#4#5#6{%
+ \unexpanded{{#1}{#2}{#3}{#4}}{#6}%
}
% 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
index 0f88ed63450..3a03985ca5a 100644
--- a/Master/texmf-dist/tex/latex/yquant/yquant-shapes.tex
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-shapes.tex
@@ -1,97 +1,63 @@
-% 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}%
-}%
+\long\def\pgf@sh@clippathhorz#1{%
+ \csgdef{pgf@sh@cliphorz@\pgf@sm@shape@name}{#1}%
+}
+\let\pgf@sh@clippath=\pgf@sh@clippathhorz%
+\long\def\pgf@sh@clippathvert#1{%
+ \csgdef{pgf@sh@clipvert@\pgf@sm@shape@name}{#1}%
+}
+\def\pgf@sh@inheritclippath[from=#1]{%
+ \global\csletcs{pgf@sh@cliphorz@\pgf@sm@shape@name}{pgf@sh@cliphorz@#1}%
+ \global\csletcs{pgf@sh@clipvert@\pgf@sm@shape@name}{pgf@sh@clipvert@#1}%
+}
\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}%
+ \let\clippathhorz=\pgf@sh@clippathhorz%
+ \let\clippathvert=\pgf@sh@clippathvert%
+ \let\clippath=\pgf@sh@clippath%
+ \let\inheritclippath=\pgf@sh@inheritclippath}%
{}%
{\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{%
+% Every shape additionally provides information about how it should clip the wires. The clipping softpath instructions of shape #1 are stored into \pgfshapeclippathresult. The path is drawn with the tikz options #2 in place.
+\protected\def\pgfshapeclippath#1#2{%
% Ok, check whether #1 is known!
\ifcsname pgf@sh@ns@#1\endcsname%
- \pgf@process{%
+ \begin{pgfinterruptpath}%
\edef\pgfreferencednodename{#1}% for use inside of anchors.
+ % install the given style and extract whether we draw a line.
+ \let\tikz@mode=\pgfutil@empty%
+ \tikzset{every path/.try,#2}%
+ \edef\oldpgflinewidth{\the\pgflinewidth}%
+ \tikz@mode@drawfalse%
+ \tikz@mode%
+ \unless\iftikz@mode@draw%
+ \pgflinewidth=0pt %
+ \fi%
% 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%
- }%
+ \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
+ \csname pgf@sh@cliphorz@\csname pgf@sh@ns@#1\endcsname\endcsname%
+ \pgfsyssoftpath@getcurrentpath\pgfshapeclippathresult%
+ \pgfprocessround{\pgfshapeclippathresult}{\pgfshapeclippathresult}%
+ \global\let\pgfshapeclippathhorzresult=\pgfshapeclippathresult%
+ \ifcsname pgf@sh@clipvert@\csname pgf@sh@ns@#1\endcsname\endcsname%
+ % different clipping in vertical direction
+ \pgfsyssoftpath@setcurrentpath\pgfutil@empty%
+ \csname pgf@sh@clipvert@\csname pgf@sh@ns@#1\endcsname\endcsname%
+ \pgfsyssoftpath@getcurrentpath\pgfshapeclippathresult%
+ \pgfprocessround{\pgfshapeclippathresult}{\pgfshapeclippathresult}%
+ \fi%
+ \global\let\pgfshapeclippathvertresult=\pgfshapeclippathresult%
+ \end{pgfinterruptpath}%
\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}{%
@@ -99,39 +65,28 @@
\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%
- }
+ \clippath{%
+ % all pgf temporaries may be overwritten by \pgfpathrectanglecorners
+ \begingroup%
+ % the outer sep may depend on the line width (though there may not be any line)
+ \pgflinewidth=\oldpgflinewidth%
+ \global\@tempdima=\pgfkeysvalueof{/pgf/outer xsep} %
+ \global\@tempdimb=\pgfkeysvalueof{/pgf/outer ysep} %
+ \endgroup%
+ \advance\@tempdima by -.5\pgflinewidth%
+ \advance\@tempdimb by -.5\pgflinewidth%
+ \pgfpathrectanglecorners%
+ {\southwest%
+ \advance\pgf@x by \@tempdima%
+ \advance\pgf@y by \@tempdimb%
+ }
+ {\northeast%
+ \advance\pgf@x by -\@tempdima%
+ \advance\pgf@y by -\@tempdimb%
+ }%
+ }%
}
\pgfdeclareshape{yquant-rectangle}{%
@@ -198,28 +153,6 @@
\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{%
@@ -227,12 +160,19 @@
{\pgfqpoint{-\xradius}{\yradius}}%
{\pgfqpoint{\xradius}{-\yradius}}%
}%
+ \clippath{%
+ \pgfpathrectanglecorners%
+ {\pgfqpoint{-\dimexpr\xradius+.5\pgflinewidth\relax}%
+ {\dimexpr\yradius+.5\pgflinewidth\relax}}%
+ {\pgfqpoint{\dimexpr\xradius+.5\pgflinewidth\relax}%
+ {-\dimexpr\yradius+.5\pgflinewidth\relax}}%
+ }%
% END_FOLD
}
\pgfdeclareshape{yquant-circle}{%
\inheritsavedanchors[from=yquant-rectangle]%
- \foreach \anc in {center, north, east, south, west, circuit, text} {%
+ \foreach \anc in {center, north, east, south, west, text} {%
\inheritanchor[from=yquant-rectangle]{\anc}%
}%
\anchor{north east}%
@@ -254,123 +194,26 @@
{\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{%
+ \backgroundpath{%
\pgfpathellipse{\pgfpointorigin}%
{\pgfqpoint{\xradius}{0pt}}%
{\pgfqpoint{0pt}{\yradius}}%
}%
+ \clippath{%
+ \pgfpathellipse{\pgfpointorigin}%
+ {\pgfqpoint{\dimexpr\xradius+.5\pgflinewidth}{0pt}}%
+ {\pgfqpoint{0pt}{\dimexpr\yradius+.5\pgflinewidth}}%
+ }%
}
-\pgfdeclareshape{yquant-zz}{%
- % Here, the radii have a special meaning, we don't put text into the shape
+\pgfdeclareshape{yquant-slash}{%
\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} {%
+ \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west} {%
\inheritanchor[from=yquant-rectangle]{\anc}%
}%
\inheritanchorborder[from=yquant-rectangle]%
@@ -378,46 +221,148 @@
\pgfpathmoveto{\pgfqpoint{\xradius}{\yradius}}%
\pgfpathlineto{\pgfqpoint{-\xradius}{-\yradius}}%
}%
+ \clippath{%
+ % we need to clip to the line; but this is not possible, we can only clip to the inner of a path. For this reason, calculate the rectangle that represents the line.
+ % TODO: for round line endings, this is not a rectangle. Only a problem if the yradius is so short that the slash ends within a wire.
+ \ifcsname yquant@math@cache1@\xradius @\yradius @\the\pgflinewidth\endcsname%
+ \letcs\tmp{yquant@math@cache1@\xradius @\yradius @\the\pgflinewidth}%
+ \dimen2=\expandafter\@firstoftwo\tmp%
+ \dimen4=\expandafter\@secondoftwo\tmp%
+ \else%
+ % cos(arctan(x)) = 1/sqrt(1+x^2)
+ % sin(arctan(x)) = x/sqrt(1+x^2)
+ \dimen2=\xradius %
+ \dimen4=\yradius %
+ % 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.
+ \dimen0=\dimexpr\dimen4*\dimen4/\dimen2*65536/\dimen2\relax%
+ % 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.
+ \pgfmathsqrt@{\the\dimexpr1pt+\dimen0\relax\@gobbletwo}%
+ \pgfmathreciprocal@\pgfmathresult%
+ \dimen2=\dimexpr.5\pgflinewidth*\dimexpr\pgfmathresult pt\relax/65536\relax%
+ \dimen4=\dimexpr\dimexpr\yradius\relax*\dimen2/\dimexpr\xradius\relax\relax%
+ \csxdef{yquant@math@cache1@\xradius @\yradius @\the\pgflinewidth}%
+ {{\the\dimen2}{\the\dimen4}}%
+ \fi%
+ \pgfpathmoveto{\pgfqpoint{-\dimexpr\xradius+\dimen4\relax}%
+ {-\dimexpr\yradius-\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{\dimexpr\xradius-\dimen4\relax}%
+ {\dimexpr\yradius+\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{\dimexpr\xradius+\dimen4\relax}%
+ {\dimexpr\yradius-\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{-\dimexpr\xradius-\dimen4\relax}%
+ {-\dimexpr\yradius+\dimen2\relax}}%
+ \pgfpathclose%
+ }%
}
\pgfdeclareshape{yquant-swap}{%
- \inheritsavedanchors[from=yquant-xx]%
- \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
+ \inheritsavedanchors[from=yquant-slash]%
+ \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west} {%
\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}}%
+ \pgfpathmoveto{\pgfqpoint{\xradius}{\yradius}}%
\pgfpathlineto{\pgfqpoint{-\xradius}{-\yradius}}%
}%
+ \clippathhorz{%
+ % we need to clip to the line; but this is not possible, we can only clip to the inner of a path. For this reason, calculate the rectangle that represents the line.
+ % TODO: for round line endings, this is not a rectangle. Only a problem if the yradius is so short that the slash ends within a wire.
+ \ifcsname yquant@math@cache1@\xradius @\yradius @\the\pgflinewidth\endcsname%
+ \letcs\tmp{yquant@math@cache1@\xradius @\yradius @\the\pgflinewidth}%
+ \dimen2=\expandafter\@firstoftwo\tmp%
+ \dimen4=\expandafter\@secondoftwo\tmp%
+ \else%
+ % cos(arctan(x)) = 1/sqrt(1+x^2)
+ % sin(arctan(x)) = x/sqrt(1+x^2)
+ \dimen2=\xradius %
+ \dimen4=\yradius %
+ % 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.
+ \dimen0=\dimexpr\dimen4*\dimen4/\dimen2*65536/\dimen2\relax%
+ % 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.
+ \pgfmathsqrt@{\the\dimexpr1pt+\dimen0\relax\@gobbletwo}%
+ \pgfmathreciprocal@\pgfmathresult%
+ \dimen2=\dimexpr.5\pgflinewidth*\dimexpr\pgfmathresult pt\relax/65536\relax%
+ \dimen4=\dimexpr\dimexpr\yradius\relax*\dimen2/\dimexpr\xradius\relax\relax%
+ \csxdef{yquant@math@cache1@\xradius @\yradius @\the\pgflinewidth}%
+ {{\the\dimen2}{\the\dimen4}}%
+ \fi%
+ \dimen6=\dimexpr\dimen2*\dimexpr\xradius\relax/\dimexpr\yradius\relax+%
+ \dimen2*\dimexpr\yradius\relax/\dimexpr\xradius\relax\relax%
+ \pgfpathmoveto{\pgfqpoint{-\dimexpr\xradius+\dimen4\relax}%
+ {\dimexpr\yradius-\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{-\dimexpr\xradius-\dimen4\relax}%
+ {\dimexpr\yradius+\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{\dimexpr\xradius-\dimen4\relax}%
+ {\dimexpr\yradius+\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{\dimexpr\xradius+\dimen4\relax}%
+ {\dimexpr\yradius-\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{\dimen6}{0pt}}%
+ \pgfpathlineto{\pgfqpoint{\dimexpr\xradius+\dimen4\relax}%
+ {-\dimexpr\yradius-\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{\dimexpr\xradius-\dimen4\relax}%
+ {-\dimexpr\yradius+\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{-\dimexpr\xradius-\dimen4\relax}%
+ {-\dimexpr\yradius+\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{-\dimexpr\xradius+\dimen4\relax}%
+ {-\dimexpr\yradius-\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{-\dimen6}{0pt}}%
+ \pgfpathclose%
+ }%
+ \clippathvert{%
+ % we need to clip to the line; but this is not possible, we can only clip to the inner of a path. For this reason, calculate the rectangle that represents the line.
+ % TODO: for round line endings, this is not a rectangle. Only a problem if the yradius is so short that the slash ends within a wire.
+ \ifcsname yquant@math@cache1@\xradius @\yradius @\the\pgflinewidth\endcsname%
+ \letcs\tmp{yquant@math@cache1@\xradius @\yradius @\the\pgflinewidth}%
+ \dimen2=\expandafter\@firstoftwo\tmp%
+ \dimen4=\expandafter\@secondoftwo\tmp%
+ \else%
+ % cos(arctan(x)) = 1/sqrt(1+x^2)
+ % sin(arctan(x)) = x/sqrt(1+x^2)
+ \dimen2=\xradius %
+ \dimen4=\yradius %
+ % 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.
+ \dimen0=\dimexpr\dimen4*\dimen4/\dimen2*65536/\dimen2\relax%
+ % 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.
+ \pgfmathsqrt@{\the\dimexpr1pt+\dimen0\relax\@gobbletwo}%
+ \pgfmathreciprocal@\pgfmathresult%
+ \dimen2=\dimexpr.5\pgflinewidth*\dimexpr\pgfmathresult pt\relax/65536\relax%
+ \dimen4=\dimexpr\dimexpr\yradius\relax*\dimen2/\dimexpr\xradius\relax\relax%
+ \csxdef{yquant@math@cache1@\xradius @\yradius @\the\pgflinewidth}%
+ {{\the\dimen2}{\the\dimen4}}%
+ \fi%
+ \dimen6=\dimexpr\dimen4*\dimexpr\xradius\relax/\dimexpr\yradius\relax+%
+ \dimen4*\dimexpr\yradius\relax/\dimexpr\xradius\relax\relax%
+ \pgfpathmoveto{\pgfqpoint{-\dimexpr\xradius+\dimen4\relax}%
+ {\dimexpr\yradius-\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{-\dimexpr\xradius-\dimen4\relax}%
+ {\dimexpr\yradius+\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{0pt}{\dimen6}}%
+ \pgfpathlineto{\pgfqpoint{\dimexpr\xradius-\dimen4\relax}%
+ {\dimexpr\yradius+\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{\dimexpr\xradius+\dimen4\relax}%
+ {\dimexpr\yradius-\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{\dimexpr\xradius+\dimen4\relax}%
+ {-\dimexpr\yradius-\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{\dimexpr\xradius-\dimen4\relax}%
+ {-\dimexpr\yradius+\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{0pt}{-\dimen6}}%
+ \pgfpathlineto{\pgfqpoint{-\dimexpr\xradius-\dimen4\relax}%
+ {-\dimexpr\yradius+\dimen2\relax}}%
+ \pgfpathlineto{\pgfqpoint{-\dimexpr\xradius+\dimen4\relax}%
+ {-\dimexpr\yradius-\dimen2\relax}}%
+ \pgfpathclose%
+ }%
}
\pgfdeclareshape{yquant-oplus}{%
- \inheritsavedanchors[from=yquant-zz]%
- \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
+ \inheritsavedanchors[from=yquant-slash]%
+ \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west} {%
\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}}%
@@ -427,6 +372,7 @@
{\pgfqpoint{\xradius}{0pt}}%
{\pgfqpoint{0pt}{\yradius}}%
}%
+ \inheritclippath[from=yquant-circle]%
}
\pgfdeclareshape{yquant-measure}{%
@@ -443,52 +389,73 @@
\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%
+ \pgf@y=\dimexpr.5\ht\pgfnodeparttextbox+.5\dp\pgfnodeparttextbox+2pt\relax%
+ \ifyquant@config@operator@multi@main%
+ \advance\pgf@y by 1.25mm %
+ \fi%
\ifdim\pgf@x<\pgf@y%
\pgf@x=\pgf@y%
\fi%
\fi%
}%
\savedanchor\stext{%
- \pgfqpoint%
- {-.5\wd\pgfnodeparttextbox}%
- {\dp\pgfnodeparttextbox}%
+ \ifyquant@config@operator@multi@main%
+ \pgfqpoint%
+ {-.5\wd\pgfnodeparttextbox}%
+ {\dp\pgfnodeparttextbox}%
+ \else%
+ \pgfqpoint%
+ {-.5\wd\pgfnodeparttextbox}%
+ {-\dimexpr.5\ht\pgfnodeparttextbox-.5\dp\pgfnodeparttextbox\relax}%
+ \fi%
}%
\saveddimen\textheight{%
\pgf@x=\ht\pgfnodeparttextbox%
- }
- \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west, circuit} {%
+ }%
+ \savedmacro\main{%
+ \ifyquant@config@operator@multi@main%
+ \def\main{\noexpand\yquant@config@operator@multi@maintrue}%
+ \else%
+ \ifdim\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox\relax=0pt%
+ \def\main{\noexpand\yquant@config@operator@multi@maintrue}%
+ \else%
+ \def\main{\noexpand\yquant@config@operator@multi@mainfalse}%
+ \fi%
+ \fi%
+ }%
+ \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west} {%
\inheritanchor[from=yquant-rectangle]{\anc}%
}%
\anchor{text}{%
\stext%
- \pgf@y=\dimexpr-\yradius+1pt+\pgf@y\relax%
+ \main%
+ \ifyquant@config@operator@multi@main%
+ \pgf@y=\dimexpr-\yradius+1pt+\pgf@y\relax%
+ \fi%
}%
\inheritanchorborder[from=yquant-rectangle]%
- \inheritanchorxproj[from=yquant-rectangle]%
- \inheritanchoryproj[from=yquant-rectangle]%
- \backgroundpath{%
- \pgfpathrectanglecorners%
- {\pgfqpoint{-\xradius}{\yradius}}%
- {\pgfqpoint{\xradius}{-\yradius}}%
- }
+ \inheritbackgroundpath[from=yquant-rectangle]%
+ \inheritclippath[from=yquant-rectangle]%
\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%
+ \main%
+ % we only draw the meter symbol if this is the main part of a multi-register (or there is no text)
+ \ifyquant@config@operator@multi@main%
+ % 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);
\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);
}%
}
@@ -521,16 +488,12 @@
{-\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} {%
+ \foreach \anc in {center, north, south, south west, west, north west, 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%
@@ -545,40 +508,6 @@
{\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}}%
@@ -586,29 +515,46 @@
\pgfpathlineto{\pgfqpoint{-\xradius}{-\yradius}}%
\pgfpathclose%
}%
+ \clippath{%
+ \pgfpathmoveto{\pgfqpoint{-\dimexpr\xradius+.5\pgflinewidth\relax}%
+ {\dimexpr\yradius+.5\pgflinewidth\relax}}%
+ \pgfpathlineto{\pgfqpoint{\dimexpr\xradius-3mm\relax}%
+ {\dimexpr\yradius+.5\pgflinewidth\relax}}%
+ \pgfpatharc{90}{-90}{3mm+.5\pgflinewidth and \yradius+.5\pgflinewidth}%
+ \pgfpathlineto{\pgfqpoint{-\dimexpr\xradius+.5\pgflinewidth\relax}%
+ {-\dimexpr\yradius+.5\pgflinewidth\relax}}%
+ \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%
- }%
+\pgfdeclareshape{yquant-line}{%
\savedanchor\shorten{%
\pgfqpoint\pgf@shorten@end@additional\pgf@shorten@start@additional%
}%
+ \saveddimen\xradius{%
+ % we only need this for the border anchor; the value is automatically correct in the paths.
+ \pgf@x=.5\pgflinewidth%
+ }%
\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} {%
+ \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west} {%
\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}}%
}%
+ \clippath{%
+ \shorten%
+ \@tempdima=\dimexpr\yradius+\pgf@x\relax%
+ \@tempdimb=\dimexpr\yradius+\pgf@y\relax%
+ \pgfpathrectanglecorners
+ {\pgfqpoint{-.5\pgflinewidth}{\@tempdima}}%
+ {\pgfqpoint{.5\pgflinewidth}{-\@tempdimb}}%
+ }%
} \ 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
index 15d3c328aad..fe1efecbf47 100644
--- a/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex
@@ -45,6 +45,11 @@
\repeat%
}
+\def\yquant@for@break{%
+ \fi%
+ \iffalse%
+}
+
% Def #1 to be the minimum of #2, ... until \relax
\protected\def\yquant@min#1{%
\def#1{2147483647}%
@@ -92,11 +97,11 @@
% 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%
+ \ifstrempty{#2}{%
\expandafter\@secondoftwo%
- \else%
+ }{%
\ifyquant@firsttoken@aux#1#2\yquant@sep%
- \fi%
+ }%
}
\def\ifyquant@firsttoken@aux#1#2#3\yquant@sep{%
@@ -110,11 +115,7 @@
% 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%
+ \ifstrempty{##1}%
}%
\ifyquant@beginswith@#1#2\yquant@end%
}
@@ -148,6 +149,14 @@
\expandafter\yquant@sort@aux\expandafter0\expandafter{\the\numexpr\yquant@sort@count-1\relax}%
}
+\def\yquant@sort@ascending#1#2{%
+ \ifnum#2>#1 %
+ \expandafter\@firstoftwo%
+ \else%
+ \expandafter\@secondoftwo%
+ \fi%
+}
+
\protected\def\yquant@sort@aux#1#2{%
\ifnum#1<#2\relax%
\yquant@sort@divide{#1}{#2}%
@@ -159,6 +168,8 @@
\fi%
}
+\def\iftrue@hidden{\iftrue}%
+\def\iffalse@hidden{\iffalse}%
\protected\def\yquant@sort@divide#1#2{%
\count0=#1\relax% i
\count2=#2\relax% j
@@ -167,7 +178,6 @@
\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%
@@ -177,21 +187,20 @@
\expandafter\expandafter\expandafter{%
\csname yquant@sort@item\the\count0\endcsname%
}{%
- \csletcs{next}{iffalse}%
+ \expandafter\iffalse@hidden%
}{%
\advance\count0 by 1 %
+ \expandafter\iftrue@hidden%
}%
\else%
- \csletcs{next}{iffalse}%
+ \expandafter\iffalse@hidden%
\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%
@@ -202,13 +211,13 @@
\csname yquant@sort@item\the\count2\endcsname%
}{%
\advance\count2 by -1 %
+ \expandafter\iftrue@hidden%
}{%
- \csletcs{next}{iffalse}%
+ \expandafter\iffalse@hidden%
}%
\else%
- \csletcs{next}{iffalse}%
+ \expandafter\iffalse@hidden%
\fi%
- \next%
\repeat%
\expandafter
}%
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant.sty b/Master/texmf-dist/tex/latex/yquant/yquant.sty
index 25c0873b70e..c402c6342c4 100644
--- a/Master/texmf-dist/tex/latex/yquant/yquant.sty
+++ b/Master/texmf-dist/tex/latex/yquant/yquant.sty
@@ -4,23 +4,23 @@
% 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
+% Public License, either version 1.3c 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
+% and version 1.3c 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]
+\ProvidesPackage{yquant}[2020/04/11 v0.1.2 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}
+\usetikzlibrary{arrows.meta,decorations.pathreplacing,decorations.pathmorphing}
\input yquant-config.tex
\input yquant-tools.tex