Skip to content

Commit 8955c7f

Browse files
committed
Add Latin Modern support for mathtext
1 parent 42c8f2a commit 8955c7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+80
-6
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,45 @@ class DejaVuSerifFonts(DejaVuFonts):
639639
}
640640

641641

642+
class LatinModernFonts(UnicodeFonts):
643+
"""
644+
A font handling class for the Latin Modern fonts
645+
646+
"""
647+
_fontmap = {
648+
'rm': 'Latin Modern Roman',
649+
'bf': 'Latin Modern Roman:weight=bold',
650+
'it': 'Latin Modern Roman:italic',
651+
'bfit': 'Latin Modern Roman:italic:bold',
652+
'ex': 'Latin Modern Math'
653+
}
654+
_fallback_font = False
655+
_sans = False
656+
657+
def __init__(self, *args, **kwargs):
658+
# This must come first so the backend's owner is set correctly
659+
self.fontmap = {}
660+
TruetypeFonts.__init__(self, *args, **kwargs)
661+
662+
for key, name in self._fontmap.items():
663+
fullpath = findfont(name)
664+
self.fontmap[key] = fullpath
665+
self.fontmap[name] = fullpath
666+
667+
def _get_glyph(self, fontname, font_class, sym):
668+
uniindex = get_unicode_index(sym)
669+
if (fontname not in self._fontmap.items()):
670+
fontname, uniindex = self._map_virtual_font(
671+
fontname, font_class, uniindex)
672+
673+
font = self._get_font(fontname)
674+
if font is not None:
675+
glyphindex = font.get_char_index(uniindex)
676+
if glyphindex != 0:
677+
return super()._get_glyph(fontname, font_class, sym)
678+
return super()._get_glyph('ex', font_class, sym)
679+
680+
642681
class DejaVuSansFonts(DejaVuFonts):
643682
"""
644683
A font handling class for the DejaVu Sans fonts
@@ -840,6 +879,10 @@ class FontConstantsBase:
840879
delta_integral = 0.1
841880

842881

882+
class LatinModernFontConstants(FontConstantsBase):
883+
pass
884+
885+
843886
class ComputerModernFontConstants(FontConstantsBase):
844887
script_space = 0.075
845888
subdrop = 0.2
@@ -887,6 +930,8 @@ class DejaVuSansFontConstants(FontConstantsBase):
887930
'cmss10': ComputerModernFontConstants,
888931
'cmsy10': ComputerModernFontConstants,
889932
'cmtt10': ComputerModernFontConstants,
933+
'Latin Modern Roman': LatinModernFontConstants,
934+
'Latin Modern Math': LatinModernFontConstants,
890935
'STIXGeneral': STIXFontConstants,
891936
'STIXNonUnicode': STIXFontConstants,
892937
'STIXSizeFiveSym': STIXFontConstants,

lib/matplotlib/font_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ class FontProperties:
562562
absolute font size, e.g., 10. Default: :rc:`font.size`
563563
564564
- math_fontfamily: The family of fonts used to render math text.
565-
Supported values are: 'dejavusans', 'dejavuserif', 'cm',
565+
Supported values are: 'lm', 'dejavusans', 'dejavuserif', 'cm',
566566
'stix', 'stixsans' and 'custom'. Default: :rc:`mathtext.fontset`
567567
568568
Alternatively, a font may be specified using the absolute path to a font

lib/matplotlib/mathtext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class MathTextParser:
4141
'dejavusans': _mathtext.DejaVuSansFonts,
4242
'stix': _mathtext.StixFonts,
4343
'stixsans': _mathtext.StixSansFonts,
44+
'lm': _mathtext.LatinModernFonts,
4445
'custom': _mathtext.UnicodeFonts,
4546
}
4647

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
% This is version 1.0, dated 22 June 2009, of the GUST Font License.
2+
% (GUST is the Polish TeX Users Group, http://www.gust.org.pl)
3+
%
4+
% For the most recent version of this license see
5+
% http://www.gust.org.pl/fonts/licenses/GUST-FONT-LICENSE.txt
6+
% or
7+
% http://tug.org/fonts/licenses/GUST-FONT-LICENSE.txt
8+
%
9+
% This work may be distributed and/or modified under the conditions
10+
% of the LaTeX Project Public License, either version 1.3c of this
11+
% license or (at your option) any later version.
12+
%
13+
% Please also observe the following clause:
14+
% 1) it is requested, but not legally required, that derived works be
15+
% distributed only after changing the names of the fonts comprising this
16+
% work and given in an accompanying "manifest", and that the
17+
% files comprising the Work, as listed in the manifest, also be given
18+
% new names. Any exceptions to this request are also given in the
19+
% manifest.
20+
%
21+
% We recommend the manifest be given in a separate file named
22+
% MANIFEST-<fontid>.txt, where <fontid> is some unique identification
23+
% of the font family. If a separate "readme" file accompanies the Work,
24+
% we recommend a name of the form README-<fontid>.txt.
25+
%
26+
% The latest version of the LaTeX Project Public License is in
27+
% http://www.latex-project.org/lppl.txt and version 1.3c or later
28+
% is part of all distributions of LaTeX version 2006/05/20 or later.
Binary file not shown.
109 KB
Binary file not shown.
115 KB
Binary file not shown.
109 KB
Binary file not shown.
116 KB
Binary file not shown.

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
#font.size: 10.0
268268

269269
#font.serif: DejaVu Serif, Bitstream Vera Serif, Computer Modern Roman, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
270-
#font.sans-serif: DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
270+
#font.sans-serif: DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, Latin Modern Roman, sans-serif
271271
#font.cursive: Apple Chancery, Textile, Zapf Chancery, Sand, Script MT, Felipa, Comic Neue, Comic Sans MS, cursive
272272
#font.fantasy: Chicago, Charcoal, Impact, Western, Humor Sans, xkcd, fantasy
273273
#font.monospace: DejaVu Sans Mono, Bitstream Vera Sans Mono, Computer Modern Typewriter, Andale Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace
@@ -335,7 +335,7 @@
335335
## The following settings allow you to select the fonts in math mode.
336336
#mathtext.fontset: dejavusans # Should be 'dejavusans' (default),
337337
# 'dejavuserif', 'cm' (Computer Modern), 'stix',
338-
# 'stixsans' or 'custom'
338+
# 'stixsans', 'custom', 'lm' (Latin Modern)
339339
## "mathtext.fontset: custom" is defined by the mathtext.bf, .cal, .it, ...
340340
## settings which map a TeX font name to a fontconfig font pattern. (These
341341
## settings are not used for other font sets.)

0 commit comments

Comments
 (0)