-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
latex textrm does not work in Cairo backend #17932
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
Comments
The cairo backend does not support usetex at all; at least as a quick improvement one could at least log a warning, e.g. diff --git i/lib/matplotlib/backends/backend_cairo.py w/lib/matplotlib/backends/backend_cairo.py
index 773886e56..e4fa01b6c 100644
--- i/lib/matplotlib/backends/backend_cairo.py
+++ w/lib/matplotlib/backends/backend_cairo.py
@@ -7,6 +7,7 @@ This backend depends on cairocffi or pycairo.
"""
import gzip
+import logging
import math
import numpy as np
@@ -35,6 +36,7 @@ from matplotlib.transforms import Affine2D
backend_version = cairo.version
+_log = logging.getLogger(__name__)
if cairo.__name__ == "cairocffi":
@@ -236,14 +238,15 @@ class RendererCairo(RendererBase):
# Note: (x, y) are device/display coords, not user-coords, unlike other
# draw_* methods
+ if ismath == "TeX":
+ _log.warning("The cairo backend does not support usetex and this "
+ "setting will be ignored.")
if ismath:
self._draw_mathtext(gc, x, y, s, prop, angle)
-
else:
ctx = gc.ctx
ctx.new_path()
ctx.move_to(x, y)
-
ctx.select_font_face(*_cairo_font_args_from_font_prop(prop))
ctx.save()
ctx.set_font_size(prop.get_size_in_points() * self.dpi / 72)
@@ -286,6 +289,9 @@ class RendererCairo(RendererBase):
def get_text_width_height_descent(self, s, prop, ismath):
# docstring inherited
+ if ismath == "TeX":
+ _log.warning("The cairo backend does not support usetex and this "
+ "setting will be ignored.")
if ismath:
width, height, descent, fonts, used_characters = \
self.mathtext_parser.parse(s, self.dpi, prop) |
Please do not remove the ability to use tex with cairo, or add any additional warnings |
Why, exactly, do you want to use the cairo backend for this purpose? diff --git i/lib/matplotlib/backends/backend_cairo.py w/lib/matplotlib/backends/backend_cairo.py
index 773886e56..244f7103d 100644
--- i/lib/matplotlib/backends/backend_cairo.py
+++ w/lib/matplotlib/backends/backend_cairo.py
@@ -286,6 +286,8 @@ class RendererCairo(RendererBase):
def get_text_width_height_descent(self, s, prop, ismath):
# docstring inherited
+ if ismath == "TeX":
+ return super().get_text_width_height_descent(s, prop, ismath)
if ismath:
width, height, descent, fonts, used_characters = \
self.mathtext_parser.parse(s, self.dpi, prop) |
In my work I have only ever seen the |
Also have you tried mplcairo? It's not part of core matplotlib yet because it's a bit harder to build but it seems more robust and is actively maintained. |
Cairo works fine except for this one issue, and has the advantage over Agg which, for example, has alignment problems #3400 |
Bug report
Bug summary
Use of \textrm latex in Cairo backend raises an exception
Code for reproduction
Raises an exception
Expected outcome
The textrm should work to produce rm text. For reference, this works fine in the
Agg
backend.Matplotlib version
Installed with conda
The text was updated successfully, but these errors were encountered: