-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop forcing mathtext mode for all strings (#4669)
* 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>
- Loading branch information
1 parent
10ac1ec
commit b84590b
Showing
25 changed files
with
84 additions
and
55 deletions.
There are no files selected for viewing
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 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 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
14 changes: 14 additions & 0 deletions
14
releasenotes/notes/pylatexenc-matplotlib-428f285f4cfd2d7c.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
upgrade: | ||
- | | ||
The ``'mpl'`` output mode for the | ||
:meth:`~qiskit.circuit.QuantumCircuit.draw` method and | ||
:func:`~qiskit.visualization.circuit_drawer` now requires the | ||
`pylatexenc <https://pylatexenc.readthedocs.io/en/latest/latexencode/>`__ | ||
library to be installed. This was already an optional dependency for | ||
visualization, but was only required for the ``'latex'`` output mode | ||
before. It is now also required for the matplotlib drawer because it is | ||
needed to handle correctly sizing gates with matplotlib's | ||
`mathtext <https://matplotlib.org/3.2.2/tutorials/text/mathtext.html>`__ | ||
labels for gates. | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.