Match fonts between LaTeX math mode and a figure generated in Python

fonts

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.

Best Answer

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