Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styling controls individually #25

Closed
tigerjack opened this issue Jan 25, 2023 · 2 comments
Closed

Styling controls individually #25

tigerjack opened this issue Jan 25, 2023 · 2 comments

Comments

@tigerjack
Copy link

Is your feature request related to a problem? Please describe.
At the moment, I can only style the whole operator or all the controls at once, but not the single controls.

Describe the solution you'd like
I would like to style each control (i.e., the dots) of a multi-controlled gate individually.

Describe alternatives you've considered
I tried to overcome the limitations using the usual begin/end{scope}, but it gets complicated and difficult to generalize.

Additional context
Using the code below

\documentclass[tikz]{standalone}
\usepackage{./yquant}
\usetikzlibrary{backgrounds,fit}
\begin{document}
\begin{tikzpicture}
  \begin{yquant}
    qubit {$q_\idx$} q[4];
    [this control/.append style={fill=orange}] 
    cnot q[3] | q[0], q[1], q[2];
    %
    [global attrs/name/.expanded={mcnot}]
    cnot q[3]| q[0], q[1], q[2];
  \end{yquant}
  \begin{scope}[on background layer, maximum width=.5pt,  every node/.style={draw,dotted}]
    \node[circle, red, fit=(mcnot-p1)] {};
    \node[circle, blue, fit=(mcnot-p2)] {};
  \end{scope}
\end{tikzpicture}
\end{document}

I obtained something like this, which is far from optimal
image

@projekter
Copy link
Owner

There is no "intrinsic" support for this, and there are only styling keys that address all gates, positive, or negative controls.
However, it is not too hard to fake this: As always, yquant defines the \idx macro before applying every style to the control. This macro holds the current visual index within the group (so, it iterates from 0 to the number of gates -1; from 0 to the number of positive control -1; and also negative controls). So you could simply define a conditional style like this:

\documentclass[tikz]{standalone}
\usepackage[compat=0.6]{yquant}
\begin{document}
   \begin{tikzpicture}
     \begin{yquant}
       qubit {$q_\idx$} q[4];
       [this control/.append style={fill=orange}]
       cnot q[3] | q[0], q[1], q[2];
       %
       [this control/.code={\unexpanded{%
         \ifcase\idx\relax%
            \pgfkeysalso{fill=red}%
         \or%
            \pgfkeysalso{fill=blue}%
         \else%
            \pgfkeysalso{fill=green}%
         \fi%
       }}]
       cnot q[3]| q[0], q[1], q[2];
     \end{yquant}
   \end{tikzpicture}
\end{document}

Of course, you can use any kind of style that you like. If you use this more often, it might be worth defining a custom style that does this job for you.

@tigerjack
Copy link
Author

Excellent! Thank you @projekter

projekter added a commit that referenced this issue Feb 19, 2023
...and also take into account controls when calculating the extent of a gate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants