You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]{\bar{#1}}.
When reading the file, each line is split at the # character and everything after it assumed as comment and thus discarded.
Proposed Solution
One solution would be to replace the line
strippedline=line.split('#', 1)[0].strip()
with a function that escapes # character(s). It would look something like this:
defstrip_comment_with_escaped_octothorpe(line):
splitline=line.split('#')
escaped_line= []
foriinrange(len(splitline)):
segment=splitline[i]
ifsegment[-1] is'\': # the character was escaped with '\#'segment=segment[:-1] # remove the escape character '\'escaped_line.append(segment)
ifsplitline[-2][-1] is'\': # the last segment was an actual commentescaped_line=escaped_line[:-1]
return''.join(escaped_line) # join backstrippedline=strip_comment_with_escaped_octothorpe(line).strip()
Additional context and prior art
Potential other use cases:
text.latex.preamble and pgf.preamble: Not just limited to \newcommand's #1
That sounds reasonable! Is that support for quoted strings being worked on?
I can't find a (draft) PR for it, but I did find this now stale PR #9528 for a MEP32 from 3 years ago, which discusses different parsers/formats for matplotlibrc files.
Activity
timhoffm commentedon Jan 13, 2021
I'd rather not expand the
matplotlibrcsyntax with escaping. Escaping is not very user friendly.Instead, I propose to add quoted strings as proposed in #15813 (comment). Then you could do:
janniklasrose commentedon Jan 14, 2021
That sounds reasonable! Is that support for quoted strings being worked on?
I can't find a (draft) PR for it, but I did find this now stale PR #9528 for a MEP32 from 3 years ago, which discusses different parsers/formats for matplotlibrc files.
timhoffm commentedon Jan 22, 2021
Currently, nobody is working on any of these. #9528 was discussed controversially and stalled at some point.
From the likelihood of getting this forward, I'd estimate:
quoted string support > YAML config > python-based config
Support quoted strings in matplotlibrc
Support quoted strings in matplotlibrc
Support quoted strings in matplotlibrc