projekter/yquant

CNOT styling with single style option

Closed this issue · 3 comments

Describe the bug
Trying to style individual CNOTs does not seem to be behaving properly. Adding a single style descriptor to an individual CNOT gate changes the target, but not the control or the line.

To Reproduce

\documentclass{standalone}
\usepackage{yquant}
\pagestyle{empty}

\begin{document}

\begin{tikzpicture}
	\begin{yquant*}
		[blue]
		cnot q[1] | q[0];
		cnot q[0] | q[1];
	\end{yquant*}
\end{tikzpicture}

\end{document}

cnot1
Instead using [control style/.append style={blue}] does nothing.

Expected output
I would expect the full CNOT to be blue (control, control line, target)

I can get the desired effect manipulating the individual elements, but it really seems this should be the output from the above.

\begin{tikzpicture}
	\begin{yquant*}
                [this control/.append style={fill=blue}, this operator/.append style={blue}, every control line/.append style={blue}]
		cnot q[1] | q[0];
		cnot q[0] | q[1];
	\end{yquant*}
\end{tikzpicture}

cnot2

Perhaps this behavior is intentional, but it's not clear from the documentation since the only examples of changing the CNOT styling is by filling in the target, and not changing the outline color. So perhaps some clarity in the documentation on this would suffice.
Environment

  • This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021) (preloaded format=pdflatex 2021.12.3)
  • yquant 2021/09/04 v0.5.1

This is indeed the expected behavior. The documentation under "2.5 Arguments" states that yquant first tries to find whether the argument that you pass to the gate is some gate-specific argument (which are documented for each gate). Then, it tries to find it in the /yquant namespace. And finally: "If it cannot be found there, it is passed to /yquant/operator style."
So this last sentence is what happens here, since blue is unknown at the other places. Basically, [blue] is equivalent to [operator style={blue}]. The definition of /yquant/operator style then is to feed its arguments to the this operator style, which only styles the operator itself. If you want to also overwrite the controls, you should additionally change the this control style. If you also want to overwrite the vertical line that connects the operator with the controls, you should additionally change the every control line style for this operator (curious, I didn't include a this control line style... Can't remember why, but for sure made some sense initially).
Since the most likely cases are that

  • you want to change the control line together with the controls, there is the control style shortcut that changes both at once and
  • you want to change both the operator, the controls, and the control line, there is the style shortcut that changes all three at once.

Note that these are not styles themselves, so the correct use is not with /.append style, as you mentioned above. Instead, you have to call these styles directly (e.g., control style={...}) and they then carry out /.append style on the appropriate styles.

Long story short: [style=blue] cnot q[1] | q[0]; should do the job.
This is documented, but apparently not well-documented. I'd appreciate suggestions on how to make this more clear. I already thought about including the crazy circuit given in the qpic manual (Introduction), this should make things clear.

Perfect! That's exactly what I was looking for. Indeed I see more explanations in the docs. I think probably just having an example would be useful, as that is usually the first resource for creating circuits. Adding an explicit example in 6.3.6 B would seem appropriate. Perhaps this is asking for too much babying, but it certainly would be handy. That example you linked would indeed would be super helpful, and definitely a bit crazy.

Closing now since nothing is broken.

Ok, so now I included a note in 6.3.6B and also started implementing the qpic manual. In particular, the first circuit can already be found in the manual; this is a really nice example to showcase how the integration with TeX allows to defer all the circuit logic to the engine. I hope this helps.