The quantikz
code is, in my opinion, badly written.
Let's consider the definition of \qwbundle
:
\newcommand{\qwbundle}[2][]{%
%\ifthenelse{\the\pgfmatrixcurrentcolumn=2}{%do the strikethrough
\pgfkeys{/quantikz/gates/.cd,style=,Strike Width=0.08cm,Strike Height=0.12cm,#1}
\pgfkeysgetvalue{/quantikz/gates/style}{\style}
\pgfkeysgetvalue{/quantikz/gates/Strike Width}{\sw}
\pgfkeysgetvalue{/quantikz/gates/Strike Height}{\sh}
\edef\arg{strike arrow={\sw}{\sh}{#2},\style}
\expandafter\arrow\expandafter[\arg,phantom]{l}%
}
If the document, by chance, has definitions for \sh
, \sw
or \style
, these commands would be overridden in the scope of the cell containing \qwbundle
. By pure chance, \qwbundle{\arg z}
would produce the expected result.
The same fate would be, with various possible problems, for \wiretype
, \length
, \tstyle
, \lstyle
, \styling
, \yshift
, \tempstyle
, \n
, \m
, \mn
, \mp
, \lim
, \newcom
, \i
, \options
, \k
, \opts
, \top
, \bottom
, \sstyle
, \slstyle,
\col,
\title,
\newoptions,
\quantwires,
\background,
\fit`.
Worse, the code uses \DeclareExpandableDocumentCommand
for
\phase \control \ocontrol \targ \targX \meter \metercw \measuretab
\meterD \inputD \measure \trash \ground \swap \gate \ghost
which means that if a user loads a package defining such commands prior to quantikz
, the meaning of those commands would be silently overridden. By the way, most of those commands aren't really expandable.
For your specific problem, you may fix the issue by protecting the argument from full expansion.
\documentclass{article}
\usepackage{quantikz}
\makeatletter
\renewcommand{\qwbundle}[2][]{%
\pgfkeys{/quantikz/gates/.cd,style=,Strike Width=0.08cm,Strike Height=0.12cm,#1}%
\pgfkeysgetvalue{/quantikz/gates/style}{\qz@style}%
\pgfkeysgetvalue{/quantikz/gates/Strike Width}{\qz@sw}%
\pgfkeysgetvalue{/quantikz/gates/Strike Height}{\qz@sh}%
\expanded{%
\noexpand\arrow[strike arrow={\qz@sw}{\qz@sh}{\unexpanded{#2}},\qz@style,phantom]{l}%
}%
}
\makeatother
\begin{document}
\begin{quantikz}
\lstick{a} & \qwbundle{\mathcal{H}(\Delta)} &
\end{quantikz}
\end{document}
I also changed the temporary commands to “safe” ones.