-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Milestone
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]{\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:
def strip_comment_with_escaped_octothorpe(line):
splitline = line.split('#')
escaped_line = []
for i in range(len(splitline)):
segment = splitline[i]
if segment[-1] is '\': # the character was escaped with '\#'
segment = segment[:-1] # remove the escape character '\'
escaped_line.append(segment)
if splitline[-2][-1] is '\': # the last segment was an actual comment
escaped_line = escaped_line[:-1]
return ''.join(escaped_line) # join back
strippedline = strip_comment_with_escaped_octothorpe(line).strip()Additional context and prior art
Potential other use cases:
text.latex.preambleandpgf.preamble: Not just limited to\newcommand's#1savefig.directory: File paths might contain#keymap: the#key cannot be remapped currently