Title: [Bug]: `multialignment='right'` in `ax.text()` with `path_effects` breaks when using LaTeX package `\usepackage[T1]{fontenc}` · Issue #28675 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: `multialignment='right'` in `ax.text()` with `path_effects` breaks when using LaTeX package `\usepackage[T1]{fontenc}` · Issue #28675 · matplotlib/matplotlib
X Title: [Bug]: `multialignment='right'` in `ax.text()` with `path_effects` breaks when using LaTeX package `\usepackage[T1]{fontenc}` · Issue #28675 · matplotlib/matplotlib
Description: Bug summary When I plot a multiline text using ax.text() with path_effects under TeX environment with package \usepackage[T1]{fontenc} the multiline coalignment to right breaks. Code for reproduction import matplotlib print(matplotlib.__...
Open Graph Description: Bug summary When I plot a multiline text using ax.text() with path_effects under TeX environment with package \usepackage[T1]{fontenc} the multiline coalignment to right breaks. Code for reproducti...
X Description: Bug summary When I plot a multiline text using ax.text() with path_effects under TeX environment with package \usepackage[T1]{fontenc} the multiline coalignment to right breaks. Code for reproducti...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/28675
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: `multialignment='right'` in `ax.text()` with `path_effects` breaks when using LaTeX package `\\usepackage[T1]{fontenc}`","articleBody":"### Bug summary\r\n\r\nWhen I plot a multiline text using `ax.text()` with `path_effects` under TeX environment with package `\\usepackage[T1]{fontenc}` the multiline coalignment to right breaks.\r\n\r\n### Code for reproduction\r\n\r\n```Python\r\nimport matplotlib\r\nprint(matplotlib.__version__)\r\nimport matplotlib.pyplot as plt\r\nfrom matplotlib import rc_context, patheffects as path_effects\r\nprint(matplotlib.get_backend())\r\n\r\nwith rc_context({'text.usetex': True, 'font.family': 'serif', 'font.serif':'cm',\r\n 'text.latex.preamble': r'\\usepackage[T1]{fontenc}'\r\n }):\r\n fig, ax = plt.subplots(layout='constrained')\r\n text1 = ax.text(0, 0.95, r'\\textbf{aaaaaaaaaaaaaaa}'\r\n \"\\n\" + r'\\textbf{{\\quad\\textsc{aaaaaa}}}',\r\n transform=ax.transAxes, fontsize=12, va='top', ha='left',linespacing=1.2,ma='left',\r\n color='green', )\r\n \r\n text2 = ax.text(0, 0.8, r'\\textbf{aa}'\r\n \"\\n\" + r'\\textbf{{aaaaaaaaaaaaaaa}}',\r\n transform=ax.transAxes, fontsize=12, va='top', ha='left',linespacing=1.2,ma='right',\r\n color='red', path_effects=[path_effects.Stroke(linewidth=1.2, foreground='black'),\r\n path_effects.Normal()])\r\n \r\n text3 = ax.text(1, 0.95, r'\\textbf{aa}'\r\n \"\\n\" + r'\\textbf{{aaaaaaaaaaaaaaa}}',\r\n transform=ax.transAxes, fontsize=12, va='top', ha='right',linespacing=1.2,ma='right',\r\n color='red',)\r\n \r\n text4 = ax.text(1, 0.8, r'\\textbf{aa}'\r\n \"\\n\" + r'\\textbf{{aaaaaaaaaaaaaaa}}',\r\n transform=ax.transAxes, fontsize=12, va='top', ha='right',linespacing=1.2,ma='right',\r\n color='red', path_effects=[path_effects.Stroke(linewidth=1.2, foreground='black'),\r\n path_effects.Normal()])\r\n \r\n ax.set_title(r'With \\textbackslash usepackage[T1]\\{fontenc\\}')\r\n\r\n plt.show()\r\n\r\nwith rc_context({'text.usetex': True, 'font.family': 'serif', 'font.serif':'cm',\r\n }):\r\n fig, ax = plt.subplots(layout='constrained')\r\n text1 = ax.text(0, 0.95, r'\\textbf{aaaaaaaaaaaaaaa}'\r\n \"\\n\" + r'\\textbf{{\\quad\\textsc{aaaaaa}}}',\r\n transform=ax.transAxes, fontsize=12, va='top', ha='left',linespacing=1.2,ma='left',\r\n color='green', )\r\n \r\n text2 = ax.text(0, 0.8, r'\\textbf{aa}'\r\n \"\\n\" + r'\\textbf{{aaaaaaaaaaaaaaa}}',\r\n transform=ax.transAxes, fontsize=12, va='top', ha='left',linespacing=1.2,ma='right',\r\n color='red', path_effects=[path_effects.Stroke(linewidth=1.2, foreground='black'),\r\n path_effects.Normal()])\r\n \r\n text3 = ax.text(1, 0.95, r'\\textbf{aa}'\r\n \"\\n\" + r'\\textbf{{aaaaaaaaaaaaaaa}}',\r\n transform=ax.transAxes, fontsize=12, va='top', ha='right',linespacing=1.2,ma='right',\r\n color='red',)\r\n \r\n text4 = ax.text(1, 0.8, r'\\textbf{aa}'\r\n \"\\n\" + r'\\textbf{{aaaaaaaaaaaaaaa}}',\r\n transform=ax.transAxes, fontsize=12, va='top', ha='right',linespacing=1.2,ma='right',\r\n color='red', path_effects=[path_effects.Stroke(linewidth=1.2, foreground='black'),\r\n path_effects.Normal()])\r\n \r\n ax.set_title(r'Without \\textbackslash usepackage[T1]\\{fontenc\\}')\r\n\r\n plt.show()\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\nThe `ma='right'` breaks for the bottom two texts with `path_effects`. \r\n\r\n\r\n\r\n### Expected outcome\r\n\r\nI would expect something similar without `\\usepackage[T1]{fontenc}` below, but somehow I really want to include it because it provides some additional support, for example, nesting `\\textsc{}` in `\\textbf{}`.\r\n\r\n\r\n### Additional information\r\n\r\n_No response_\r\n\r\n### Operating system\r\n\r\nWSL 2.2.4.0/Ubuntu 22.04.3 LTS\r\n\r\n### Matplotlib Version\r\n\r\n3.9.1\r\n\r\n### Matplotlib Backend\r\n\r\nqtagg\r\n\r\n### Python version\r\n\r\n3.12.2\r\n\r\n### Jupyter version\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\nNone","author":{"url":"https://github.com/yjzhu-solar","@type":"Person","name":"yjzhu-solar"},"datePublished":"2024-08-07T15:36:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/28675/matplotlib/issues/28675"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:82000d05-b8cb-71dd-1ca7-411a356c84bd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DCBC:2D857A:61DA2C:83CE15:6A52FE06 |
| html-safe-nonce | 204fa705b544a4e3d6938947947d72de68c2d3d4b1fd24bd95acba6b055bd773 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQ0JDOjJEODU3QTo2MURBMkM6ODNDRTE1OjZBNTJGRTA2IiwidmlzaXRvcl9pZCI6IjM1OTY1NzQxNjc3MDM2ODI1NjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e4758d027f18d94358795de44fcf20c83b48a2bbcca7b755d4b26fa1d999f0be |
| hovercard-subject-tag | issue:2453788349 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/28675/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dd60b2a2b4115f470aa034b0f083bd980815cc3d3a102dab1d0ae7d2cb28b8a9/matplotlib/matplotlib/issues/28675 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dd60b2a2b4115f470aa034b0f083bd980815cc3d3a102dab1d0ae7d2cb28b8a9/matplotlib/matplotlib/issues/28675 |
| og:image:alt | Bug summary When I plot a multiline text using ax.text() with path_effects under TeX environment with package \usepackage[T1]{fontenc} the multiline coalignment to right breaks. Code for reproducti... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yjzhu-solar |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width