# Fallback for mathcal unicode characters in lualatex with proper height

Very few monospace fonts support unicode characters like U+1D4AA (Mathematical Script Capital O). I'm using DejaVu Sans Mono, and I'd like to define a fallback. Right now I have this:

\documentclass{article}
\usepackage{fontspec}
\usepackage{newunicodechar}
\setmonofont{DejaVu Sans Mono}[Scale=MatchLowercase]
\newunicodechar{𝒪}{$\mathcal{O}$}
\begin{document}
Aa\texttt{Aa𝒪A}
\end{document}


Which produces:

I'd like the O to be the same size as the monospaced A (but keeping the height of the monospaced a the same as the body text a).

I'm not seeing any OpenType font with the Computer Modern calligraphic letters. With Latin Modern Math you get a similar glyph. Anyway, I'm afraid you need to compute the scale factor yourself.

\documentclass{article}
\usepackage{fontspec}
\usepackage{newunicodechar}

\setmonofont{DejaVu Sans Mono}[Scale=MatchLowercase]
\newfontface{\calligraphic}{Latin Modern Math}[Scale=0.85]
\newunicodechar{𝒪}{{\normalfont\calligraphic 𝒪}}

\begin{document}

Aa\texttt{Aa𝒪A}

\end{document}


• @DavidCarlisle Can you elaborate why it's an issue in this case? I'd like to understand this. We're dealing with a true unicode character, not trying to make a font change. – ipswitch Jun 13 at 11:07
• @DavidCarlisle Ah, got it. Thanks! This is just a minimal example. I'm using it to typeset Julia code that has some unicode characters. – ipswitch Jun 13 at 16:28
\documentclass{article}
\usepackage{unicode-math}
\usepackage{newunicodechar}
\setmonofont{DejaVu Sans Mono}[Scale=MatchLowercase]
\setmathfont{XITS Math}
\setmathfont[Scale=0.85,range="1D4AA]{XITS Math}
\newunicodechar{𝒪}{$\symcal{O}$}
\begin{document}
Aa\texttt{Aa𝒪A}\tiny Aa\texttt{Aa𝒪A}
\end{document}


• That's definitely the desired effect! Does there happen to be a way to do it without using the unicode-math package? – ipswitch Jun 12 at 20:57
• Yes, you can define your own virtual font, but that is more work than using unicode-math which itself should already be loaded if someone uses xelatex or lualatex – Red-Cloud Jun 13 at 6:17