Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f22259

Browse files
authored
Merge pull request #12805 from anntzer/texpreamble
Don't insert spurious newlines by joining tex.preamble.
2 parents ed0ae16 + 9bf512b commit 0f22259

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

doc/api/next_api_changes/2018-10-30-rcparams-pgf.preamble-full-LaTeX-support.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ The parsing has been modified to pass the complete line to the LaTeX system,
99
keeping all commas.
1010

1111
Passing a list of strings from within a Python script still works as it used to.
12+
13+
Passing a list containing non-strings now fails, instead of coercing the results to strings.

lib/matplotlib/rcsetup.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,17 @@ def validate_string_or_None(s):
175175
raise ValueError('Could not convert "%s" to string' % s)
176176

177177

178-
def _validate_stringlist_or_string(s):
179-
"""convert s to string or raise"""
178+
def _validate_tex_preamble(s):
180179
if s is None or s == 'None':
181180
return ""
182181
try:
183182
if isinstance(s, str):
184183
return s
185-
if isinstance(s, Iterable):
186-
return '\n'.join([str(i) for i in s])
187-
raise ValueError()
188-
except ValueError:
184+
elif isinstance(s, Iterable):
185+
return '\n'.join(s)
186+
else:
187+
raise TypeError
188+
except TypeError:
189189
raise ValueError('Could not convert "%s" to string' % s)
190190

191191

@@ -412,7 +412,7 @@ def validate_color(s):
412412

413413

414414
def validate_string(s):
415-
if isinstance(s, (str, str)):
415+
if isinstance(s, str):
416416
# Always leave str as str and unicode as unicode
417417
return s
418418
else:
@@ -1129,7 +1129,7 @@ def _validate_linestyle(ls):
11291129
'text.color': ['black', validate_color],
11301130
'text.usetex': [False, validate_bool],
11311131
'text.latex.unicode': [True, validate_bool],
1132-
'text.latex.preamble': ['', _validate_stringlist_or_string],
1132+
'text.latex.preamble': ['', _validate_tex_preamble],
11331133
'text.latex.preview': [False, validate_bool],
11341134
'text.dvipnghack': [None, validate_bool_maybe_none],
11351135
'text.hinting': ['auto', validate_hinting],
@@ -1405,7 +1405,7 @@ def _validate_linestyle(ls):
14051405
# use matplotlib rc settings for font configuration
14061406
'pgf.rcfonts': [True, validate_bool],
14071407
# provide a custom preamble for the latex process
1408-
'pgf.preamble': ['', _validate_stringlist_or_string],
1408+
'pgf.preamble': ['', _validate_tex_preamble],
14091409

14101410
# write raster image data directly into the svg file
14111411
'svg.image_inline': [True, validate_bool],

lib/matplotlib/texmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def get_font_preamble(self):
181181

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

186186
def make_tex(self, tex, fontsize):
187187
"""

0 commit comments

Comments
 (0)