3

I am trying to typeset a circuit where there is a letter in \mathcal font on a \qwbundle label. Here is a minimal example:

\documentclass{article}
\usepackage{quantikz}

\begin{document}

\begin{quantikz}
\lstick{a} & \qwbundle{\mathcal{H}(\Delta)} &
\end{quantikz}

\end{document}

And this is the "Missing control sequence inserted" error I am getting:

<inserted text> 
                \inaccessible 
l.8 \end
        {quantikz}
Please don't say `\def cs{...}', say `\def\cs{...}'.
I've inserted an inaccessible control sequence so that your
definition will be completed without mixing me up too badly.
You can recover graciously from this error, if you're
careful; see exercise 27.2 in The TeXbook.

[1

If I remove the \mathcal or if I change the TeX Live version in Overleaf to 2022 or earlier, this error disappears. What could be causing this, and is there a different / more correct way to accomplish this?

2 Answers 2

1

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.

enter image description here

3

Something in pgfdecorations is applying \edef to the argument rather than \protected@edef so causing premature expansion, even though \mathcal is a robust command that uses \protect internally.

You can make it e-tex \protected so it is safe in an edef,

\documentclass{article}
\usepackage{quantikz}

\let\hmm\mathcal
\protected\def\mathcal{\hmm}
\begin{document}

\begin{quantikz}
\lstick{a} & \qwbundle{\mathcal{H}(\Delta)} &
\end{quantikz}

\end{document}

But it should be reported as a bug to the package maintainer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .