Here's my MWE:
% !TEX program = lualatex
% DOCUMENT CLASS
\documentclass[11pt,preview,varwidth,%
border={5pt 5pt 5pt 5pt}% left bottom right top
]{standalone}
% PACKAGES
\usepackage{mathtools, amssymb} % Math packages
\let\oldmathbb\mathbb % Computer Modern blackboard bold
\let\oldmathcal\mathcal % Computer Modern calligraphic
\AtBeginDocument{\def\mathbb{\oldmathbb}} % Redefine \mathbb to use Computer Modern
\AtBeginDocument{\def\mathcal{\oldmathcal}} % Redefine \mathcal to use Computer Modern
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math} % Math fonts
\setmathfont{Latin Modern Math}
\let\newmathbb\mathbb % Latin Modern blackboard bold
\let\newmathcal\mathcal % Latin Modern calligraphic
\newcommand{\AtoZ}{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
% START OF DOCUMENT
\begin{document}
Computer Modern's \verb|\mathbb|: (\mathbb{\AtoZ})
Latin Modern's \verb|\mathbb|: \(\newmathbb{\AtoZ}\)
Computer Modern's \verb|\mathcal|: \(\mathcal{\AtoZ}\)
Latin Modern's \verb|\mathcal|: \(\newmathcal{\AtoZ}\)
\end{document}
% END OF DOCUMENT
I am trying to mainly use Computer Modern's blackboard bold (\mathbb) and calligraphic (\mathcal) fonts in LuaTeX with the unicode-math package simply because I prefer them over Latin Modern's (in those particular cases) but I would still want to be able to access Latin Modern's blackboard bold and calligraphic fonts, hence the \newmathbb and \newmathcal macros.
As seen from my MWE, I seem to have a problem accessing Computer Modern's calligraphic font for some reason.
I've read this TeX.SX answer but when I used \setmathfont[range={cal}]{cmsy10}, I ended up not being able to access Latin Modern's calligraphic font instead as it seems to globally change every calligraphic font to cmsy10:
% !TEX program = lualatex
% DOCUMENT CLASS
\documentclass[11pt,preview,varwidth,%
border={5pt 5pt 20pt 5pt}% left bottom right top
]{standalone}
% PACKAGES
\usepackage{mathtools, amssymb} % Math packages
\let\oldmathbb\mathbb % Computer Modern blackboard bold
\AtBeginDocument{\def\mathbb{\oldmathbb}} % Redefine \mathbb to use Computer Modern
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math} % Math fonts
\setmathfont{Latin Modern Math}
\let\newmathbb\mathbb % Latin Modern blackboard bold
\let\newmathcal\mathcal % Latin Modern calligraphic
\setmathfont[range={cal}]{cmsy10} % Computer Modern calligraphic
\newcommand{\AtoZ}{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
% START OF DOCUMENT
\begin{document}
Computer Modern's \verb|\mathbb|: (\mathbb{\AtoZ})
Latin Modern's \verb|\mathbb|: \(\newmathbb{\AtoZ}\)
Computer Modern's \verb|\mathcal|: \(\mathcal{\AtoZ}\)
Latin Modern's \verb|\mathcal|: \(\newmathcal{\AtoZ}\)
\end{document}
% END OF DOCUMENT
(I received the warnings Package fontspec Warning: Font "cmsy10" does not contain requested Script "Math"., Package fontspec Warning: OpenType feature 'Style=MathScript' (ssty) not available for font 'cmsy10' with script '' and language 'Default'., and Package fontspec Warning: OpenType feature 'Style=MathScriptScript' (ssty) not available for font 'cmsy10' with script '' and language 'Default'.)
I've also read another TeX.SX answer but when I tried its approach I still couldn't use both Computer Modern and Latin Modern's calligraphic fonts at the same time:
% !TEX program = lualatex
% DOCUMENT CLASS
\documentclass[11pt,preview,varwidth,%
border={5pt 5pt 20pt 5pt}% left bottom right top
]{standalone}
% PACKAGES
\usepackage{mathtools, amssymb} % Math packages
\let\oldmathbb\mathbb % Computer Modern blackboard bold
\AtBeginDocument{\def\mathbb{\oldmathbb}} % Redefine \mathcal to use Computer Modern
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math} % Math fonts
\setmathfont{Latin Modern Math}
\let\newmathbb\mathbb % Latin Modern blackboard bold
\ExplSyntaxOn
\makeatletter
\cs_new:Npn\definemathgroup#1#2#3#4{
\fontspec_set_family:Nnn\l_my_math_font_family{SmallCapsFont={},ItalicFont={},BoldFont={},Script=Math,#3}{#4}
\exp_args:Nc\new@mathgroup{\string#1}
::c::n::f:::\new@symbolfont{\string#1}{TU}{\l_my_math_font_family}{\seriesdefault}{\shapedefault}
\cs_new:Npn#1##1{#2{\fam\use:c{\string#1}##1}}
}
\makeatother
\ExplSyntaxOff
\definemathgroup{\oldmathcal}{\symcal}{}{cmsy10} % Computer Modern calligraphic
\AtBeginDocument{\def\mathcal{\oldmathcal}} % Redefine \mathcal to use Computer Modern
\definemathgroup{\newmathcal}{\symcal}{}{Latin Modern Math} % Latin Modern calligraphic
\newcommand{\AtoZ}{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
% START OF DOCUMENT
\begin{document}
Computer Modern's \verb|\mathbb|: (\mathbb{\AtoZ})
Latin Modern's \verb|\mathbb|: \(\newmathbb{\AtoZ}\)
Computer Modern's \verb|\mathcal|: \(\mathcal{\AtoZ}\)
Latin Modern's \verb|\mathcal|: \(\newmathcal{\AtoZ}\)
\end{document}
% END OF DOCUMENT
(I also received the warning Package fontspec Warning: Font "cmsy10" does not contain requested Script "Math".)
What went wrong and how do I fix this issue?
Thank you.




\let\oldmathbb\mathbbdo not do what your comments say they do after such a defintion, at best,\oldmathbbwill access whatever font has the same\famas the original\mathbb, but it will not be the same font if you redeclared math fonts. Also you are mixing opentype math where\mathbbdoes not change fonts (\mathbb{Z}is character U+2124 ℤ in the same font as Z) with classic 8 bit tex fonts (where\mathbb{Z}s the character Z but in a different font). Hence warnings about cmsy10. – David Carlisle Nov 29 '22 at 12:28\old...and\new,,,? – barbara beeton Nov 29 '22 at 12:49\oldmathcalto be Computer Modern's calligraphic font in math mode and\newmathcalfor Latin Modern's calligraphic font in math mode. Then I want to redefine\mathcalto be\oldmathcal. – Amanuensis Frances Nov 29 '22 at 13:08