0

I need to write a circuit in thin lines where an operation is exception to this. For example

\begin{quantikz}[thin lines]
& \qw & \ctrl{1} & \qw\\
& \qw & \targ{} & \qw
\end{quantikz}

Is it possible to ``exclude'' the operation coming from \ctrl{1} and \targ{} together to the thin lines option?

1 Answer 1

1
+50

First of all, a disclaimer: I never used the quantikz-usepackage before. All my suggestions are based upon my knowledge of standard TikZ and a quick analysis of the quantikz source code.
From the limited details given in your question, I assume you want to have all HORIZONTAL lines thin and the VERTICAL line between \ctrl{1} and \targ{} in standard thickness.
Furthermore, I assume the following MWE as basis:

\documentclass{standalone}

\usepackage{quantikz}

\begin{document}
    \begin{quantikz}[thin lines]
        & \qw & \ctrl{1} & \qw\\
        & \qw & \targ{} & \qw\\
    \end{quantikz}
\end{document}

Analysis of quantikz source code

For the explanation why there might be no clean solution or a solution at all, one has to look at the implementation of the quantikz-usepackage.
The quantikz-environment is defined such that it accepts a command string, which is internally parsed and broken up. Like the syntax already implies, the "drawing" is handled like a table/matrix with rows and columns. However, the way the logic of the quantikz-package works is not identical to what \usetikzlibrary{matrix} would allow you to do. So all these standard matrix/TikZ syntax is not available (quantikz works with self defined boxes). So the only option is to retrace exactly how the macros are defined/processed and work within the quite unusual quantikz-way-of-doing-things. Changing line options in post-processing is no option either due to the fact that a) quantikz uses path-post-processing itself and b) the way the content in the quantikz-environment is handled does not play well with standard TikZ commands.
In the tikzlibraryquantikz.code.tex, the macro \ctrl{} is defined as

\def\ctrl#1{\control{}  \vqw{#1}}

In theory, one could locally redefine \ctrl{}, apply it and immediately define it back to the default. I tried that, but that failed due to numerous reasons (one being that the quantikz-environment could not parse the (re-)definition properly).
The argument #1 in \vqw{#1} indicates how many vertical layers (= rows) to go down. Since the TikZ-libaries calc and positioning are loaded in the quantikz source file, I hoped to gain direct access to coordinates. This did not work either (naming of the coordinates unclear/parsing of standard TikZ-syntax denied).
From the definition of \vqw one is immediately redirected to \vqwexplicit, which is defined as follows:

\newcommand{\vqwexplicit}[2]{
    \arrow[from=#1,to=#2,arrows] {}
}

Playing a bit with \arrow, I obtained the following:

\documentclass{standalone}

\usepackage{quantikz}

\begin{document}
    \begin{quantikz}[thin lines]
        & \qw & \control{}  \vqw{1} & \qw\\
        & \qw & \targ{} & \qw
        \arrow[from=2-3,to=1-3,red,thick]{}
    \end{quantikz}
\end{document}

It turns out that the coordinate names that the quantikz-usepackage uses are constructed as follows:ROW-COL.
So the \arrow-macro allows one to draw lines ON-TOP of the diagram and one has full control over the line style. Unfortunately, there is still the arrow tip one has to get rid off.
The next step would be to replace \arrow with the default TikZ \draw, which is unfortunately not recognized by the quantikz-usepackage. However, there is a cheat for the options of the \arrow-command: For TikZ arrows, one could specify the tip type with the short syntax
TipType-TipType, e. g. "<->", "->", "->>", etc. It turns out "-" works and produces an arrow without a tip.

Solution 1: Manual

A hacky and not-at-all clean suggested solution would be:

\documentclass{standalone}

\usepackage{quantikz}

\begin{document}
    \begin{quantikz}[thin lines]
        & \qw & \control{} & \qw\\ % neither \ctrl{1} nor \vqw{1} required
        & \qw & \targ{} & \qw
        \arrow[from=2-3,to=1-3,black,thick,-]{}
    \end{quantikz}
\end{document}

Please be aware that:

  1. The line is drawn on-top of everything else (could lead to visual artifacts),
  2. It is a manual solution which has to be applied every time.

Solution 2: Somewhat more automated

One can define a new object with vertical line/just a vertical line as a macro. Or alternatively, re-define the original vertical line macro to take an additional optional macro.

Please be aware that:

  1. One needs to define a new object for each of the original quantikz-elements,
  2. Re-defining the original macros could lead to issues,
  3. The re-definition I did does not work for bundles.

You must log in to answer this question.

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