8000 Don't insert spurious newlines by joining tex.preamble. by anntzer · Pull Request #12805 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Don't insert spurious newlines by joining tex.preamble. #12805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ The parsing has been modified to pass the complete line to the LaTeX system,
keeping all commas.

Passing a list of strings from within a Python script still works as it used to.

Passing a list containing non-strings now fails, instead of coercing the results to strings.
18 changes: 9 additions & 9 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,17 @@ def validate_string_or_None(s):
raise ValueError('Could not convert "%s" to string' % s)


def _validate_stringlist_or_string(s):
"""convert s to string or raise"""
def _validate_tex_preamble(s):
if s is None or s == 'None':
return ""
try:
if isinstance(s, str):
return s
if isinstance(s, Iterable):
return '\n'.join([str(i) for i in s])
raise ValueError()
except ValueError:
elif isinstance(s, Iterable):
return '\n'.join(s)
else:
raise TypeError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The try-except seem unnecessary. Afaics, this can only come from the explicit raise and thus can be simplified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it can also happen if s is not an iterable of strings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

except TypeError:
raise ValueError('Could not convert "%s" to string' % s)


Expand Down Expand Up @@ -412,7 +412,7 @@ def validate_color(s):


def validate_string(s):
if isinstance(s, (str, str)):
if isinstance(s, str):
# Always leave str as str and unicode as unicode
return s
else:
Expand Down Expand Up @@ -1129,7 +1129,7 @@ def _validate_linestyle(ls):
'text.color': ['black', validate_color],
'text.usetex': [False, validate_bool],
'text.latex.unicode': [True, validate_bool],
'text.latex.preamble': ['', _validate_stringlist_or_string],
'text.latex.preamble': ['', _validate_tex_preamble],
'text.latex.preview': [False, validate_bool],
'text.dvipnghack': [None, validate_bool_maybe_none],
'text.hinting': ['auto', validate_hinting],
Expand Down Expand Up @@ -1405,7 +1405,7 @@ def _validate_linestyle(ls):
# use matplotlib rc settings for font configuration
'pgf.rcfonts': [True, validate_bool],
# provide a custom preamble for the latex process
'pgf.preamble': ['', _validate_stringlist_or_string],
'pgf.preamble': ['', _validate_tex_preamble],

# write raster image data directly into the svg file
'svg.image_inline': [True, validate_bool],
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def get_font_preamble(self):

def get_custom_preamble(self):
"""Return a string containing user additions to the tex preamble."""
return '\n'.join(rcParams['text.latex.preamble'])
return rcParams['text.latex.preamble']

def make_tex(self, tex, fontsize):
"""
Expand Down
0