Title: Escape # character in matplotlibrc · Issue #19288 · matplotlib/matplotlib · GitHub
Open Graph Title: Escape # character in matplotlibrc · Issue #19288 · matplotlib/matplotlib
X Title: Escape # character in matplotlibrc · Issue #19288 · matplotlib/matplotlib
Description: Problem It currently seems impossible to escape the # character inside matplotlibrc files. I would like to include it as part of the parameter value for text.latex.preamble to add a LaTeX command definition such as \newcommand{\foo}[1]{\...
Open Graph Description: Problem It currently seems impossible to escape the # character inside matplotlibrc files. I would like to include it as part of the parameter value for text.latex.preamble to add a LaTeX command d...
X Description: Problem It currently seems impossible to escape the # character inside matplotlibrc files. I would like to include it as part of the parameter value for text.latex.preamble to add a LaTeX command d...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/19288
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Escape # character in matplotlibrc","articleBody":"\u003c!--\r\nWelcome! Thanks for thinking of a way to improve Matplotlib.\r\n\r\n\r\nBefore creating a new feature request please search the issues for relevant feature requests.\r\n--\u003e\r\n\r\n### Problem\r\n\r\nIt currently seems impossible to escape the `#` character inside matplotlibrc files. I would like to include it as part of the parameter value for `text.latex.preamble` to add a LaTeX command definition such as `\\newcommand{\\foo}[1]{\\bar{#1}}`.\r\n\r\nWhen reading the file, each line is [split](https://github.com/matplotlib/matplotlib/blob/2219872528f2f7d1557126b15451489918225318/lib/matplotlib/__init__.py#L776) at the `#` character and everything after it assumed as comment and thus discarded.\r\n\r\n\u003c!--\r\nProvide a clear and concise description of the problem this feature will solve. \r\n\r\nFor example:\r\n* I'm always frustrated when [...] because [...]\r\n* I would like it if [...] happened when I [...] because [...]\r\n* Here is a sample image of what I am asking for [...]\r\n--\u003e\r\n\r\n### Proposed Solution\r\n\r\n\u003c!-- Provide a clear and concise description of a way to accomplish what you want. For example:\r\n\r\n* Add an option so that when [...] [...] will happen\r\n --\u003e\r\n\r\nOne solution would be to replace the line\r\n\r\n```python\r\nstrippedline = line.split('#', 1)[0].strip()\r\n```\r\n\r\nwith a function that escapes `#` character(s). It would look something like this:\r\n\r\n```python\r\ndef strip_comment_with_escaped_octothorpe(line):\r\n splitline = line.split('#')\r\n escaped_line = []\r\n for i in range(len(splitline)):\r\n segment = splitline[i]\r\n if segment[-1] is '\\': # the character was escaped with '\\#'\r\n segment = segment[:-1] # remove the escape character '\\'\r\n escaped_line.append(segment)\r\n if splitline[-2][-1] is '\\': # the last segment was an actual comment\r\n escaped_line = escaped_line[:-1]\r\n return ''.join(escaped_line) # join back\r\n\r\nstrippedline = strip_comment_with_escaped_octothorpe(line).strip()\r\n```\r\n\r\n\r\n### Additional context and prior art\r\n\r\n\u003c!-- Add any other context or screenshots about the feature request here. You can also include links to examples of other programs that have something similar to your request. For example:\r\n\r\n* Another project [...] solved this by [...]\r\n--\u003e\r\n\r\nPotential other use cases:\r\n- `text.latex.preamble` and `pgf.preamble`: Not just limited to `\\newcommand`'s `#1`\r\n- `savefig.directory`: File paths might contain `#`\r\n- `keymap`: the `#` key cannot be remapped currently\r\n\r\n\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/janniklasrose","@type":"Person","name":"janniklasrose"},"datePublished":"2021-01-13T16:16:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/19288/matplotlib/issues/19288"}
| 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:bc14423b-c39c-6b27-14c1-ce3b0ceff587 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EE42:2C65A3:2DC882:3D393F:6A52EB3D |
| html-safe-nonce | 1ef381a552871066a5df8a8249440e834c4873cdaf36bf8a4266846944c8734f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRTQyOjJDNjVBMzoyREM4ODI6M0QzOTNGOjZBNTJFQjNEIiwidmlzaXRvcl9pZCI6IjgyNzQ2OTY3NTg5MDAyMjI3ODEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 467310f80e758f30cce69fa8bb68b30efe452114334d273a011930b8ae4656f5 |
| hovercard-subject-tag | issue:785242873 |
| 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/19288/issue_layout |
| twitter:image | https://opengraph.githubassets.com/22b71e95a04e420462dc5cdbfc48a336f5487710ca20093d88bfad5a58f2861d/matplotlib/matplotlib/issues/19288 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/22b71e95a04e420462dc5cdbfc48a336f5487710ca20093d88bfad5a58f2861d/matplotlib/matplotlib/issues/19288 |
| og:image:alt | Problem It currently seems impossible to escape the # character inside matplotlibrc files. I would like to include it as part of the parameter value for text.latex.preamble to add a LaTeX command d... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | janniklasrose |
| 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 | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width