summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/yquant/yquant-env.tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-12-28 22:48:51 +0000
committerKarl Berry <karl@freefriends.org>2021-12-28 22:48:51 +0000
commit3a8f490ec582c95b7adc117b1f8d3debb60b7f88 (patch)
tree555a386e2cd67bb1f172b2a5d65bbfe983ff60df /Master/texmf-dist/tex/latex/yquant/yquant-env.tex
parentad334beadbb0679b7608a2d9612050802d5273d1 (diff)
yquant (28dec21)
git-svn-id: svn://tug.org/texlive/trunk@61429 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/yquant/yquant-env.tex')
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-env.tex303
1 files changed, 289 insertions, 14 deletions
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-env.tex b/Master/texmf-dist/tex/latex/yquant/yquant-env.tex
index c6e9f52b01c..f26919c8d16 100644
--- a/Master/texmf-dist/tex/latex/yquant/yquant-env.tex
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-env.tex
@@ -56,7 +56,7 @@
\edef\yquant@prefix{yquant@env\the\yquant@env @}%
\ifnum\yquant@env=1 %
\yquantmeasuringtrue%
- \yquant@env@substikz#1%
+ \yquant@env@substitute%
\global\cslet{\yquant@prefix parameters}\empty%
\else%
\let\yquant@lang@reset@attrs@inputoutput=\yquant@lang@reset@attrs@inputoutput@subcircuit%
@@ -529,8 +529,29 @@
\pgftransformreset%
}
+\protected\def\yquant@env@protectidx{%
+ \ifundef\idx{%
+ \let\idx=\yquant@protectedempty%
+ }\relax%
+ \ifundef\reg{%
+ \let\reg=\yquant@protectedempty%
+ }\relax%
+ \ifundef\regidx{%
+ \let\regidx=\yquant@protectedempty%
+ }\relax%
+ \ifundef\len{%
+ \let\len=\yquant@protectedempty%
+ }\relax%
+}
+
+\let\yquant@env@substitutions=\empty
+\def\yquant@env@substitute{%
+ \forlistloop\@firstofone\yquant@env@substitutions%
+}
+
% substitute the tikz commands (defined in \tikz@installcommands) so that they can be arbitrarily interleaved with yquant code. We patch \path, \scope, \endscope, \stopscope, their internal complements, and also patch \yquantset.
-\protected\def\yquant@env@substikz#1{%
+\listadd\yquant@env@substitutions\yquant@env@substikz
+\protected\def\yquant@env@substikz{%
% \tikz@path@do@at@end is called after a path. Hence, it is an ideal candidate to re-invoke \yquant@env@scan. However, it is by default defined to be \tikz@lib@scope@check, and we need this definition for the scopes library to work correctly. But since \tikz@lib@scope@check is also called after a scope and the end of a scope, this is even better. Yet, we need to check whether the scopes library is present or not.
\let\yquant@env@substikz@scopecheck=\tikz@lib@scope@check%
\ifx\tikz@lib@scope@check\pgfutil@empty%
@@ -547,25 +568,31 @@
\protected@csxappto{\yquant@prefix draw}{%
\noexpand\path##1;%
}%
- #1%
+ \yquant@env@scan%
}%
% no need for \scoped, because it internally calls \scope.
% We need to hack into \scope, but this is a bit tricky due to its argument handling. In order to get all optional arguments, including the possible animations library, correct, we change \tikz@scope@opt.
\ifdefined\tikz@scope@opt%
\let\yquant@env@substikz@scope=\tikz@scope@opt%
\def\tikz@scope@opt[##1]{%
- \protected@csxappto{\yquant@prefix draw}{%
- \noexpand\tikz@scope@env[{##1}]%
- }%
+ \begingroup%
+ \yquant@env@protectidx% scope options may contain \idx, \reg, and \regidx
+ \protected@csxappto{\yquant@prefix draw}{%
+ \noexpand\tikz@scope@env[{##1}]%
+ }%
+ \endgroup%
\yquant@env@substikz@scope[{##1}]%
}%
\else%
% this is for the arXiv, which has a very outdated version of TikZ
\let\yquant@env@substikz@scope=\tikz@@scope@env%
\def\tikz@@scope@env[##1]{%
- \protected@csxappto{\yquant@prefix draw}{%
- \noexpand\tikz@@scope@env[{##1}]%
- }%
+ \begingroup%
+ \yquant@env@protectidx% scope options may contain \idx, \reg, and \regidx
+ \protected@csxappto{\yquant@prefix draw}{%
+ \noexpand\tikz@@scope@env[{##1}]%
+ }%
+ \endgroup%
\yquant@env@substikz@scope[{##1}]%
}%
\fi%
@@ -580,14 +607,39 @@
\let\stopscope=\endscope%
% We define \yquantset as a pgfkeys-like macro. Anything else would deteriorate performance badly, as \pgfkeys, \pgfqkeys, or \tikzset are used a lot internally.
\protected\def\yquantset##1{%
- \protected@csxappto{\yquant@prefix draw}{%
- \noexpand\pgfqkeys{/yquant}{##1}%
- }%
+ \begingroup%
+ \yquant@env@protectidx% yquant options may contain \idx, \reg, and \regidx
+ \protected@csxappto{\yquant@prefix draw}{%
+ \noexpand\pgfqkeys{/yquant}{##1}%
+ }%
+ \endgroup%
\pgfqkeys{/yquant}{##1}%
\yquant@env@scan%
}%
}
+\listadd\yquant@env@substitutions\yquant@env@secondpass
+\protected\def\yquant@env@secondpass{%
+ \protected\long\def\yquantsecondpass##1{%
+ \csgappto{\yquant@prefix draw}{##1}%
+ \yquant@env@scan%
+ }%
+ \protected\long\def\yquantesecondpass##1{%
+ \protected@csxappto{\yquant@prefix draw}{##1}%
+ \yquant@env@scan%
+ }%
+ \protected\long\def\yquantescape##1{%
+ ##1%
+ \protected@csxappto{\yquant@prefix draw}{##1}%
+ \yquant@env@scan%
+ }%
+ \protected\long\def\yquanteescape##1{%
+ ##1%
+ \csgappto{\yquant@prefix draw}{##1}%
+ \yquant@env@scan%
+ }%
+}
+
% Scan until the next non-space token is found and execute it as a csname
\def\yquant@env@scan{%
\begingroup%
@@ -604,6 +656,230 @@
\yquant@env@scan%
}
+\ifdefined\beamer@masterdecode
+ \expandafter\@firstoftwo
+\else
+ \expandafter\@secondoftwo
+\fi{%
+ \protected\def\yquant@env@check@findmacro{%
+ % we only put the beamer macros in here that effectively remove things from the input stream. Everything that is typeset in a special way will end the group
+ \ifx\yquant@env@nextchar\only%
+ \let\next=\yquant@env@beamer@only%
+ \else%
+ \ifx\yquant@env@nextchar\alt%
+ \let\next=\yquant@env@beamer@alt%
+ \else%
+ \ifx\yquant@env@nextchar\temporal%
+ \let\next=\yquant@env@beamer@temporal%
+ \else%
+ \ifx\yquant@env@nextchar\note%
+ \let\next=\yquant@env@beamer@note%
+ \else%
+ % in principle: \endgroup for all in here, but need to preserve \yquant@env@nextchar
+ \ifx\yquant@env@nextchar\uncover%
+ \endgroup%
+ \let\next=\yquant@env@beamer@uncover%
+ \else%
+ \ifx\yquant@env@nextchar\visible%
+ \endgroup%
+ \let\next=\yquant@env@beamer@visible%
+ \else%
+ \ifx\yquant@env@nextchar\invisible%
+ \endgroup%
+ \let\next=\yquant@env@beamer@invisible%
+ \else%
+ \ifx\yquant@env@nextchar\onslide%
+ \endgroup%
+ \let\next=\yquant@env@beamer@onslide%
+ \else%
+ \ifx\yquant@env@nextchar\pause%
+ \endgroup%
+ \let\next=\yquant@env@beamer@pause%
+ \else%
+ \ifx\yquant@env@nextchar\yquant@env@beamer@checkifactive%
+ \endgroup%
+ \let\yquant@env@beamer@checkifactive@true=\relax%
+ \let\next=\relax%
+ \else%
+ \endgroup%
+ \let\next=\relax%
+ \fi%
+ \fi%
+ \fi%
+ \fi%
+ \fi%
+ \fi%
+ \fi%
+ \fi%
+ \fi%
+ \fi%
+ }%
+
+ \listadd\yquant@env@substitutions\yquant@env@substbeamer
+ \protected\def\yquant@env@substbeamer{%
+ \long\def\yquant@env@beamer@only@arga<##1>##2{%
+ \beamer@alt<##1>{\yquant@env@contscan##2}{\yquant@env@contscan}%
+ }%
+ \long\def\yquant@env@beamer@alt@arga<##1>##2##3{%
+ \beamer@alt<##1>{\yquant@env@contscan##2}{\yquant@env@contscan##3}%
+ }%
+ \protected\long\def\yquant@env@beamer@temporal\temporal<##1>##2##3##4{%
+ \temporal<##1>{\yquant@env@contscan##2}{\yquant@env@contscan##3}{\yquant@env@contscan##4}%
+ }%
+ % There's no need for the fakeinvisible or spacingcover macros, since we are within TikZ anyway
+ \mode<presentation>{
+ \protected\long\def\yquant@env@beamer@visibilitymacros##1##2##3##4{%
+ \yquant@env@beamer@visibilitymacros@flip##1%
+ \beamer@altget%
+ {\yquant@env@scan##3}%
+ {%
+ \begingroup%
+ \letcs\yquant@env@beamer@olddraw{\yquant@prefix draw}%
+ \global\cslet{\yquant@prefix draw}\empty%
+ \undef\yquant@env@beamer@checkifactive@true%
+ ##2{\yquant@env@scan##3\yquant@env@beamer@checkifactive}%
+ \csxdef{\yquant@prefix draw}{%
+ \unexpanded\expandafter{\yquant@env@beamer@olddraw}%
+ \ifx0##1%
+ \noexpand\beamer@alt##4{}%
+ \else%
+ \noexpand\beamer@only##4%
+ \fi%
+ {%
+ \unexpanded{##2}{%
+ \unexpanded\expandafter\expandafter\expandafter{\csname\yquant@prefix draw\endcsname}%
+ }%
+ }%
+ }%
+ \expandafter%
+ \endgroup%
+ \ifdefined\yquant@env@beamer@checkifactive@true%
+ \expandafter\@firstofone%
+ \else%
+ \expandafter\@gobble%
+ \fi%
+ \yquant@env@scan%
+ }%
+ ##4%
+ }
+ \newcommand<>\yquant@env@beamer@onslidenoargs[2]{%
+ \let\yquant@env@beamer@onslideappdraw=\empty%
+ \appto\yquant@env@beamer@onslideappdraw{\beamer@endpause}%
+ \yquant@for \i := 1 to \csname\yquant@prefix registers\endcsname{%
+ \eappto\yquant@env@beamer@onslideappdraw{\noexpand\yquant@circuit@flushwire{\i}}%
+ }%
+ \csxappto{\yquant@prefix draw}%
+ {\unexpanded\expandafter{\yquant@env@beamer@onslideappdraw}}%
+ \beamer@alt##3%
+ {\csgappto{\yquant@prefix draw}{%
+ \global\let\beamer@endpause=\empty%
+ }%
+ \yquant@env@scan}%
+ {\csgappto{\yquant@prefix draw}{%
+ ##1%
+ \gdef\beamer@endpause{##2}%
+ }%
+ \yquant@env@scan%
+ }%
+ }
+ % This is \beamer@inframenote, but we are always in a frame if we an in yquant
+ \newcommand<>{\yquant@env@beamer@note@}[2][]{%
+ \beamer@inframenote##3[{##1}]{##2}%
+ \yquant@env@contscan%
+ }
+ }%
+ \mode<article>{
+ \newcommand<>\yquant@env@beamer@uncover@[1]{%
+ \beamer@alt##2{\yquant@env@scan##1}{\yquant@env@scan}%
+ }
+ % we don't need \yquant@env@beamer@visible@ in this mode, since \uncover and \visible are equal (w.r.t. \ifx), so we will always end up with the \uncover path
+ \newcommand<>\yquant@env@beamer@invisible@[1]{%
+ \beamer@alt##2{\yquant@env@scan}{\yquant@env@scan##1}%
+ }
+ \newcommand<>{\yquant@env@beamer@note@}[2][]{\yquant@env@contscan}
+ \newrobustcmd\yquant@env@beamer@pause@[1][]{\yquant@env@scan}
+ }
+ \protected\def\yquant@env@beamer@onslide@{%
+ \@ifstar{\yquant@env@scan\only}%
+ {\@ifnextchar+{\expandafter\yquant@env@beamer@visibleonslide\@gobble}%
+ {\yquant@env@beamer@mainonslide}%
+ }%
+ }%
+ }
+
+ \protected\def\yquant@env@beamer@only\only{\@ifnextchar<{\yquant@env@beamer@only@arga}%
+ {\yquant@env@beamer@only@argb}}%
+ \long\def\yquant@env@beamer@only@argb#1{%
+ \beamer@ifnextcharospec{\yquant@env@beamer@only@argb@{#1}}{#1}%
+ }%
+ \long\def\yquant@env@beamer@only@argb@#1<#2>{%
+ \yquant@env@beamer@only@arga<#2>{#1}%
+ }%
+ \protected\def\yquant@env@beamer@alt\alt{\@ifnextchar<{\yquant@env@beamer@alt@arga}%
+ {\yquant@env@beamer@alt@argb}}%
+ \long\def\yquant@env@beamer@alt@argb#1#2{%
+ \beamer@ifnextcharospec{\yquant@env@beamer@alt@argb@{#1}{#2}}{#1}%
+ }
+ \long\def\yquant@env@beamer@alt@argb@#1#2<#3>{%
+ \yquant@env@beamer@alt@arga<#3>{#1}{#2}%
+ }
+
+ \def\yquant@env@beamer@checkifactive{%
+ % this should not compare to anything else, but should also not give an error on expansion
+ \yquant@env@beamer@checkifactive@%
+ }
+ \let\yquant@env@beamer@checkifactive@=\empty%
+ \def\yquant@env@beamer@note\note{\yquant@env@beamer@note@}
+ % note: in article mode, the definitions of \uncover and \visible are identical, hence we will mistake \visible for \uncover (which is checked first); therefore, \yquant@env@beamer@uncover may be followed by \uncover or \visible, just take an arbitrary argument.
+ \def\yquant@env@beamer@uncover#1{\yquant@env@beamer@uncover@}
+ \def\yquant@env@beamer@visible\visible{\yquant@env@beamer@visible@}
+ \def\yquant@env@beamer@invisible\invisible{\yquant@env@beamer@invisible@}
+ \def\yquant@env@beamer@onslide\onslide{\yquant@env@beamer@onslide@}
+ \def\yquant@env@beamer@pause\pause{\yquant@env@beamer@pause@}
+
+ \mode<presentation>{
+ \long\def\yquant@env@beamer@visibilitymacros@flip#1#2#3#4{%
+ \ifx1#1%
+ \expandafter\@firstoftwo%
+ \else%
+ \expandafter\@secondoftwo%
+ \fi%
+ {#2{#4}{#3}}{#2{#3}{#4}}%
+ }
+ \newcommand<>\yquant@env@beamer@uncover@[1]{%
+ \yquant@env@beamer@visibilitymacros0\beamer@makecovered{#1}{#2}%
+ }
+ \newcommand<>\yquant@env@beamer@visible@[1]{%
+ \yquant@env@beamer@visibilitymacros0\beamer@reallymakeinvisible{#1}{#2}%
+ }
+ \newcommand<>\yquant@env@beamer@invisible@[1]{%
+ \yquant@env@beamer@visibilitymacros1\beamer@reallymakeinvisible{#1}{#2}%
+ }
+ \newrobustcmd\yquant@env@beamer@pause@[1][]{%
+ \ifblank{#1}%
+ {\stepcounter{beamerpauses}}%
+ {\setcounter{beamerpauses}{#1}}%
+ \yquant@env@beamer@onslidenoargs<\value{beamerpauses}->\beamer@startcovered\beamer@endcovered%
+ }
+ }
+ \mode<article>{
+ \newcommand<>\yquant@env@beamer@onslidenoargs[2]{}
+ }
+ \newcommand<>{\yquant@env@beamer@visibleonslide}{%
+ \@ifnextchar\bgroup{\yquant@env@beamer@visible@#1}%
+ {\yquant@env@beamer@onslidenoargs#1\beamer@begininvisible\beamer@endinvisible}%
+ }
+ \newcommand<>{\yquant@env@beamer@mainonslide}{%
+ \@ifnextchar\bgroup{\yquant@env@beamer@uncover@#1}%
+ {\yquant@env@beamer@onslidenoargs#1\beamer@startcovered\beamer@endcovered}%
+ }
+}{%
+ \def\yquant@env@check@findmacro{%
+ \endgroup%
+ \let\next=\relax%
+ }
+}%
+
\protected\def\yquant@env@check@{%
\let\next=\relax%
% Here we assume standard catcodes for A and [, but our language specification also requires this implicitly.
@@ -625,8 +901,7 @@
\let\next=\yquant@env@gobblepar%
\else%
\ifcat\noexpand\yquant@env@nextchar\relax%
- \endgroup%
- \let\next=\relax%
+ \yquant@env@check@findmacro%
\else%
\PackageError{yquant.sty}%
{Invalid yquant syntax: `\meaning\yquant@env@nextchar'}%