[Tex/LaTex] Calligraphic and script fonts with both upper and lower case

alphabetfontsmath-mode

What do I need to do to define a \mathscr which can handle both upper and lower case letters and a \mathcal which can handle both upper and lower case, with the latter staying as close to the default \mathcal as possible?

A simple approach with a single \usepackage line along with some options supplied would be desirable. Every other solution I run into which involves a \newcommand, makeatletter, \newenvironment, \setmathfont, etc., has failed me.

Below, boondox was as close as I could get to the existing \mathcal. Note that my definition for scr did not support lowercase, for some reason.

XeLaTeX/PdfLaTeX make no difference here.

I've gone through a number of posts related to this topic, with none just working for me. I may have an issue with not being able to install font packages correctly? This is mysterious.

\documentclass{article}
\usepackage{mathrsfs}
\usepackage[scr=rsfs,cal=boondox]{mathalfa}
\begin{document}
    $$\mathscr{abcdefghijklmnopqrstuvwxyz}$$
    $$\mathscr{ABCDEFGHIJKLMNOPQRST}$$
    $$\mathcal{abcdefghijklmnopqrstuvwxyz}$$
    $$\mathcal{ABCDEFGHIJKLMNOPQRST}$$
\end{document}

enter image description here

UPDATE: This may just be an issue with the rsfs font. Replacing my usepackage line above with

\usepackage[scr=esstix,cal=boondox]{mathalfa} 

produces results for all four lines. I prefer the rsfs fonts to esstix and prefer whatever the default \mathcal font is to boondox. But if no one has another solution, this may just need to be what I go with.

Best Answer

The unicode-math package supports OpenType math fonts, all of which have lowercase script letters (as well as bold).

By default, the package loads the same font as \mathcal and \mathscr, but you can override this with \setmathfont[range={cal,bfcal}, Scale=MatchUppercase]{...} or \setmathfont[range={scr,bfscr}, Scale=MatchUppercase]{...}.

\documentclass{article}
\usepackage{unicode-math}
% So that the output fits the allowed width on TeX.SX:
\usepackage[paperwidth=10cm]{geometry}

\setmathfont{STIX Two Math}
% Unicode uses the same range for `\mathcal` and `\mathscr` letters, but the
% STIX Two font provides a separate script alphabet as Stylistic Set 01.
\setmathfont[range={scr,bfscr}, StylisticSet=1]{STIX Two Math}

\begin{document}
    \[\mathscr{abcdefghijklmnopqrstuvwxyz}\]
    \[\mathscr{ABCDEFGHIJKLMNOPQRST}\]
    \[\mathcal{abcdefghijklmnopqrstuvwxyz}\]
    \[\mathcal{ABCDEFGHIJKLMNOPQRST}\]
\end{document}

STIX Two font sample

A few other OpenType math fonts come with separate \mathcal and \mathscr alphabets, including XITS Math and Asana Math. You can, however, mix and match however you like. You could, for example, add

\setmathfont[range={cal,bfcal},
                    Scale=MatchUppercase
                   ]{STIX Two Math}

or

\setmathfont[range={scr,bfscr},
             Scale=MatchUppercase,
             StylisticSet=1
            ]{STIX Two Math}

to use the script or calligraphic alphabets above in another document.

There are a handful of legacy NFSS math script fonts that come in lowercase. For example, stix2-mathscr does, but stix2-mathcal does not. The mathalfa package ought to be able to load the lowercase alphabet if it exists; you should not need to load both mathalfa and a package such as mathrsfs.