Skip to content

Route selected mathtext glyphs to Computer Modern#744

Open
cvanelteren wants to merge 3 commits into
mainfrom
fix/mathtext-computer-modern-routing
Open

Route selected mathtext glyphs to Computer Modern#744
cvanelteren wants to merge 3 commits into
mainfrom
fix/mathtext-computer-modern-routing

Conversation

@cvanelteren

Copy link
Copy Markdown
Collaborator

Closes #717

This patch allows users to use Computer Modern font for certain latex symbols.

test
snippet
import ultraplot as uplt

expr = (
    r"$\mathcal{ABCXYZ}\quad"
    r"\sum_{i=0}^{n}\quad"
    r"\prod_{j=1}^{m}\quad"
    r"\int_a^b\quad"
    r"\oint_C$"
)

fig, axs = uplt.subplots(
    nrows=2,
    refwidth=9,
    refheight=1.7,
    share=False,
    span=False,
)

contexts = (
    (
        "Control: DejaVu math fontset",
        {
            "mathtext.fontset": "dejavusans",
            "mathtext.default": "it",
        },
    ),
    (
        "UltraPlot patched default: selective Computer Modern",
        {},
    ),
)

for ax, (title, rc_kw) in zip(axs, contexts):
    with uplt.rc.context(rc_kw):
        ax.text(0.02, 0.5, expr, transform="axes", fontsize=34, va="center")
    ax.format(title=title, titleloc="left")

axs.format(xlocator="null", ylocator="null", xspineloc="none", yspineloc="none")
uplt.show()

@cvanelteren

Copy link
Copy Markdown
Collaborator Author

This patch adds an opt-in mathtext.cm to the RC settings that leaves the current math rendering unchanged by default. When it is enabled it routes \mathcal through Computer Modern (cmsy10) and selected large operators (\sum, \prod, \coprod, \int, \oint) through Matplotlib's CM/Bakoma while preserving the active UltraPlot font for normal letters and numbers.

@cvanelteren

cvanelteren commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

Can you test this PR @lzhang1994 to see if this would work for you?

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.38554% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultraplot/internals/fonts.py 87.50% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Math font

1 participant