Title: [Bug]: Right-to-left text that starts with a Latin word is laid out left-to-right · Issue #32511 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Right-to-left text that starts with a Latin word is laid out left-to-right · Issue #32511 · matplotlib/matplotlib
X Title: [Bug]: Right-to-left text that starts with a Latin word is laid out left-to-right · Issue #32511 · matplotlib/matplotlib
Description: Bug summary Since 3.11, text is shaped with libraqm, but the paragraph direction is always auto-detected from the first strong character. An Urdu (or Arabic, Hebrew) sentence that starts with a Latin word, a product name or a version num...
Open Graph Description: Bug summary Since 3.11, text is shaped with libraqm, but the paragraph direction is always auto-detected from the first strong character. An Urdu (or Arabic, Hebrew) sentence that starts with a Lat...
X Description: Bug summary Since 3.11, text is shaped with libraqm, but the paragraph direction is always auto-detected from the first strong character. An Urdu (or Arabic, Hebrew) sentence that starts with a Lat...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/32511
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Right-to-left text that starts with a Latin word is laid out left-to-right","articleBody":"### Bug summary\n\nSince 3.11, text is shaped with libraqm, but the paragraph direction is always auto-detected from\nthe first strong character. An Urdu (or Arabic, Hebrew) sentence that starts with a Latin word, a\nproduct name or a version number is therefore laid out left-to-right, so its words and punctuation\ncome out in the wrong order. There is currently no way to set the direction.\n\n### Code for reproduction\n\n```Python\nimport matplotlib.pyplot as plt\n\ntext = \"Python اور matplotlib میں اردو؟\" # Urdu sentence that starts with an English word\n\nfig = plt.figure(figsize=(6, 1.6))\nfig.text(0.95, 0.70, text, ha=\"right\", fontsize=18, language=\"ur\")\nfig.text(0.95, 0.25, \"\" + text, ha=\"right\", fontsize=18, language=\"ur\") # RLM prefix\nfig.savefig(\"repro_direction.png\", dpi=100)\n```\n\n### Actual outcome\n\nThe top line is laid out left-to-right: \"Python\" is on the left and the Urdu question mark ؟ ends up\nin the middle of the line instead of at the end of the sentence.\n\n\u003cimg width=\"600\" height=\"160\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/a2d12f03-bd28-48e4-b6dc-4c3f899d5a37\" />\n\n### Expected outcome\n\nThe bottom line, where the only change is a U+200F RIGHT-TO-LEFT MARK prefix: the sentence reads\nright-to-left, \"Python\" is on the right where the sentence starts, and ؟ is at the end.\n\n### Additional information\n\n- `FT2Font::layout` in `src/ft2font.cpp` sets the text, face, features and language on the raqm\n object but never calls `raqm_set_par_direction`, so libraqm uses `RAQM_DIRECTION_DEFAULT`. The\n libraqm documentation for that function notes that this default \"has problems when a mainly\n right-to-left paragraph starts with a left-to-right character and vice versa as the detected\n paragraph direction will be the wrong one\". The same is true on `main`.\n- Passing `language=\"ur\"` does not change the direction.\n- The reverse also happens: a left-to-right label whose first letter is Urdu is laid out\n right-to-left.\n- Workaround: prefix the string with U+200F (RLM) or U+061C (ALM), or wrap it in U+2067 ... U+2069\n (RLI ... PDI).\n- This is common in Urdu text: technical terms, names and numbers are often written in Latin script\n at the start of a sentence.\n- A second image shows the same sentence in Noto Nastaliq Urdu, as is, with each direction mark, \n and an Urdu-first sentence for comparison.\n\n\u003cimg width=\"1210\" height=\"770\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/07925eb1-dcab-4305-b86b-0f3ca04d6be3\" />\n\n- Possible fix: a `direction` text property (\"auto\" by default, \"rtl\", \"ltr\"), passed down to\n `raqm_set_par_direction` the same way `language` is passed to `raqm_set_language`. I would be\n happy to work on a PR if that approach sounds acceptable.\n\n### Operating system\n\nWindows 11\n\n### Matplotlib Version\n\n3.11.2\n\n### Matplotlib Backend\n\nAgg\n\n### Python version\n\n3.12.15\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/msarmadsohail","@type":"Person","name":"msarmadsohail"},"datePublished":"2026-10-20T14:48:40Z","url":"https://github.com/matplotlib/matplotlib/issues/32511"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:b056551a-00b5-cd29-c8ba-6cdb5ded5a2f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B058:3CBF9:10E5070:1651DF0:6B064EEB |
| html-safe-nonce | 5d6e9b5eebc7f52b10e95f72dd30c2a63171a6e320c4bf73f7f18087012daaf0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDU4OjNDQkY5OjEwRTUwNzA6MTY1MURGMDo2QjA2NEVFQiIsInZpc2l0b3JfaWQiOiIxMjcwODQ4NDM2MzMzNTk2Mzk1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b3b9290eb35aa52f32314db7c5ae7d2ce27f6b5383742f8c836fa90eacaebfd3 |
| hovercard-subject-tag | issue:5943834407 |
| 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/32511/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3edd91000fc016d45397358a810b34e8eea77f0a1a7d91486bcc031519b390d7/matplotlib/matplotlib/issues/32511 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3edd91000fc016d45397358a810b34e8eea77f0a1a7d91486bcc031519b390d7/matplotlib/matplotlib/issues/32511 |
| og:image:alt | Bug summary Since 3.11, text is shaped with libraqm, but the paragraph direction is always auto-detected from the first strong character. An Urdu (or Arabic, Hebrew) sentence that starts with a Lat... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | msarmadsohail |
| hostname | github.com |
| expected-hostname | github.com |
| None | 772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e |
| 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 | f1f9a08f7c769a37f1dfc18ad43d463c222a7eea |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width