-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add dual of mpl mathtext syntax for latex drawer labels #3224
Merged
1ucian0
merged 18 commits into
Qiskit:master
from
mtreinish:mpl-latexmode-for-latex-drawer
Oct 28, 2019
Merged
Add dual of mpl mathtext syntax for latex drawer labels #3224
1ucian0
merged 18 commits into
Qiskit:master
from
mtreinish:mpl-latexmode-for-latex-drawer
Oct 28, 2019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit adds a new feature to the latex drawer that adds support for a similar syntax to matplotlib's mathtext to labels on the latex drawer. In matplotlib if you specify a string between two dollar signs (for example $\gamma$) that string will be parsed with mpl's native TeX expression parser and that will be used to layout and render the string per the TeX syntax. This uses the same syntax as mathtext, and enables users to write raw latex syntax as gate labels between a pair of dollar signs. All characters outside of the dollar signs are treated as utf8 and get encoded by pylatexenc to create valid latex, however all text inside the dollar signs get passed verbatim to the output latex. This enables users to mix and match having their unicode encoded for them and manually passing latex Fixes Qiskit#3171
ajavadia
previously approved these changes
Oct 8, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome thanks
Just for everyone's reference taking the example the release notes and running it locally will yield: |
This reverts commit ab7bc18. Running the code example in jupyter-execute will require a latex distribution with qcircuit to be installed. That adds a lot of run time to the doc build and a non-obvious dependency. To avoid this, we'll just rely on the code example and a description of the output.
1ucian0
approved these changes
Oct 28, 2019
mtreinish
added a commit
to mtreinish/qiskit-core
that referenced
this pull request
Nov 14, 2019
In Qiskit#3459 the latex circuit drawer recently received support for drawing with symbolic parameters. However, the review of that PR it was raised that the latex drawer does not currently have support for drawing parameters with unicode characters in them. For example you would have to write out theta instead of using the chracter θ. This limits how people could use the latex drawer for representing parameteric circuits. This commit fixes this issue by checking in the latex drawer if the parameter is symbolic or numeric and then passing that value to either generate_latex_label() or pi_check() respectively. This will let the strings representing symbolic parameters either use unicode characters and have that work in the output latex, or use the math mode for labels introduced in Qiskit#3224 as the symbol name to use arbitrary latex.
mergify bot
pushed a commit
that referenced
this pull request
Nov 20, 2019
* Handle unicode parameters in latex circuit drawer In #3459 the latex circuit drawer recently received support for drawing with symbolic parameters. However, the review of that PR it was raised that the latex drawer does not currently have support for drawing parameters with unicode characters in them. For example you would have to write out theta instead of using the chracter θ. This limits how people could use the latex drawer for representing parameteric circuits. This commit fixes this issue by checking in the latex drawer if the parameter is symbolic or numeric and then passing that value to either generate_latex_label() or pi_check() respectively. This will let the strings representing symbolic parameters either use unicode characters and have that work in the output latex, or use the math mode for labels introduced in #3224 as the symbol name to use arbitrary latex. * Fix lint
mtreinish
added a commit
to mtreinish/qiskit-core
that referenced
this pull request
Jul 8, 2020
In Qiskit#4616 the gate title and labels were changed to always use matplotlib's mathtext mode. [1] This was a breaking change and will result in users having weirdly formatted names and labels. For example places in qiskit itself set gate names like 'Controlled-Evolution^1_dg' which will not get rendered as expected in mathtext mode. The documented behavior for labels and gate names before was to rely on matplotlib's rendering behavior to expliclictly add '$' to the label string for sections that should be rendered in mathtext mode. For example, this behavior was ported to the latex circuit drawer in Qiskit#3224 so that users could take advantage of the same flexibility in how text was rendered by the drawer. This commit removes the forced addition of '$' around all the label strings to go back to the expected behavior. Fixes Qiskit#4667 [1] https://matplotlib.org/3.2.2/tutorials/text/usetex.html
mergify bot
pushed a commit
that referenced
this pull request
Jul 28, 2020
* Stop forcing mathtext mode for all strings In #4616 the gate title and labels were changed to always use matplotlib's mathtext mode. [1] This was a breaking change and will result in users having weirdly formatted names and labels. For example places in qiskit itself set gate names like 'Controlled-Evolution^1_dg' which will not get rendered as expected in mathtext mode. The documented behavior for labels and gate names before was to rely on matplotlib's rendering behavior to expliclictly add '$' to the label string for sections that should be rendered in mathtext mode. For example, this behavior was ported to the latex circuit drawer in #3224 so that users could take advantage of the same flexibility in how text was rendered by the drawer. This commit removes the forced addition of '$' around all the label strings to go back to the expected behavior. Fixes #4667 [1] https://matplotlib.org/3.2.2/tutorials/text/usetex.html * Also fix parameters * Add explicit math mode to default gate names where necessary * Remove conversions assuming hard coded mathtext mode * Don't slant letters for standard gates * Stop hard coding latex characters and use pylatexenc Previously the manual text width detection had a hard coded subset of latex special characters to try and convert a latex string to a text string. This however is quite error prone because it's missing a large portion of valid latex commands. For example, in the previous commit when we added \\mathrm to stop slanting text in the standard gates was missed by this. Instead of maintaing a manual list of commands this commit just switches to use pylatexenc, which is already a visualization requirement for the latex drawers, to do the conversion from latex to unicode. This is much less error prone and will give a true width of the strings even for user supplied gate names which can use any latex commands they want. * Use mathtext for U_* standard gates too * Add pylatexenc to binder build * Add release note * Don't slant standard gate subscript and ALL CAPS * Fix spacing with mathmode labels This comit fixes a few edge case with mathmode text spacing. The first is relying on pylatexenc to convert latex to text leaves '_' in for subscripts in math mode strings. This fixes this by finding manually removing those from the output string used for finding label width. The other 2 fixes are from review comments about spacing for cui1/rzz and a minus sign width. * Use \psi \rangle for initialize label * Fix oversight in mathmode handling * new references Co-authored-by: Luciano Bello <luciano.bello@ibm.com> Co-authored-by: Julien Gacon <jules.gacon@googlemail.com>
faisaldebouni
pushed a commit
to faisaldebouni/qiskit-terra
that referenced
this pull request
Aug 5, 2020
* Add dual of mpl mathtext syntax for latex drawer labels This commit adds a new feature to the latex drawer that adds support for a similar syntax to matplotlib's mathtext to labels on the latex drawer. In matplotlib if you specify a string between two dollar signs (for example $\gamma$) that string will be parsed with mpl's native TeX expression parser and that will be used to layout and render the string per the TeX syntax. This uses the same syntax as mathtext, and enables users to write raw latex syntax as gate labels between a pair of dollar signs. All characters outside of the dollar signs are treated as utf8 and get encoded by pylatexenc to create valid latex, however all text inside the dollar signs get passed verbatim to the output latex. This enables users to mix and match having their unicode encoded for them and manually passing latex Fixes Qiskit#3171 * Fix lint * Use jupyter-execute instead of describing diagram * Revert "Use jupyter-execute instead of describing diagram" This reverts commit ab7bc18. Running the code example in jupyter-execute will require a latex distribution with qcircuit to be installed. That adds a lot of run time to the doc build and a non-obvious dependency. To avoid this, we'll just rely on the code example and a description of the output.
faisaldebouni
pushed a commit
to faisaldebouni/qiskit-terra
that referenced
this pull request
Aug 5, 2020
* Handle unicode parameters in latex circuit drawer In Qiskit#3459 the latex circuit drawer recently received support for drawing with symbolic parameters. However, the review of that PR it was raised that the latex drawer does not currently have support for drawing parameters with unicode characters in them. For example you would have to write out theta instead of using the chracter θ. This limits how people could use the latex drawer for representing parameteric circuits. This commit fixes this issue by checking in the latex drawer if the parameter is symbolic or numeric and then passing that value to either generate_latex_label() or pi_check() respectively. This will let the strings representing symbolic parameters either use unicode characters and have that work in the output latex, or use the math mode for labels introduced in Qiskit#3224 as the symbol name to use arbitrary latex. * Fix lint
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This commit adds a new feature to the latex drawer that adds support for$\gamma$ ) that string will be parsed with mpl's native TeX
a similar syntax to matplotlib's mathtext to labels on the latex drawer.
In matplotlib if you specify a string between two dollar signs (for
example
expression parser and that will be used to layout and render the string
per the TeX syntax. This uses the same syntax as mathtext, and enables
users to write raw latex syntax as gate labels between a pair of dollar
signs. All characters outside of the dollar signs are treated as utf8
and get encoded by pylatexenc to create valid latex, however all text
inside the dollar signs get passed verbatim to the output latex. This
enables users to mix and match having their unicode encoded for them and
manually passing latex
Details and comments
Fixes #3171