38
38
39
39
def _get_preamble ():
40
40
"""Prepare a LaTeX preamble based on the rcParams configuration."""
41
- font_size_pt = FontProperties (
42
- size = mpl .rcParams ["font.size" ]
43
- ).get_size_in_points ()
41
+ def _to_fontspec ():
42
+ for command , family in [("setmainfont" , "serif" ),
43
+ ("setsansfont" , "sans\\ -serif" ),
44
+ ("setmonofont" , "monospace" )]:
45
+ font_path = fm .findfont (family )
46
+ path = pathlib .Path (font_path )
47
+ yield r" \%s{%s}[Path=\detokenize{%s/}%s]" % (
48
+ command , path .name , path .parent .as_posix (),
49
+ f',FontIndex={ font_path .face_index :d} ' if path .suffix == '.ttc' else '' )
50
+
51
+ font_size_pt = FontProperties (size = mpl .rcParams ["font.size" ]).get_size_in_points ()
44
52
return "\n " .join ([
45
53
# Remove Matplotlib's custom command \mathdefault. (Not using
46
54
# \mathnormal instead since this looks odd with Computer Modern.)
@@ -63,15 +71,8 @@ def _get_preamble():
63
71
* ([
64
72
r"\ifdefined\pdftexversion\else % non-pdftex case." ,
65
73
r" \usepackage{fontspec}" ,
66
- ] + [
67
- r" \%s{%s}[Path=\detokenize{%s/}]"
68
- % (command , path .name , path .parent .as_posix ())
69
- for command , path in zip (
70
- ["setmainfont" , "setsansfont" , "setmonofont" ],
71
- [pathlib .Path (fm .findfont (family ))
72
- for family in ["serif" , "sans\\ -serif" , "monospace" ]]
73
- )
74
- ] + [r"\fi" ] if mpl .rcParams ["pgf.rcfonts" ] else []),
74
+ * _to_fontspec (),
75
+ r"\fi" ] if mpl .rcParams ["pgf.rcfonts" ] else []),
75
76
# Documented as "must come last".
76
77
mpl .texmanager ._usepackage_if_not_loaded ("underscore" , option = "strings" ),
77
78
])
0 commit comments