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

math mode in gate names is not working #9208

Open
1ucian0 opened this issue Nov 28, 2022 · 2 comments
Open

math mode in gate names is not working #9208

1ucian0 opened this issue Nov 28, 2022 · 2 comments
Labels
bug Something isn't working help wanted community contributions welcome. For filters like http://github-help-wanted.com/

Comments

@1ucian0
Copy link
Member

1ucian0 commented Nov 28, 2022

Environment

  • Qiskit Terra version: 0.23.0.dev0+67f85b0
  • Python version: 3.9
  • Operating system: MacOS

What is happening?

Inspired by https://quantumcomputing.stackexchange.com/a/29167/1859
According with #4669, it is possible to use $ for activate LaTeX math mode in gate names. However, that triggers an error.

How can we reproduce the issue?

Take the possible example:

from qiskit import QuantumCircuit
from qiskit.circuit.library import HGate
circ = QuantumCircuit(1)
circ.append(HGate(label="$U^a$"),[0])
circ.draw('latex')  

This triggers a pdflatex compilation error. However, circ.append(HGate(label="U^a"),[0]) works.

What should happen?

This might be a regression. I think at some point we supported math mode in names. What it should happen is that $ activates it.

Any suggestions?

No response

@1ucian0 1ucian0 added the bug Something isn't working label Nov 28, 2022
@jakelishman
Copy link
Member

The PR you reference is for the MPL drawer, not the LaTeX one. From a quick scan-through, it looks like we've pretty much always been drawing LaTeX labels in math mode, except wrapped in a \mathrm. #5855 added the explicit escaping for ^ and _.

We could probably use a similar approach to #4669; escape the name components that are outside the dollar signs, and pass through the inside-dollar-sign bits to LaTeX verbatim.

(I note that in that stackexchange question, the user's gate name isn't valid LaTeX already - _ consumes one single token, but they want it to consume the entire \mathrm{rot}. They should have written $U_{\mathrm{rot}}$, most likely.)

@1ucian0
Copy link
Member Author

1ucian0 commented Nov 29, 2022

The PR you reference is for the MPL drawer, not the LaTeX one.

ups! my bad.

(I note that in that stackexchange question, the user's gate name isn't valid LaTeX already - _ consumes one single token, but they want it to consume the entire \mathrm{rot}. They should have written $U_{\mathrm{rot}}$, most likely.)

I extended the answer with that clarification, thanks.

@1ucian0 1ucian0 added the help wanted community contributions welcome. For filters like http://github-help-wanted.com/ label Nov 29, 2022
@javabster javabster moved this to Tagged but unassigned in Contributor Monitoring Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted community contributions welcome. For filters like http://github-help-wanted.com/
Projects
Status: Tagged but unassigned
Development

No branches or pull requests

2 participants