8

I'm trying to create a figure in Python whose text matches (at least closely) Latex's math mode font. However, I'm not finding any information online that gives results close to the desired font, particularly on the Greek characters. For example, Latex produces the following:

\documentclass{article}
\usepackage{textgreek}
\begin{document}
\textit{testθτμ}

$test\theta\tau\mu$

\end{document}

Latex output

I'm trying to replicate the second line of text. Based on other answers on SE, and information I've found online, I've tried the following fonts, and had the following issues:

Computer Modern: way too curly/cursive

Computer Modern Sans: different style, most noticeable on tau

New Computer Modern 10: way too curly/cursive

New Computer Modern Math: not italic

Latin Modern Math: not italic

Is there something I'm missing here? Am I just not finding the italic variants of the math fonts, or is math mode using an entirely different font? Any clues would be appreciated; any links to a download would be very much appreciated.

8
  • 4
    It is Computer modern, which you'll see from e.g. \documentclass{article} \begin{document} $\theta\tau\mu$ \end{document}: adding \showouput gives e.g. \OML/cmm/m/it/10. Perhaps you are using a document that does not use the standard font setup?
    – Joseph Wright
    Dec 14, 2023 at 4:59
  • 1
    Computer Modern Roman. OpenType versions include New Computer Modern Math and Latin Modern Math. The Latin letters are based on Monotype Modern and the Greek letters on Porson.
    – Davislor
    Dec 14, 2023 at 5:06
  • 4
    The font is named "computer modern math", but I suspect your actual question is e.g. "how to use font Computer Modern Math in Microsoft Word" or something like that. In which case, the font is a Type1 font which is not particularly usable in Microsoft Word, so consider using Latin Modern Math instead.
    – user202729
    Dec 14, 2023 at 6:38
  • 2
    @RyanWhite Your issue likely is that over the years subtle re-designs have been made, so the exact shapes you want are only available in the classical TeX fonts. For example, Computer Modern Unicode has Greek letter shapes for typing Greek, not for maths - there are different typographic traditions and so there is no one 'right' answer.
    – Joseph Wright
    Dec 14, 2023 at 7:33
  • 1
    text.usetex perhaps? stackoverflow.com/questions/11367736/… (tex.stackexchange.com/questions/30998/… has an alternative)
    – user202729
    Dec 14, 2023 at 7:45

3 Answers 3

14

Classic TeX does not use a math font. The fonts only have 127 characters and so many (up to 16) fonts per math expression are used. (The system allows 256 characters per font but using 8 bits was thought too radical in 1980 so only the lower half of each font is used)

so

\documentclass{article}
\showoutput
\begin{document}

$test\theta\tau\mu+1$

\end{document}

uses cmmi10.pfb for test (with the letters in standard ascii positions). It uses the same font but the positions for Ctrl-R, Ctrl-\ , and Ctrl-V for the Greek and it uses cmr10.pfb for the + and 1.

This makes it very tricky to use TeX math fonts from other systems even if they can use Type 1 fonts.

A Unicode math font has all these characters in a single font, in standard positions which makes it much easier to use in other systems.

Processing with LuaLaTeX

\documentclass{article}
\usepackage{unicode-math}
\showoutput
\begin{document}

$test\theta\tau\mu+1$

\end{document}

All the characters come from Latin Modern Math (latinmodern-math.otf) in standard Unicode slots, note the math italic are separate characters.

The resulting string will work with any Unicode math font, not just Latin Modern.

For example on this site it will pick up whatever font you have installed locally (it uses the Windows font Segoe UI Symbol here)

𝑡𝑒𝑠𝑡𝜃𝜏𝜇+1

Or see this URL for a listing of all the Unicode slots used.

Result:

 U+1d461 MATHEMATICAL ITALIC SMALL T     \mitt \mathmit{t}
 U+1d452 MATHEMATICAL ITALIC SMALL E     \mite \mathmit{e}
 U+1d460 MATHEMATICAL ITALIC SMALL S     \mits \mathmit{s}
 U+1d461 MATHEMATICAL ITALIC SMALL T     \mitt \mathmit{t}
 U+1d703 MATHEMATICAL ITALIC SMALL THETA     \mittheta \mathmit{\theta}
 U+1d70f MATHEMATICAL ITALIC SMALL TAU     \mittau \mathmit{\tau}
 U+1d707 MATHEMATICAL ITALIC SMALL MU     \mitmu \mathmit{\mu}
 U+002b PLUS SIGN     + \mathplus +
 U+0031 DIGIT ONE     1
6

(too long for a comment, hence posted as an answer)

In this answer, I mainly address the OP's claim that Latin Modern Math (LMM ) "doesn't seem to have [math] italics". I'm puzzled by this claim. Indeed, the following example, which needs to be compiled with either XeLaTeX or LuaLaTeX, demonstrates that LMM does have math-italic latin and greek letters.

Of course, you should use text-italic rather than math-italic glyphs if you want to write something in text-mode italics.

The unicode-math package provides the command \symup to write symbols in upright mode.

enter image description here

\documentclass{article}
\usepackage{unicode-math} % for '\setmathfont' macro; load 'fontspec' package automatically
\setmainfont{Latin Modern Roman}
\setmathfont{Latin Modern Math}

\begin{document}

\textit{abcxyz} $abcxzy$ $\theta\tau\mu$ abcxyz $\symup{\theta\tau\mu}$

