texlive[61897] Master/texmf-dist: yquant (5feb22)

commits+karl at tug.org commits+karl at tug.org
Sat Feb 5 22:23:01 CET 2022


Revision: 61897
          http://tug.org/svn/texlive?view=revision&revision=61897
Author:   karl
Date:     2022-02-05 22:23:01 +0100 (Sat, 05 Feb 2022)
Log Message:
-----------
yquant (5feb22)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/yquant/README.md
    trunk/Master/texmf-dist/doc/latex/yquant/yquant-doc.pdf
    trunk/Master/texmf-dist/doc/latex/yquant/yquant-doc.tex
    trunk/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex
    trunk/Master/texmf-dist/tex/latex/yquant/yquant-config.tex
    trunk/Master/texmf-dist/tex/latex/yquant/yquant-draw.tex
    trunk/Master/texmf-dist/tex/latex/yquant/yquant-env.tex
    trunk/Master/texmf-dist/tex/latex/yquant/yquant-lang.tex
    trunk/Master/texmf-dist/tex/latex/yquant/yquant-prepare.tex
    trunk/Master/texmf-dist/tex/latex/yquant/yquant-registers.tex
    trunk/Master/texmf-dist/tex/latex/yquant/yquant-shapes.tex
    trunk/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex
    trunk/Master/texmf-dist/tex/latex/yquant/yquant.sty
    trunk/Master/texmf-dist/tex/latex/yquant/yquantlanguage-groups.sty

Modified: trunk/Master/texmf-dist/doc/latex/yquant/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/yquant/README.md	2022-02-05 21:22:43 UTC (rev 61896)
+++ trunk/Master/texmf-dist/doc/latex/yquant/README.md	2022-02-05 21:23:01 UTC (rev 61897)
@@ -6,6 +6,8 @@
 It builds on and interacts with TiKZ, which brings an enourmous flexibility for customization of individual circuit.
 
 Important features in the latest updates (for a much more complete list, see the documentation):
+- Support for vertical circuit layout (since 0.7)
+- Support for a simplified drawing pipeline (since 0.7)
 - Support the `beamer` package (since 0.6)
 - New `text` gate, which replaces the common `[draw=none] box` situation (since 0.6)
 - Integration of all qpic examples in the manual, showcasing some very advanced circuits (since 0.6)

Modified: trunk/Master/texmf-dist/doc/latex/yquant/yquant-doc.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/yquant/yquant-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/yquant/yquant-doc.tex	2022-02-05 21:22:43 UTC (rev 61896)
+++ trunk/Master/texmf-dist/doc/latex/yquant/yquant-doc.tex	2022-02-05 21:23:01 UTC (rev 61897)
@@ -16,7 +16,7 @@
 \usepackage[english]{babel}
 \usepackage[colorlinks, linkcolor=darkblue, bookmarksdepth=paragraph]{hyperref}
 \usepackage[compat=newest]{yquant}
-\usepackage{braket,hyphenat,microtype,hologo,minted,import,ragged2e}
+\usepackage{braket,hyphenat,microtype,hologo,minted,import,ragged2e,booktabs}
 \usetikzlibrary{quotes,fit,shapes.symbols,backgrounds,quantikz}
 \useyquantlanguage{qasm,groups}
 \usepackage{amsmath,adjustbox,cleveref}
@@ -219,7 +219,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 available on CTAN.
-      This beta version~0.6 \emph{should} be stable and interfaces are not very likely to change in an incompatible way in the future.
+      This beta version~0.7 \emph{should} be stable and interfaces are not very likely to change in an incompatible way in the future.
       \compat{New in 0.4}Sometimes, backwards\hyp incompatible changes are required or advisable, in which case a compatibility setting will allow to revert back to the old behavior (rather, to maximize compatibility, this is an opt\hyp in setting: unless you choose the new behavior, you will get the old one).
       Please do report all issues and desirable additions on \href{https://github.com/projekter/yquant/issues}{GitHub}.
 
@@ -394,6 +394,9 @@
          Deviations are noted in this manual.
 
          Valid values for
+         \begingroup%
+            % since v2.6 of minted, \PYG is no longer universally defined, so bring it into scope
+            \minted at defstyle{\minted at get@opt{style}{default}}%
          \begin{BVerbatim}[commandchars=\\\{\}]
 \PYG{n+ni}{?command?}
          \end{BVerbatim}
@@ -416,7 +419,7 @@
          \begin{BVerbatim}[commandchars=\\\{\}]
 \PYG{l+s+s2}{\PYGZdq{}+\PYGZdq{}}
          \end{BVerbatim}
-         ).
+         ).\endgroup
 
       \subsection{Registers}\label{sec:registers}
          Every quantum circuit is structured by means of \emph{registers}.
@@ -628,6 +631,23 @@
          Note that the backend interface changed in version~0.4.
          For the declaration of custom shapes, see \texttt{yquant-shapes.tex} for examples.
 
+      \subsection[The flow of time: horizontal and vertical layout]{\compat{New in 0.7}The flow of time: horizontal and vertical layout}
+         By default, quantum circuits are oriented \emph{horizontally}, i.e., time flows from left to right.
+         Sometimes, this is problematic when printed on a portrait page layout and a \emph{vertical} layout would be better suited.
+         \Yquant{} supports this by simply passing the configuration option \style{/yquant/vertical} to the circuit (this can even be done globally, so that all circuits are rendered vertically).
+
+         The vertical layout is supposed to work exactly as the horizontal layout; however, most testing occurs for horizontal mode only (basically, for every release, the examples in this manual comprise the testsuite).
+         Hence, if something weird happens in vertical mode, please file a bug report.
+
+         Most of the internal and exposed nomenclature in \Yquant{} is designed for the horizontal case (names such as ``height'' or ``width'').
+         For some of the exposed configuration options, synonyms are provided which are more meaningful in vertical mode or that are more orientation\hyp agnostic.
+         These synonyms are merely conveniences, they do not provide any new functionality.
+         As a general rule of thumb, everything that was ``atop'' becomes ``left.''
+
+         Some relevant \TikZ{} options refer to a fixed direction, namely \texttt{[x|y] radius} and \texttt{[inner|outer] [x|y]sep}.
+         If you think that maybe you want to change the orientation of your circuit at some point, you should never use the original \TikZ{} styles---their meaning would depend on the current orientation.
+         Instead, consider using the \Yquant{} alternatives \texttt{[time|space] radius} and \texttt{[inner|outer] [time|space]sep}.
+
    \section{Configuration}\label{sec:config}
       \Yquant{} uses \pkg{pgfkeys} to control its options, which are located in the path \texttt{/yquant}.
       The following list contains all options and styles that are recognized, apart from gate arguments.
@@ -634,8 +654,8 @@
       Those are listed together with their operations.
 
       \subsection{Circuit layout}\unskipOpt
-         \begin{option}[Changed in 0.4]{register/minimum height}!1.5mm!
-            \Yquant{} automatically determines the height (extent from wire to top boundary) of a register as the height of the largest operation.
+         \begin{option}[Changed in 0.7, 0.4]{register/minimum height}!1.5mm!
+            \Yquant{} automatically determines the height (extent from wire to top boundary; in vertical mode: from wire to left boundary) of a register as the height of the largest operation.
             This might be too small for two reasons:
             \begin{itemize}
                \item if the register is used only with small gates (e.g., only as a control, or as a swap), and it does not have a label (or one containing only x\hyp height letters).
@@ -645,6 +665,8 @@
             This key provides an easy alleviation of the problem by requiring a minimal height for every register.
             As the value of this key is relevant at the time of register declaration, it can also be changed for each register individually.
 
+            Note that in vertical mode, the default of this setting is \tex!2.5mm!.
+
             Note that this key is affected by the \texttt{compat} setting.
             Before version \texttt{0.4}, there was no \style{/yquant/register/minimum depth} key.
             In this compatibility setting, passing the value $x$ to this key will set both height and depth to $\frac x2$.
@@ -651,27 +673,51 @@
             The default for $x$ is then \texttt{3mm}.
          \end{option}
 
-         \begin{option}[New in 0.4]{register/minimum depth}!1.5mm!
+         \begin{option}[Changed in 0.4\\New in 0.4]{register/minimum depth}!1.5mm!
             \emph{see} \style{/yquant/register/minimum height}
 
-            This key allows to specify a minimum depth (extent from wire to bottom boundary) for a register.
+            This key allows to specify a minimum depth (extent from wire to bottom boundary; in vertical mode: from wire to right boundary) for a register.
 
+            Note that in vertical mode, the default of this setting is \tex!2.5mm!.
+
             Note that this key is affected by the \texttt{compat} setting.
             Before version \texttt{0.4}, this key will not be available.
          \end{option}
 
+         \begin{option}[New in 0.7]{register/minimum left}!1.5mm!
+            This is a synonym for \style{/yquant/register/minimum height}, as this naming makes more sense for vertical circuits.
+         \end{option}
+
+         \begin{option}[New in 0.7]{register/minimum right}!1.5mm!
+            This is a synonym for \style{/yquant/register/minimum depth}, as this naming makes more sense for vertical circuits.
+         \end{option}
+
+         \begin{option}[New in 0.7]{register/minimum before}!1.5mm!
+            This is a synonym for \style{/yquant/register/minimum height}, which provides a naming that makes sense in both horizontal and vertical mode.
+         \end{option}
+
+         \begin{option}[New in 0.7]{register/minimum after}!1.5mm!
+            This is a synonym for \style{/yquant/register/minimum depth}, which provides a naming that makes sense in both horizontal and vertical mode.
+         \end{option}
+
          \begin{option}{register/separation}!1mm!
             This key controls the amount of vertical space that is inserted between two successive registers.
             Half of this value is also the length that multi\hyp\gate{init} or multi\hyp\gate{output} braces extend beyond the mid position of the register.
          \end{option}
 
-         \begin{option}{operator/minimum width}!3mm!
-            \Yquant{} automatically determines the width of an operator according to its content.
+         \begin{option}[Changed in 0.7]{operator/minimum width}!5mm!
+            \Yquant{} automatically determines the width (in vertical mode: the vertical extent) of an operator according to its content.
             However, single\hyp letter boxes are among the most common operators, and giving them slightly different widths would result in a very uneven spacing, as \Yquant{} does not use a grid layout but stacks the operators horizontally one after each other.
             Hence, this key provides a minimum width that will be set for every operator.
             This does not imply that the \emph{visual} appearance (i.e., the \texttt{x radius} key) is enlarged, but that operators of a smaller actual width will be centered in a virtual box of the minimum width.
+
+            Note that in vertical mode, the default of this setting is \tex!3mm!.
          \end{option}
 
+         \begin{option}[New in 0.7]{operator/minimum extent}!3mm!
+            This is a synonym for \style{/yquant/operator/minimum width}, which provides a naming that makes sense in both horizontal and vertical mode.
+         \end{option}
+
          \begin{option}{operator/separation}!1mm!
             This key controls the amount of horizontal space that is inserted between two successive operators and at the beginning and end of a circuit.
          \end{option}
@@ -682,6 +728,22 @@
             You may disable this warning globally, on a per\hyp circuit, or even on a per\hyp gate basis.
          \end{option}
 
+         \begin{option}[New in 0.7]{drawing mode}!quality!
+            This key determines which drawing pipeline is enabled.
+            For more details, see \cref{sec:pipeline}.
+            The option should not be changed within a circuit (though only the last value will be relevant).
+            Allowed values are \texttt{quality} for the default clipping\hyp based pipeline, and \texttt{size} of the filling\hyp based one.
+            Note that choosing \texttt{quality} will set \style{/yquant/default background} to \texttt{none}; choosing \texttt{size} will set it to \texttt{white} (though this can be changed after setting the option).
+         \end{option}
+
+         \begin{option}[New in 0.7]{default background}!none!
+            This key contains the default color that is used to fill all gates with a nonempty interior.
+         \end{option}
+
+         \begin{option}[New in 0.7]{default fill}!fill/.expanded=\pgfkeysvalueof{/yquant/default background}!
+            Use this style if you want to apply the default filling to a user\hyp defined gate.
+         \end{option}
+
       \subsection{Register creation}\unskipOpt
          \begin{option}{register/default name}!\regidx!
             The printed name that is used by default if a new register is created explicitly (\gate{qubit}, \gate{cbit}, \gate{qubits}; not used for \gate{nobit} or for implicit declarations) and no value is specified.
@@ -700,18 +762,20 @@
             Note that this default setting is not used when the register is created via an \gate{init} gate---its value always overwrites the default.
          \end{option}
 
-         \begin{option}[Changed in 0.4]{every label}!shape=yquant-init, anchor=center, align=right, outer xsep=2pt, /yquant/operator/if multi={draw, decoration={gapped brace, mirror, raise=2pt}, decorate}!
+         \begin{option}[Changed in 0.7, 0.4]{every label}!shape=yquant-init, anchor=center, align/.expanded=\ifyquanthorz{right}{center}, outer timesep=2pt, /yquant/operator/if multi={draw, decoration={gapped brace, raise=2pt, \ifyquanthorz{mirror}{}}, decorate}!
             This style is installed for every single register name label (i.e., upon creation and when used with the \gate{init} gate).
             The default style allows to use line breaks in the labels.
-            The node shape, \texttt{yquant-init}, will generate a path at its right side, which is replaced by the \texttt{gapped brace} decoration if the gate is used in a multi\hyp register fashion.
+            The node shape, \texttt{yquant-init}, will generate a path at its right side (in vertical mode: at its bottom side), which is replaced by the \texttt{gapped brace} decoration if the gate is used in a multi\hyp register fashion.
             The decoration is similar to \TikZ's \texttt{brace} decoration, but additionally allows specify the regions in which a line should be drawn by using the \texttt{/tikz/decoration/from to} key, which expects a comma\hyp separated list of dimension ranges, and which is automatically populated by \Yquant.
 
             Note that if the \texttt{compat} key is below \texttt{0.3}, the multi options are instead read from \style{/yquant/every multi label}.
          \end{option}
 
-         \begin{option}{every initial label}!anchor=east!
+         \begin{option}[Changed in 0.7]{every initial label}!anchor/.expanded=\ifyquanthorz{east}{south}, /yquant/internal/autorotate init!
             This style is installed for every single register name label at the left border of the circuit.
             \compat{Changed in 0.4}It is therefore used if a label is specified upon declaration and also for the \gate{init} gate if it happens to be the first gate on an unlabelled register (use a zero\hyp width \gate{hspace} gate before if you want to suppress this).
+
+            \compat{New in 0.7}The automatic rotation will be set up by using the \style{/yquant/vertical} style with an argument; by default, it is empty.
          \end{option}
 
          \begin{option}{every qubit label}!!
@@ -740,12 +804,14 @@
          \end{option}
 
       \subsection{Register outputs}\unskipOpt
-         \begin{option}[Changed in 0.4]{every output}!shape=yquant-output, anchor=west, align=left, outer xsep=2pt, /yquant/operator/if multi={draw, decoration={gapped brace, raise=2pt}, decorate}!
+         \begin{option}[Changed in 0.7, 0.4]{every output}!shape=yquant-output, anchor/.expanded=\ifyquanthorz{west}{north}, align/.expanded=\ifyquanthorz{left}{center}, outer timesep=2pt, /yquant/operator/if multi={draw, decoration={gapped brace, raise=2pt, \ifyquanthorz{}{mirror}}, decorate}, /yquant/internal/autorotate output!
             This style is installed for every \gate{output} label at the end of the circuit.
             The default style allows to use line breaks in the labels.
 
-            The node shape, \texttt{yquant-output}, will generate a path at its left side, which is replaced by the \texttt{gapped brace} decoration in the case of multi\hyp register usage.
+            The node shape, \texttt{yquant-output}, will generate a path at its left side (in vertical mode: at its top side), which is replaced by the \texttt{gapped brace} decoration in the case of multi\hyp register usage.
             See \style{/yquant/every label} for a more detailed explanation.
+
+            \compat{New in 0.7}The automatic rotation will be set up by using the \style{/yquant/vertical} style with an argument; by default, it is empty.
          \end{option}
 
          \begin{option}{every qubit output}!!
@@ -806,7 +872,7 @@
             This style is installed for every positive control (i.e., one that conditions on the register being in state $\ket1$ or $1$).
          \end{option}
 
-         \begin{option}{every negative control}!draw!
+         \begin{option}[Changed in 0.7]{every negative control}!draw, /yquant/default fill!
             This style is installed for every negative control (i.e., one that conditions on the register being in state $\ket0$ or $0$).
          \end{option}
 
@@ -861,6 +927,58 @@
             Only access it via \style{/yquant/operators/subcircuit/seamless}.
          \end{option}
 
+         \begin{option}[New in 0.7]{circuit/orientation}!horizontal!
+            This setting allows two possible values, \texttt{horizontal} and \texttt{vertical}.
+            It must only be changed before a circuit or at latest with the option arguments to the \tex!yquant! environment, but not within a circuit.
+
+            In the default \texttt{horizontal} mode, time flows from left to right and registers will be created from top to bottom.
+            In the alternative \texttt{vertical} mode, time flows from top to bottom and registers will be created from left to right.
+
+            Note that this setting influences the behavior of various macros and styles:
+            \begin{center}
+               \begin{tabular}{lrr}
+                  \toprule
+                  Macro/Style & \texttt{horizontal} meaning & \texttt{vertical} meaning \\\midrule
+                  \tex!\ifyquanthorz{a}{b}! & \tex!a! & \tex!b! \\
+                  \texttt{/tikz/time radius} & \texttt{/tikz/x radius} & \texttt{/tikz/y radius} \\
+                  \texttt{/tikz/space radius} & \texttt{/tikz/y radius} & \texttt{/tikz/x radius} \\
+                  \texttt{/tikz/inner timesep} & \texttt{/tikz/inner xsep} & \texttt{/tikz/inner ysep} \\
+                  \texttt{/tikz/inner spacesep} & \texttt{/tikz/inner ysep} & \texttt{/tikz/inner xsep} \\
+                  \texttt{/tikz/outer timesep} & \texttt{/tikz/outer xsep} & \texttt{/tikz/outer ysep} \\
+                  \texttt{/tikz/outer spacesep} & \texttt{/tikz/outer ysep} & \texttt{/tikz/outer xsep} \\
+                  \bottomrule
+               \end{tabular}
+            \end{center}
+            Additionally, this setting influences the default values of various \Yquant{} styles---note that if a style was once overwritten, the user\hyp supplied value will be never be changed!
+            Here, we use the orientation\hyp independent names of the styles, although all their synonyms are equivalent.
+            \begin{center}
+               \begin{tabular}{lrr}
+                  \toprule
+                  Style & \texttt{horizontal} def. & \texttt{vertical} def. \\\midrule
+                  \style{/yquant/register/minimum before} & \tex!1.5mm! & \tex!2.5mm! \\
+                  \style{/yquant/register/minimum after} & \tex!1.5mm! & \tex!2.5mm! \\
+                  \style{/yquant/operator/minimum extent} & \tex!5mm! & \tex!3mm! \\
+                  \bottomrule
+               \end{tabular}
+            \end{center}
+         \end{option}
+
+         \begin{option}[New in 0.7]{horizontal}
+            This style is a shorthand that sets \style{/yquant/circuit/orientation} to the \texttt{horizontal} value (which is the default).
+         \end{option}
+
+         \begin{option}[New in 0.7]{vertical}!0!
+            This style is a shorthand that sets \style{/yquant/circuit/orientation} to the \texttt{vertical} value.
+            Additionally, it accepts a parameter which should be an angle value (in degrees) between \tex!-180! and \tex!180!.
+            This is a rotation that is automatically applied to the text in every \gate{init} gate at the beginning of a circuit; the inverse rotation is automatically applied to the text in every \gate{output} gate at the end of a circuit.
+
+            Note that the gates themselves are \emph{not} rotated.
+            This would be counterproductive for multi\hyp qubit gates that contain braces---those should still be orthogonal to the wire lines.
+            In order to achieve this, the macro will use internal \TikZ{} details and exploit that the \texttt{execute at begin node} key is directly followed by the braced content of the node.
+            Hence, it will add a corresponding \tex!\adjustbox{rotate=#1}! to this style.
+            Therefore, \Yquant{} will raise a warning if the argument is used and the \pkg{adjustbox} package is not loaded, in which case the rotation is just ignored.
+         \end{option}
+
          \begin{option}[New in 0.4]{every post measurement control}!indirect!
             This style determines the default arrangement of measurements that are followed by positive controls.
 
@@ -899,7 +1017,7 @@
             Note that with the \texttt{compat} key set before \texttt{0.4}, this style instead defaults to \tex!/yquant/operators/subcircuit/frameless, /yquant/register/default name=!.
          \end{option}
 
-         \begin{option}{operators/every dmeter}!shape=yquant-dmeter, x radius=2mm, y radius=2mm, fill=white, draw!
+         \begin{option}[Changed in 0.7]{operators/every dmeter}!shape=yquant-dmeter, time radius=2mm, space radius=2mm, draw, /yquant/default fill!
             This style is installed for every \gate{dmeter} gate.
             The \texttt{yquant-dmeter} shape consists of a rectangle whose right side is replaced by a circle, resembling the letter ``D.''
          \end{option}
@@ -908,12 +1026,12 @@
             This style is installed for every \gate{h} (Hadamard) operator.
          \end{option}
 
-         \begin{option}{operators/every inspect}!shape=yquant-output, align=left, outer xsep=.3333em, y radius=2.47mm, /yquant/operator/if multi={draw, decoration={gapped brace, raise=2pt}, decorate}!
+         \begin{option}[Changed in 0.7]{operators/every inspect}!shape=yquant-output, align/.expanded=\ifyquanthorz{left}{center}, outer timesep=.3333em, space radius=2.47mm, /yquant/default fill, /yquant/operator/if multi={draw, decoration={gapped brace, raise=2pt, \ifyquanthorz{}{mirror}}, decorate}!
             This style is installed for every \gate{inspect} gate.
-            It does not have any shape on its own, apart from multi\hyp register uses, in which it will contain a brace on its left.
+            It does not have any shape on its own, apart from multi\hyp register uses, in which it will contain a brace on its left (in vertical mode: on its top).
          \end{option}
 
-         \begin{option}{operators/every measure}!shape=yquant-measure, x radius=4mm, y radius=2.5mm, draw!
+         \begin{option}[Changed in 0.7]{operators/every measure}!shape=yquant-measure, x radius=4mm, y radius=2.5mm, draw, /yquant/default fill!
             This style is installed for every \gate{measure} gate.
             The \texttt{yquant-measure} shape is a rectangle that contains a ``meter'' symbol.
             It allows for a text to be put inside (e.g., a basis), which then shifts the meter symbol accordingly.
@@ -937,7 +1055,7 @@
             This style is installed for every \gate{phase} gate $\ketbra00 + \ee^{\ii\phi} \ketbra11$.
          \end{option}
 
-         \begin{option}[New in 0.6]{operators/every rectangular box}!shape=yquant-rectangle, draw, align=center, inner xsep=1mm, x radius=2mm, y radius=2.47mm!
+         \begin{option}[Changed in 0.7\\New in 0.6]{operators/every rectangular box}!shape=yquant-rectangle, draw, align=center, inner timesep=1mm, time radius=2mm, space radius=2.47mm, /yquant/default fill!
             This style is not associated to any particular gate, but will be inherited by a lot of gates that have a rectangular box frame with some text.
             This style should not be used with a \texttt{compat} setting strictly smaller than~\texttt{0.6}.
          \end{option}
@@ -951,7 +1069,7 @@
             Note that all styles given here will also apply to every element in the subcircuit; in a way, this is an addition to \style{/yquant/every circuit} (which is also again put into effect at the beginning of a subcircuit).
          \end{option}
 
-         \begin{option}[New in 0.2]{operators/every subcircuit box}!/yquant/operators/every box!
+         \begin{option}[New in 0.2]{operators/every subcircuit box}!/yquant/operators/every rectangular box, fill=none!
             This style is installed for every \gate{subcircuit}.
             Note that in contrast to all other styles such as \style{/yquant/operators/every subcircuit} or \style{/yquant/this operator}, this style is only applied to the ``container'' node of the subcircuit, but not to the elements in the subcircuit themselves.
             Also note that the box style by default contains an \texttt{inner xsep} that will be added as an inside padding.
@@ -1020,7 +1138,7 @@
             The \texttt{yquant-swap} shape consists of a single cross.
          \end{option}
 
-         \begin{option}[New in 0.6]{operators/every text}!shape=yquant-rectangle, align=center, inner xsep=1mm, x radius=2mm, y radius=2.47mm!
+         \begin{option}[Changed in 0.7\\New in 0.6]{operators/every text}!shape=yquant-rectangle, align=center, inner timesep=1mm, time radius=2mm, space radius=2.47mm, /yquant/default fill!
             This style is installed for every \gate{text} gate.
          \end{option}
 
@@ -1032,7 +1150,7 @@
             This style is installed for every Pauli operator $\sigma_x$, i.e., \gate{x}.
          \end{option}
 
-         \begin{option}{operators/every xx}!shape=yquant-rectangle, radius=.75mm, draw!
+         \begin{option}[Changed in 0.7]{operators/every xx}!shape=yquant-rectangle, radius=.75mm, draw, /yquant/default fill!
             This style is installed for every \gate{xx} gate in symmetrized notation ($\ketbra{++}{++} + \ketbra{+-}{+-} + \ketbra{-+}{-+} - \ketbra{--}{--}$).
          \end{option}
 
@@ -1107,6 +1225,30 @@
                \end{itemize}
          \end{itemize}
 
+         \compat{New in 0.7}Note that \Yquant{} also supports a simplified drawing pipeline which does not involve clipping paths.
+         It can be enabled by setting the \style{/yquant/drawing mode} option to \texttt{size}.
+         The simplified pipeline has the following benefits:
+         \begin{itemize}
+            \item \TeX{} has to compute a bit less, so the compilation process can be sped up.
+            \item PDF readers may render the circuit faster.
+            \item The size of the output files is decreased.
+            \item Compatibility with very simplistic clients that don't support clipping well is improved (this may be an issue for some PDF to image converters, for example).
+            \item Theoretically, you may use any kind of predefined shape in this mode (from \TikZ{} or other packages), since the clipping paths are no longer required.
+         \end{itemize}
+         However, with it come certain drawbacks:
+         \begin{itemize}
+            \item Gates are no longer transparent, but filled with some fixed background color, so if transparency is important for you, this just does not work.
+            \item \Yquant{} relies on \TikZ's layering capabilities; if you use layers by yourself, you have to pay some attention to do it correctly.
+            \item The z\hyp order may not be as you expect it; in particular:
+               All the gates will be drawn on the \texttt{main} layer; all the wires on the \texttt{wires} layer, which is behind \texttt{main}; so if you don't use layers by yourself, everything that you draw will overshadow the wires, but not necessarily the gates.
+            \item If you were to fill a subcircuit, this would then erase all the internal wires.
+               Hence, the box of a subcircuit is drawn on the \texttt{behindwires} layer; but this implies that also the \emph{frame} of the box is drawn behind the wires and that this box is also overshadowed by any of your drawing.
+            \item Wires that visually cross gates which are not part of the gate may be displayed differently from the standard pipeline.
+         \end{itemize}
+         Unless you use \tex!\pgfsetlayers! to add the layers \texttt{wires} and \texttt{behindwires} manually, \Yquant{} will automatically place the \texttt{wires} layer directly before \texttt{main}; then it will place \texttt{behindwires} directly before \texttt{wires}.
+         This in particular ensures full compatibility with the \texttt{backgrounds} library: the background layer is still the very first in the layer list.
+         In contrast to \pkg{pgfplots}, this automatism should work even if the \Yquant{} environment is placed within groups.
+
       \subsection{Overwriting the height and depth calculation}
          \Yquant{} automatically takes care of calculating the height and depth of all registers, so that their final vertical positions are chosen without overlap.
          This is almost always advisable, but it has some weaknesses:
@@ -1138,8 +1280,8 @@
          \begin{itemize}
             \item \texttt{true} (default if no value given, combines \texttt{multi}, \texttt{height}, and \texttt{depth}),
             \item \texttt{multi} (short \texttt{m}),
-            \item \texttt{height} (short \texttt{ht}, \texttt{h}),
-            \item \texttt{depth} (short \texttt{dp}, \texttt{d}),
+            \item \texttt{height} (short \texttt{ht}, \texttt{h}), equivalent to \texttt{left} (short \texttt{l}) and \texttt{before} (short \texttt{bef}, \texttt{b}), which sound more meaningful for vertical and generic circuit orientations,
+            \item \texttt{depth} (short \texttt{dp}, \texttt{d}), equivalent to \texttt{right} (short \texttt{r}) and \texttt{after} (short \texttt{aft}, \texttt{a}), which sound more meaningful for vertical and generic circuit orientations,
             \item \texttt{single} (short \texttt{s}, combines \texttt{height} and \texttt{depth}), and
             \item \texttt{false} (useless, default if attribute not given).
          \end{itemize}
@@ -1340,7 +1482,7 @@
          It may only be specified once per register.
          It may span multiple registers, but does not allow for controls.
          The style \style{/yquant/every output} is installed, and also the style \texttt{/yquant/every <type> output}, where \texttt{<type>} is the type of the affected register (at the time of printout).
-         \compat{New in 0.6}Note that while outputs can be named, the name will only become available after the \texttt{yquant} environment itself was ended (but of course before the outer \texttt{tikzpicture} was closed).
+         \compat{New in 0.6}Note that while outputs can be named, the name will only become available after the \tex!yquant! environment itself was ended (but of course before the outer \texttt{tikzpicture} was closed).
 
          \emph{Possible attributes:}
          \begin{itemize}
@@ -2437,7 +2579,6 @@
                   \end{codeexample}
                   We support measurements with vertical outputs, but only if they replace the positive control of some action.
                   Here, we fake this behavior by introducing an invisible register at the bottom, which will contain the outputs.
-                  In order to disable the line around the \gate{box}es, we used the \style{/yquant/operators/every box} style, which here was most convenient, as the only \gate{box}es in use are those without an outline.
                   Note that if we were to give style options to the \gate{text}s, they would also affect the measurements.
                   The reason for this is that internally, the measurement will be nested within the same scope that draws the \gate{text}---so the options given to the \gate{text} will be inherited by the \gate{measure}ment.
                   As an operator style overwrites default styles, this will also apply to the measurements.
@@ -3387,7 +3528,7 @@
                   Since they will always follow in this order, we also define a \tex!\cnotBlock! abbreviation that executes these configurations together with their intermediate \gate{barrier}.
                   We do not include the final barrier, since it is not present in the last block.
 
-                  Now, we start the \texttt{yquant} environment.
+                  Now, we start the \tex!yquant! environment.
                   We give some options for a nicer spacing and initialize the registers.
                   In the \pkg{qpic} example, the registers are $1$\hyp indexed, so we use \tex!\The\numexpr\idx+1! to give back the value of the current register index (\tex!\idx!) plus one; we also conditionally color the register name in red if the index coincides with the parameter.
                   Note that here we use \Yquant's shorthand for \tex!\protect\the!, \tex!\protect\ifnum!, and \tex!\protect\fi!, which are \tex!\The!, \tex!\Ifnum!, and \tex!\Fi!, to get the correct expansion behavior.
@@ -3462,25 +3603,24 @@
             \paragraph{2.3 Example 3: Shor's Algorithm}\leavevmode
             \begingroup%
                \mdfapptodefinestyle{bdBox}{%
-                  leftmargin=-.12\linewidth,
-                  rightmargin=-.12\linewidth
+                  leftmargin=-.04\linewidth,
+                  rightmargin=-.02\linewidth
                }%
-               \begin{example}
+               \begin{example}<Updated in 0.7>
                   \begin{codeexample*}
-\begin{tikzpicture}[rotate=-90, yscale=-1, every node/.append style={rotate=90, xscale=-1}]
+\begin{tikzpicture}
    \def\explain#1#2{%
       \yquant
-      [anchor=east] text {#1} explainLeft;
-      [anchor=west] text {$\displaystyle#2$} explainRight;
+      [anchor=east, overlay=right] text {#1} explainLeft;
+      [anchor=west, overlay=left] text {$\displaystyle#2$} explainRight;
       align -;
    }
-   \begin{yquant}[every initial label/.style={anchor=south},
-                  every output/.style={anchor=north},
+   \begin{yquant}[vertical,
                   every control/.append style={radius=1.5mm},
                   operators/every slash/.append style={x radius=3mm, y radius=1.5mm},
                   operators/every box/.append style={y radius=4mm},
                   operators/every measure/.append style={y radius=4mm},
-                  operator/minimum width=1.32cm]
+                  operator/minimum extent=1.32cm]
       nobit explainLeft;
       qubit {$\ket{0\dotsm0}$} x; slash x;
       qubit {$\ket{0\dotsm0}$} y; slash y;
@@ -3509,28 +3649,15 @@
 \end{tikzpicture}
                   \end{codeexample*}
                   Once again, this is a very interesting example.
-                  \Yquant{} does not support a vertical circuit layout \emph{officially}.
-                  However, \Yquant{} is built on top of \TikZ, so we can certainly try to emulate a vertical layout by means of rotations.
-                  First of all, we rotate the whole \texttt{tikzpicture}, saying \tex!rotate=-90!, so that the circuit grows downwards.
-                  While this is very straightforward, it leads to two immediate problems:
-                  \begin{itemize}
-                     \item The registers were declared in top\hyp to\hyp bottom order; if we rotate everything, this becomes a right\hyp to\hyp left order.
-                        In order to change this to a left\hyp to\hyp right order, we must mirror every horizontal coordinate; due to the rotation, this corresponds to \tex!yscale=-1! (not \tex!xscale!).
-                     \item The gates themselves should not be rotated.
-                        In fact, no text should be rotated.
-                        However, as by default, the \style{/yquant/every circuit} style will install the \texttt{transform shape} option to every node as of version~0.4, the nodes will also be rotated.
-                        The first idea to disable \texttt{transform shape} does not turn out to work well, as the spacings are somehow messed up.
-                        Instead, we just undo the rotation and scaling (note that now we need \tex!xscale=-1!, as after the reverse rotation, we are back to the ``proper'' coordinate system).
-                  \end{itemize}
-                  Then, there are some minor issues regarding the anchors of initial labels and output.
-                  The default settings for them, \texttt{east} and \texttt{west} are of course inappropriate in a rotated layout, so those must be changed.
-                  All the rest of the options that are given to the \texttt{yquant} environment just serve to match the appearance given in the \pkg{qpic} manual: we enlarge the \gate{slash}, the \gate{box}es and the \gate{measure}ments, and we also increase the global value of \style{/yquant/operator/minimum width}.
-                  Remember that this is the minimum ``width'' (in the rotated scenario, it becomes a height) that \Yquant{} reserves for every single operator (unless it is larger), and it will center the operator within an invisible rectangle of this width if it is smaller.
-                  So by matching this value to the largest height that occurs in the explanations in the circuit, we achieve an approximate vertical centering.
+                  The circuit itself is very standard (though it is the first one in vertical mode).
+                  In order to output the explanations, we define two invisible wires together with a macro that populates the corresponding \gate{text} gates on those wires.
+                  Note that usually, in a vertical layout, all gates would be center\hyp aligned.
+                  In order to align the left explanations to the right and the right explanations to the left, we just redefine the \texttt{anchor}s of the gates.
+                  However, since \Yquant{} expects the gates to connect at the \texttt{center} anchor and hence equally distributes the required space for the wire to its left and right, this would lead to a very large gap between the explanations and the circuit itself.
+                  Here, we don't need \Yquant's wire extent calculations at all---the explanation wires are invisible and at the border of the circuit.
+                  Therefore, we just disable the calculations using the \texttt{overlay} attribute.
+                  After all the explanations are done, we \gate{align} all registers (if the minimum extent was chosen to be exactly larger or equal to the actual vertical extent of every gate, this would not be necessary; but with two decimals, this is probably not precisely the case).
 
-                  Finally, there is some repetitive structure within the circuit, which we defer to a custom macro \tex!\explain!: We always want to draw a \gate{text} gate in our first invisible register \yquant!explainLeft!; however, this should not be centered, but rather aligned to the right, so we give the proper \tex!anchor=east!.
-                  We also need the same thing on the right, just mirrored and with a \tex!\displaystyle! math environment; and after all the explanations are done, we \gate{align} all registers (if the minimum width/height was chosen to be exactly larger or equal to the actual height of every gate, this would not be necessary; but with two decimals, this is probably not precisely the case).
-
                   Note that the code example above would work exactly in this way in traditional \LaTeX{} documents; however, this document is set with \pkg{unicode-math}.
                   This leads to a problem when using \tex!\bmod!, which has to be \tex!\protect!ed---or, as we did here, just say \tex!\robustify\bmod! somewhere before its usage and after loading all the packages.
                \end{example}
@@ -3538,60 +3665,62 @@
 
             \clearpage
             \paragraph{2.4 Example 4: Teleportation}
-               \begin{example}
+               \begin{example}<Updated in 0.7>
                   \begin{codeexample*}
-\begin{tikzpicture}[rotate=-90, yscale=-1, every node/.append style={rotate=90, xscale=-1}]
-   \begin{yquant}[every initial label/.style={anchor=south},
-                  every output/.style={anchor=north},
-                  operators/every barrier/.append style={rotate=-90}]
-      nobit explainLeft;
+\begin{tikzpicture}
+   \newcommand\leftExplain[2][]{
+      \yquantsecondpass{
+         \draw[decoration={brace, mirror}, decorate, #1]
+            let \p1=(leftComments), \p2=(explainTop-0.north), \p3=(explainBottom-0.south) in
+            (\x1, \y2) -- (\x1, \y3) node[midway, left=2pt, align=right] {#2};
+      }
+   }
+   \newcommand\rightExplain[2][]{
+      \yquantsecondpass{
+         \draw[decoration=brace, decorate, #1]
+            let \p1=(rightComments), \p2=(explainTop-0.north), \p3=(explainBottom-0.south) in
+            (\x1, \y2) -- (\x1, \y3) node[midway, right=2pt, align=left] {#2};
+      }
+   }
+   \begin{yquant}[vertical]
+      [name=leftComments] nobit explainLeft;
       qubit {\color{red}$\ket\phi$} q;
       qubit {$\ket0$} q[+2];
-      nobit explainRight;
+      [name=rightComments] nobit explainRight;
       setstyle {red} q[0];
 
+      [name=explainTop]
       h q[1];
+      [name=explainBottom]
       cnot q[2] | q[1];
+      \rightExplain{Alice and Bob form an\\entangled pair of qubits}
       setstyle {red} q[1];
       setstyle {blue} q[2];
-      [y radius=5mm, anchor=west]
-      inspect {Alice and Bob form an\\entangled pair of qubits} (explainRight);
-      [operator/separation=0pt]
       barrier (q);
-      align -;
 
-      [style=red, operator/separation=0pt] cnot q[1] | q[0];
+      [style=red, operator/separation=0pt, name=explainTop] cnot q[1] | q[0];
       [red] h q[0];
-      [red] measure q[0, 1];
-      [red, y radius=9mm, anchor=east, align=right, shape=yquant-init, decoration={mirror}]
-      inspect {Alice entangles\\and measures} (explainLeft);
-      align -;
+      [red, name=explainBottom] measure q[0, 1];
+      \leftExplain[red]{Alice entangles\\and measures}
 
-      [style=blue] x q[2] | q[1];
-      [style=blue] z q[2] | q[0];
+      [style=blue, name=explainTop] x q[2] | q[1];
+      [style=blue, name=explainBottom] z q[2] | q[0];
       discard q[0, 1];
-      [blue, y radius=5.5mm, anchor=west]
-      inspect {Bob applies gates based on\\Alice's measurements} (explainRight);
+      \rightExplain[blue]{Bob applies gates based on\\Alice's measurements}
 
       output {\color{blue}$\ket\phi$} q[2];
    \end{yquant}
 \end{tikzpicture}
                   \end{codeexample*}
-                  Again, we ignore that it is not possible to render the circuit in this way and do it anyway.
-                  The structure is similar to what we previously did.
-                  For some reason, the \gate{barrier} shape is not content with the back\hyp rotation and we must again rotate it.
-
-                  We now use \gate{inspect} gates to mimic the state information.
-                  This gate will automatically draw curly braces as soon as it encounters a multi\hyp register use; hence, despite the fact that \yquant!explainRight! and \yquant!explainLeft! are single registers, we use them in a multi\hyp register fashion.
-                  Next, the brace would only be high enough to incorporate the text (since it knows nothing about what goes on in the rest of the circuit); hence, we manually give it a \texttt{y radius} value that has to be determined appropriately.
-
-                  Since the default operator separation before and after the \gate{barrier} look a bit large, we set them to zero (\style{/yquant/operator/separation} will always affect the distance of the current operator to the previous one, so we need this for the \gate{barrier} and for the first \gate{cnot} gate after the \gate{barrier}).
-
-                  The \gate{inspect} gate on the left\hyp hand side needs some special attention.
-                  In a horizontal layout, the brace will of course always be drawn left to the text, as the \gate{inspect} gate is supposed to denote the current state of the registers.
-                  Therefore, we need to mirror the brace itself (\tex!decoration={mirror}!), and we also need to put it to the right\hyp hand side.
-                  Coincidentally, the \texttt{yquant-init} style has the brace at its right\hyp hand side, so we just choose to change the style.
-                  Using the \gate{init} gate instead would directly have invoked the correct \texttt{shape}; however, semantically, it is wrong, it would have changed the wire type to something visible (requiring a \gate{discard} directly afterwards) and it is also not scalable via \texttt{y radius}.
+                  This example shows a different way of providing explanations along the circuit, which this time also works for hints encompassing more than a single gate.
+                  We define the macros \tex!\leftExplain! and \tex!\rightExplain!, which in the circuit will do the job.
+                  They rely on the existent of a couple of named nodes: The node \texttt{leftComments} (or \texttt{rightComments}) is the named node created at the beginning of the circuit when declaring the two invisible wires.
+                  They will serve with their horizontal position.
+                  Additionally, we require the named gates \texttt{explainTop} and \texttt{explainBottom}, which should correspond to the first and last gate that is supposed to be enclosed in the brace.
+                  We then use \TikZ's \texttt{let} functionality in order to extract the required coordinates and draw the nodes.
+                  Note that the macros \tex!\p!, \tex!\x!, and \tex!\y! come into existence only when the \tex!\draw! command is executed; hence, just writing the \tex!\draw! call would lead to an error: \Yquant{} would first try to add (using \tex!\protected at edef!) the content of the macro to its output routine for the second pass, then call it in the first pass.
+                  We don't need the execution in the first pass---though it would not do harm---but we cannot allow for the expansion at this stage.
+                  Hence, we wrap the whole command in \tex!\yquantsecondpass! (which automatically restarts the parser afterwards, so we don't have to do this).
                \end{example}
 
          \subsubsection{3.1 Wires}
@@ -3790,16 +3919,16 @@
 
                \begin{example}
                   \begin{codeexample}
-\begin{tikzpicture}[rotate=-90]
-   \begin{yquant*}[every initial label/.style={anchor=east}]
-      box {\rotatebox{90}{$M$}} (c, b) | a;
-      box {\rotatebox{90}{GATE}} (-);
-      box {\rotatebox{90}{$M^{-1}$}} (c, b) | a;
-   \end{yquant*}
+\begin{tikzpicture}
+   \begin{yquant}[vertical=-90]
+      qubit a; qubit b; qubit c;
+      box {$M$} (c, b) | a;
+      box {GATE} (-);
+      box {$M^{-1}$} (c, b) | a;
+   \end{yquant}
 \end{tikzpicture}
                   \end{codeexample}
-                  Remember that \Yquant{} doesn't really support vertical layout, so it is always a bit of an experiment to make this work.
-                  Multi\hyp register gates don't work too well when trying to apply the back\hyp rotation trick of before.
+                  Here, we use the automatic rotation feature that the \style{/yquant/vertical} style provides.
                \end{example}
 
                \begin{example}
@@ -3881,30 +4010,31 @@
 
          \subsubsection{3.3 Attributes}
             \paragraph{Size Attributes}
-               \begin{example}
-                  \begin{codeexample}
+               \begin{example}<Changed in 0.7>
+                  \begin{codeexample*}
 \begin{tikzpicture}
    \begin{yquant*}
       [y radius=20pt] box {HIGH} (a, b);
       [x radius=20pt] box {WIDE} (-);
+      [time radius=20pt] box {LONG} (-);
+      [space radius=20pt] box {BROAD} (-);
    \end{yquant*}
 \end{tikzpicture}
-                  \end{codeexample}
-                  Note that \texttt{LONG} and \texttt{BROAD} do not make sense, as \Yquant{} does not support vertical layout.
+                  \end{codeexample*}
+                  In horizontal mode, \texttt{time radius} is a synonym for \texttt{x radius}, while \texttt{space radius} is a synonym for \texttt{y radius}.
                \end{example}
 
-               \begin{example}
+               \begin{example}<Changed in 0.7>
                   \begin{codeexample}
-\begin{tikzpicture}[rotate=-90, yscale=-1, every node/.append style={yscale=-1}]
-   \begin{yquant*}[every initial label/.style={rotate=45, anchor=east, shift={(.15, .15)}}]
-      [x radius=20pt]
-      box {\rotatebox{90}{HIGH}} (a, b);
-      [y radius=20pt]
-      box {\rotatebox{90}{WIDE}} (a, b);
+\begin{tikzpicture}
+   \begin{yquant*}[vertical=45]
+      [y radius=20pt] box {HIGH} (a, b);
+      [x radius=20pt] box {WIDE} (-);
+      [time radius=20pt] box {LONG} (-);
+      [space radius=20pt] box {BROAD} (-);
    \end{yquant*}
 \end{tikzpicture}
                   \end{codeexample}
-                  Again, trying to properly adjust the position of the initial labels is more trial\hyp and\hyp error than anything else, and very fragile with respect to changes in the circuit.
                \end{example}
 
                \begin{example}
@@ -4638,7 +4768,7 @@
                The background path deserves more attention.
                We draw the two circles and the vertical and horizontal lines; but note that we disable the \pkg{pgf}'s size protocol for all but the right circle.
                Hence, when this shape is used, \TeX{} and \Yquant{} will actually think that it only occupies space for the right circle; the left one will protrude in the margin.
-               (Actually, we could wrap this in a test such as \tex!\ifdefined\yquant at prefix! to only discard protocoling within a \texttt{yquant} environment, so that the shape is properly usable outside.)
+               (Actually, we could wrap this in a test such as \tex!\ifdefined\yquant at prefix! to only discard protocoling within a \tex!yquant! environment, so that the shape is properly usable outside.)
 
                Next, we must take care of re\hyp inserting this ``lost'' margin whenever the gate is used; and we also define a style that appropriately uses the shape:
                \begin{codeexample*}
@@ -4685,7 +4815,7 @@
                We append the style that we just defined to the list of attributes, and execute the gate preparation.
                Finally, we also declare the attributes that this gate takes---no required and no optional attributes.
 
-               After all this work, which can be saved in some shared document and used whenever necessary, we can come to the application, which is now very straightforward.
+               After all this work, which can be saved in some shared document and used whenever necessary, we can come to the application, which is now very straightforward (however, note that our gate declaration was too simplistic for vertical mode; but an adaptation is not difficult).
 
                \begin{codeexample}
 \begin{tikzpicture}
@@ -4731,7 +4861,7 @@
       \compat{New in 0.3}\Yquant{} not only understands its own language, but also others.
       \compat{New in 0.5}Although we refer to ``foreign languages,'' additional extension packages of the \Yquant{} language itself are also covered in this section and can be loaded by the same syntax.
 
-      \subsection[groups]{\compat{New in 0.5}groups}\label{sec:foreign:groups}
+      \subsection[groups]{\compat{Updated in 0.7\\New in 0.5}groups}\label{sec:foreign:groups}
          By saying \tex!\useyquantlanguage{groups}! in the preamble after loading \Yquant{} itself, additional support for groups of \Yquant{} circuits is loaded.
          Various circuits in a group share a common set of registers, are appropriately aligned horizontally if on the same line and can also be aligned vertically among multiple lines.
          The main intended use is for circuit equations.
@@ -4834,60 +4964,75 @@
                Typically, you will not want to refer to named gates in a circuit on a different page; remember that if you need this feature, you must pass the \texttt{remember picture} key in the \style{/yquant/preamble} option, as this is a reference to another \tex!tikzpicture!.
                Also don't forget to use the (\TikZ) \texttt{overlay} key on the corresponding path that references the node in order not to mess up with the bounding box (see the \TikZ{} documentation for those two keys).
 
-            \subsubsection{Configuration}
-               Loading the \pkg{groups} language extension will define several new configuration keys.
+         \subsubsection{Configuration}
+            Loading the \pkg{groups} language extension will define several new configuration keys.
 
-               \begin{option}{group/every group}!!
-                  Style that is installed for every \tex!yquantgroup! and \tex!yquantgroup*! environment, as if it had been given as an option.
-                  The style's default path is \texttt{/tikz}.
-               \end{option}
+            \begin{option}{group/every group}!!
+               Style that is installed for every \tex!yquantgroup! and \tex!yquantgroup*! environment, as if it had been given as an option.
+               The style's default path is \texttt{/tikz}.
+            \end{option}
 
-               \begin{option}{group/line separation}!5mm!
-                  This is the default vertical line separation that is inserted whenever a new line is issued in a \tex!yquantgroup!.
-               \end{option}
+            \begin{option}{group/line separation}!5mm!
+               This is the default vertical line separation that is inserted whenever a new line is issued in a \tex!yquantgroup!.
+            \end{option}
 
-               \begin{option}{group/aligned}!false!
-                  This boolean flag defines whether \tex!\shiftright! is automatically issued after \tex!\\! and the starred page breaking commands.
-               \end{option}
+            \begin{option}{group/aligned}!false!
+               This boolean flag defines whether \tex!\shiftright! is automatically issued after \tex!\\! and the starred page breaking commands.
+            \end{option}
 
-               \begin{option}{preamble}!!
-                  This style may only be passed to the \tex!yquantgroup! alignment directly as an option; it is not available via \tex!\yquantset! and the like.
-                  It is only relevant if the \tex!yquantgroup! is not contained in a \tex!tikzpicture!.
-                  The content of this style will be given as an optional argument to the \tex!tikzpicture!; this is the recommended way to specify \TikZ{} options, as they are automatically preserved among page breaks.
-               \end{option}
+            \begin{option}{preamble}!!
+               This style may only be passed to the \tex!yquantgroup! alignment directly as an option; it is not available via \tex!\yquantset! and the like.
+               It is only relevant if the \tex!yquantgroup! is not contained in a \tex!tikzpicture!.
+               The content of this style will be given as an optional argument to the \tex!tikzpicture!; this is the recommended way to specify \TikZ{} options, as they are automatically preserved among page breaks.
+            \end{option}
 
-               \begin{option}{operators/every group circuit}!/yquant/operators/every subcircuit, /yquant/operators/subcircuit/frameless, /yquant/operators/subcircuit/name mangling=transparent!
-                  This style is installed for the \gate{subcircuit} that implicitly wraps each \tex!\circuit!.
-                  Note that some magic is carried out to ensure that the name mangling setting only applies to the \emph{direct} content of the \tex!\circuit!; any \gate{subcircuit}s within the \tex!\circuit! will use the default name mangling scheme.
-               \end{option}
+            \begin{option}{operators/every group circuit}!/yquant/operators/every subcircuit, /yquant/operators/subcircuit/frameless, /yquant/operators/subcircuit/name mangling=transparent!
+               This style is installed for the \gate{subcircuit} that implicitly wraps each \tex!\circuit!.
+               Note that some magic is carried out to ensure that the name mangling setting only applies to the \emph{direct} content of the \tex!\circuit!; any \gate{subcircuit}s within the \tex!\circuit! will use the default name mangling scheme.
+            \end{option}
 
-               \begin{option}{operators/every group equals}!shape=yquant-rectangle, align=center, inner xsep=1mm, x radius=2mm, y radius=2.47mm!
-                  This style is installed for every \tex!\equals!, which is internally realized similarly to a \gate{box} gate.
-               \end{option}
+            \begin{option}[Changed in 0.7]{operators/every group equals}!shape=yquant-rectangle, align=center, anchor/.expanded=\ifyquanthorz{center}{north west}, inner xsep=1mm, x radius=2mm, y radius=2.47mm!
+               This style is installed for every \tex!\equals!, which is internally realized similarly to a \gate{box} gate.
+            \end{option}
 
-            \subsubsection{Gates and operations}
-               No gates or operations may be used directly within the \tex!yquantgroup! environment, but all the usual \Yquant{} gates and operations are available within \tex!\registers! and \tex!\circuit!.
-               Additionally, within \tex!\circuit!, the \gate{import} gate is available.
+         \subsubsection{Gates and operations}
+            No gates or operations may be used directly within the \tex!yquantgroup! environment, but all the usual \Yquant{} gates and operations are available within \tex!\registers! and \tex!\circuit!.
+            Additionally, within \tex!\circuit!, the \gate{import} gate is available.
 
-               \paragraph*{\yquant!import!}\label{gate:import}\leavevmode\\
-                  Syntax: \yquant!import <target>;! \\
-                  This is a pseudo\hyp gate that makes all the outer registers given in \tex!<target>! available in the current circuit.
-                  Consequently, the register names that are specified in \tex!<target>!, also ranges, do not refer to the registers in the \emph{current} \tex!\circuit!, but instead to those defined via \tex!\registers!.
-                  Therefore, it is for example possible to import all outer registers at once using \yquant!import -;!.
-                  Vector registers can also be imported partially.
+            \paragraph*{\yquant!import!}\label{gate:import}\leavevmode\\
+               Syntax: \yquant!import <target>;! \\
+               This is a pseudo\hyp gate that makes all the outer registers given in \tex!<target>! available in the current circuit.
+               Consequently, the register names that are specified in \tex!<target>!, also ranges, do not refer to the registers in the \emph{current} \tex!\circuit!, but instead to those defined via \tex!\registers!.
+               Therefore, it is for example possible to import all outer registers at once using \yquant!import -;!.
+               Vector registers can also be imported partially.
 
-                  If additional content (\TeX{} commands such as \TikZ{} paths, non\hyp creation gates) is used within \tex!\registers!, everything that comes \emph{before} the declaration of a register will be copied into the \tex!\circuit! when the register is imported; for a vector, this refers to the index zero.
-                  Additionally, any additional content that comes \emph{after} the declaration of the last register will be copied directly after the last register was imported.
+               If additional content (\TeX{} commands such as \TikZ{} paths, non\hyp creation gates) is used within \tex!\registers!, everything that comes \emph{before} the declaration of a register will be copied into the \tex!\circuit! when the register is imported; for a vector, this refers to the index zero.
+               Additionally, any additional content that comes \emph{after} the declaration of the last register will be copied directly after the last register was imported.
 
-                  \begin{warning}[Out-of-order importing]
-                     Note that it is principle possible to import registers out\hyp of\hyp order.
-                     Since matching outer and inner wires in subcircuits is done in the order in which they appear, this will lead to inner registers with names that do not match their outer registers and is probably highly undesirable.
-                  \end{warning}
+               \begin{warning}[Out-of-order importing]
+                  Note that it is principle possible to import registers out\hyp of\hyp order.
+                  Since matching outer and inner wires in subcircuits is done in the order in which they appear, this will lead to inner registers with names that do not match their outer registers and is probably highly undesirable.
+               \end{warning}
 
-                  Usually, this gate will not be needed as \Yquant{} will automatically import an outer register upon its first use.
+               Usually, this gate will not be needed as \Yquant{} will automatically import an outer register upon its first use.
 
-                  \emph{Possible attributes:} none
+               \emph{Possible attributes:} none
 
+         \subsubsection[Vertical layout]{\compat{New in 0.7}Vertical layout}
+            This library is aware of vertical circuits.
+            Note that the layout \emph{between} the circuits will always be the same, irrespective of the actual circuit orientation: Circuit will be set from left to right, and line breaks will always lead to a vertical shift and a reset of the horizontal position.
+
+            That said, the circuits may \emph{internally} be set in vertical mode.
+            Every invocation of \tex!\circuit! will then always restart a new \tex!yquant! environment.
+            While the content will still be put in a lonely \gate{subcircuit}---to keep consistency in the styling options---no inter\hyp circuit wire alignment will be carried out.
+
+            There is an additional complication regarding the vertical alignment of circuit and equality signs within one ``line.''
+            Now, the circuits can very well have a varying height, so vertically centering the circuits with respect to each other would not lead to a satisfying layout.
+            We might desire to vertically center the equality sign between its two enclosing circuits.
+            However, what if the line contains more than a two circuits and they all have different heights?
+            Then, the equality signs would be at different positions.
+            For this reason, all \tex!\circuit!s and \tex!\equals! will be aligned at their top.
+
       \subsection{qasm}\label{sec:foreign:qasm}
          By saying \tex!\useyquantlanguage{qasm}! in the preamble after loading \Yquant{} itself, the parser for \pkg{qasm} (not OpenQASM) is loaded.
          It provides the environment \tex!qasm! as well as the macro \tex!\qasmimport!, which works similarly to \tex!\yquantimport! (but does not accept additional options).
@@ -4985,7 +5130,7 @@
             \emph{Symptom:} Unexpected error messages
          \item Does the macro depend on other macros defined \emph{within} the circuit?
             The double pass may lead to problems.
-            If possible, define your macros outside of the \texttt{yquant} environment.
+            If possible, define your macros outside of the \tex!yquant! environment.
             If this is not possible, make sure the definitions are expandable, then at measurement stage, \Yquant{} will do the expansion, so that you get the correct results. \\
             \emph{Symptom:} Only the latest assignment will show up whenever the macro is used; the vertical spacing (for subcircuits, possibly also the horizontal spacing) may even be screwed.
          \item Does the macro create output, using its own font?
@@ -5160,5 +5305,13 @@
          New configuration: \style{/yquant/register/default lazy name} \\
          Documentation: Replace the wishlist by a section on integration with other packages. \\
          Documentation: Include the examples of \pkg{qpic} in this manual.
+
+      \subsection*{2022-02-05: Version 0.7}
+         New: Support for vertical layout. \\
+         Various bugfixes. \\
+         Internal change of the loading order of the package files. \\
+         Fix \href{https://github.com/projekter/yquant/issues/18}{\#18}: Subcircuit boxes don't render in \texttt{groups} environment.
+         Now, styles can properly modify the \style{/yquant/operators/this subcircuit box} style without affecting the content of the subcircuit, only the box. \\
+         New: Support for a simplified drawing pipeline without clipping paths.
 %END_FOLD
 \end{document}
\ No newline at end of file

Modified: trunk/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex	2022-02-05 21:22:43 UTC (rev 61896)
+++ trunk/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex	2022-02-05 21:23:01 UTC (rev 61897)
@@ -6,9 +6,9 @@
          \edef\wirexpos{\the\dimen0}%
       \else%
          \pgfpointanchor{yquantbox}{#2}%
-         \edef\wirexpos{\the\pgf at x}%
+         \edef\wirexpos{\the\yquant at pgf@x}%
       \fi%
-      \ifdim\wirexpos>0pt % may be negative for init gates
+      \ifdim\yquant at orientation@plus\wirexpos>0pt % may be negative for init gates
          \yquant at register@get at typeywire{#1}\wiretype\wireypos\wirelast%
          \edef\wirexprevpos{\expandafter\@firstoffour\wirelast}%
          \ifnum\wiretype=\yquant at register@type at none%
@@ -15,7 +15,9 @@
             % 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 at register@set at lastwire{#1}{%
                {\wirexprevpos}{\wirexpos}{}%
-               {\unexpanded\expandafter{\pgfshapeclippathhorzresult}}%
+               {\ifyquant at config@draw at quality%
+                   \unexpanded\expandafter{\pgfshapeclippathhorzresult}%
+                \fi}%
             }%
          \else%
             % append the previous `last' clipping to the old list and insert the new one
@@ -25,7 +27,9 @@
                    \expandafter\@thirdandfourthoffour\wirelast%
                 }%
                }%
-               {\unexpanded\expandafter{\pgfshapeclippathhorzresult}}%
+               {\ifyquant at config@draw at quality%
+                  \unexpanded\expandafter{\pgfshapeclippathhorzresult}%
+                \fi}%
             }%
          \fi%
       \fi%
@@ -41,10 +45,14 @@
    % to have a symmetric situation, we extend again one separation at the end, unless this is supposed to be seamless and we don't have outputs (for seamless circuits with outputs, extend - since this extension will be between last register and output)
    \ifyquant at env@seamless{%
       \expandafter\unless\expandafter\ifx\csname\yquant at prefix outputs\endcsname\relax%
-         \dimdef\yquant at circuit@endwires at x{\yquant at circuit@endwires at x+\yquant at config@operator at sep}%
+         \dimdef\yquant at circuit@endwires at x{%
+            \yquant at circuit@endwires at x\yquant at orientation@plus\yquant at config@operator at sep%
+         }%
       \fi%
    }{%
-      \dimdef\yquant at circuit@endwires at x{\yquant at circuit@endwires at x+\yquant at config@operator at sep}%
+      \dimdef\yquant at circuit@endwires at x{%
+         \yquant at circuit@endwires at x\yquant at orientation@plus\yquant at config@operator at sep%
+      }%
    }%
    \let\yquant at circuit@endwires at finalize=\relax%
    \yquant at for \yquant at circuit@endwires at i := 1 to \csname\yquant at prefix registers\endcsname {%
@@ -52,9 +60,15 @@
       \ifcsname\yquant at prefix registermap@\yquant at circuit@endwires at i\endcsname%
          \xifinlistcs\yquant at circuit@endwires at i{\yquant at prefix inonly}{%
             % however, the wire is to be discarded after this circuit
-            \edef\storedleft{\the\pgf at picminx}%
-            \yquant at draw@wire\yquant at circuit@endwires at i1%
-            \global\pgf at picminx=\storedleft%
+            \ifyquanthorz{%
+               \edef\storedleft{\the\pgf at picminx}%
+               \yquant at draw@wire\yquant at circuit@endwires at i1%
+               \global\pgf at picminx=\storedleft%
+            }{%
+               \edef\storedtop{\the\pgf at picmaxy}%
+               \yquant at draw@wire\yquant at circuit@endwires at i1%
+               \global\pgf at picmaxy=\storedtop%
+            }%
             \eappto\yquant at circuit@endwires at finalize{%
                \yquant at register@set at type%
                   \yquant at circuit@endwires at i\noexpand\yquant at register@type at none%
@@ -84,9 +98,11 @@
 % 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 the \pgfshapeclippathvertresult was set up appropriately for this node. At the first call, \yquant at circuit@extendcontrolline at cmd must be \let to \empty and \yquant at circuit@extendcontrolline at prev to \relax.
 \protected\def\yquant at circuit@extendcontrolline#1#2{%
-   \eappto\yquant at circuit@extendcontrolline at clip{%
-      \unexpanded\expandafter{\pgfshapeclippathvertresult}%
-   }%
+   \ifyquant at config@draw at quality%
+      \eappto\yquant at circuit@extendcontrolline at clip{%
+         \unexpanded\expandafter{\pgfshapeclippathvertresult}%
+      }%
+   \fi%
    \begingroup%
       \tikzset{/yquant/every control line}%
       \expandafter%
@@ -100,7 +116,7 @@
       \unless\ifx\yquant at circuit@extendcontrolline at prev\relax%
          \eappto\yquant at circuit@extendcontrolline at cmd{%
             \expandafter\@secondofthree\yquant at circuit@extendcontrolline at prev%
-            -- (#2,\the\pgf at y)%
+            -- \yquant at coords(#2,\the\yquant at pgf@y)%
          }%
       \fi%
       \yquant at circuit@extendcontrolline at store{#2}%
@@ -110,9 +126,9 @@
       \unless\ifx\yquant at circuit@extendcontrolline at prev\relax%
          \eappto\yquant at circuit@extendcontrolline at cmd{%
             \expandafter\@firstofthree\yquant at circuit@extendcontrolline at prev%
-            -- (\the\dimexpr#2-2\@tempdima\relax,\the\pgf at y)%
+            -- \yquant at coords(\the\dimexpr#2-2\@tempdima\relax,\the\yquant at pgf@y)%
             \expandafter\@thirdofthree\yquant at circuit@extendcontrolline at prev%
-            -- (\the\dimexpr#2+2\@tempdima\relax,\the\pgf at y)%
+            -- \yquant at coords(\the\dimexpr#2+2\@tempdima\relax,\the\yquant at pgf@y)%
          }%
       \fi%
       \yquant at circuit@extendcontrolline at store{#2}%
@@ -122,11 +138,11 @@
       \unless\ifx\yquant at circuit@extendcontrolline at prev\relax%
          \eappto\yquant at circuit@extendcontrolline at cmd{%
             \expandafter\@firstofthree\yquant at circuit@extendcontrolline at prev%
-            -- (\the\dimexpr#2-2\@tempdima\relax,\the\pgf at y)%
+            -- \yquant at coords(\the\dimexpr#2-2\@tempdima\relax,\the\yquant at pgf@y)%
             \expandafter\@secondofthree\yquant at circuit@extendcontrolline at prev%
-            -- (\the\dimexpr#2\relax,\the\pgf at y)%
+            -- \yquant at coords(\the\dimexpr#2\relax,\the\yquant at pgf@y)%
             \expandafter\@thirdofthree\yquant at circuit@extendcontrolline at prev%
-            -- (\the\dimexpr#2+2\@tempdima\relax,\the\pgf at y)%
+            -- \yquant at coords(\the\dimexpr#2+2\@tempdima\relax,\the\yquant at pgf@y)%
          }%
       \fi%
       \yquant at circuit@extendcontrolline at store{#2}%
@@ -138,9 +154,9 @@
 
 \protected\def\yquant at circuit@extendcontrolline at store#1{%
    \edef\yquant at circuit@extendcontrolline at prev{%
-      {(\the\dimexpr#1-2\@tempdima\relax,\the\pgf at y)}%
-      {(\the\dimexpr#1\relax,\the\pgf at y)}%
-      {(\the\dimexpr#1+2\@tempdima\relax,\the\pgf at y)}%
+      {\yquant at coords(\the\dimexpr#1-2\@tempdima\relax,\the\yquant at pgf@y)}%
+      {\yquant at coords(\the\dimexpr#1\relax,\the\yquant at pgf@y)}%
+      {\yquant at coords(\the\dimexpr#1+2\@tempdima\relax,\the\yquant at pgf@y)}%
    }%
 }
 
@@ -150,18 +166,20 @@
       \tikzset{/yquant/every multi line}%
       \expandafter%
    \endgroup%
-   \eappto\yquant at circuit@extendmultiline at clip{%
-      \unexpanded\expandafter{\pgfshapeclippathvertresult}%
-   }%
+   \ifyquant at config@draw at quality%
+      \eappto\yquant at circuit@extendmultiline at clip{%
+         \unexpanded\expandafter{\pgfshapeclippathvertresult}%
+      }%
+   \fi%
    \expandafter\@tempdima\the\pgflinewidth%
    \pgfpointanchor{yquantbox}{center}%
    \unless\ifx\yquant at circuit@extendmultiline at prev\relax%
       \eappto\yquant at circuit@extendmultiline at cmd{%
-         \yquant at circuit@extendmultiline at prev -- (#1,\the\pgf at y)%
+         \yquant at circuit@extendmultiline at prev -- \yquant at coords(#1,\the\yquant at pgf@y)%
       }%
    \fi%
    \edef\yquant at circuit@extendmultiline at prev{%
-      (\the\dimexpr#1\relax,\the\pgf at y)%
+      \yquant at coords(\the\dimexpr#1\relax,\the\yquant at pgf@y)%
    }%
 }
 % END_FOLD

Modified: trunk/Master/texmf-dist/tex/latex/yquant/yquant-config.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/yquant/yquant-config.tex	2022-02-05 21:22:43 UTC (rev 61896)
+++ trunk/Master/texmf-dist/tex/latex/yquant/yquant-config.tex	2022-02-05 21:23:01 UTC (rev 61897)
@@ -26,18 +26,99 @@
       register/minimum height/.code=%
          {\dimdef\yquant at config@register at minimum@height{#1}},%
       register/minimum depth/.code=%
-         {\dimdef\yquant at config@register at minimum@depth{#1}}%
+         {\dimdef\yquant at config@register at minimum@depth{#1}},%
+      register/minimum left/.forward to=/yquant/register/minimum height,%
+      register/minimum right/.forward to=/yquant/register/minimum depth,%
+      register/minimum before/.forward to=/yquant/register/minimum height,%
+      register/minimum after/.forward to=/yquant/register/minimum after%
    }
 \fi
+\def\yquant at config@draw at ensurelayers@addwires#1,main,#2\yquant at stop{%
+   \ifstrempty{#2}{%
+      % main was the last item in the list, so we needed to add the comma
+      \edef\pgf at layerlist{\@gobble#1,wires,main}%
+   }{%
+      % there were more items in the list, so we have a spurious comma in #2
+      \expandafter\yquant at config@draw at ensurelayers@addwires@%
+         \expandafter,\pgf at layerlist\yquant at stop%
+   }%
+}
+\def\yquant at config@draw at ensurelayers@addwires@#1,main,#2\yquant at stop{%
+   \edef\pgf at layerlist{\@gobble#1,wires,main,#2}%
+}
+\def\yquant at config@draw at ensurelayers@haswires#1,wires,#2\yquant at stop{%
+   \ifstrempty{#2}{%
+      % wires not present yet, take action
+      \expandafter\yquant at config@draw at ensurelayers@addwires%
+         \expandafter,\pgf at layerlist,\yquant at stop%
+   }\relax%
+}
+\def\yquant at config@draw at ensurelayers@addbehindwires#1,wires,#2\yquant at stop{%
+   \ifstrempty{#2}{%
+      % wires was the last item in the list, so we needed to add the comma (should never happen)
+      \edef\pgf at layerlist{\@gobble#1,behindwires,wires}%
+      \PackageWarning{yquant.sty}{The wires layer was set on top of the main layer - expect undesirable outcomes.}%
+   }{%
+      % there were more items in the list, so we have a spurious comma in #2
+      \expandafter\yquant at config@draw at ensurelayers@addbehindwires@%
+         \expandafter,\pgf at layerlist\yquant at stop%
+   }%
+}
+\def\yquant at config@draw at ensurelayers@addbehindwires@#1,wires,#2\yquant at stop{%
+   \edef\pgf at layerlist{\@gobble#1,behindwires,wires,#2}%
+}
+\def\yquant at config@draw at ensurelayers@hasbehindwires#1,behindwires,#2\yquant at stop{%
+   \ifstrempty{#2}{%
+      % wires not present yet, take action
+      \expandafter\yquant at config@draw at ensurelayers@addbehindwires%
+         \expandafter,\pgf at layerlist,\yquant at stop%
+   }\relax%
+}
+\def\yquant at config@draw at ensurelayers{%
+   \expandafter\yquant at config@draw at ensurelayers@haswires%
+      \expandafter,\pgf at layerlist,wires,\yquant at stop%
+   \expandafter\yquant at config@draw at ensurelayers@hasbehindwires%
+      \expandafter,\pgf at layerlist,behindwires,\yquant at stop%
+   \ifyquant at config@draw at quality%
+      % maybe the option was set outside of a tikzpicture, then we need to keep this
+      \global\let\endpgfpicture=\yquant at old@endpgfpicture%
+      \global\yquant at config@requirelayersfalse%
+   \fi%
+}
+
 \pgfqkeys{/yquant}{%
    register/separation/.code=%
       {\dimdef\yquant at config@register at sep{#1}},%
    operator/minimum width/.code=%
       {\dimdef\yquant at config@operator at minimum@width{#1}},%
+   operator/minimum extent/.forward to=/yquant/operator/minimum width,%
    operator/separation/.code=%
       {\dimdef\yquant at config@operator at sep{#1}},%
    operator/multi warning/.is if=%
-      yquant at config@operator at multi@warn%
+      yquant at config@operator at multi@warn,%
+   drawing mode/.is choice,%
+   drawing mode/quality/.code=%
+      {\yquant at config@draw at qualitytrue%
+       \pgfkeysalso{/yquant/default background=none}%
+       \unless\ifpgfpicture%
+          % we do not reset the special layer injection (there may be multiple yquant environments, and only one of them had the "size" drawing mode; then, we still need the layers), unless this is actually set outside of a tikzpicture
+          \ifdefined\yquant at old@endpgfpicture% only if we changed before
+            \global\let\endpgfpicture=\yquant at old@endpgfpicture%
+            \global\yquant at config@requirelayersfalse%
+          \fi%
+       \fi},%
+   drawing mode/size/.code=%
+      {\yquant at config@draw at qualityfalse%
+       \pgfkeysalso{/yquant/default background=white}%
+       \unless\ifyquant at config@requirelayers%
+          \global\let\yquant at old@endpgfpicture=\endpgfpicture%
+          \gpreto\endpgfpicture\yquant at config@draw at ensurelayers%
+       \fi%
+       \global\yquant at config@requirelayerstrue},%
+   default background/.initial=%
+      {none},%
+   default fill/.style={%
+      fill/.expanded=\pgfkeysvalueof{/yquant/default background}}
 }%
 % END_FOLD
 % BEGIN_FOLD Register creation
@@ -50,20 +131,22 @@
 \ifnum\yquant at compat<2 %
    \pgfqkeys{/yquant}{%
       every label/.style=%
-         {shape=yquant-init, anchor=center, align=right, outer xsep=2pt},%
+         {shape=yquant-init, anchor=center,%
+          align/.expanded=\ifyquanthorz{right}{center}, outer timesep=2pt},%
       every multi label/.style=%
-         {draw, decoration={gapped brace, mirror, raise=2pt}, decorate}%
+         {draw, decoration/.expanded={gapped brace, raise=2pt, \ifyquanthorz{mirror}{}}, decorate}%
    }
 \else
    \pgfqkeys{/yquant}{%
       every label/.style=%
-         {shape=yquant-init, anchor=center, align=right, outer xsep=2pt,%
-          /yquant/operator/if multi={draw, decoration={gapped brace, mirror, raise=2pt}, decorate}}%
+         {shape=yquant-init, anchor=center,%
+          align/.expanded=\ifyquanthorz{right}{center}, outer timesep=2pt,%
+          /yquant/operator/if multi={draw, decoration/.expanded={gapped brace, raise=2pt, \ifyquanthorz{mirror}{}}, decorate}}%
     }
 \fi
 \pgfqkeys{/yquant}{
    every initial label/.style=%
-      {anchor=east},%
+      {anchor/.expanded=\ifyquanthorz{east}{south}, /yquant/internal/autorotate init},%
    every qubit label/.style=%
       {},%
    every cbit label/.style=%
@@ -82,15 +165,19 @@
 \ifnum\yquant at compat<2 %
    \pgfqkeys{/yquant}{%
       every output/.style=%
-         {shape=yquant-output, anchor=west, align=left, outer xsep=2pt},%
+         {shape=yquant-output, anchor/.expanded=\ifyquanthorz{west}{north},%
+          align/.expanded=\ifyquanthorz{left}{center}, outer timesep=2pt,%
+          /yquant/internal/autorotate output},%
       every multi output/.style=%
-         {draw, decoration={gapped brace, raise=2pt}, decorate}%
+         {draw, decoration/.expanded={gapped brace, raise=2pt, \ifyquanthorz{}{mirror}}, decorate}%
    }
 \else
    \pgfqkeys{/yquant}{%
       every output/.style=%
-         {shape=yquant-output, anchor=west, align=left, outer xsep=2pt,%
-          /yquant/operator/if multi={draw, decoration={gapped brace, raise=2pt}, decorate}}%
+         {shape=yquant-output, anchor/.expanded=\ifyquanthorz{west}{north},%
+          align/.expanded=\ifyquanthorz{left}{center}, outer timesep=2pt,%
+          /yquant/operator/if multi={draw, decoration/.expanded={gapped brace, raise=2pt, \ifyquanthorz{}{mirror}}, decorate},%
+          /yquant/internal/autorotate output}%
    }
 \fi
 \pgfqkeys{/yquant}{%
@@ -129,7 +216,7 @@
    every positive control/.style=%
       {fill=black},%
    every negative control/.style=%
-      {draw},%
+      {draw, /yquant/default fill},%
    every operator/.style=%
       {anchor=center},%
    every multi line/.style=%
@@ -152,6 +239,41 @@
    operator/if multi/.code=%
       {\ifyquant at config@operator at multi\pgfkeysalso{#1}\fi},%
    circuit/seamless/.is if=yquant at config@circuit at seamless,%
+   circuit/orientation/.is choice,%
+   circuit/orientation/horizontal/.code={%
+      \ifyquant at config@circuitsetup%
+         \pgfkeysalso{/yquant/internal/autorotate init/.style={},%
+            /yquant/internal/autorotate output/.style={}}%
+         \yquant at config@circuit at orientation@horizontal%
+      \else%
+         \PackageError{yquant.sty}{`circuit/orientation' can only be modified in the environment options or globally.}{Don't modify this within a circuit.}%
+      \fi%
+   },%
+   circuit/orientation/vertical/.code={%
+      \ifyquant at config@circuitsetup%
+         \yquant at config@circuit at orientation@vertical%
+      \else%
+         \PackageError{yquant.sty}{`circuit/orientation' can only be modified in the environment options or globally.}{Don't modify this within a circuit.}%
+      \fi%
+   },%
+   horizontal/.forward to=/yquant/circuit/orientation/horizontal,%
+   vertical/.code={%
+      \pgfkeysalso{/yquant/circuit/orientation/vertical}%
+      \unless\ifdim#1 pt=0pt %
+         \ifdefined\adjustbox%
+            \pgfkeysalso{%
+               /yquant/internal/autorotate init/.style={%
+                  /tikz/execute at begin node={\adjustbox{rotate=#1}}%
+               }, /yquant/internal/autorotate output/.style={%
+                  /tikz/execute at begin node={\adjustbox{rotate=-#1}}%
+               }%
+            }%
+         \else%
+            \PackageWarning{yquant.sty}{In order to use the automatic rotation of initial labels for vertical circuits, you need to load the `adjustbox' package.}%
+         \fi%
+      \fi%
+   },%
+   vertical/.default=0,%
    every post measurement control/.is choice,
    every post measurement control/indirect/.code={%
       \undef\yquant at lang@attr at directcontrol%
@@ -175,7 +297,7 @@
 \fi
 \pgfqkeys{/yquant}{%
    operators/every text/.style=%
-      {shape=yquant-rectangle, align=center, inner xsep=1mm, x radius=2mm, y radius=2.47mm}%
+      {shape=yquant-rectangle, align=center, inner timesep=1mm, time radius=2mm, space radius=2.47mm, /yquant/default fill}%
 }
 \ifnum\yquant at compat<3 %
    \pgfqkeys{/yquant}{%
@@ -183,12 +305,12 @@
       operators/every rectangular box/.style=%
          {/yquant/operators/every box},%
       operators/every box/.style=%
-         {shape=yquant-rectangle, draw, align=center, inner xsep=1mm, x radius=2mm, y radius=2.47mm}%
+         {shape=yquant-rectangle, draw, align=center, inner timesep=1mm, time radius=2mm, space radius=2.47mm, /yquant/default fill}%
    }
 \else
    \pgfqkeys{/yquant}{%
       operators/every rectangular box/.style=%
-         {shape=yquant-rectangle, draw, align=center, inner xsep=1mm, x radius=2mm, y radius=2.47mm},%
+         {shape=yquant-rectangle, draw, align=center, inner timesep=1mm, time radius=2mm, space radius=2.47mm, /yquant/default fill},%
       operators/every box/.style=%
          {/yquant/operators/every rectangular box}%
    }
@@ -206,17 +328,18 @@
 \fi
 \pgfqkeys{/yquant}{%
    operators/every dmeter/.style=%
-      {shape=yquant-dmeter, x radius=2mm, y radius=2mm, draw},
+      {shape=yquant-dmeter, time radius=2mm, space radius=2mm, draw, /yquant/default fill},
    % every h is implicitly defined during gate declaration
    operators/every inspect/.style=%
-      {shape=yquant-output, align=left, outer xsep=.3333em, y radius=2.47mm,%
-       /yquant/operator/if multi={draw, decoration={gapped brace, raise=2pt}, decorate}},%
+      {shape=yquant-output, align/.expanded=\ifyquanthorz{left}{center},
+       outer timesep=.3333em, space radius=2.47mm, /yquant/default fill,%
+       /yquant/operator/if multi={draw, decoration/.expanded={gapped brace, raise=2pt, \ifyquanthorz{}{mirror}}, decorate}},%
    operators/every measure/.style=%
-      {shape=yquant-measure, x radius=4mm, y radius=2.5mm, draw},%
+      {shape=yquant-measure, x radius=4mm, y radius=2.5mm, draw, /yquant/default fill},%
    operators/every measure meter/.style=%
       {draw, -{Latex[length=2.5pt]}},%
    operators/every not/.style=%
-      {shape=yquant-oplus, radius=1.3mm, draw},%
+      {shape=yquant-oplus, radius=1.3mm, draw, /yquant/default fill},%
    operators/every pauli/.style=%
       {/yquant/operators/every rectangular box},%
    operators/every phase/.style=%
@@ -226,7 +349,7 @@
    operators/every subcircuit/.style=%
       {},%
    operators/every subcircuit box/.style=%
-      {/yquant/operators/every rectangular box},%
+      {/yquant/operators/every rectangular box, fill=none},%
    subcircuit box style/.style=%
       {/yquant/operators/every subcircuit box/.append style={#1}},%
    operators/this subcircuit box/.style=%
@@ -260,7 +383,7 @@
       {shape=yquant-circle, radius=.5mm, fill},%
    % every x is implicitly defined during gate declaration
    operators/every xx/.style=%
-      {shape=yquant-rectangle, radius=.75mm, draw},%
+      {shape=yquant-rectangle, radius=.75mm, draw, /yquant/default fill},%
    % every y is implicitly defined during gate declaration
    % every z is implicitly defined during gate declaration
    operators/every zz/.style=%
@@ -277,6 +400,10 @@
        \fi},
    internal/multi main/.is if=%
       yquant at config@internal at multi@main,%
+   internal/setup done/.code=%
+      {\yquant at config@circuitsetupfalse},%
+   internal/autorotate init/.style={},%
+   internal/autorotate output/.style={},%
 }
 \ifnum\yquant at compat<2 %
    \pgfqkeys{/yquant}{%
@@ -291,13 +418,105 @@
 \fi
 % END_FOLD
 
+\protected\def\yquant at config@circuit at orientation@horizontal{%
+   \let\ifyquanthorz=\@firstoftwo%
+   \tikzset{%
+      % in principle, these are all /.forward to handlers, but we want them non-accumulative
+      time radius/.code={\pgfkeys{/tikz/x radius={##1}}},%
+      space radius/.code={\pgfkeys{/tikz/y radius={##1}}},%
+      inner timesep/.code={\pgfkeys{/tikz/inner xsep={##1}}},%
+      inner spacesep/.code={\pgfkeys{/tikz/inner ysep={##1}}},%
+      outer timesep/.code={\pgfkeys{/tikz/outer xsep={##1}}},%
+      outer spacesep/.code={\pgfkeys{/tikz/outer ysep={##1}}}%
+   }%
+   \def\yquant at config@register at minimum@height at default{1.5mm}%
+   \def\yquant at config@register at minimum@depth at default{1.5mm}%
+   \def\yquant at config@operator at minimum@width at default{5mm}%
+   \let\yquant at pgf@picminx=\pgf at picminx%
+   \let\yquant at pgf@picmaxx=\pgf at picmaxx%
+   \let\yquant at pgf@picminy=\pgf at picminy%
+   \let\yquant at pgf@picmaxy=\pgf at picmaxy%
+   \let\yquant at pgf@x=\pgf at x%
+   \let\yquant at pgf@y=\pgf at y%
+   \let\yquant at pgf@pt at x=\pgf at pt@x%
+   \let\yquant at pgf@pt at y=\pgf at pt@y%
+   \let\yquant at pgfqpoint=\pgfqpoint%
+   \let\yquant at coords=\empty%
+   \let\pgfshapeclippath=\yquant at pgfshapeclippath@horz%
+   \def\yquant at orientation@x{x}%
+   \def\yquant at orientation@y{y}%
+   \def\yquant at orientation@plus{+}%
+   \def\yquant at orientation@minus{-}%
+}
+
+\protected\def\yquant at config@circuit at orientation@vertical{%
+   \let\ifyquanthorz=\@secondoftwo%
+   \tikzset{%
+      % in principle, these are all /.forward to handlers, but we want them non-accumulative
+      time radius/.code={\pgfkeys{/tikz/y radius={##1}}},%
+      space radius/.code={\pgfkeys{/tikz/x radius={##1}}},%
+      inner timesep/.code={\pgfkeys{/tikz/inner ysep={##1}}},%
+      inner spacesep/.code={\pgfkeys{/tikz/inner xsep={##1}}},%
+      outer timesep/.code={\pgfkeys{/tikz/outer ysep={##1}}},%
+      outer spacesep/.code={\pgfkeys{/tikz/outer xsep={##1}}}%
+   }%
+   \def\yquant at config@register at minimum@height at default{2.5mm}%
+   \def\yquant at config@register at minimum@depth at default{2.5mm}%
+   \def\yquant at config@operator at minimum@width at default{3mm}%
+   \let\yquant at pgf@picminx=\pgf at picminy%
+   \let\yquant at pgf@picmaxx=\pgf at picmaxy%
+   \let\yquant at pgf@picminy=\pgf at picminx%
+   \let\yquant at pgf@picmaxy=\pgf at picmaxx%
+   \let\yquant at pgf@x=\pgf at y%
+   \let\yquant at pgf@y=\pgf at x%
+   \let\yquant at pgf@pt at x=\pgf at pt@y%
+   \let\yquant at pgf@pt at y=\pgf at pt@x%
+   \def\yquant at pgfqpoint##1##2{\pgfqpoint{##2}{##1}}%
+   \def\yquant at coords(##1,##2){({##2},{##1})}%
+   \let\pgfshapeclippath=\yquant at pgfshapeclippath@vert%
+   \def\yquant at orientation@x{y}%
+   \def\yquant at orientation@y{x}%
+   \def\yquant at orientation@plus{-}%
+   \def\yquant at orientation@minus{+}%
+}
+
+\let\yquant at pgfshapeclippath@horz=\pgfshapeclippath
+\let\yquant at pgfshapeclippath@vert=\pgfshapeclippath
+\patchcmd\yquant at pgfshapeclippath@vert{%
+   \global\let\pgfshapeclippathhorzresult=\pgfshapeclippathresult%
+   \ifcsname pgf at sh@clipvert@\csname pgf at sh@ns@#1\endcsname\endcsname%
+      % different clipping in vertical direction
+      \pgfsyssoftpath at setcurrentpath\pgfutil at empty%
+      \csname pgf at sh@clipvert@\csname pgf at sh@ns@#1\endcsname\endcsname%
+      \pgfsyssoftpath at getcurrentpath\pgfshapeclippathresult%
+      \pgfprocessround{\pgfshapeclippathresult}{\pgfshapeclippathresult}%
+   \fi%
+   \global\let\pgfshapeclippathvertresult=\pgfshapeclippathresult%
+}{%
+   \global\let\pgfshapeclippathvertresult=\pgfshapeclippathresult%
+   \ifcsname pgf at sh@clipvert@\csname pgf at sh@ns@#1\endcsname\endcsname%
+      % different clipping in vertical direction
+      \pgfsyssoftpath at setcurrentpath\pgfutil at empty%
+      \csname pgf at sh@clipvert@\csname pgf at sh@ns@#1\endcsname\endcsname%
+      \pgfsyssoftpath at getcurrentpath\pgfshapeclippathresult%
+      \pgfprocessround{\pgfshapeclippathresult}{\pgfshapeclippathresult}%
+   \fi%
+   \global\let\pgfshapeclippathhorzresult=\pgfshapeclippathresult%
+}{}{%
+   \PackageError{yquant.sty}{Unable to path \string\pgfshapeclippath}%
+                {Vertical layout will not work.}%
+}
+
 \def\yquant at config@register at default@name{\regidx}
 \let\yquant at config@register at default@lazyname=\empty
-\def\yquant at config@register at minimum@height{1.5mm}
-\def\yquant at config@register at minimum@depth{1.5mm}
+\def\yquant at config@register at minimum@height{\yquant at config@register at minimum@height at default}
+\def\yquant at config@register at minimum@height at default{1.5mm}
+\def\yquant at config@register at minimum@depth{\yquant at config@register at minimum@depth at default}
+\def\yquant at config@register at minimum@depth at default{1.5mm}
 \def\yquant at config@register at sep{1mm}
 \def\yquant at config@operator at sep{1mm}
-\def\yquant at config@operator at minimum@width{5mm}
+\def\yquant at config@operator at minimum@width{\yquant at config@operator at minimum@width at default}
+\def\yquant at config@operator at minimum@width at default{5mm}
 \newif\ifyquant at config@internal at multi@main%
 \yquant at config@internal at multi@maintrue
 \newif\ifyquant at config@operator at multi@warn
@@ -310,6 +529,12 @@
 \newif\ifyquant at config@operator at subcircuit@manglingreset
 \yquant at config@operator at subcircuit@manglingresettrue
 \newif\ifyquant at config@operator at multi
+\newif\ifyquant at config@circuitsetup
+\yquant at config@circuitsetuptrue
+\yquant at config@circuit at orientation@horizontal
+\newif\ifyquant at config@draw at quality
+\yquant at config@draw at qualitytrue
+\newif\ifyquant at config@requirelayers
 
 \protected\def\yquant at config@operator at subcircuit@mangling at set#1{%
    \ifyquant at config@operator at subcircuit@manglingreset%

Modified: trunk/Master/texmf-dist/tex/latex/yquant/yquant-draw.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/yquant/yquant-draw.tex	2022-02-05 21:22:43 UTC (rev 61896)
+++ trunk/Master/texmf-dist/tex/latex/yquant/yquant-draw.tex	2022-02-05 21:23:01 UTC (rev 61897)
@@ -62,19 +62,19 @@
          \ifyquant at env@seamless{%
             \unless\ifdim\yquant at draw@@x=\yquant at draw@subcircuit at leftpos%
                \dimdef\yquant at draw@@x{%
-                  \yquant at draw@@x+\yquant at config@operator at sep%
+                  \yquant at draw@@x\yquant at orientation@plus\yquant at config@operator at sep%
                }%
             \fi%
          }{%
             \dimdef\yquant at draw@@x{%
-               \yquant at draw@@x+\yquant at config@operator at sep%
+               \yquant at draw@@x\yquant at orientation@plus\yquant at config@operator at sep%
             }%
          }%
          \ifyquant at config@operator at position@advance%
-            \dimdef\newx{\yquant at draw@@x+#1}%
+            \dimdef\newx{\yquant at draw@@x\yquant at orientation@plus#1}%
             \forlistloop\yquant at draw@group at advance{#6}%
          \fi%
-         \dimdef\yquant at draw@@x{\yquant at draw@@x+.5\dimexpr#1\relax}%
+         \dimdef\yquant at draw@@x{\yquant at draw@@x\yquant at orientation@plus.5\dimexpr#1\relax}%
       \fi%
 }
 
@@ -157,9 +157,11 @@
    \fi%
    \edef\process{%
          \endgroup%
-         \def\noexpand\yquant at circuit@extendcontrolline at clip{%
-            \unexpanded\expandafter{\yquant at circuit@extendcontrolline at clip}%
-         }%
+         \ifyquant at config@draw at quality%
+            \def\noexpand\yquant at circuit@extendcontrolline at clip{%
+               \unexpanded\expandafter{\yquant at circuit@extendcontrolline at clip}%
+            }%
+         \fi%
          \def\noexpand\yquant at circuit@extendcontrolline at prev{%
             \unexpanded\expandafter{\yquant at circuit@extendcontrolline at prev}%
          }%
@@ -196,13 +198,15 @@
    \let\idx=\yquant at draw@@idx at content%
    \yquant at config@operator at multifalse%
    \edef\cmd{%
-      \noexpand\path (\yquant at draw@@x, \yquant at register@get at y{#1})%
+      \noexpand\path \yquant at coords(\yquant at draw@@x, \yquant at register@get at y{#1})%
          node[/yquant/every operator, \yquant at draw@@style, /yquant/this operator,%
               name prefix=, name suffix=, name=yquantbox]%
          {\unexpanded\expandafter{\yquant at draw@@content}};%
-      \pgfshapeclippath{yquantbox}%
-                       {/yquant/every operator, \yquant at draw@@style,%
-                        /yquant/this operator}%
+      \ifyquant at config@draw at quality%
+         \pgfshapeclippath{yquantbox}%
+                          {/yquant/every operator, \yquant at draw@@style,%
+                           /yquant/this operator}%
+      \fi%
    }%
    \cmd%
    \yquant at circuit@extendwire{#1}{center}%
@@ -239,18 +243,20 @@
 \protected\def\yquant at draw@multi at contiguous#1#2#3{%
    % We need to somehow extract the y radius
    \edef\cmd{%
-      \noexpand\path (\yquant at draw@@x, \the\dimexpr.5\dimexpr%
+      \noexpand\path \yquant at coords(\yquant at draw@@x, \the\dimexpr.5\dimexpr%
                          \yquant at register@get at y{#1}+\yquant at register@get at y{#2}\relax%
                       \relax)%
          node[/yquant/every operator, \yquant at draw@@style, /yquant/this operator,%
               /yquant/internal/multi main=\ifnum#3=1 true\else false\fi\unless\ifnum#1=#2 ,%
-              y radius/.expanded=\the\dimexpr.5\dimexpr\yquant at register@get at ydist{#1}{#2}\relax\relax+%
-                     .5*\noexpand\pgfkeysvalueof{/tikz/y radius}\fi,%
+              space radius/.expanded=\the\dimexpr.5\dimexpr\yquant at register@get at ydist{#1}{#2}\relax\relax+%
+                     .5*\noexpand\pgfkeysvalueof{/tikz/\yquant at orientation@y\space radius}\fi,%
               name prefix=, name suffix=, name=yquantbox]%
             {\unexpanded\expandafter{\yquant at draw@@content}};%
-      \pgfshapeclippath{yquantbox}%
-                       {/yquant/every operator, \yquant at draw@@style,%
-                        /yquant/this operator}%
+      \ifyquant at config@draw at quality%
+         \pgfshapeclippath{yquantbox}%
+                          {/yquant/every operator, \yquant at draw@@style,%
+                           /yquant/this operator}%
+      \fi%
    }%
    \cmd%
    \yquant at for \i := #1 to #2 {%
@@ -271,7 +277,7 @@
 
 \protected\def\yquant at draw@multiinit#1#2#3#4#5{%
    \let\idx=\yquant at draw@@idx at content%
-   \@tempdima=-.5\dimexpr\yquant at config@register at sep\relax%
+   \@tempdima=\yquant at orientation@minus.5\dimexpr\yquant at config@register at sep\relax%
    \dimdef\yquant at draw@multiinit@@min{\yquant at register@get at y{#1}-\@tempdima}%
    \dimdef\yquant at draw@multiinit@@max{\yquant at register@get at y{#2}+\@tempdima}%
    \dimdef\yquant at draw@multiinit@@total{%
@@ -285,19 +291,21 @@
    \yquant at config@operator at multitrue%
    % We need to somehow extract the y radius
    \edef\cmd{%
-      \noexpand\path (\yquant at draw@@x, \the\dimexpr.5\dimexpr%
+      \noexpand\path \yquant at coords(\yquant at draw@@x, \the\dimexpr.5\dimexpr%
                          \yquant at draw@multiinit@@min+\yquant at draw@multiinit@@max\relax%
                       \relax)%
          node[/yquant/every operator, \yquant at draw@@style,
               \ifnum\yquant at compat<2 /yquant/every multi label,\fi%
               /yquant/this operator,%
-              y radius=\yquant at abs{\the\dimexpr.5\dimexpr\yquant at draw@multiinit@@total\relax\relax},%
+              space radius=\yquant at abs{\the\dimexpr.5\dimexpr\yquant at draw@multiinit@@total\relax\relax},%
               name prefix=, name suffix=, name=yquantbox]%
             {\unexpanded\expandafter{\yquant at draw@@content}};%
-      \pgfshapeclippath{yquantbox}%
-                       {/yquant/every operator, \yquant at draw@@style,%
-                        \ifnum\yquant at compat<2 /yquant/every multi label,\fi%
-                        /yquant/this operator}%
+      \ifyquant at config@draw at quality%
+         \pgfshapeclippath{yquantbox}%
+                          {/yquant/every operator, \yquant at draw@@style,%
+                           \ifnum\yquant at compat<2 /yquant/every multi label,\fi%
+                           /yquant/this operator}%
+      \fi%
    }%
    \cmd%
    \yquant at for \i := #1 to #2 {%
@@ -353,7 +361,7 @@
    \let\idx=\yquant at draw@@idx at content%
    \yquant at config@operator at multifalse%
    \edef\cmd{%
-      \noexpand\path (\yquant at circuit@endwires at x, \yquant at register@get at y{#1})%
+      \noexpand\path \yquant at coords(\yquant at circuit@endwires at x, \yquant at register@get at y{#1})%
          node[\ifnum\yquant at compat>1 /yquant/every operator,\fi%
               /yquant/every output,%
               /yquant/every \yquant at register@type at tostring{\yquant at register@get at type{#1}} output,%
@@ -360,13 +368,15 @@
               \yquant at draw@@style, /yquant/this operator,%
               name prefix=, name suffix=, name=yquantbox]%
          {\unexpanded\expandafter{\yquant at draw@@content}};%
-      \ifdefined\yquant at parent%
-         \pgfshapeclippath{yquantbox}%
-                          {\ifnum\yquant at compat>1 /yquant/every operator,\fi%
-                           /yquant/every output,%
-                           /yquant/every \yquant at register@type at tostring{\yquant at register@get at type{#1}} output,%
-                           \yquant at draw@@style,%
-                           /yquant/this operator}%
+      \ifyquant at config@draw at quality%
+         \ifdefined\yquant at parent%
+            \pgfshapeclippath{yquantbox}%
+                             {\ifnum\yquant at compat>1 /yquant/every operator,\fi%
+                              /yquant/every output,%
+                              /yquant/every \yquant at register@type at tostring{\yquant at register@get at type{#1}} output,%
+                              \yquant at draw@@style,%
+                              /yquant/this operator}%
+         \fi%
       \fi%
    }%
    \cmd%
@@ -383,7 +393,7 @@
 
 \protected\long\def\yquant at draw@output at multi#1#2#3#4#5{%
    \let\idx=\yquant at draw@@idx at content%
-   \@tempdima=-.5\dimexpr\yquant at config@register at sep\relax%
+   \@tempdima=\yquant at orientation@minus.5\dimexpr\yquant at config@register at sep\relax%
    \dimdef\yquant at draw@multiinit@@min{\yquant at register@get at y{#1}-\@tempdima}%
    \dimdef\yquant at draw@multiinit@@max{\yquant at register@get at y{#2}+\@tempdima}%
    \dimdef\yquant at draw@multiinit@@total{%
@@ -397,7 +407,7 @@
    \yquant at config@operator at multitrue%
    % We need to somehow extract the y radius
    \edef\cmd{%
-      \noexpand\path (\yquant at circuit@endwires at x, \the\dimexpr.5\dimexpr%
+      \noexpand\path \yquant at coords(\yquant at circuit@endwires at x, \the\dimexpr.5\dimexpr%
                          \yquant at draw@multiinit@@min+\yquant at draw@multiinit@@max\relax%
                       \relax)%
          node[\ifnum\yquant at compat>1 /yquant/every operator,\fi /yquant/every output,%
@@ -404,15 +414,17 @@
               \yquant at draw@@style,%
               \ifnum\yquant at compat<2 /yquant/every multi output,\fi%
               /yquant/this operator,%
-              y radius=\yquant at abs{\the\dimexpr.5\dimexpr\yquant at draw@multiinit@@total\relax\relax},%
+              space radius=\yquant at abs{\the\dimexpr.5\dimexpr\yquant at draw@multiinit@@total\relax\relax},%
               name prefix=, name suffix=, name=yquantbox]%
             {\unexpanded\expandafter{\yquant at draw@@content}};%
-      \ifdefined\yquant at parent%
-         \pgfshapeclippath{yquantbox}%
-                          {\ifnum\yquant at compat>1 /yquant/every operator,\fi /yquant/every output,%
-                           \yquant at draw@@style,
-                           \ifnum\yquant at compat<2 /yquant/every multi output,\fi%
-                           /yquant/this operator}%
+      \ifyquant at config@draw at quality%
+         \ifdefined\yquant at parent%
+            \pgfshapeclippath{yquantbox}%
+                             {\ifnum\yquant at compat>1 /yquant/every operator,\fi /yquant/every output,%
+                              \yquant at draw@@style,
+                              \ifnum\yquant at compat<2 /yquant/every multi output,\fi%
+                              /yquant/this operator}%
+         \fi%
       \fi%
    }%
    \cmd%
@@ -449,15 +461,16 @@
    \global\cslet\yquant at draw@subcircuit at nodelist\empty%
    % \pgfinterruptboundingbox, but just for y
    \begingroup%
-      \edef\pgf at interrupt@savemaxy{\the\pgf at picmaxy}%
-      \edef\pgf at interrupt@saveminy{\the\pgf at picminy}%
-      \pgf at picmaxy=-16000pt %
-      \pgf at picminy=16000pt %
+      \edef\pgf at interrupt@savemaxy{\the\yquant at pgf@picmaxy}%
+      \edef\pgf at interrupt@saveminy{\the\yquant at pgf@picminy}%
+      \yquant at pgf@picmaxy=-16000pt %
+      \yquant at pgf@picminy=16000pt %
       \pgf at size@hookedfalse%
       \let\pgf at path@size at hook=\pgfutil at empty%
       % now we must take care of extending all the wires appropriately until the beginning of the box. #4 contains width of this box, #5 contains registers affected by this box. Note that for subcircuits, x extension by the group is disabled.
       \dimdef\newx{%
-         \yquant at draw@@x-.5\dimexpr\@secondofthree#4\relax%
+         \yquant at draw@@x\yquant at orientation@minus%
+         .5\dimexpr\@secondofthree#4\relax%
       }%
       \dimen0=\newx%
       \let\yquant at draw@subcircuit at leftpos=\newx% seamless subcircuits: do not add another separation if we are there
@@ -465,7 +478,9 @@
       \forlistloop\yquant at draw@move at loop{#5}%
       % but the new positions are not at the beginning of the box, but inside (with possible margin)
       \dimdef\newx{%
-         \yquant at draw@@x-.5\dimexpr\@firstofthree#4\relax-\@thirdofthree#4%
+         \yquant at draw@@x\yquant at orientation@minus%
+         .5\dimexpr\@firstofthree#4\relax\yquant at orientation@minus%
+         \@thirdofthree#4%
       }%
       \forlistloop\yquant at draw@group at advance{#5}%
       \setbox\yquant at prepare@subcircuit at box=\hbox{{%
@@ -509,53 +524,55 @@
             /yquant/this operator, /yquant/internal/multi main=true,%
          }%
          \expandafter\tikzset\expandafter{\yquant at draw@subcircuit at style}%
+         % #18: The styles may have set this subcircuit box again, but we disallow this. The "this" style is only supposed to effect the actual box and nothing else, so it should not permeat in the inner of the circuit. This is what every subcircuit box is for!
+         \pgfkeys{/yquant/operators/this subcircuit box/.style={}}%
          \begingroup%
             \csname\yquant at prefix draw\endcsname%
          \endgroup%
          % BEGIN_FOLD bounding box
          % Completely empty wires did not yet affect the bounding box
-         % Problem: we compare an user-mode TikZ position (register y position) with a system-level pgf position (picture boundary box). If shifts or scalings are in effect, we must first transform the point appropriately. Note that negative scalings may upset our assumption of which is the minimum and which is the maximum! If additionally rotations are in effect, we must even consider those transformations for the leftmost and the rightmost point, which makes all of this far more complicated than it should be. For this reason, we have a shortcut in action in case no nontranslation transformations are present.
+         % Problem: we compare a user-mode TikZ position (register y position) with a system-level pgf position (picture boundary box). If shifts or scalings are in effect, we must first transform the point appropriately. Note that negative scalings may upset our assumption of which is the minimum and which is the maximum! If additionally rotations are in effect, we must even consider those transformations for the leftmost and the rightmost point, which makes all of this far more complicated than it should be. For this reason, we have a shortcut in action in case no nontranslation transformations are present.
          \ifpgf at pt@identity%
-            \dimen0=\dimexpr\yquant at register@get at y1+\pgf at pt@y\relax%
-            \ifdim\dimen0>\pgf at picmaxy %
-               \global\pgf at picmaxy=\dimen0 %
+            \dimen0=\dimexpr\yquant at register@get at y1+\yquant at pgf@pt at y\relax%
+            \ifdim\dimen0>\yquant at pgf@picmaxy %
+               \global\yquant at pgf@picmaxy=\dimen0 %
             \fi%
-            \dimen0=\dimexpr\yquant at register@get at y{\csname\yquant at prefix registers\endcsname}+\pgf at pt@y\relax%
-            \ifdim\dimen0<\pgf at picminy %
-               \global\pgf at picminy=\dimen0 %
+            \dimen0=\dimexpr\yquant at register@get at y{\csname\yquant at prefix registers\endcsname}+\yquant at pgf@pt at y\relax%
+            \ifdim\dimen0<\yquant at pgf@picminy %
+               \global\yquant at pgf@picminy=\dimen0 %
             \fi%
          \else%
             % first wire, left end
-            \pgfpointtransformed{\pgfqpoint{\yquant at draw@@x-.5\dimexpr\@firstofthree#4\relax}{\yquant at register@get at y1\relax}}%
-            \ifdim\pgf at y>\pgf at picmaxy %
-               \global\pgf at picmaxy=\pgf at y %
+            \pgfpointtransformed{\yquant at pgfqpoint{\yquant at draw@@x-.5\dimexpr\@firstofthree#4\relax}{\yquant at register@get at y1\relax}}%
+            \ifdim\yquant at pgf@y>\yquant at pgf@picmaxy %
+               \global\yquant at pgf@picmaxy=\yquant at pgf@y %
             \fi%
-            \ifdim\pgf at y<\pgf at picminy % negative scaling
-               \global\pgf at picminy=\pgf at y %
+            \ifdim\yquant at pgf@y<\yquant at pgf@picminy % negative scaling
+               \global\yquant at pgf@picminy=\yquant at pgf@y %
             \fi%
             % first wire, right end
-            \pgfpointtransformed{\pgfqpoint{\yquant at draw@@x+.5\dimenxpr\@firstofthree#4\relax}{\yquant at register@get at y1\relax}}%
-            \ifdim\pgf at y>\pgf at picmaxy %
-               \global\pgf at picmaxy=\pgf at y %
+            \pgfpointtransformed{\yquant at pgfqpoint{\yquant at draw@@x+.5\dimenxpr\@firstofthree#4\relax}{\yquant at register@get at y1\relax}}%
+            \ifdim\yquant at pgf@y>\yquant at pgf@picmaxy %
+               \global\yquant at pgf@picmaxy=\yquant at pgf@y %
             \fi%
-            \ifdim\pgf at y<\pgf at picminy % negative scaling
-               \global\pgf at picminy=\pgf at y %
+            \ifdim\yquant at pgf@y<\yquant at pgf@picminy % negative scaling
+               \global\yquant at pgf@picminy=\yquant at pgf@y %
             \fi%
             % last wire, left end
-            \pgfpointtransformed{\pgfqpoint{\yquant at draw@@x-.5\dimexpr\@firstofthree#4\relax}{\yquant at register@get at y{\csname\yquant at prefix registers\endcsname}\relax}}%
-            \ifdim\pgf at y>\pgf at picmaxy %
-               \global\pgf at picmaxy=\pgf at y %
+            \pgfpointtransformed{\yquant at pgfqpoint{\yquant at draw@@x-.5\dimexpr\@firstofthree#4\relax}{\yquant at register@get at y{\csname\yquant at prefix registers\endcsname}\relax}}%
+            \ifdim\yquant at pgf@y>\yquant at pgf@picmaxy %
+               \global\yquant at pgf@picmaxy=\yquant at pgf@y %
             \fi%
-            \ifdim\pgf at y<\pgf at picminy % negative scaling
-               \global\pgf at picminy=\pgf at y %
+            \ifdim\yquant at pgf@y<\yquant at pgf@picminy % negative scaling
+               \global\yquant at pgf@picminy=\yquant at pgf@y %
             \fi%
             % last wire, right end
-            \pgfpointtransformed{\pgfqpoint{\yquant at draw@@x+.5\dimenxpr\@firstofthree#4\relax}{\yquant at register@get at y{\csname\yquant at prefix registers\endcsname}\relax}}%
-            \ifdim\pgf at y>\pgf at picmaxy %
-               \global\pgf at picmaxy=\pgf at y %
+            \pgfpointtransformed{\yquant at pgfqpoint{\yquant at draw@@x+.5\dimenxpr\@firstofthree#4\relax}{\yquant at register@get at y{\csname\yquant at prefix registers\endcsname}\relax}}%
+            \ifdim\yquant at pgf@y>\yquant at pgf@picmaxy %
+               \global\yquant at pgf@picmaxy=\yquant at pgf@y %
             \fi%
-            \ifdim\pgf at y<\pgf at picminy % negative scaling
-               \global\pgf at picminy=\pgf at y %
+            \ifdim\yquant at pgf@y<\yquant at pgf@picminy % negative scaling
+               \global\yquant at pgf@picminy=\yquant at pgf@y %
             \fi%
          \fi%
          % END_FOLD
@@ -581,46 +598,57 @@
          \fi%
       }}%
       \ifpgf at pt@identity%
-         \dimen0=\dimexpr.5\pgf at picminy+.5\pgf at picmaxy-\pgf at pt@y\relax%
-         \dimen2=\dimexpr\pgf at picmaxy-\pgf at picminy\relax%
+         \dimen0=\dimexpr.5\yquant at pgf@picminy+.5\yquant at pgf@picmaxy-\yquant at pgf@pt at y\relax%
+         \dimen2=\dimexpr\yquant at pgf@picmaxy-\yquant at pgf@picminy\relax%
       \else%
          \begingroup%
             \pgftransforminvert%
             \pgfpointtransformed{\pgfqpoint{\pgf at picminx}{\pgf at picminy}}%
-            \@tempdima=\pgf at y%
+            \@tempdima=\yquant at pgf@y%
             \pgfpointtransform{\pgfqpoint{\pgf at picmaxx}{\pgf at picmaxy}}%
-            \edef\cmd{\@tempdima=\the\@tempdima\space\@tempdimb=\the\@tempdimb\space}%
+            \edef\cmd{\@tempdima=\the\@tempdima\space\@tempdimb=\the\yquant at pgf@y\space}%
             \expandafter%
          \endgroup%
          \cmd%
-         \pgfpointtransformed{\pgfqpoint{\yquant at draw@@x}%
-                                        {.5\dimexpr\@tempdima+\@tempdimb\relax}}%
-         \dimen0=\pgf at y%
-         \pgfpointtransformed{\pgfqpoint{\yquant at draw@@x}%
-                                        {\dimexpr\@tempdimb-\@tempdima\relax}}%
-         \dimen2=\pgf at y%
+         \pgfpointtransformed{\yquant at pgfqpoint{\yquant at draw@@x}%
+                                               {.5\dimexpr\@tempdima+\@tempdimb\relax}}%
+         \dimen0=\yquant at pgf@y%
+         \pgfpointtransformed{\yquant at pgfqpoint{\yquant at draw@@x}%
+                                               {\dimexpr\@tempdimb-\@tempdima\relax}}%
+         \dimen2=\yquant at pgf@y%
       \fi%
       \edef\cmd{%
-         \noexpand\path (\yquant at draw@@x, \the\dimen0)%
+         \noexpand\path \yquant at coords(\yquant at draw@@x, \the\dimen0)%
             node[/yquant/every operator, \yquant at draw@@style,%
                  /yquant/operators/every subcircuit box, /yquant/this operator,%
                  /yquant/operators/this subcircuit box,%
                  /yquant/internal/multi main=true,%
                  name prefix=, name suffix=, name=yquantbox]%
-            {\vbox to \the\dimen2 {\hbox to \@firstofthree#4 {}}};%
+            {\ifyquanthorz{\vbox to \the\dimen2 {\hbox to \@firstofthree#4 {}}}%
+                          {\hbox to \the\dimen2 {\vbox to \@firstofthree#4 {}}}};%
       }%
-      \cmd%
+      \ifyquant at config@draw at quality%
+         \cmd%
+      \else%
+         % we draw the box on the behindwires layer. In this way, the box can even be filled without overshadowing the wires. However, this implies that the frame of the box will also be drawn behind the wires. If the color of the frame is different from the color of the wires, this may not be desired. In this case, there's no alternative to the quality layout.
+         \begingroup%
+            \let\pgfonlayer at assert@is at active=\relax%
+            \pgfonlayer{behindwires}%
+               \cmd%
+            \endpgfonlayer%
+         \endgroup%
+      \fi%
       \unhbox\yquant at prepare@subcircuit at box%
    % \endpgfinterruptboundingbox + increase
-      \ifdim\pgf at interrupt@savemaxy>\pgf at picmaxy%
-         \global\pgf at picmaxy=\pgf at interrupt@savemaxy%
+      \ifdim\pgf at interrupt@savemaxy>\yquant at pgf@picmaxy%
+         \global\yquant at pgf@picmaxy=\pgf at interrupt@savemaxy%
       \fi%
-      \ifdim\pgf at interrupt@saveminy<\pgf at picminy%
-         \global\pgf at picminy=\pgf at interrupt@saveminy%
+      \ifdim\pgf at interrupt@saveminy<\yquant at pgf@picminy%
+         \global\yquant at pgf@picminy=\pgf at interrupt@saveminy%
       \fi%
    \endgroup%
    % Now that the subcircuit is finished, we need advance all the wires
-   \dimdef\newx{\yquant at draw@@x+.5\dimexpr\yquant at draw@@width\relax}%
+   \dimdef\newx{\yquant at draw@@x\yquant at orientation@plus.5\dimexpr\yquant at draw@@width\relax}%
    \forlistloop\yquant at draw@group at advance{#5}%
    % name mangling
    \ifcase\yquant at config@operator at subcircuit@mangling\relax%
@@ -679,18 +707,29 @@
 \protected\long\def\yquant at draw@subcircuit at single#1#2#3#4#5{%
    \yquant at config@operator at multifalse%
    \yquant at draw@subcircuit at prepare{#2}{#3}{#4}{#5}{#1}%
-   \edef\cmd{%
-      \pgfshapeclippath{yquantbox}{%
-          /yquant/every operator, \yquant at draw@@style,%
-          /yquant/operators/every subcircuit box, /yquant/this operator,%
-          /yquant/operators/this subcircuit box,%
+   \ifyquant at config@draw at quality%
+      \edef\cmd{%
+         \pgfshapeclippath{yquantbox}{%
+             /yquant/every operator, \yquant at draw@@style,%
+             /yquant/operators/every subcircuit box, /yquant/this operator,%
+             /yquant/operators/this subcircuit box,%
+         }%
       }%
-   }%
-   \cmd%
-   % see comment in draw at subcircuit@multi
-   \yquant at softpath@extractmaxxat\pgfshapeclippathhorzresult{\yquant at register@get at y{#1}}%
-   \let\pgfshapeclippathhorzresult=\empty%
-   \yquant at circuit@extendwire{#1}*%
+      \cmd%
+      % see comment in draw at subcircuit@multi
+      \yquant at softpath@extractmaxxat\pgfshapeclippathhorzresult{\yquant at register@get at y{#1}}%
+      \let\pgfshapeclippathhorzresult=\empty%
+      \yquant at circuit@extendwire{#1}*%
+   \else%
+      \ifyquanthorz{%
+         \pgfpointanchor{yquantbox}{east}%
+         \dimen0=\pgf at x%
+      }{%
+         \pgfpointanchor{yquantbox}{south}%
+         \dimen0=\pgf at y%
+      }%
+      \yquant at circuit@extendwire{#1}*%
+   \fi%
    \expandafter\yquant at circuit@extendcontrolline\expandafter%
       {\the\yquant at draw@@currentcontroltype}\yquant at draw@@x%
    % check for empty name parameter
@@ -704,30 +743,48 @@
    \yquant at config@operator at multitrue%
    % there is no contiguous slicing for subcircuits, as they may have all kinds of wire operations that can extend beyond the individual slices, let alone ancillas
    \yquant at draw@subcircuit at prepare{#5}{#6}{#7}{#8}{#4}%
-   \edef\cmd{%
-      \pgfshapeclippath{yquantbox}{%
-          /yquant/every operator, \yquant at draw@@style,%
-          /yquant/operators/every subcircuit box, /yquant/this operator,%
-          /yquant/operators/this subcircuit box,%
-          /yquant/internal/multi main=true,%
+   \ifyquant at config@draw at quality%
+      \edef\cmd{%
+         \pgfshapeclippath{yquantbox}{%
+             /yquant/every operator, \yquant at draw@@style,%
+             /yquant/operators/every subcircuit box, /yquant/this operator,%
+             /yquant/operators/this subcircuit box,%
+             /yquant/internal/multi main=true,%
+         }%
       }%
-   }%
-   \cmd%
-   % install the clippings - but only on wires that are visually between the first and list while not being part of the circuit.
-   \let\nonaffectedpgfshapeclippathhorzresult=\pgfshapeclippathhorzresult%
-   \yquant at for \i := #1 to #2 {%
-      \xifinlist{\i}{#4}{%
-         % Usually, we always begin with a wire from the center of the operator shape and clip the inner parts away. This can't be done here, as the wire needs to be drawn _inside_ of the outer box operator here. Instead of clipping against the clip path, we extract its maximum x position at the position of the wire (which is an overkill for simple shapes, but allows to specify even more complicated ones) and place the wire at this position without clipping.
-         % Note: this works very well for lines joining at perpendicular angles; but if the shape of the box is more fancy, while the position will be calculated correctly, the wire has a rectangular (or rounded, depending on the line cap) shape that is drawn on top of the operator. While \yquant at softpath@extractmaxxat could without much effort determine exactly the segment of the path that corresponds to the rightmost line, we would then have to convert this single line into a closed path that fills the linewidth and clip against it to get proper joiners. Since most likely, no-one will ever need this, we don't do it. But file a feature request if desired.
-         \yquant at softpath@extractmaxxat\nonaffectedpgfshapeclippathhorzresult%
-                                       {\yquant at register@get at y\i}%
-         \let\pgfshapeclippathhorzresult=\empty%
-         \yquant at circuit@extendwire\i*%
+      \cmd%
+      % install the clippings - but only on wires that are visually between the first and list while not being part of the circuit.
+      \let\nonaffectedpgfshapeclippathhorzresult=\pgfshapeclippathhorzresult%
+      \yquant at for \i := #1 to #2 {%
+         \xifinlist{\i}{#4}{%
+            % Usually, we always begin with a wire from the center of the operator shape and clip the inner parts away. This can't be done here, as the wire needs to be drawn _inside_ of the outer box operator here. Instead of clipping against the clip path, we extract its maximum x position at the position of the wire (which is an overkill for simple shapes, but allows to specify even more complicated ones) and place the wire at this position without clipping.
+            % Note: this works very well for lines joining at perpendicular angles; but if the shape of the box is more fancy, while the position will be calculated correctly, the wire has a rectangular (or rounded, depending on the line cap) shape that is drawn on top of the operator. While \yquant at softpath@extractmaxxat could without much effort determine exactly the segment of the path that corresponds to the rightmost line, we would then have to convert this single line into a closed path that fills the linewidth and clip against it to get proper joiners. Since most likely, no-one will ever need this, we don't do it. But file a feature request if desired.
+            \yquant at softpath@extractmaxxat\nonaffectedpgfshapeclippathhorzresult%
+                                          {\yquant at register@get at y\i}%
+            \let\pgfshapeclippathhorzresult=\empty%
+            \yquant at circuit@extendwire\i*%
+         }{%
+            \let\pgfshapeclippathhorzresult=\nonaffectedpgfshapeclippathhorzresult%
+            \yquant at circuit@extendwire\i{center}%
+         }%
+      }%
+   \else%
+      % we don't fill subcircuits, so the nonaffected wires will be drawn through (we deliberatly fill the subcircuit on the behindwires layer, so that the wires within a subcircuit will be visible despite the filling; but we cannot differentiate between "good" internal and "bad" nonaffected wires). If such a constellation arises, better use the quality layout
+      \ifyquanthorz{%
+         \pgfpointanchor{yquantbox}{east}%
+         \dimen0=\pgf at x%
       }{%
-         \let\pgfshapeclippathhorzresult=\nonaffectedpgfshapeclippathhorzresult%
-         \yquant at circuit@extendwire\i{center}%
+         \pgfpointanchor{yquantbox}{south}%
+         \dimen0=\pgf at y%
       }%
-   }%
+      \yquant at for \i := #1 to #2 {%
+         \xifinlist{\i}{#4}{%
+            \yquant at circuit@extendwire\i*%
+         }{%
+            \yquant at circuit@extendwire\i{center}%
+         }%
+      }%
+   \fi%
    \expandafter\yquant at circuit@extendcontrolline\expandafter%
       {\the\yquant at draw@@currentcontroltype}\yquant at draw@@x%
    \ifstrempty{#6}\relax{%
@@ -738,13 +795,15 @@
 
 \protected\def\yquant at draw@control#1#2#3{%
    \edef\cmd{%
-      \noexpand\path (\yquant at draw@@x, \yquant at register@get at y{#2})%
+      \noexpand\path \yquant at coords(\yquant at draw@@x, \yquant at register@get at 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}%
+      \ifyquant at config@draw at quality%
+         \pgfshapeclippath{yquantbox}%
+                          {/yquant/every control, /yquant/every #1 control,%
+                           /yquant/this control}%
+      \fi%
    }%
    \cmd%
    \yquant at circuit@extendwire{#2}{center}%
@@ -769,31 +828,50 @@
    \numdef\yquant at draw@@idx at ncontrol{\yquant at draw@@idx at ncontrol+1}%
 }
 
+\protected\long\def\yquant at draw@onwires#1{%
+   \begingroup%
+      \let\pgfonlayer at assert@is at active=\relax%
+      \pgfonlayer{wires}%
+         #1%
+      \endpgfonlayer%
+   \endgroup%
+}
+
 \protected\def\yquant at draw@cline{%
-   \pgfscope%
-      % install the clipping
-      \pgfsyssoftpath at setcurrentpath\yquant at circuit@extendcontrolline at 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 at picminx}{\pgf at picminy}}%
-               {\pgfqpoint{\pgf at picmaxx}{\pgf at picmaxy}}%
-            \pgfseteorule% even-odd to properly invert the clipping
-            \pgfusepathqclip%
-         \endgroup%
-      \fi%
-      \edef\cmd{%
-         \noexpand\path[/yquant/every control line]%
-            \yquant at circuit@extendcontrolline at cmd;%
+   \ifyquant at config@draw at quality%
+      \pgfscope%
+         % install the clipping
+         \pgfsyssoftpath at setcurrentpath\yquant at circuit@extendcontrolline at 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 at picminx}{\pgf at picminy}}%
+                  {\pgfqpoint{\pgf at picmaxx}{\pgf at picmaxy}}%
+               \pgfseteorule% even-odd to properly invert the clipping
+               \pgfusepathqclip%
+            \endgroup%
+         \fi%
+         \edef\cmd{%
+            \noexpand\path[/yquant/every control line]%
+               \yquant at circuit@extendcontrolline at cmd;%
+         }%
+         \cmd%
+      \endpgfscope%
+   \else%
+      \yquant at draw@onwires{%
+         \edef\cmd{%
+            \noexpand\path[/yquant/every control line]%
+               \yquant at circuit@extendcontrolline at cmd;%
+         }%
+         \cmd%
       }%
-      \cmd%
-   \endpgfscope%
+   \fi%
 }
 
 \protected\def\yquant at draw@mline at prep{%
@@ -805,27 +883,33 @@
 }
 
 \protected\def\yquant at draw@mline#1#2{%
-   \pgfscope%
-      % install the clipping
-      \def\pgfsyssoftpath at thepath{#1}%
-      \pgfsyssoftpath at setcurrentpath\pgfsyssoftpath at 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 at picminx}{\pgf at picminy}}%
-               {\pgfqpoint{\pgf at picmaxx}{\pgf at picmaxy}}%
-            \pgfseteorule% even-odd to properly invert the clipping
-            \pgfusepathqclip%
-         \endgroup%
-      \fi%
-      \path[/yquant/every multi line] #2;%
-   \endpgfscope%
+   \ifyquant at config@draw at quality%
+      \pgfscope%
+         % install the clipping
+         \def\pgfsyssoftpath at thepath{#1}%
+         \pgfsyssoftpath at setcurrentpath\pgfsyssoftpath at 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 at picminx}{\pgf at picminy}}%
+                  {\pgfqpoint{\pgf at picmaxx}{\pgf at picmaxy}}%
+               \pgfseteorule% even-odd to properly invert the clipping
+               \pgfusepathqclip%
+            \endgroup%
+         \fi%
+         \path[/yquant/every multi line] #2;%
+      \endpgfscope%
+   \else%
+      \yquant at draw@onwires{%
+         \path[/yquant/every multi line] #2;%
+      }%
+   \fi%
 }
 
 \protected\def\yquant at draw@alias#1{%
@@ -846,7 +930,7 @@
          \else%
             \let\wirexpos=\yquant at circuit@endwires at x%
          \fi%
-         \ifdim\wirexpos>\wirexprevpos %
+         \ifdim\yquant at orientation@plus\wirexpos>\yquant at orientation@plus\wirexprevpos %
             \edef\wirestyle{\noexpand\tikzset{%
                /yquant/this wire/.style={%
                   /yquant/every wire,%
@@ -855,63 +939,71 @@
                }, /yquant/this wire%
             }}%
             \wirestyle%
-            % load all clippings
-            \edef\wireclipping{%
-               \unexpanded\expandafter\expandafter\expandafter{%
-                  \expandafter\@thirdandfourthoffour\wirelast%
+            \ifyquant at config@draw at quality%
+               % load all clippings
+               \edef\wireclipping{%
+                  \unexpanded\expandafter\expandafter\expandafter{%
+                     \expandafter\@thirdandfourthoffour\wirelast%
+                  }%
                }%
-            }%
-            \pgfscope%
-               \unless\ifx\wireclipping\empty% may happen if the style is altered to be invisible, though the type is not none
-                  % install the clipping
-                  \pgfsyssoftpath at 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%
-                        \ifdim\pgf at picminx>\pgf at picmaxx%
-                           % nothing drawn yet (or bounding box reset)
-                           \pgf at picminx=0pt %
-                           \pgf at picmaxx=0pt %
+               \pgfscope%
+                  \unless\ifx\wireclipping\empty% may happen if the style is altered to be invisible, though the type is not none
+                     % install the clipping
+                     \pgfsyssoftpath at 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%
+                           \ifdim\pgf at picminx>\pgf at picmaxx%
+                              % nothing drawn yet (or bounding box reset)
+                              \pgf at picminx=0pt %
+                              \pgf at picmaxx=0pt %
+                           \fi%
+                           \ifdim\pgf at picminy>\pgf at picmaxy%
+                              \pgf at picminy=0pt %
+                              \pgf at picmaxy=0pt %
+                           \fi%
+                           \pgftransforminvert%
+                           \pgfpointtransformed{\pgfqpoint{\pgf at picminx}{\pgf at picminy}}%
+                           \global\@tempdima=\yquant at pgf@y%
+                           \pgfpointtransformed{\pgfqpoint{\pgf at picmaxx}{\pgf at picmaxy}}%
+                           \global\@tempdimb=\yquant at 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 is no or a tiny wire label and only registers of a small height. In this case, take 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\pgf at picminy>\pgf at picmaxy%
-                           \pgf at picminy=0pt %
-                           \pgf at picmaxy=0pt %
+                        \ifdim\dimexpr\@tempdimb-\@tempdima\relax<1cm %
+                           \@tempdima=\dimexpr\wireypos-5mm\relax%
+                           \@tempdimb=\dimexpr\wireypos+5mm\relax%
                         \fi%
-                        \pgftransforminvert%
-                        \pgfpointtransformed{\pgfqpoint{\pgf at picminx}{\pgf at picminy}}%
-                        \global\@tempdima=\pgf at y%
-                        \pgfpointtransformed{\pgfqpoint{\pgf at picmaxx}{\pgf at picmaxy}}%
-                        \global\@tempdimb=\pgf at 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 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%
+                        \pgf at relevantforpicturesizefalse%
+                           \pgfpathrectanglecorners%
+                              {\yquant at pgfqpoint{\dimexpr\wirexprevpos\yquant at orientation@minus%
+                                                         2\pgflinewidth\relax}%
+                                                {\@tempdima}}%
+                              {\yquant at pgfqpoint{\dimexpr\wirexpos\yquant at orientation@plus%
+                                                         2\pgflinewidth\relax}%
+                                                {\@tempdimb}}%
+                        \pgf at relevantforpicturesizetrue%
+                        \pgfseteorule% even-odd to properly invert the clipping
+                        \pgfusepathqclip%
                      \fi%
-                     \ifdim\dimexpr\@tempdimb-\@tempdima\relax<1cm %
-                        \@tempdima=\dimexpr\wireypos-5mm\relax%
-                        \@tempdimb=\dimexpr\wireypos+5mm\relax%
-                     \fi%
-                     \pgf at relevantforpicturesizefalse%
-                        \pgfpathrectanglecorners%
-                           {\pgfqpoint{\dimexpr\wirexprevpos-2\pgflinewidth\relax}%
-                                      {\@tempdima}}%
-                           {\pgfqpoint{\dimexpr\wirexpos+2\pgflinewidth\relax}%
-                                      {\@tempdimb}}%
-                     \pgf at relevantforpicturesizetrue%
-                     \pgfseteorule% even-odd to properly invert the clipping
-                     \pgfusepathqclip%
                   \fi%
-               \fi%
-               % the clip inversion is left to the drawing commands (clip two \pgflinewidth more to avoid renderer artifacts)
-               \csname yquant at draw@wire@\wiretype\endcsname{#1}%
-            \endpgfscope%
+                  % the clip inversion is left to the drawing commands (clip two \pgflinewidth more to avoid renderer artifacts)
+                  \csname yquant at draw@wire@\wiretype\endcsname{#1}%
+               \endpgfscope%
+            \else%
+               \yquant at draw@onwires{%
+                  \csname yquant at draw@wire@\wiretype\endcsname{#1}%
+               }%
+            \fi%
          \fi%
       \fi%
    \endgroup%
@@ -921,7 +1013,7 @@
 \protected\csdef{yquant at draw@wire@\yquant at register@type at q}#1{%
    \edef\cmd{%
       \noexpand\path [/yquant/this wire]%
-         (\wirexprevpos,\wireypos) -- (\wirexpos,\wireypos);%
+         \yquant at coords(\wirexprevpos,\wireypos) -- \yquant at coords(\wirexpos,\wireypos);%
    }%
    \cmd%
 }
@@ -930,8 +1022,10 @@
 \protected\csdef{yquant at draw@wire@\yquant at register@type at 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);%
+         \yquant at coords(\wirexprevpos,\wireypos+2\pgflinewidth) --
+         \yquant at coords(\wirexpos,\wireypos+2\pgflinewidth)%
+         \yquant at coords(\wirexprevpos,\wireypos-2\pgflinewidth) --
+         \yquant at coords(\wirexpos,\wireypos-2\pgflinewidth);%
    }%
    \cmd%
 }
@@ -940,9 +1034,12 @@
 \protected\csdef{yquant at draw@wire@\yquant at register@type at 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);%
+         \yquant at coords(\wirexprevpos,\wireypos+2\pgflinewidth) --
+         \yquant at coords(\wirexpos,\wireypos+2\pgflinewidth)%
+         \yquant at coords(\wirexprevpos,\wireypos) --
+         \yquant at coords(\wirexpos,\wireypos)%
+         \yquant at coords(\wirexprevpos,\wireypos-2\pgflinewidth) --
+         \yquant at coords(\wirexpos,\wireypos-2\pgflinewidth);%
    }%
    \cmd%
 }
@@ -950,7 +1047,7 @@
 \protected\def\yquant at draw@hspace#1#2{%
    \begingroup%
       \yquant at register@get at maxxlist\newx{#1}%
-      \dimdef\newx{\newx+#2}%
+      \dimdef\newx{\newx\yquant at orientation@plus#2}%
       \dimen0=\newx%
       \let\pgfshapeclippathhorzresult=\empty%
       \forlistloop\yquant at draw@move at loop{#1}%

Modified: trunk/Master/texmf-dist/tex/latex/yquant/yquant-env.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/yquant/yquant-env.tex	2022-02-05 21:22:43 UTC (rev 61896)
+++ trunk/Master/texmf-dist/tex/latex/yquant/yquant-env.tex	2022-02-05 21:23:01 UTC (rev 61897)
@@ -85,7 +85,7 @@
          \expandafter\noexpand\csname\yquant at prefix seamless\endcsname%
          \expandafter\noexpand\csname\yquant at prefix cleanup\endcsname%
       }%
-      \scope[{/yquant/.cd, #2, /tikz/.cd, /yquant/every circuit}]%
+      \scope[{/yquant/.cd, #2, /tikz/.cd, /yquant/every circuit, /yquant/internal/setup done}]%
 }
 
 \protected\def\yquant at env@end{%
@@ -175,7 +175,7 @@
       \yquant at env@end at calcypositions@run1%
       \yquant at env@end at calcypositions@godeepfalse%
       \yquant at env@end at calcypositions@redo%
-%      % The macros now set up performed all the proper and unambiguous justification. After that, we will also need to take care of the multi gates. We expect that for most of all multi gates, we already have enough space. But sometimes, this may not be the case, so we need to increase overall spacing and re-evaluate all spacing. In order to get a proper balanced layout, we start with the largest enlargement that is required. Every enlargement step will equally distribute the registers in between. Starting with the largest one, this is likely to also solve issues with smaller ones.
+      % The macros now set up performed all the proper and unambiguous justification. After that, we will also need to take care of the multi gates. We expect that for most of all multi gates, we already have enough space. But sometimes, this may not be the case, so we need to increase overall spacing and re-evaluate all spacing. In order to get a proper balanced layout, we start with the largest enlargement that is required. Every enlargement step will equally distribute the registers in between. Starting with the largest one, this is likely to also solve issues with smaller ones.
       \yquant at env@end at calcypositions@multi%
       % Turn the preliminary positions into true ones at every level.
       \yquant at env@end at setypositions1%
@@ -477,16 +477,17 @@
    \ifyquantdebug%
       \yquant at for \i := 1 to \csname\yquant at prefix registers\endcsname {%
          \ifcsname\yquant at prefix registermap@\i\endcsname%
-            \message{^^J y(#1, \i): external}%
+            \message{^^J \yquant at orientation@y(#1, \i): external}%
          \else%
-            \message{^^J y(#1, \i): \csname\yquant at prefix env at endy@\i\endcsname}%
-            \yquant at register@set at y\i{-\csname\yquant at prefix env at endy@\i\endcsname}%
+            \message{^^J \yquant at orientation@y(#1, \i): \csname\yquant at prefix env at endy@\i\endcsname}%
+            % do not use \yquant at orientation@minus: this will lead to an explicit + in vertical mode, and the value of the register y position is directly used for TikZ coordinates. However, those are parsed using \pgfmathsetlength, which will skip pgf's parser if the value starts with an explicit +. We don't want this.
+            \yquant at register@set at y\i{\ifyquanthorz{-}{}\csname\yquant at prefix env at endy@\i\endcsname}%
          \fi%
       }%
    \else%
       \yquant at for \i := 1 to \csname\yquant at prefix registers\endcsname {%
          \unless\ifcsname\yquant at prefix registermap@\i\endcsname%
-            \yquant at register@set at y\i{-\csname\yquant at prefix env at endy@\i\endcsname}%
+            \yquant at register@set at y\i{\ifyquanthorz{-}{}\csname\yquant at prefix env at endy@\i\endcsname}%
          \fi%
       }%
    \fi%

Modified: trunk/Master/texmf-dist/tex/latex/yquant/yquant-lang.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/yquant/yquant-lang.tex	2022-02-05 21:22:43 UTC (rev 61896)
+++ trunk/Master/texmf-dist/tex/latex/yquant/yquant-lang.tex	2022-02-05 21:23:01 UTC (rev 61897)
@@ -65,9 +65,19 @@
    overlay/height/.is if=yquant at lang@attr at overlay@height,%
    overlay/ht/.forward to=/yquant/global attrs/overlay/height,%
    overlay/h/.forward to=/yquant/global attrs/overlay/height,%
+   overlay/left/.forward to=/yquant/global attrs/overlay/height,%
+   overlay/l/.forward to=/yquant/global attrs/overlay/height,%
+   overlay/before/.forward to=/yquant/global attrs/overlay/height,%
+   overlay/bef/.forward to=/yquant/global attrs/overlay/height,%
+   overlay/b/.forward to=/yquant/global attrs/overlay/height,%
    overlay/depth/.is if=yquant at lang@attr at overlay@depth,%
    overlay/dp/.forward to=/yquant/global attrs/overlay/depth,%
    overlay/d/.forward to=/yquant/global attrs/overlay/depth,%
+   overlay/right/.forward to=/yquant/global attrs/overlay/depth,%
+   overlay/r/.forward to=/yquant/global attrs/overlay/depth,%
+   overlay/after/.forward to=/yquant/global attrs/overlay/depth,%
+   overlay/aft/.forward to=/yquant/global attrs/overlay/depth,%
+   overlay/a/.forward to=/yquant/global attrs/overlay/depth,%
    overlay/single/.code={\pgfkeysalso{%
       /yquant/global attrs/overlay/height={#1},%
       /yquant/global attrs/overlay/depth={#1}%

Modified: trunk/Master/texmf-dist/tex/latex/yquant/yquant-prepare.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/yquant/yquant-prepare.tex	2022-02-05 21:22:43 UTC (rev 61896)
+++ trunk/Master/texmf-dist/tex/latex/yquant/yquant-prepare.tex	2022-02-05 21:23:01 UTC (rev 61897)
@@ -84,7 +84,7 @@
          \expandafter%
       \endpgfinterruptboundingbox%
       \expandafter\dimen\expandafter0\expandafter=%
-         \the\dimexpr\pgf at picmaxx-\pgf at picminx\relax\relax%
+         \the\dimexpr\yquant at pgf@picmaxx-\yquant at pgf@picminx\relax\relax%
       \ifdim\dimen0>\dimen2 %
          \dimen2=\dimen0 %
       \fi%
@@ -375,8 +375,8 @@
          (0pt, 0pt)%
          node[/yquant/every operator, #2, /yquant/this operator,%
               name prefix=, name suffix=, name=] {#1};%
-      \yquant at register@update at height{#3}{\the\pgf at picmaxy}%
-      \yquant at register@update at depth{#3}{\the\dimexpr-\pgf at picminy\relax}%
+      \yquant at register@update at height{#3}{\the\yquant at pgf@picmaxy}%
+      \yquant at register@update at depth{#3}{\the\dimexpr-\yquant at pgf@picminy\relax}%
 }
 
 \protected\def\yquant at prepare@multi#1#2#3{%
@@ -397,7 +397,7 @@
       \def\yquant at prepare@style{#2}%
       \let\yquant at register@multi at contiguous=\yquant at prepare@multi at contiguous%
       \@fifthoffive#3%
-      \ifdim\pgf at picmaxy=-16000pt %
+      \ifdim\yquant at pgf@picmaxy=-16000pt %
          % if there was no single contiguous part before, determine the width now
          \path%
             (0pt, 0pt)%
@@ -407,8 +407,8 @@
 }
 
 \protected\def\yquant at prepare@multi at contiguous#1#2#3{%
-   \global\pgf at picmaxy=-16000pt %
-   \global\pgf at picminy=16000pt %
+   \global\yquant at pgf@picmaxy=-16000pt %
+   \global\yquant at pgf@picminy=16000pt %
    \edef\cmd{%
       \noexpand\path (0pt, 0pt)%
          node[/yquant/every operator, \yquant at prepare@style, /yquant/this operator,%
@@ -419,10 +419,10 @@
    \cmd%
    \ifnum#1=#2 %
       % this is a single register in disguise
-      \yquant at register@update at height{#1}{\the\pgf at picmaxy}%
-      \yquant at register@update at depth{#1}{\the\dimexpr-\pgf at picminy\relax}%
+      \yquant at register@update at height{#1}{\the\yquant at pgf@picmaxy}%
+      \yquant at register@update at depth{#1}{\the\dimexpr-\yquant at pgf@picminy\relax}%
    \else%
-      \yquant at register@update at multispace{#1}{#2}{\the\dimexpr\pgf at picmaxy-\pgf at picminy\relax}%
+      \yquant at register@update at multispace{#1}{#2}{\the\dimexpr\yquant at pgf@picmaxy-\yquant at pgf@picminy\relax}%
    \fi%
 }
 
@@ -454,14 +454,14 @@
       \fi%
       \ifnum\@secondoffive#3=\@thirdoffive#3 %
          % this is a single register in disguise
-         \yquant at register@update at height{\first}{\the\pgf at picmaxy}%
-         \yquant at register@update at depth{\first}{\the\dimexpr-\pgf at picminy\relax}%
+         \yquant at register@update at height{\first}{\the\yquant at pgf@picmaxy}%
+         \yquant at register@update at depth{\first}{\the\dimexpr-\yquant at pgf@picminy\relax}%
       \else%
          % this may not be sufficient. Since the text position need not necessarily be at the center (if the register corresponding to the visual center is excluded), we may require some space here which we will later only use in parts, but then extend where we should not. However, resolving this would require a special handling when calculating the y positions at the end, meaning we could not use the multispace facility. Let's assume discontiguous init registers are so scarce that this does not matter (disable the acquiration by using the operator/overlay key).
          \edef\upd{%
             \yquant at register@update at multispace%
                {\first}{\@thirdoffive#3}%
-               {\the\dimexpr\pgf at picmaxy-\pgf at picminy\relax}%
+               {\the\dimexpr\yquant at pgf@picmaxy-\yquant at pgf@picminy\relax}%
          }%
          \upd%
       \fi%
@@ -502,8 +502,8 @@
                  name prefix=, name suffix=, name=] {\unexpanded{#1}};%
       }%
       \cmd%
-      \yquant at register@update at height{#3}{\the\pgf at picmaxy}%
-      \yquant at register@update at depth{#3}{\the\dimexpr-\pgf at picminy\relax}%
+      \yquant at register@update at height{#3}{\the\yquant at pgf@picmaxy}%
+      \yquant at register@update at depth{#3}{\the\dimexpr-\yquant at pgf@picminy\relax}%
 }
 
 \protected\long\def\yquant at prepare@output at multi#1#2#3{%
@@ -545,14 +545,14 @@
       \cmd%
       \ifnum\@secondoffive#3=\@thirdoffive#3 %
          % this is a single register in disguise
-         \yquant at register@update at height{\first}{\the\pgf at picmaxy}%
-         \yquant at register@update at depth{\first}{\the\dimexpr-\pgf at picminy\relax}%
+         \yquant at register@update at height{\first}{\the\yquant at pgf@picmaxy}%
+         \yquant at register@update at depth{\first}{\the\dimexpr-\yquant at pgf@picminy\relax}%
       \else%
          % this may not be sufficient. Since the text position need not necessarily be at the center (if the register corresponding to the visual center is excluded), we may require some space here which we will later only use in parts, but then extend where we should not. However, resolving this would require a special handling when calculating the y positions at the end, meaning we could not use the multispace facility. Let's assume discontiguous output registers are so scarce that this does not matter (disable the acquiration by using the operator/overlay key).
          \edef\upd{%
             \yquant at register@update at multispace%
                {\first}{\@thirdoffive#3}%
-               {\the\dimexpr\pgf at picmaxy-\pgf at picminy\relax}%
+               {\the\dimexpr\yquant at pgf@picmaxy-\yquant at pgf@picminy\relax}%
          }%
          \upd%
       \fi%
@@ -566,11 +566,11 @@
 
 \protected\def\yquant at prepare@subcircuit at getmaxx#1{%
    \begingroup%
-      \dimen0=-16383.99999pt %
+      \dimen0=\yquant at orientation@minus16383.99999pt %
       \def\do##1{%
          \ifcsname\yquant at prefix xpos@##1\endcsname%
             \dimen2=\csname\yquant at prefix xpos@##1\endcsname\relax%
-            \ifdim\dimen0<\dimen2 %
+            \ifdim\yquant at orientation@plus\dimen0<\yquant at orientation@plus\dimen2 %
                \dimen0=\dimen2 %
             \fi%
          \else%
@@ -598,28 +598,40 @@
       \yquant at set{#3}%
       \let\next=\endgroup%
       \ifyquant at config@operator at position@rightalign%
-         \ifdim#1>-\pgf at picminx%
-            \global\pgf at picminx=-\dimexpr#1\relax%
-         \fi%
+         \ifyquanthorz{%
+            \ifdim#1>-\pgf at picminx%
+               \global\pgf at picminx=-\dimexpr#1\relax%
+            \fi%
+         }{%
+            \ifdim#1>\pgf at picmaxy%
+               \global\pgf at picmaxy=#1 %
+            \fi%
+         }%
       \else%
          \ifyquant at env@seamless{%
             \ifdim\newx=0pt %
                \dimdef\newx{%
-                  \newx+#1%
+                  \newx\yquant at orientation@plus#1%
                }%
             \else%
                \dimdef\newx{%
-                  \newx+\yquant at config@operator at sep+#1%
+                  \newx\yquant at orientation@plus\yquant at config@operator at sep\yquant at orientation@plus#1%
                }%
             \fi%
          }{%
             \dimdef\newx{%
-               \newx+\yquant at config@operator at sep+#1%
+               \newx\yquant at orientation@plus\yquant at config@operator at sep\yquant at orientation@plus#1%
             }%
          }%
-         \ifdim\newx>\pgf at picmaxx%
-            \global\pgf at picmaxx=\newx%
-         \fi%
+         \ifyquanthorz{%
+            \ifdim\newx>\pgf at picmaxx%
+               \global\pgf at picmaxx=\newx%
+            \fi%
+         }{%
+            \ifdim\newx<\pgf at picminy%
+               \global\pgf at picminy=\newx%
+            \fi%
+         }%
          \ifyquant at config@operator at position@advance%
             \edef\next{%
                \endgroup%
@@ -647,11 +659,17 @@
 
 \protected\def\yquant at prepare@subcircuit at hspace#1#2{%
    \yquant at prepare@subcircuit at getmaxx{#1}%
-   \dimdef\newx{\newx+#2}%
+   \dimdef\newx{\newx\yquant at orientation@plus#2}%
    \forlistloop\yquant at prepare@subcircuit at move@loop{#1}%
-   \ifdim\newx>\pgf at picmaxx %
-      \global\pgf at picmaxx=\newx %
-   \fi%
+   \ifyquanthorz{%
+      \ifdim\newx>\pgf at picmaxx %
+         \global\pgf at picmaxx=\newx %
+      \fi%
+   }{%
+      \ifdim\newx<\pgf at picminy%
+         \global\pgf at picminy=\newx %
+      \fi%
+   }%
 }
 
 \protected\def\yquant at prepare@subcircuit at endwires{%
@@ -658,16 +676,20 @@
    \expandafter\ifx\csname\yquant at prefix outputs\endcsname\relax%
       % to have a symmetric situation, we extend again one separation at the end, unless this is supposed to be seamless and we don't have outputs (for seamless circuits with outputs, extend - since this extension will be between last register and output)
       \ifyquant at env@seamless\relax{%
-         \global\advance\pgf at picmaxx by \yquant at config@operator at sep\relax%
+         \ifyquanthorz{%
+            \global\advance\pgf at picmaxx by \yquant at config@operator at sep\relax%
+         }{%
+            \global\advance\pgf at picminy by -\yquant at config@operator at sep\relax%
+         }%
       }%
    \else%
       % if we have outputs, those will be realized as additional drawing groups following this macro, so increasing the picture at this point is rather pointless. Instead, we adjust the wire positions appropriately. The additional separation will be inserted by the outputs.
       \begingroup%
-         \dimen0=-16383.99999pt %
+         \dimen0=\yquant at orientation@minus16383.99999pt %
          \yquant at fordown \i := \csname\yquant at prefix registers\endcsname downto 1 {%
             \ifcsname\yquant at prefix xpos@\i\endcsname%
                \dimen2=\csname\yquant at prefix xpos@\i\endcsname\relax%
-               \ifdim\dimen0<\dimen2 %
+               \ifdim\yquant at orientation@plus\dimen0<\yquant at orientation@plus\dimen2 %
                   \dimen0=\dimen2 %
                \fi%
             \else%
@@ -746,27 +768,39 @@
             \let\endtikz at scope@env=\yquant at env@substikz at endscope%
             \let\endscope=\endtikz at scope@env%
             \let\stopscope=\endscope%
-            \global\pgf at picmaxx=0pt %
-            \global\pgf at picminx=0pt %
+            \global\yquant at pgf@picmaxx=0pt %
+            \global\yquant at pgf@picminx=0pt %
             \global\setbox\yquant at prepare@subcircuit at box=\vbox to 1sp{%
                \csname\yquant at prefix draw\endcsname%
             }%
-            \ifdim\pgf at picmaxy=-16000pt %
-               \global\pgf at picmaxy=0pt %
-               \global\pgf at picminy=0pt %
+            \ifdim\yquant at pgf@picmaxy=-16000pt %
+               \global\yquant at pgf@picmaxy=0pt %
+               \global\yquant at pgf@picminy=0pt %
             \fi%
             \ifyquant at env@seamless{%
                % for seamless circuits, we do not have an initial separation. However, if there is a label to registers (which you should not do for seamless subcircuits), the "initial" separation is in fact an inner one, so we need it.
-               \ifdim\pgf at picminx<0pt %
-                  \global\advance\pgf at picmaxx by \yquant at config@operator at sep\relax%
-               \fi%
+               \ifyquanthorz{%
+                  \ifdim\pgf at picminx<0pt %
+                     \global\advance\pgf at picmaxx by \yquant at config@operator at sep\relax%
+                  \fi%
+               }{%
+                  \ifdim\pgf at picmaxy>0pt %
+                     \global\advance\pgf at picminy by -\yquant at config@operator at sep\relax%
+                  \fi%
+               }%
             }\relax%
-            \global\wd\yquant at prepare@subcircuit at box=\dimexpr\pgf at picmaxx-\pgf at picminx\relax%
+            \ifyquanthorz{%
+               \global\wd\yquant at prepare@subcircuit at box=\dimexpr\pgf at picmaxx-\pgf at picminx\relax%
+            }{%
+               \global\ht\yquant at prepare@subcircuit at box=\pgf at picmaxy%
+               \global\dp\yquant at prepare@subcircuit at box=-\pgf at picminy%
+            }%
          \endgroup%
          \edef\yquant at prepare@subcircuit at width{%
-            {\the\wd\yquant at prepare@subcircuit at box}% inner width
-            {\noexpand\the\dimexpr\pgf at picmaxx-\pgf at picminx\relax}% outer width
-            {\the\pgf at picminx}% left margin
+            {\ifyquanthorz{\the\wd\yquant at prepare@subcircuit at box}% inner width
+                          {\the\dimexpr\ht\yquant at prepare@subcircuit at box+\dp\yquant at prepare@subcircuit at box\relax}}%
+            {\noexpand\the\dimexpr\yquant at pgf@picmaxx-\yquant at pgf@picminx\relax}% outer width
+            {\ifyquanthorz{\the\pgf at picminx}{-\the\pgf at picmaxy}}% left margin
          }%
          \pgfresetboundingbox%
          \path%
@@ -774,12 +808,12 @@
             node[/yquant/every operator, #1,%
                  /yquant/operators/every subcircuit box, /yquant/this operator,%
                  /yquant/operators/this subcircuit box,%
-                 name prefix=, name suffix=, name=, y radius=0pt]%
+                 name prefix=, name suffix=, name=, space radius=0pt]%
             {\box\yquant at prepare@subcircuit at box};%
          % the extra height is taken care for by manually inserting it to the height of the first and last register in the subcircuit
-         \yquant at register@inject at extents{\pgf at picmaxy}{-\pgf at picminy}%
+         \yquant at register@inject at extents{\yquant at pgf@picmaxy}{-\yquant at pgf@picminy}%
          \edef\cmd{%
-            \dimen0=\the\dimexpr\pgf at picmaxx-\pgf at picminx\relax\relax%
+            \dimen0=\the\dimexpr\yquant at pgf@picmaxx-\yquant at pgf@picminx\relax\relax%
             \yquant at prepare@subcircuit at add%
          }%
          \expandafter%

Modified: trunk/Master/texmf-dist/tex/latex/yquant/yquant-registers.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/yquant/yquant-registers.tex	2022-02-05 21:22:43 UTC (rev 61896)
+++ trunk/Master/texmf-dist/tex/latex/yquant/yquant-registers.tex	2022-02-05 21:23:01 UTC (rev 61897)
@@ -882,13 +882,13 @@
    \def#9{#4}%
 }%
 
-% Set #1 to the maximum x value found between #2 and #3
+% Set #1 to the maximum x (vertical: minimum y) value found between #2 and #3
 \protected\def\yquant at register@get at maxxrange#1#2#3{%
    \begingroup%
-      \dimen0=-16383.99999pt %
+      \dimen0=\yquant at orientation@minus16383.99999pt %
       \yquant at for \yquant at register@get at maxx@i := #2 to #3 {%
          \dimen2=\yquant at register@get at x{\yquant at register@get at maxx@i}\relax%
-         \ifdim\dimen0<\dimen2 %
+         \ifdim\yquant at orientation@plus\dimen0<\yquant at orientation@plus\dimen2 %
             \dimen0=\dimen2 %
          \fi%
       }%
@@ -897,13 +897,13 @@
    \expandafter\def\expandafter#1\expandafter{\the\dimen0}%
 }
 
-% Set #1 to the maximum x value found in the list #2
+% Set #1 to the maximum x (vertical: minimum y) value found in the list #2
 \protected\def\yquant at register@get at maxxlist#1#2{%
    \begingroup%
-      \dimen0=-16383.99999pt %
+      \dimen0=\yquant at orientation@minus16383.99999pt %
       \def\do##1{%
          \dimen2=\yquant at register@get at x{##1}\relax%
-         \ifdim\dimen0<\dimen2 %
+         \ifdim\yquant at orientation@plus\dimen0<\yquant at orientation@plus\dimen2 %
             \dimen0=\dimen2 %
          \fi%
       }%

Modified: trunk/Master/texmf-dist/tex/latex/yquant/yquant-shapes.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/yquant/yquant-shapes.tex	2022-02-05 21:22:43 UTC (rev 61896)
+++ trunk/Master/texmf-dist/tex/latex/yquant/yquant-shapes.tex	2022-02-05 21:23:01 UTC (rev 61897)
@@ -22,6 +22,7 @@
                  {Failed to patch \string\pgfdeclareshape}%
                  {yquant could not provide a necessary extension to pgf.}}%
 % Every shape additionally provides information about how it should clip the wires. The clipping softpath instructions of shape #1 are stored into \pgfshapeclippath[horz|vert]result. The path is drawn with the tikz options #2 in place.
+% sync with yquant at config
 \protected\def\pgfshapeclippath#1#2{%
    % Ok, check whether #1 is known!
    \ifcsname pgf at sh@ns@#1\endcsname%
@@ -459,6 +460,7 @@
    }%
 }
 
+% The dmeter shape is aware of the circuit orientation
 \pgfdeclareshape{yquant-dmeter}{%
    \saveddimen\xradius{%
       \pgfmathsetlength\pgf at x{\pgfkeysvalueof{/tikz/x radius}}%
@@ -465,7 +467,7 @@
       \ifdim\wd\pgfnodeparttextbox=0pt %
          \pgf at xa=0pt %
       \else%
-         \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}+.5mm}%
+         \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}\ifyquanthorz{+.5mm}{}}%
       \fi%
       \ifdim\dimexpr.5\wd\pgfnodeparttextbox+\pgf at xa\relax>\pgf at x%
          \pgf at x=\dimexpr.5\wd\pgfnodeparttextbox+\pgf at xa\relax%
@@ -476,7 +478,7 @@
       \ifdim\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox\relax=0pt %
          \pgf at xa=0pt %
       \else%
-         \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner ysep}}%
+         \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner ysep}\ifyquanthorz{}{+.325mm}}%
       \fi%
       \@tempdima=\dimexpr.5\ht\pgfnodeparttextbox+.5\dp\pgfnodeparttextbox+\pgf at xa\relax%
       \ifdim\@tempdima>\pgf at x%
@@ -484,10 +486,25 @@
       \fi%
    }%
    \savedanchor\stext{%
-      \pgfqpoint%
-         {-\dimexpr.5\wd\pgfnodeparttextbox+1mm\relax}%
-         {-\dimexpr.5\ht\pgfnodeparttextbox-.5\dp\pgfnodeparttextbox\relax}%
+      \ifyquanthorz{%
+         \pgfqpoint%
+            {-\dimexpr.5\wd\pgfnodeparttextbox+1mm\relax}%
+            {-\dimexpr.5\ht\pgfnodeparttextbox-.5\dp\pgfnodeparttextbox\relax}%
+      }{%
+         % \pgf at x is still \yradius
+         \@tempdima=\pgf at x%
+         \pgfqpoint%
+            {-\dimexpr.5\wd\pgfnodeparttextbox\relax}%
+            {-\dimexpr.5\ht\pgfnodeparttextbox-.5\dp\pgfnodeparttextbox-.75mm\relax}%
+      }%
    }%
+   \savedmacro\ifhorz{%
+      \ifyquanthorz{%
+         \def\ifhorz{\noexpand\@firstoftwo}%
+      }{%
+         \def\ifhorz{\noexpand\@secondoftwo}%
+      }%
+   }%
    \foreach \anc in {center, north, south, south west, west, north west, text} {%
       \inheritanchor[from=yquant-rectangle]{\anc}%
    }%
@@ -497,44 +514,113 @@
    \anchorborder{%
       \@tempdima=\pgf at x%
       \@tempdimb=\pgf at y%
-      \ifdim\pgf at x>\dimexpr\xradius-3mm\relax%
-         \pgfpointborderellipse{\pgfqpoint{\dimexpr\@tempdima-\xradius+3mm\relax}%
-                                          {\@tempdimb}}%
-                               {\pgfqpoint{3mm}%
-                                          {.707107\dimexpr\yradius\relax}}%
-         \advance\pgf at x by \dimexpr\xradius-3mm\relax%
-      \else%
-         \pgfpointborderrectangle{\pgfqpoint{\@tempdima}{\@tempdimb}}%
-                                 {\pgfqpoint{\xradius}{\yradius}}%
-      \fi%
+      \pgfpointborderrectangle{\pgfqpoint{\@tempdima}{\@tempdimb}}%
+                              {\pgfqpoint{\xradius}{\yradius}}%
+      % for very distorted shapes, we lose a lot of accuracy in these calculations
+      \ifhorz{%
+         \ifdim\pgf at x>\dimexpr\xradius-3mm\relax%
+            \pgf at xa=\dimexpr\xradius-3mm\relax% shift of the ellipse
+            \pgf at xb=\dimexpr\@tempdimb*65536/\@tempdima\relax%
+            \pgf at xb=\dimexpr\pgf at xb*\pgf at xb/65536\relax% slope^2
+            \pgf at ya=72.86009pt % xradius^2 of ellipse (72.86009pt = 3mm^2/65536)
+            \pgf at yb=\yradius\relax%
+            \pgf at yb=\dimexpr\pgf at yb*\pgf at yb/65536\relax% yradius^2
+            % sqrt(slope^2 * (xradius^2 - shift^2) + yradius^2)
+            \pgfmathsqrt@{\the\dimexpr\pgf at xb*\dimexpr\pgf at ya-\pgf at xa*\pgf at xa/65536\relax/65536+%
+                                      \pgf at yb\relax\@gobbletwo}%
+            % yradius (shift yradius + xradius sqrt(...)) / (slope^2 xradius^2 + yradius^2)
+            \pgf at x=\dimexpr\dimexpr\yradius\relax*%
+                           \dimexpr\pgf at xa*\dimexpr\yradius\relax/65536+%
+                                   9\dimexpr\pgfmathresult pt\relax% 9 = 3mm/65536
+                                   \relax/%
+                           \dimexpr\pgf at xb*\pgf at ya/65536+\pgf at yb\relax%
+                   \relax%
+            % y = slope x
+            \pgf at y=\dimexpr\@tempdimb*\pgf at x/\@tempdima\relax%
+         \fi%
+      }{%
+         \ifdim\pgf at y<\dimexpr-\yradius+3mm\relax%
+            \pgf at xa=\dimexpr-\yradius+3mm\relax% shift of the ellipse
+            \pgf at xb=\dimexpr\@tempdima*65536/\@tempdimb\relax%
+            \pgf at xb=\dimexpr\pgf at xb*\pgf at xb/65536\relax% 1/slope^2
+            \pgf at ya=\xradius\relax% xradius
+            \pgf at ya=\dimexpr\pgf at ya*\pgf at ya/65535\relax% xradius^2
+            \pgf at yb=72.86009pt % yradius^2 of ellipse (72.86009pt = 3mm^2/65536)
+            % sqrt(1/slope^2 * (yradius^2 - shift^2) + xradius^2)
+            \pgfmathsqrt@{\the\dimexpr\pgf at xb*\dimexpr\pgf at yb-\pgf at xa*\pgf at xa/65536\relax/65536+%
+                                      \pgf at ya\relax\@gobbletwo}%
+            % xradius (shift xradius - yradius sqrt(...)) / (1/slope^2 yradius^2 + xradius^2)
+            \pgf at y=\dimexpr\dimexpr\xradius\relax*%
+                           \dimexpr\pgf at xa*\dimexpr\xradius\relax/65536-%
+                                   9\dimexpr\pgfmathresult pt\relax% 9 = 3mm/65536
+                                   \relax/%
+                           \dimexpr\pgf at xb*\pgf at yb/65536+\pgf at ya\relax%
+                   \relax%
+            % x = 1/slope y
+            \pgf at x=\dimexpr\@tempdima*\pgf at y/\@tempdimb\relax%
+         \fi%
+      }%
    }%
    \backgroundpath{%
-      \pgfpathmoveto{\pgfqpoint{-\xradius}{\yradius}}%
-      \pgfpathlineto{\pgfqpoint{\dimexpr\xradius-3mm\relax}{\yradius}}%
-      \pgfpatharc{90}{-90}{3mm and \yradius}%
-      \pgfpathlineto{\pgfqpoint{-\xradius}{-\yradius}}%
+      \ifhorz{%
+         \pgfpathmoveto{\pgfqpoint{-\xradius}{\yradius}}%
+         \pgfpathlineto{\pgfqpoint{\dimexpr\xradius-3mm\relax}{\yradius}}%
+         \pgfpatharc{90}{-90}{3mm and \yradius}%
+         \pgfpathlineto{\pgfqpoint{-\xradius}{-\yradius}}%
+      }{%
+         \pgfpathmoveto{\pgfqpoint{\xradius}{\yradius}}%
+         \pgfpathlineto{\pgfqpoint{\xradius}{\dimexpr-\yradius+3mm\relax}}%
+         \pgfpatharc{0}{-180}{\xradius and 3mm}%
+         \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}}%
+      \ifhorz{%
+         \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}}%
+      }{%
+         \pgfpathmoveto{\pgfqpoint{\dimexpr\xradius+.5\pgflinewidth\relax}%
+                                  {\dimexpr\yradius+.5\pgflinewidth\relax}}%
+         \pgfpathlineto{\pgfqpoint{\dimexpr\xradius+.5\pgflinewidth\relax}%
+                                  {\dimexpr-\yradius+3mm\relax}}%
+         \pgfpatharc{0}{-180}{\xradius+.5\pgflinewidth and 3mm+.5\pgflinewidth}%
+         \pgfpathlineto{\pgfqpoint{-\dimexpr\xradius+.5\pgflinewidth\relax}%
+                                  {\dimexpr\yradius+.5\pgflinewidth}}%
+      }%
       \pgfpathclose%
    }%
 }
 
+% The line shape is aware of the circuit orientation (it always extends in space dimension with constant time)
 \pgfdeclareshape{yquant-line}{%
    \saveddimen\xradius{%
       % we only need this for the border anchor; the value is automatically correct in the paths.
-      \pgf at x=.5\pgflinewidth%
+      \ifyquanthorz{%
+         \pgf at x=.5\pgflinewidth%
+      }{%
+         \pgfmathsetlength\pgf at x{\pgfkeysvalueof{/tikz/x radius}+.5*\yquant at config@register at sep}%
+      }%
    }%
    \saveddimen\yradius{%
-      \pgfmathsetlength\pgf at x{\pgfkeysvalueof{/tikz/y radius}+.5*\yquant at config@register at sep}%
+      \ifyquanthorz{%
+         \pgfmathsetlength\pgf at x{\pgfkeysvalueof{/tikz/y radius}+.5*\yquant at config@register at sep}%
+      }{%
+         \pgf at x=.5\pgflinewidth%
+      }%
    }%
+   \savedmacro\ifhorz{%
+      \ifyquanthorz{%
+         \def\ifhorz{\noexpand\@firstoftwo}%
+      }{%
+         \def\ifhorz{\noexpand\@secondoftwo}%
+      }%
+   }%
    \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west} {%
       \inheritanchor[from=yquant-rectangle]{\anc}%
    }%
@@ -541,19 +627,36 @@
    \inheritanchorborder[from=yquant-rectangle]%
    \backgroundpath{%
       % manually shorten for the bounding box
-      \pgf at xa=\dimexpr\yradius-\pgf at shorten@end at additional\relax%
-      \pgf at ya=\dimexpr\yradius-\pgf at shorten@start at additional\relax%
-      \pgf at shorten@end at additional=0pt %
-      \pgf at shorten@start at additional=0pt %
-      \pgfpathmoveto{\pgfqpoint{0pt}{\pgf at xa}}%
-      \pgfpathlineto{\pgfqpoint{0pt}{-\pgf at ya}}%
+      \ifhorz{%
+         \pgf at xa=\dimexpr\yradius-\pgf at shorten@end at additional\relax%
+         \pgf at ya=\dimexpr\yradius-\pgf at shorten@start at additional\relax%
+         \pgf at shorten@end at additional=0pt %
+         \pgf at shorten@start at additional=0pt %
+         \pgfpathmoveto{\pgfqpoint{0pt}{\pgf at xa}}%
+         \pgfpathlineto{\pgfqpoint{0pt}{-\pgf at ya}}%
+      }{%
+         \pgf at xa=\dimexpr\xradius-\pgf at shorten@end at additional\relax%
+         \pgf at ya=\dimexpr\xradius-\pgf at shorten@start at additional\relax%
+         \pgf at shorten@end at additional=0pt %
+         \pgf at shorten@start at additional=0pt %
+         \pgfpathmoveto{\pgfqpoint{\pgf at xa}{0pt}}%
+         \pgfpathlineto{\pgfqpoint{-\pgf at ya}{0pt}}%
+      }%
    }%
    \clippath{%
-      \@tempdima=\dimexpr\yradius-\pgf at shorten@end at additional\relax%
-      \@tempdimb=\dimexpr\yradius-\pgf at shorten@start at additional\relax%
-      \pgfpathrectanglecorners%
-         {\pgfqpoint{-.5\pgflinewidth}{\@tempdima}}%
-         {\pgfqpoint{.5\pgflinewidth}{-\@tempdimb}}%
+      \ifhorz{%
+         \@tempdima=\dimexpr\yradius-\pgf at shorten@end at additional\relax%
+         \@tempdimb=\dimexpr\yradius-\pgf at shorten@start at additional\relax%
+         \pgfpathrectanglecorners%
+            {\pgfqpoint{-.5\pgflinewidth}{\@tempdima}}%
+            {\pgfqpoint{.5\pgflinewidth}{-\@tempdimb}}%
+      }{%
+         \@tempdima=\dimexpr\xradius-\pgf at shorten@end at additional\relax%
+         \@tempdimb=\dimexpr\xradius-\pgf at shorten@start at additional\relax%
+         \pgfpathrectanglecorners%
+            {\pgfqpoint{\@tempdima}{-.5\pgflinewidth}}%
+            {\pgfqpoint{-\@tempdimb}{.5\pgflinewidth}}%
+      }%
    }%
 }
 
@@ -708,77 +811,145 @@
 }
 % END_FOLD
 
+% The init and output shapes are tightly connected to quantum circuits, so they will depend on the current circuit orientation!
 \pgfdeclareshape{yquant-init}{%
    \saveddimen\xradius{%
       \pgfmathsetlength\pgf at x{\pgfkeysvalueof{/tikz/x radius}}%
-      % inner xsep is between the brace tip and the right end of the text. Check if the decoration is raised (will define \def\tikz at dec@shift{\pgftransformyshift{#1}})
-      \iftikz at decoratepath%
-         \ifx\tikz at dec@shift\relax%
-            \pgf at xa=\pgfdecorationsegmentamplitude %
+      \ifyquanthorz{%
+         % inner xsep is between the brace tip and the right end of the text. Check if the decoration is raised (will define \def\tikz at dec@shift{\pgftransformyshift{#1}})
+         \iftikz at decoratepath%
+            \ifx\tikz at dec@shift\relax%
+               \pgf at xa=\pgfdecorationsegmentamplitude %
+            \else%
+               \pgfmathsetlength\pgf at xa{\expandafter\@secondoftwo\tikz at dec@shift+\pgfdecorationsegmentamplitude}%
+            \fi%
+            \pgfmathaddtolength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}}%
          \else%
-            \pgfmathsetlength\pgf at xa{\expandafter\@secondoftwo\tikz at dec@shift+\pgfdecorationsegmentamplitude}%
+            \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}}%
          \fi%
-         \pgfmathaddtolength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}}%
-      \else%
-         \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}}%
-      \fi%
-      % outer xsep is (a lower bound) from the left end of the border to the left end of the text
-      \pgfmathsetlength\pgf at xb{\pgfkeysvalueof{/pgf/outer xsep}}%
-      \@tempdima=.5\dimexpr\wd\pgfnodeparttextbox+\pgf at xa+\pgf at xb\relax%
-      \ifdim\@tempdima>\pgf at x%
-         \pgf at x=\@tempdima%
-      \fi%
+         % outer xsep is (a lower bound) from the left end of the border to the left end of the text
+         \pgfmathsetlength\pgf at xb{\pgfkeysvalueof{/pgf/outer xsep}}%
+         \@tempdima=.5\dimexpr\wd\pgfnodeparttextbox+\pgf at xa+\pgf at xb\relax%
+         \ifdim\@tempdima>\pgf at x%
+            \pgf at x=\@tempdima%
+         \fi%
+      }{%
+         \ifdim.5\wd\pgfnodeparttextbox>\pgf at x%
+            \pgf at x=.5\wd\pgfnodeparttextbox%
+         \fi%
+         \iftikz at decoratepath%
+            \ifdim2\pgfdecorationsegmentamplitude>\pgf at x%
+               \pgf at x=2\pgfdecorationsegmentamplitude%
+            \fi%
+         \fi%
+      }%
+      \global\pgf at y=\pgf at x%
    }%
    \saveddimen\yradius{%
       \pgfmathsetlength\pgf at x{\pgfkeysvalueof{/tikz/y radius}}%
-      \@tempdima=.5\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox\relax%
-      \ifdim\@tempdima>\pgf at x%
-         \pgf at x=\@tempdima%
-      \fi%
-      \iftikz at decoratepath%
-         \ifdim2\pgfdecorationsegmentamplitude>\pgf at x%
-            \pgf at x=2\pgfdecorationsegmentamplitude%
+      \ifyquanthorz{%
+         \@tempdima=.5\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox\relax%
+         \ifdim\@tempdima>\pgf at x%
+            \pgf at x=\@tempdima%
          \fi%
-      \fi%
+         \iftikz at decoratepath%
+            \ifdim2\pgfdecorationsegmentamplitude>\pgf at x%
+               \pgf at x=2\pgfdecorationsegmentamplitude%
+            \fi%
+         \fi%
+      }{%
+         % inner ysep is between the brace tip and the bottom end of the text. Check if the decoration is raised (will define \def\tikz at dec@shift{\pgftransformyshift{#1}})
+         \iftikz at decoratepath%
+            \ifx\tikz at dec@shift\relax%
+               \pgf at xa=\pgfdecorationsegmentamplitude %
+            \else%
+               \pgfmathsetlength\pgf at xa{\expandafter\@secondoftwo\tikz at dec@shift+\pgfdecorationsegmentamplitude}%
+            \fi%
+            \pgfmathaddtolength\pgf at xa{\pgfkeysvalueof{/pgf/inner ysep}}%
+         \else%
+            \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner ysep}}%
+         \fi%
+         % outer ysep is (a lower bound) from the top end of the border to the top end of the text
+         \pgfmathsetlength\pgf at xb{\pgfkeysvalueof{/pgf/outer ysep}}%
+         \@tempdima=.5\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox+\pgf at xa+\pgf at xb\relax%
+         \ifdim\@tempdima>\pgf at x%
+            \pgf at x=\@tempdima%
+         \fi%
+      }%
    }%
    \savedanchor\stext{%
-      \iftikz at decoratepath%
-         % \pgf at x is still \yradius...
-         % first set \pgfdecoratedremainingdistance appropriately
-         \pgfdecoratedremainingdistance=2\pgf at x%
-         % now perform the transformation
-         \yquant at gappedbrace@calcshift%
-         \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}+\pgfdecorationsegmentamplitude}%
-         \unless\ifx\tikz at dec@shift\relax%
-            \pgfmathaddtolength\pgf at xa{\expandafter\@secondoftwo\tikz at dec@shift}%
+      % \pgf at x is still \yradius, \pgf at y is still \xradius
+      \@tempdima=\pgf at y%
+      \@tempdimb=\pgf at x%
+      \ifyquanthorz{%
+         \iftikz at decoratepath%
+            % first set \pgfdecoratedremainingdistance appropriately
+            \pgfdecoratedremainingdistance=2\@tempdimb%
+            % now perform the transformation
+            \yquant at gappedbrace@calcshift%
+            \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}+\pgfdecorationsegmentamplitude}%
+            \unless\ifx\tikz at dec@shift\relax%
+               \pgfmathaddtolength\pgf at xa{\expandafter\@secondoftwo\tikz at dec@shift}%
+            \fi%
+            \pgfqpoint%
+               {\dimexpr\@tempdima-\wd\pgfnodeparttextbox-\pgf at xa\relax}%
+               {\dimexpr\@tempdimb% = \yradius
+                        -\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance% - aspect
+                        -.5\ht\pgfnodeparttextbox+.5\dp\pgfnodeparttextbox% center there
+                \relax}%
+         \else%
+            \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}}%
+            \pgfqpoint%
+               {\dimexpr\@tempdima-\wd\pgfnodeparttextbox-\pgf at xa\relax}%
+               {-.5\dimexpr\ht\pgfnodeparttextbox-\dp\pgfnodeparttextbox\relax}%
          \fi%
-         \pgfqpoint%
-            {-\dimexpr\wd\pgfnodeparttextbox+\pgf at xa\relax}%
-            {\dimexpr.5\pgfdecoratedremainingdistance% = \yradius
-                     -\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance% - aspect
-                     -.5\ht\pgfnodeparttextbox+.5\dp\pgfnodeparttextbox% center there
-             \relax}%
-       \else%
-         \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}}%
-         \pgfqpoint%
-            {-\dimexpr\wd\pgfnodeparttextbox+\pgf at xa\relax}%
-            {-.5\dimexpr\ht\pgfnodeparttextbox-\dp\pgfnodeparttextbox\relax}%
-       \fi%
+      }{%
+         \iftikz at decoratepath%
+            % first set \pgfdecoratedremainingdistance appropriately
+            \pgfdecoratedremainingdistance=2\@tempdima%
+            % now perform the transformation
+            \yquant at gappedbrace@calcshift%
+            \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner ysep}+\pgfdecorationsegmentamplitude}%
+            \unless\ifx\tikz at dec@shift\relax%
+               \pgfmathaddtolength\pgf at xa{\expandafter\@secondoftwo\tikz at dec@shift}%
+            \fi%
+            \pgfqpoint%
+               {\dimexpr-\@tempdima+%
+                        \pgfdecorationsegmentaspect\pgfdecoratedremainingdistance% - aspect
+                        -.5\wd\pgfnodeparttextbox% center there
+                \relax}%
+               {\dimexpr-\@tempdimb+\dp\pgfnodeparttextbox+\pgf at xa\relax}%
+         \else%
+            \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner ysep}}%
+            \pgfqpoint%
+               {-.5\wd\pgfnodeparttextbox}%
+               {\dimexpr-\@tempdimb+\dp\pgfnodeparttextbox+\pgf at xa\relax}%
+         \fi%
+      }%
    }%
+   \savedmacro\ifhorz{%
+      \ifyquanthorz{%
+         \def\ifhorz{\noexpand\@firstoftwo}%
+      }{%
+         \def\ifhorz{\noexpand\@secondoftwo}%
+      }%
+   }%
    % BEGIN_FOLD Operator anchors
    \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west} {%
       \inheritanchor[from=yquant-rectangle]{\anc}%
    }%
-   \anchor{text}{%
-      \stext%
-      \advance \pgf at x by \xradius\relax%
-   }%
+   \anchor{text}{\stext}%
    \inheritanchorborder[from=yquant-rectangle]%
    % END_FOLD
    % BEGIN_FOLD Path
    \backgroundpath{%
-      \pgfpathmoveto{\pgfqpoint{\xradius}{\yradius}}%
-      \pgfpathlineto{\pgfqpoint{\xradius}{-\yradius}}%
+      \ifhorz{%
+         \pgfpathmoveto{\pgfqpoint{\xradius}{\yradius}}%
+         \pgfpathlineto{\pgfqpoint{\xradius}{-\yradius}}%
+      }{%
+         \pgfpathmoveto{\pgfqpoint{-\xradius}{-\yradius}}%
+         \pgfpathlineto{\pgfqpoint{\xradius}{-\yradius}}%
+      }%
       \pgfpointtransformed{\pgfqpoint{-\xradius}{\yradius}}%
       \pgf at protocolsizes{\pgf at x}{\pgf at y}%
       \pgfpointtransformed{\pgfqpoint{-\xradius}{-\yradius}}% for rotations
@@ -788,8 +959,8 @@
       \pgfpathrectanglecorners%
          {\pgfqpoint{-\dimexpr\xradius\relax}%
                     {\dimexpr\yradius\relax}}%
-         {\pgfqpoint{\dimexpr\xradius+.5\pgflinewidth\relax}%
-                    {-\dimexpr\yradius\relax}}%
+         {\pgfqpoint{\dimexpr\xradius\ifhorz{+.5\pgflinewidth}{}\relax}%
+                    {-\dimexpr\yradius\ifhorz{}{+.5\pgflinewidth}\relax}}%
    }%
    % END_FOLD
 }
@@ -798,74 +969,141 @@
    % Almost the same as in yquant-input, only a minimal change in \stext's x position
    \saveddimen\xradius{%
       \pgfmathsetlength\pgf at x{\pgfkeysvalueof{/tikz/x radius}}%
-      % inner xsep is from the brace tip and the left end of the text. Check if the decoration is raised (will define \def\tikz at dec@shift{\pgftransformyshift{#1}})
-      \iftikz at decoratepath%
-         \ifx\tikz at dec@shift\relax%
-            \pgf at xa=\pgfdecorationsegmentamplitude %
+      \ifyquanthorz{%
+         % inner xsep is between the brace tip and the left end of the text. Check if the decoration is raised (will define \def\tikz at dec@shift{\pgftransformyshift{#1}})
+         \iftikz at decoratepath%
+            \ifx\tikz at dec@shift\relax%
+               \pgf at xa=\pgfdecorationsegmentamplitude %
+            \else%
+               \pgfmathsetlength\pgf at xa{\expandafter\@secondoftwo\tikz at dec@shift+\pgfdecorationsegmentamplitude}%
+            \fi%
+            \pgfmathaddtolength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}}%
          \else%
-            \pgfmathsetlength\pgf at xa{\expandafter\@secondoftwo\tikz at dec@shift+\pgfdecorationsegmentamplitude}%
+            \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}}%
          \fi%
-         \pgfmathaddtolength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}}%
-      \else%
-         \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}}%
-      \fi%
-      % outer xsep is (a lower bound) from the left end of the border to the left end of the text
-      \pgfmathsetlength\pgf at xb{\pgfkeysvalueof{/pgf/outer xsep}}%
-      \@tempdima=.5\dimexpr\wd\pgfnodeparttextbox+\pgf at xa+\pgf at xb\relax%
-      \ifdim\@tempdima>\pgf at x%
-         \pgf at x=\@tempdima%
-      \fi%
+         % outer xsep is (a lower bound) from the right end of the border to the right end of the text
+         \pgfmathsetlength\pgf at xb{\pgfkeysvalueof{/pgf/outer xsep}}%
+         \@tempdima=.5\dimexpr\wd\pgfnodeparttextbox+\pgf at xa+\pgf at xb\relax%
+         \ifdim\@tempdima>\pgf at x%
+            \pgf at x=\@tempdima%
+         \fi%
+      }{%
+         \ifdim.5\wd\pgfnodeparttextbox>\pgf at x%
+            \pgf at x=.5\wd\pgfnodeparttextbox%
+         \fi%
+         \iftikz at decoratepath%
+            \ifdim2\pgfdecorationsegmentamplitude>\pgf at x%
+               \pgf at x=2\pgfdecorationsegmentamplitude%
+            \fi%
+         \fi%
+      }%
+      \global\pgf at y=\pgf at x%
    }%
    \saveddimen\yradius{%
       \pgfmathsetlength\pgf at x{\pgfkeysvalueof{/tikz/y radius}}%
-      \@tempdima=.5\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox\relax%
-      \ifdim\@tempdima>\pgf at x%
-         \pgf at x=\@tempdima%
-      \fi%
-      \iftikz at decoratepath%
-         \ifdim2\pgfdecorationsegmentamplitude>\pgf at x%
-            \pgf at x=2\pgfdecorationsegmentamplitude%
+      \ifyquanthorz{%
+         \@tempdima=.5\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox\relax%
+         \ifdim\@tempdima>\pgf at x%
+            \pgf at x=\@tempdima%
          \fi%
-      \fi%
+         \iftikz at decoratepath%
+            \ifdim2\pgfdecorationsegmentamplitude>\pgf at x%
+               \pgf at x=2\pgfdecorationsegmentamplitude%
+            \fi%
+         \fi%
+      }{%
+         % inner ysep is between the brace tip and the top end of the text. Check if the decoration is raised (will define \def\tikz at dec@shift{\pgftransformyshift{#1}})
+         \iftikz at decoratepath%
+            \ifx\tikz at dec@shift\relax%
+               \pgf at xa=\pgfdecorationsegmentamplitude %
+            \else%
+               \pgfmathsetlength\pgf at xa{\expandafter\@secondoftwo\tikz at dec@shift+\pgfdecorationsegmentamplitude}%
+            \fi%
+            \pgfmathaddtolength\pgf at xa{\pgfkeysvalueof{/pgf/inner ysep}}%
+         \else%
+            \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner ysep}}%
+         \fi%
+         % outer ysep is (a lower bound) from the bottom end of the border to the bottom end of the text
+         \pgfmathsetlength\pgf at xb{\pgfkeysvalueof{/pgf/outer ysep}}%
+         \@tempdima=.5\dimexpr\ht\pgfnodeparttextbox+\dp\pgfnodeparttextbox+\pgf at xa+\pgf at xb\relax%
+         \ifdim\@tempdima>\pgf at x%
+            \pgf at x=\@tempdima%
+         \fi%
+      }%
    }%
    \savedanchor\stext{%
-      \iftikz at decoratepath%
-         % \pgf at x is still \yradius...
-         % first set \pgfdecoratedremainingdistance appropriately
-         \pgfdecoratedremainingdistance=2\pgf at x%
-         % now perform the transformation
-         \yquant at gappedbrace@calcshift%
-         \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}+\pgfdecorationsegmentamplitude}%
-         \unless\ifx\tikz at dec@shift\relax%
-            \pgfmathaddtolength\pgf at xa{\expandafter\@secondoftwo\tikz at dec@shift}%
+      % \pgf at x is still \yradius, \pgf at y is still \xradius
+      \@tempdima=\pgf at y%
+      \@tempdimb=\pgf at x%
+      \ifyquanthorz{%
+         \iftikz at decoratepath%
+            % first set \pgfdecoratedremainingdistance appropriately
+            \pgfdecoratedremainingdistance=2\@tempdimb%
+            % now perform the transformation
+            \yquant at gappedbrace@calcshift%
+            \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}+\pgfdecorationsegmentamplitude}%
+            \unless\ifx\tikz at dec@shift\relax%
+               \pgfmathaddtolength\pgf at xa{\expandafter\@secondoftwo\tikz at dec@shift}%
+            \fi%
+            \pgfqpoint%
+               {\dimexpr-\@tempdima+\pgf at xa\relax}%
+               {\dimexpr\@tempdimb% = \yradius
+                        -\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance% - aspect
+                        -.5\ht\pgfnodeparttextbox+.5\dp\pgfnodeparttextbox% center there
+                \relax}%
+         \else%
+            \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}}%
+            \pgfqpoint%
+               {\dimexpr-\@tempdima+\pgf at xa\relax}%
+               {-.5\dimexpr\ht\pgfnodeparttextbox-\dp\pgfnodeparttextbox\relax}%
          \fi%
-         \pgfqpoint%
-            {\dimexpr\pgf at xa\relax}%
-            {\dimexpr.5\pgfdecoratedremainingdistance% = \yradius
-                     -\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance% - aspect
-                     -.5\ht\pgfnodeparttextbox+.5\dp\pgfnodeparttextbox% center there
-             \relax}%
-       \else%
-         \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner xsep}}%
-         \pgfqpoint%
-            {\dimexpr\pgf at xa\relax}%
-            {-.5\dimexpr\ht\pgfnodeparttextbox-\dp\pgfnodeparttextbox\relax}%
-       \fi%
+      }{%
+         \iftikz at decoratepath%
+            % first set \pgfdecoratedremainingdistance appropriately
+            \pgfdecoratedremainingdistance=2\@tempdima%
+            % now perform the transformation
+            \yquant at gappedbrace@calcshift%
+            \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner ysep}+\pgfdecorationsegmentamplitude}%
+            \unless\ifx\tikz at dec@shift\relax%
+               \pgfmathaddtolength\pgf at xa{\expandafter\@secondoftwo\tikz at dec@shift}%
+            \fi%
+            \pgfqpoint%
+               {\dimexpr-\@tempdima% = \xradius
+                        +\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance% - aspect
+                        -.5\wd\pgfnodeparttextbox% center there
+                \relax}%
+               {\dimexpr\@tempdimb-\ht\pgfnodeparttextbox-\pgf at xa\relax}%
+         \else%
+            \pgfmathsetlength\pgf at xa{\pgfkeysvalueof{/pgf/inner ysep}}%
+            \pgfqpoint%
+               {-.5\wd\pgfnodeparttextbox}%
+               {\dimexpr\@tempdimb-\ht\pgfnodeparttextbox-\pgf at xa\relax}%
+         \fi%
+      }%
    }%
+   \savedmacro\ifhorz{%
+      \ifyquanthorz{%
+         \def\ifhorz{\noexpand\@firstoftwo}%
+      }{%
+         \def\ifhorz{\noexpand\@secondoftwo}%
+      }%
+   }%
    % BEGIN_FOLD Operator anchors
    \foreach \anc in {center, north, north east, east, south east, south, south west, west, north west} {%
       \inheritanchor[from=yquant-init]{\anc}%
    }%
-   \anchor{text}{%
-      \stext%
-      \advance \pgf at x by -\xradius\relax%
-   }%
+   \anchor{text}{\stext}%
    \inheritanchorborder[from=yquant-init]%
    % END_FOLD
    % BEGIN_FOLD Path
    \backgroundpath{%
-      \pgfpathmoveto{\pgfqpoint{-\xradius}{\yradius}}%
-      \pgfpathlineto{\pgfqpoint{-\xradius}{-\yradius}}%
+      \ifhorz{%
+         \pgfpathmoveto{\pgfqpoint{-\xradius}{\yradius}}%
+         \pgfpathlineto{\pgfqpoint{-\xradius}{-\yradius}}%
+      }{%
+         \pgfpathmoveto{\pgfqpoint{-\xradius}{\yradius}}%
+         \pgfpathlineto{\pgfqpoint{\xradius}{\yradius}}%
+      }%
       \pgfpointtransformed{\pgfqpoint{\xradius}{\yradius}}%
       \pgf at protocolsizes{\pgf at x}{\pgf at y}%
       \pgfpointtransformed{\pgfqpoint{\xradius}{-\yradius}}% for rotations
@@ -873,8 +1111,8 @@
    }%
    \clippath{%
       \pgfpathrectanglecorners%
-         {\pgfqpoint{-\dimexpr\xradius+.5\pgflinewidth\relax}%
-                    {\dimexpr\yradius\relax}}%
+         {\pgfqpoint{-\dimexpr\xradius\ifhorz{+.5\pgflinewidth}{}\relax}%
+                    {\dimexpr\yradius\ifhorz{}{+.5\pgflinewidth}\relax}}%
          {\pgfqpoint{\dimexpr\xradius\relax}%
                     {-\dimexpr\yradius\relax}}%
    }%

Modified: trunk/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex	2022-02-05 21:22:43 UTC (rev 61896)
+++ trunk/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex	2022-02-05 21:23:01 UTC (rev 61897)
@@ -455,9 +455,10 @@
 }
 
 % #1 is a pgf soft path. We extract the maximum x position at the y position specified in #2 and assign it to \dimen0, which is translated to the user coordinate system.
+% If the circuit is currently vertical, we extract the minimum y position at the x position specified in #2.
 \protected\def\yquant at softpath@extractmaxxat#1#2{%
    \begingroup%
-      \dimen0=-16000pt %
+      \dimen0=\yquant at orientation@minus16000pt %
       \dimen2=#2 %
       \pgftransforminvert%
       \let\pgfsyssoftpath at movetotoken=\yquant at softpath@extractmaxxat at moveto%
@@ -473,7 +474,7 @@
 }
 
 \protected\def\yquant at softpath@extractmaxxat at update#1{%
-   \ifdim\dimen0<#1 %
+   \ifdim\yquant at orientation@plus\dimen0<\yquant at orientation@plus#1 %
       \dimen0=#1 %
    \fi%
 }
@@ -480,37 +481,38 @@
 
 \protected\def\yquant at softpath@extractmaxxat at moveto#1#2{%
    \pgfpointtransformed{\pgfqpoint{#1}{#2}}%
-   \dimen4=\pgf at x %
-   \dimen6=\pgf at y %
+   \dimen4=\yquant at pgf@x %
+   \dimen6=\yquant at pgf@y %
 }
 
 \protected\def\yquant at softpath@extractmaxxat at lineto#1#2{%
    \pgfpointtransformed{\pgfqpoint{#1}{#2}}%
-   \ifyquant at OR{\ifdim\dimen4>\dimen0 }{\ifdim\pgf at x>\dimen0 }{%
+   \ifyquant at OR{\ifdim\yquant at orientation@plus\dimen4>\yquant at orientation@plus\dimen0 }%
+               {\ifdim\yquant at orientation@plus\yquant at pgf@x>\yquant at orientation@plus\dimen0 }{%
       \ifdim\dimen6=\dimen2 %
          \yquant at softpath@extractmaxxat at update{\dimen4}%
       \else%
          \ifdim\dimen6<\dimen2 %
-            \unless\ifdim\pgf at y<\dimen2 %
+            \unless\ifdim\yquant at pgf@y<\dimen2 %
                \expandafter\yquant at softpath@extractmaxxat at update\expandafter{\the\dimexpr%
                   \dimen4+% x0
-                  \dimexpr\pgf at x-\dimen4\relax*% (x1-x0)
-                  \dimexpr\dimen2-\dimen6\relax/\dimexpr\pgf at y-\dimen6\relax% (y-y0)/(y1-y0)
+                  \dimexpr\yquant at pgf@x-\dimen4\relax*% (x1-x0)
+                  \dimexpr\dimen2-\dimen6\relax/\dimexpr\yquant at pgf@y-\dimen6\relax% (y-y0)/(y1-y0)
                \relax}%
             \fi%
          \else%
-            \unless\ifdim\pgf at y>\dimen2 %
+            \unless\ifdim\yquant at pgf@y>\dimen2 %
                \expandafter\yquant at softpath@extractmaxxat at update\expandafter{\the\dimexpr%
                   \dimen4+% x0
-                  \dimexpr\pgf at x-\dimen4\relax*% (x1-x0)
-                  \dimexpr\dimen2-\dimen6\relax/\dimexpr\pgf at y-\dimen6\relax% (y-y0)/(y1-y0)
+                  \dimexpr\yquant at pgf@x-\dimen4\relax*% (x1-x0)
+                  \dimexpr\dimen2-\dimen6\relax/\dimexpr\yquant at pgf@y-\dimen6\relax% (y-y0)/(y1-y0)
                \relax}%
             \fi%
          \fi%
       \fi%
    }\relax%
-   \dimen4=\pgf at x%
-   \dimen6=\pgf at y%
+   \dimen4=\yquant at pgf@x%
+   \dimen6=\yquant at pgf@y%
 }
 
 \protected\def\yquant at softpath@extractmaxxat at curveto@checkx{%
@@ -520,12 +522,12 @@
          % it is. \dimen4: x0, \pgf at xa: xa, \pgf at xb: xb, \pgf at xc: x1
          \begingroup%
             \dimen12=\dimexpr1pt-\dimen11\relax% 1 - t
-            \dimen13=\dimexpr\dimen11*\dimen11/65535\relax% t^2
-            \dimen14=\dimexpr\dimen12*\dimen12/65535\relax% (1 - t)^2
-            \dimen255=\dimexpr\dimen13*\dimen11/65535*\pgf at xc/65535+% t^3 x1
-                              3\dimen13*\dimen12/65535*\pgf at xb/65535+% t^2(1 - t) xb
-                              \dimen14*\dimen12/65535*\dimen4/65535+% (1 - t)^3 x0
-                              3\dimen11*\dimen14/65535*\pgf at xa/65535% 3t(1 - t)^2 xa
+            \dimen13=\dimexpr\dimen11*\dimen11/65536\relax% t^2
+            \dimen14=\dimexpr\dimen12*\dimen12/65536\relax% (1 - t)^2
+            \dimen255=\dimexpr\dimen13*\dimen11/65536*\pgf at xc/65536+% t^3 x1
+                              3\dimen13*\dimen12/65536*\pgf at xb/65536+% t^2(1 - t) xb
+                              \dimen14*\dimen12/65536*\dimen4/65536+% (1 - t)^3 x0
+                              3\dimen11*\dimen14/65536*\pgf at xa/65536% 3t(1 - t)^2 xa
                       \relax%
             \expandafter%
          \endgroup%
@@ -542,60 +544,80 @@
    % Likewise for y:
    %       y0 = \dimen6 (the moveto point), ya = #2, yb = #4, y1 = #6.
    \pgfpointtransformed{\pgfqpoint{#1}{#2}}%
-   \pgf at xa=\pgf at x%
-   \pgf at ya=\pgf at y%
+   \pgf at xa=\yquant at pgf@x%
+   \pgf at ya=\yquant at pgf@y%
    \pgfpointtransformed{\pgfqpoint{#3}{#4}}%
-   \pgf at xb=\pgf at x%
-   \pgf at yb=\pgf at y%
+   \pgf at xb=\yquant at pgf@x%
+   \pgf at yb=\yquant at pgf@y%
    \pgfpointtransformed{\pgfqpoint{#5}{#6}}%
-   \pgf at xc=\pgf at x%
-   \pgf at yc=\pgf at y%
+   \pgf at xc=\yquant at pgf@x%
+   \pgf at yc=\yquant at pgf@y%
    % We first solve the third-order polynomial for t using the y value, then plug it back into the x value.
    % TODO: this is accurate to approx. 3 digits. Can this be improved by reformulating Cardanos formula to involve less divisions?
    \begingroup%
-      % We need so may dimensions that we break with TeX's convention for their use.
-      % for the multiplications with and divisions by dimensions, we exploit that eTeX fuses muldiv to 64 bits. Further note that each dimension has a scaling factor of 65535 for sp<->pt conversion. This is why don't factor out divisions (which would be more efficient, but not give the benefit of 64bit accuracy).
+      % We need so many dimensions that we break with TeX's convention for their use.
+      % for the multiplications with and divisions by dimensions, we exploit that eTeX fuses muldiv to 64 bits. Further note that each dimension has a scaling factor of 65536 for sp<->pt conversion. This is why don't factor out divisions (which would be more efficient, but not give the benefit of 64bit accuracy).
       % a = 3(ya - yb) + (y1 - y0)
       \dimen1=\dimexpr3\pgf at ya-3\pgf at yb+\pgf at yc-\dimen6\relax%
+      \ifdim\dimen1<1pt %
+         \ifdim\dimen1>-1pt %
+            \dimen1=0pt % this is almost a quadratic curve
+         \fi%
+      \fi%
       \ifdim\dimen1=0pt %
          % this is only a quadratic curve!
          % b = 3(y0 - 2ya + yb)
-         \dimen3=\dimexpr3\dimexpr\dimen6-2\pgf at ya+\pgf at yb\relax*65535\relax%
+         \dimen3=3\dimexpr\dimen6-2\pgf at ya+\pgf at yb\relax%
          % c: 3(ya - y0)
-         \dimen5=\dimexpr3\dimexpr\pgf at ya-\dimen6\relax*65535\relax%
+         \dimen5=3\dimexpr\pgf at ya-\dimen6\relax%
          % d: y0 - <desired y>
-         \dimen7=\dimexpr\dimexpr\dimen6-\dimen2\relax*65535\relax%
-         % check the discriminant of the equation
-         \dimen8=\dimexpr\dimen3*\dimen3/65535-4\dimen3*\dimen7/65535\relax%
-         \unless\ifdim\dimen8<0pt%
-            % there are two potential candidates, (-c +- sqrt(c^2 - 4b d))/2b
-            \pgfmathsqrt@{\the\dimen8\@gobbletwo}%
-            \dimen11=\dimexpr\dimexpr-\dimen5+\pgfmathresult pt\relax*65535/%
-                             \dimexpr2\dimen3\relax\relax%
-            \yquant at softpath@extractmaxxat at curveto@checkx%
-            \dimen11=\dimexpr\dimexpr-\dimen5-\pgfmathresult pt\relax*65535/%
-                             \dimexpr2\dimen3\relax\relax%
-            \yquant at softpath@extractmaxxat at curveto@checkx%
-         \fi%
+         \dimen7=\dimexpr\dimen6-\dimen2\relax%
+         \ifdim\dimen3<1pt %
+            \expandafter\@firstofone%
+         \else%
+            \expandafter\@secondoftwo%
+         \fi{%
+            \ifdim\dimen3>-1pt %
+               % this is almost a linear curve!
+               \dimen11=\dimexpr-\dimen7*65536/\dimen5\relax%
+               \yquant at softpath@extractmaxxat at curveto@checkx%
+               \expandafter\@gobble%
+            \else%
+               \expandafter\@firstofone%
+            \fi%
+         }{%
+            % check the discriminant of the equation
+            \dimen8=\dimexpr\dimen3*\dimen3/65536-4\dimen3*\dimen7/65536\relax%
+            \unless\ifdim\dimen8<0pt%
+               % there are two potential candidates, (-c +- sqrt(c^2 - 4b d))/2b
+               \pgfmathsqrt@{\the\dimen8\@gobbletwo}%
+               \dimen11=\dimexpr\dimexpr-\dimen5+\pgfmathresult pt\relax*65536/%
+                                \dimexpr2\dimen3\relax\relax%
+               \yquant at softpath@extractmaxxat at curveto@checkx%
+               \dimen11=\dimexpr\dimexpr-\dimen5-\pgfmathresult pt\relax*65536/%
+                                \dimexpr2\dimen3\relax\relax%
+               \yquant at softpath@extractmaxxat at curveto@checkx%
+            \fi%
+         }%
       \else%
          % We will simplify by directly dividing all coefficients by a
          % b = 3(y0 - 2ya + yb)
-         \dimen3=\dimexpr3\dimexpr\dimen6-2\pgf at ya+\pgf at yb\relax*65535/\dimen1\relax%
+         \dimen3=\dimexpr3\dimexpr\dimen6-2\pgf at ya+\pgf at yb\relax*65536/\dimen1\relax%
          % c: 3(ya - y0)
-         \dimen5=\dimexpr3\dimexpr\pgf at ya-\dimen6\relax*65535/\dimen1\relax%
+         \dimen5=\dimexpr3\dimexpr\pgf at ya-\dimen6\relax*65536/\dimen1\relax%
          % d: y0 - <desired y>
-         \dimen7=\dimexpr\dimexpr\dimen6-\dimen2\relax*65535/\dimen1\relax%
+         \dimen7=\dimexpr\dimexpr\dimen6-\dimen2\relax*65536/\dimen1\relax%
          % Note that now our a value (\dimen1) is no longer needed, it is one.
          % check the discriminant of the equation
          % Q = (3c - b^2)/9
-         \dimen8=\dimexpr\dimexpr3\dimen5-\dimen3*\dimen3/65535\relax/9\relax%
+         \dimen8=\dimexpr\dimexpr3\dimen5-\dimen3*\dimen3/65536\relax/9\relax%
          % R = (9bc - 27d - 2b^3)/54 = bc/6 - d/2 - b^3/27
-         \dimen9=\dimexpr\dimen3*\dimen5/393210-% 6*65535
+         \dimen9=\dimexpr\dimen3*\dimen5/393216-% 6*65536
                           .5\dimen7-%
-                          \dimen3*\dimen3/65535*\dimen3/1769445% 27*65535
+                          \dimen3*\dimen3/65536*\dimen3/1769472% 27*65536
                   \relax%
          % D = Q^3 + R^2
-         \dimen10=\dimexpr\dimen8*\dimen8/65535*\dimen8/65535+\dimen9*\dimen9/65535\relax%
+         \dimen10=\dimexpr\dimen8*\dimen8/65536*\dimen8/65536+\dimen9*\dimen9/65536\relax%
          \ifdim\dimen10>0pt %
             % only one real root: y_1 = S + T - b/3a
             % S = cbrt(R + sqrt(Q^3 + R^2))
@@ -641,7 +663,7 @@
                \pgfmathsqrt@{\the\dimexpr-\dimen10\relax\@gobbletwo}%
                \dimen10=\pgfmathresult pt %
                % Let us first find the absolute value
-               \dimen12=\dimexpr\dimen9*\dimen9/65535+\dimen10*\dimen10/65535\relax%
+               \dimen12=\dimexpr\dimen9*\dimen9/65536+\dimen10*\dimen10/65536\relax%
                \pgfmathpow@{\the\dimen12\@gobbletwo}{.1666666667}%
                \dimen12=\pgfmathresult pt%
                % then we need 1/3 the argument of R + i sqrt(|D|).
@@ -676,15 +698,15 @@
 \protected\def\yquant at softpath@extractmaxxat at rectto#1#2\pgfsyssoftpath at rectsizetoken#3#4{%
    % #1: lower left x, #2: lower left y, #3: width, #4: height
    \pgfpointtransformed{\pgfqpoint{#1}{#2}}%
-   \pgf at xa=\pgf at x%
-   \pgf at ya=\pgf at y%
+   \pgf at xa=\yquant at pgf@x%
+   \pgf at ya=\yquant at pgf@y%
    \pgfpointtransformed{\pgfqpoint{\dimexpr#1+#3\relax}{\dimexpr#2+#4\relax}}%
    % (\pgf at xa, \pgf at ya) one corner, (\pgf at x, \pgf at y) other corner
-   \ifdim\pgf at y>\pgf at ya %
+   \ifdim\yquant at pgf@y>\pgf at ya %
       \unless\ifdim\pgf at ya>\dimen2 %
-         \unless\ifdim\pgf at y<\dimen2 %
-            \ifdim\pgf at x>\pgf at xa %
-               \yquant at softpath@extractmaxxat at update\pgf at x%
+         \unless\ifdim\yquant at pgf@y<\dimen2 %
+            \ifdim\yquant at orientation@plus\yquant at pgf@x>\yquant at orientation@plus\pgf at xa %
+               \yquant at softpath@extractmaxxat at update\yquant at pgf@x%
             \else%
                \yquant at softpath@extractmaxxat at update\pgf at xa%
             \fi%
@@ -692,9 +714,9 @@
       \fi%
    \else%
       \unless\ifdim\pgf at ya<\dimen2 %
-         \unless\ifdim\pgf at y>\dimen2 %
-            \ifdim\pgf at x>\pgf at xa %
-               \yquant at softpath@extractmaxxat at update\pgf at x%
+         \unless\ifdim\yquant at pgf@y>\dimen2 %
+            \ifdim\yquant at orientation@plus\yquant at pgf@x>\yquant at orientation@plus\pgf at xa %
+               \yquant at softpath@extractmaxxat at update\yquant at pgf@x%
             \else%
                \yquant at softpath@extractmaxxat at update\pgf at xa%
             \fi%

Modified: trunk/Master/texmf-dist/tex/latex/yquant/yquant.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/yquant/yquant.sty	2022-02-05 21:22:43 UTC (rev 61896)
+++ trunk/Master/texmf-dist/tex/latex/yquant/yquant.sty	2022-02-05 21:23:01 UTC (rev 61897)
@@ -15,7 +15,7 @@
 %
 % The Current Maintainer of this work is Benjamin Desef.
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{yquant}[2021/12/28 v0.6 Yet another quantum circuit library for LaTeX]
+\ProvidesPackage{yquant}[2022/02/05 v0.7 Yet another quantum circuit library for LaTeX]
 
 \RequirePackage{etoolbox}[2018/02/11]
 \RequirePackage{tikz}[2015/08/29]
@@ -37,8 +37,11 @@
 \fi
 
 \newif\ifyquantdebug
+\pgfdeclarelayer{wires}
+\pgfdeclarelayer{behindwires}
+\input yquant-tools.tex
+\input yquant-shapes.tex
 \input yquant-config.tex
-\input yquant-tools.tex
 \input yquant-registers.tex
 \input yquant-env.tex
 \input yquant-langhelper.tex
@@ -45,7 +48,6 @@
 \input yquant-circuit.tex
 \input yquant-prepare.tex
 \input yquant-draw.tex
-\input yquant-shapes.tex
 \input yquant-lang.tex
 
 % usually, \\ is robust; but when using \centering, it is \let to \@centercr, which is not robust (probably because this happens only when not protecting). Fix this, so that \\ does not require \protect if a centered circuit is drawn.

Modified: trunk/Master/texmf-dist/tex/latex/yquant/yquantlanguage-groups.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/yquant/yquantlanguage-groups.sty	2022-02-05 21:22:43 UTC (rev 61896)
+++ trunk/Master/texmf-dist/tex/latex/yquant/yquantlanguage-groups.sty	2022-02-05 21:23:01 UTC (rev 61897)
@@ -15,9 +15,9 @@
 %
 % The Current Maintainer of this work is Benjamin Desef.
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{yquantlanguage-groups}[2021/08/14 v0.6 yquant-groups]
+\ProvidesPackage{yquantlanguage-groups}[2022/01/07 v0.7 yquant-groups]
 
-\RequirePackage{yquant}[2021/12/24]
+\RequirePackage{yquant}[2022/01/07]
 
 % BEGIN_FOLD Config
 \newif\ifyquantgroup at config@aligned
@@ -39,7 +39,11 @@
          }%
       \fi%
    },%
-   operators/every group equals/.style={shape=yquant-rectangle, align=center, inner xsep=1mm, x radius=2mm, y radius=2.47mm}
+   operators/every group equals/.style={%
+      shape=yquant-rectangle, align=center,
+      anchor/.expanded=\ifyquanthorz{center}{north west},%
+      inner xsep=1mm, x radius=2mm, y radius=2.47mm%
+   }
 }
 \def\yquantgroup at config@lineseparation{5mm}%
 % END_FOLD
@@ -66,7 +70,7 @@
    \let\equals=\yquantgroup at equals%
    \let\shiftright=\yquantgroup at shiftright%
    \let\\=\yquantgroup at linebreak%
-   % This is a bit inconsistent, we should check \iftikz at inside@picture, but this is no longer appropriately set since at pgf 3.1.2.
+   % This is a bit inconsistent, we should check \iftikz at inside@picture, but this is no longer appropriately set since at least pgf 3.1.2.
    \let\ifyquantgroup at inpicture=\ifpgfpicture%
    \pgfkeysgetvalue{/yquant/preamble}\yquantgroup at save@preamble%
    \ifpgfpicture%
@@ -127,6 +131,10 @@
 
 % BEGIN_FOLD Register declaration
 \protected\long\def\yquantgroup at registers#1{%
+   \def\registers{%
+      \PackageError{yquant.sty}{Double invocation of \string\registers}%
+                   {All registers must be specified once at the beginning of the group. Multiple declarations or later additions are not allowed.}%
+   }%
    \begingroup%
       \gdef\yquantgroup at registers@text{#1}%
       \let\yquantgroup at save@lang at create@parse=\yquant at lang@create at parse@name%
@@ -152,10 +160,6 @@
             \yquant at env@end%
          \endpgfinterruptboundingbox%
       }%
-      \def\registers{%
-         \PackageError{yquant.sty}{Double invocation of \string\registers}%
-                      {All registers must be specified once at the beginning of the group. Multiple declarations or later additions are not allowed.}%
-      }%
       \unless\ifx\yquantgroup at registers@text\empty%
          \csxappto{\yquantgroup at prefix import@\csname\yquantgroup at prefix registers\endcsname}{%
             \unexpanded\expandafter{\yquantgroup at registers@text}%
@@ -248,14 +252,25 @@
    \fi%
    % since \registers is in subcircuit mode, that the existence of the macro implies that it is greater than zero
    \ifdef\yquant at prefix{%
-      % We already started the yquant environment - but this means that potentially, we could have changed our wire styles. The underlying subcircuit architecture will preserve these changes, but since in our context, we treat the circuits as independent, this is not the desired behavior: remove all styles.
-      \yquant at for \i := 1 to \csname\yquant at prefix registers\endcsname {%
-         % we don't really need to flush a wire, since it is discarded anyway
-         \csxappto{\yquant at prefix draw}{%
-            \yquant at register@set at style{\i}{}%
+      \ifyquanthorz{%
+         % We already started the yquant environment - but this means that potentially, we could have changed our wire styles. The underlying subcircuit architecture will preserve these changes, but since in our context, we treat the circuits as independent, this is not the desired behavior: remove all styles.
+         \yquant at for \i := 1 to \csname\yquant at prefix registers\endcsname {%
+            % we don't really need to flush a wire, since it is discarded anyway
+            \csxappto{\yquant at prefix draw}{%
+               \yquant at register@set at style{\i}{}%
+            }%
          }%
+         \@gobble%
+      }{%
+         % We already started the yquant environment, but it was a vertical one. We are unable to perform wire alignment with vertical circuits. We want to place the next circuit to its right, which means that we acutually need to end the environment.
+         \expandafter%
+         \yquant at env@end%
+         \expandafter\def\expandafter\yquantgroup at currentxpos\expandafter{\the\dimexpr%
+            \pgf at picmaxx+\yquant at config@operator at sep%
+         }%
       }%
-   }{%
+   }\@firstofone%
+   {%
       \yquant at env@begin[/tikz/shift={(\yquantgroup at currentxpos, \yquantgroup at currentypos)}]%
          % we re-create all the outer registers, but without the names.
          % sync with yquant-registers/\yquant at register@define
@@ -377,18 +392,48 @@
 }
 
 \protected\long\def\yquantgroup at equals@ii#1[#2]{%
-   \yquantgroup at startenvironments%
-   \ifx0#1%
-      \yquant group\space equals {#2} (-);%
-   \else%
+   \unless\ifx0#1%
       \numgdef\yquantgroup at alignments{\yquantgroup at alignments+1}%
-      % hopefully no prefixes/suffixes are installed - if we reset them here, it will also reset them for the content, which we don't want to do; but this will then give an error when we try to access the node. Probably never a problem.
-      \yquant [name=yquantgroup at internal@alignment@\yquantgroup at alignments]%
-         group\space equals {#2} (-);%
+   \fi%
+   \ifyquanthorz{%
+      \yquantgroup at startenvironments%
+      \ifx0#1%
+         \yquant group\space equals {#2} (-);%
+      \else%
+         % hopefully no prefixes/suffixes are installed - if we reset them here, it will also reset them for the content, which we don't want to do; but this will then give an error when we try to access the node. Probably never a problem.
+         \yquant [name=yquantgroup at internal@alignment@\yquantgroup at alignments]%
+            group\space equals {#2} (-);%
+      \fi%
+   }{%
+      % in vertical mode, we must be very careful: we cannot place the box in a circuit, as it would go under the others. In principle, it would be nice to place the equals vertically centered to the right of the last circuit, but the circuits may well have different vertical extents, so a centering does not make sense. Therefore, we place it to the top.
+      \ifdefined\yquant at prefix%
+         \edef\yquantgroup at handlesize{%
+            \global\pgf at picmaxx=-16000pt %
+            \yquant at env@end%
+            \edef\noexpand\yquantgroup at currentxpos{%
+               \noexpand\the\dimexpr\pgf at picmaxx+%
+                                    \noexpand\yquant at config@operator at sep\relax%
+            }%
+            \noexpand\ifdim\pgf at picmaxx<\the\pgf at picmaxx\space%
+               \global\pgf at picmaxx=\the\pgf at picmaxx\space%
+            \noexpand\fi%
+         }%
+         \yquantgroup at handlesize%
+      \fi%
+      \node[/yquant/operators/every group equals] (yquantnode) at (\yquantgroup at currentxpos, \yquantgroup at currentypos) {#2};
+      \unless\ifx0#1%
+         \pgfcoordinate{yquantgroup at internal@alignment@\yquantgroup at alignments}%
+                       {\pgfqpoint{\dimexpr\yquantgroup at currentxpos+\yquant at config@operator at sep}%
+                                  {\yquantgroup at currentypos}}%
+      \fi%
+      \pgfpointanchor{yquantnode}{north east}
+      \dimdef\yquantgroup at currentxpos{\pgf at x+\yquant at config@operator at sep}%
+   }%
+   \unless\ifx0#1%
       \ifnum\yquantgroup at alignments>1 %
-         \pgfcoordinate{yquantgroup at internal@alignment@\the\numexpr\yquantgroup at alignments-1\relax}{west}%
+         \pgfpointanchor{yquantgroup at internal@alignment@\the\numexpr\yquantgroup at alignments-1\relax}{west}%
          \pgf at xa=\pgf at x%
-         \pgfcoordinate{yquantgroup at internal@alignment@\yquantgroup at alignments}{west}%
+         \pgfpointanchor{yquantgroup at internal@alignment@\yquantgroup at alignments}{west}%
          \unless\ifdim\pgf at x>\pgf at xa%
             \PackageError{yquant.sty}{Invalid alignment mark position}%
                          {The desired alignment mark position would be to the left of an already existing mark.}%
@@ -431,7 +476,7 @@
    }%
    \ifx1#1%
       \ifnum\yquantgroup at alignments>0 %
-         \pgfcoordinate{yquantgroup at internal@alignment@\yquantgroup at alignments}{west}%
+         \pgfpointanchor{yquantgroup at internal@alignment@\yquantgroup at alignments}{west}%
          \unless\ifdim\dimexpr\yquantgroup at currentxpos+\yquant at config@operator at sep\relax>\pgf at x%
             \PackageError{yquant.sty}{Invalid alignment mark position}%
                          {The desired alignment mark position would be to the left of an already existing mark.}%



More information about the tex-live-commits mailing list.