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

Feature request: Get "cleaner" tex code from QuantumCircuit.draw('latex_source') #6447

Closed
1ucian0 opened this issue May 20, 2021 · 5 comments · Fixed by #6483
Closed

Feature request: Get "cleaner" tex code from QuantumCircuit.draw('latex_source') #6447

1ucian0 opened this issue May 20, 2021 · 5 comments · Fixed by #6483
Assignees
Labels
good first issue Good for newcomers type: feature request New feature or request

Comments

@1ucian0
Copy link
Member

1ucian0 commented May 20, 2021

The output of QuantumCircuit.draw('latex_source') not standalone, creating a full page. This creates an effect of a lot of spacing around it (like in here https://quantumcomputing.stackexchange.com/questions/17573/saving-vectorized-circuits-in-qiskit ). Additionally, many of the output code is not necessary and might look intimidating:

Currently, this is the output:

from qiskit import *

circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)
print(circuit.draw('latex_source'))
% \documentclass[preview]{standalone}
% If the image is too large to fit on this documentclass use
\documentclass[draft]{beamer}
% img_width = 2, img_depth = 4
\usepackage[size=custom,height=10,width=12,scale=0.7]{beamerposter}
% instead and customize the height and width (in cm) to fit.
% Large images may run out of memory quickly.
% To fix this use the LuaLaTeX compiler, which dynamically
% allocates memory.
\usepackage[braket, qm]{qcircuit}
\usepackage{amsmath}
\pdfmapfile{+sansmathaccent.map}
% \usepackage[landscape]{geometry}
% Comment out the above line if using the beamer documentclass.
\begin{document}

\begin{equation*}
    \Qcircuit @C=1.0em @R=0.2em @!R {
	 	\lstick{ {q}_{0} :  } & \gate{\mathrm{H}} & \ctrl{1} & \qw & \qw\\
	 	\lstick{ {q}_{1} :  } & \qw & \targ & \qw & \qw\\
	 }
\end{equation*}

\end{document}

It would be great if could look more like this:

\documentclass{standalone}
\usepackage[braket, qm]{qcircuit}

\begin{document}
    \Qcircuit @C=1.0em @R=0.2em @!R {
                \lstick{ {q}_{0} :  } & \gate{\mathrm{H}} & \ctrl{1} & \qw & \qw\\
                \lstick{ {q}_{1} :  } & \qw & \targ & \qw & \qw\\
         }
\end{document}

I'm aware that qcircuit and standalone do not play well together. However, I still thing would it be possible to hack the way around while waiting for a solution in that front. For example (I did not test this solution extensibly), this code produces this image (which is correctly cropped):

\documentclass[border=2px]{standalone}

\usepackage[braket, qm]{qcircuit}

\begin{document}
\Qcircuit @C=1.0em @R=0.2em @!R {
    \nghost{} & \lstick{ {q}_{0} :  } & \gate{\mathrm{H}} & \ctrl{1} & \qw & \qw\\
    \nghost{} & \lstick{ {q}_{1} :  } & \qw & \targ & \qw & \qw\\
}

\end{document}

Screenshot 2021-05-20 at 14 44 20

@1ucian0 1ucian0 added type: feature request New feature or request good first issue Good for newcomers labels May 20, 2021
@JoshDumo
Copy link
Contributor

Hi! Can I work on this one?

@tnemoz
Copy link
Contributor

tnemoz commented May 26, 2021

Hi @1ucian0! Don't you think that #2015 should be fixed/discussed beforehand? Adding to the arguments discussed there, I never had any problem using standalone with quantikz.

@1ucian0
Copy link
Member Author

1ucian0 commented May 26, 2021

@JoshDumo assigning you!

@tnemoz #2015 seems stalled to me and, even if the outcome of that discussion is to change to quantikz in the future, I don't see that happening any time soon. So, in that context and for the sake of avoiding blockers, I think moving forward here is easier.

@tnemoz
Copy link
Contributor

tnemoz commented May 26, 2021

@1ucian0 In that case, would you mind if I were to work in this direction (that is, switching from qcircuit to quantikz)? Or do you prefer to wait for this issue to be closed?

@1ucian0
Copy link
Member Author

1ucian0 commented May 26, 2021

A discussion for #2015 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers type: feature request New feature or request
Projects
None yet
3 participants