CQCL/tket

`Circuit.to_latex_file` generates invalid LaTeX for register names containing underscores

Closed this issue · 1 comments

The Circuit.to_latex_file method seems to produce invalid LaTeX if the names of the registers contain underscores.

Build circuit

from pytket import Circuit
from pytket.circuit.display import render_circuit_jupyter as draw

circ = Circuit()

s = circ.add_q_register("s_register", 2)
l = circ.add_q_register("l_register", 3)

circ.CCX(s[0], l[1], l[2])
circ.CRy(0.75, s[1], l[1])
circ.CRx(0.71, l[0], s[1])

draw(circ)

latex_circuit

export to LaTeX

circ.to_latex_file( "test.tex")

I get the following ouput

\documentclass[tikz]{standalone}
\usetikzlibrary{quantikz}
\begin{document}
\begin{quantikz}
\lstick{l_register[0]} & \qw & \qw & \ctrl{4} & \qw \\
\lstick{l_register[1]} & \ctrl{1} & \gate{\text{$R_Y$(0.75)}} & \qw & \qw \\
\lstick{l_register[2]} & \targ{} & \qw & \qw & \qw \\
\lstick{s_register[0]} & \ctrl{-1} & \qw & \qw & \qw \\
\lstick{s_register[1]} & \qw & \ctrl{-3} & \gate{\text{$R_X$(0.71)}} & \qw \\
\end{quantikz}
\end{document}

This LaTeX doesn't compile. If I manually remove the underscores then it compiles and I get a circuit diagram. Seems the underscored names are casuing an issue.

I also get a warning noting that we use Quantikz rather than Quantikz2.

Thanks for this Callum! Yes and since the warning is so unhelpful, it leaves one at a complete loss for what they did wrong.