\end{document}
2
  • I'm not sure how Latex handles LMM italics in math mode (maybe it knows to use the separate italic characters, as mentioned in David's answer). But these are separate characters, not a separate fontset, and at this point my issue becomes a Python issue. I believe the standard way of using italics in Python is to point to an italic fontset, whereas LMM would require me to find the individual italic unicode characters, rather than just typing like normal.
    – Ryan White
    Dec 14, 2023 at 16:21
  • 3
    @RyanWhite I would use opentype latin modern math, and simply map the characters in python, the relevant tables are in w3c.github.io/xml-entities/italic.html if you use the classic math fonts you can type italic abc "as normal" but everything else is far more complicated you need mapping tables for every character saying what position it is in and in what font, eg Greek isn't in a single font as any greek that looks like Latin shares a slot with so there is no Alpha for example. and Greek is in an ad-hoc encoding in the Control character range (Gamma is in position 0, ascii null) Dec 14, 2023 at 16:47
3

This post shows another tool in addition to the other good answers. The following is based on your MWE

\documentclass{article}
\usepackage{textgreek}
\begin{document}
\textit{testθτμ}%ϑ

$test\theta\tau\mu$

\end{document}

You might be able to use pdffonts in a shell of your choice to generate a table of all fonts of the PDF (I replaced some parts by [...]):

$ pdflatex Example.SE.tex; echo "\nTable for Ryan White:"; pdffonts Example.SE.pdf
This is pdfTeX, Version 3.141592653-2.6-1.40.25 (TeX Live 2023) (preloaded format=pdflatex)
[...]
Output written on Example.SE.pdf (1 page, 39405 bytes).
Transcript written on Example.SE.log.

Table for Ryan White:
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
MSKRKD+CMTI10                        Type 1            Builtin          yes yes yes      4  0
TPJLSH+grmi1000                      Type 1            Builtin          yes yes yes      5  0
OIWUEJ+SFTI1000                      Type 1            Custom           yes yes yes      6  0
RYTSZC+CMMI10                        Type 1            Builtin          yes yes yes      7  0
SDXKYB+CMR10                         Type 1            Builtin          yes yes yes      8  0

I get a similar table by $ latex Example.SE.tex; vipdfm Example.SE.dvi; echo "\nTable for Ryan White:"; pdffonts Example.SE.pdf:

name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
BGNOPA+CMTI10                        Type 1C           Builtin          yes yes yes      4  0
DOYMNM+grmi1000                      Type 1C           Builtin          yes yes yes      5  0
VQMNVE+SFTI1000                      Type 1C           WinAnsi          yes yes yes      6  0
SIZLWA+CMMI10                        Type 1C           Builtin          yes yes yes      7  0
ZIUSPE+CMR10                         Type 1C           Builtin          yes yes yes      8  0

You will find descriptions of the abbreviations like CMTI10 (Computer Modern Italic, "more condensed and slightly lighter", size 10pt) on https://ctan.org/tex-archive/fonts/cm/mf. Others informations are available at https://eng.m.fontke.com/font/10030505/detail/. SFTI1000 is listed on SFTI1000 as "Postscript name" of Computer Modern. grmi1000 seems to be an italic one of the Claudio Beccari Greek fonts, see https://ctan.org/tex-archive/fonts/greek/cbfonts/fonts/tfm/cbgreek and https://ctan.org/pkg/cbgreek-complete. If you remove \usepackage{textgreek} and \textit{testθτμ}of your file and compile again then only CMMI10 (Computer Modern Italic, "not condensed and not quite as light", 10pt) and CMR10 (Computer Modern Italic, "basic", 10pt) remain.

Thus, a precise nerd's answer to your question (before an edit) "What is Latex's math mode font?" is CMMI10 (Computer Modern Italic, "not condensed and not quite as light", 10pt) with respect to the set up mentioned above.

Observe the differences to LuaTeX:

$ lualatex Example.SE.tex; echo "\nTable for Ryan White:"; pdffonts Example.SE.pdf 
This is LuaHBTeX, Version 1.17.0 (TeX Live 2023) 
[...]
Output written on Example.SE.pdf (1 page, 12154 bytes).
Transcript written on Example.SE.log.

Table for Ryan White:
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
EJJTSY+LMRoman10-Italic              CID Type 0C       Identity-H       yes yes yes      4  0
RYTSZC+CMMI10                        Type 1            Builtin          yes yes no       5  0
JFRMQG+LMRoman10-Regular             CID Type 0C       Identity-H       yes yes yes      6  0

LMRoman is Latin Modern.

Compiling

\documentclass{article}
\usepackage{textgreek}
\usepackage{unicode-math} % ADDED
\begin{document}
\textit{testθτμ}

$test\theta\tau\mu$

\end{document}

gives

$ lualatex Example.SE.tex; echo "\nTable for Ryan White:"; pdffonts Example.SE.pdf 
This is LuaHBTeX, Version 1.17.0 (TeX Live 2023) 
[...]
Output written on Example.SE.pdf (1 page, 6180 bytes).
Transcript written on Example.SE.log.

Table for Ryan White:
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
EJJTSY+LMRoman10-Italic              CID Type 0C       Identity-H       yes yes yes      4  0
WLUBUQ+LatinModernMath-Regular       CID Type 0C       Identity-H       yes yes yes      5  0
JFRMQG+LMRoman10-Regular             CID Type 0C       Identity-H       yes yes yes      6  0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .