4

As the title states, Unicode characters do not appear in math-mode. From my understanding, the package "unicode-math" should make them appear.

My question is, why don't they appear and how I can get it working.

A minimal working example is this:

\documentclass[a4paper,12pt,DIV=15, ngerman, parskip=half]{scrartcl}  % parskip=half or parskip=full

\usepackage{csquotes}
\usepackage[ngerman]{babel}


%% The AMS-Packages
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}

\usepackage{ifluatex}
\ifluatex%
  % Lua(La)TeX
  \usepackage{fontspec}
  \usepackage[math-style=ISO, bold-style=ISO]{unicode-math}

\else
  %default: pdf(La)TeX
  \usepackage{lmodern} % load vector font
  \usepackage[T1]{fontenc} % font encoding
  \usepackage[utf8]{inputenc} % input encoding
\fi


\usepackage[stretch=10,shrink=10]{microtype}


\begin{document}

Latex: \(\hbar\) vs. Unicode: \(ħ\) (Unicode normal: ħ)

Latex: \(\mu\) vs. Unicode: \(µ\) (Unicode normal: µ)

\end{document}

Which leads to the following output:

Unicode-Math-Demonstration

As one can see, the Symbols simply do not appear, when used in Mathmode. I am using Texlive 2021 and luatex and I can not find any relevant warnings, nor errors.

3 Answers 3

6

You are using the wrong input. The mathematical ℏ is U+210F and not ħ (U+0127). Similar for the mu: 𝜇 is U+1D707 and not μ (U+03BC)

\documentclass{article}  

\usepackage{fontspec}
\usepackage[math-style=ISO, bold-style=ISO]{unicode-math}

\begin{document}

Latex: \(\hbar\) vs. Unicode: \(ℏ\neq ħ\) (Unicode normal: ħ)

Latex: \(\mu\) vs. Unicode: \(𝜇\neq µ\) (Unicode normal: µ)

\end{document}

enter image description here

Side remark: unicode-math is not so much about input but about output. So it ensures that \hbar adds an ℏ to the PDF (and I could copy it from there).

9
  • This makes sense, thank you! Do you by chance have tips on how to find the "right" unicode-characters? And how to typeset them efficiently?
    – Sinthoras
    Nov 12, 2022 at 13:44
  • well it depends on your OS and keyboard what you can type easily. I normally simply use the commands, that is fastest. Nov 12, 2022 at 13:47
  • I use Fedora Linux with a standard German keyboard. (I think I will probably remap some keys for the often used symbols, e.g. greek letters...) What I meant to ask with the first question was about some kind of list of symbols that will be recognized in math mode and these, which will be recognized in textmode. (I assume all of these are suitable for math mode, compart.com/en/unicode/block/U+1D400. As a remark, the math hbar is not U+201F, because that seems to be "Double High-Reversed-9 Quotation Mark" (unicodeplus.com/U+201F)).
    – Sinthoras
    Nov 12, 2022 at 14:00
  • I personally would find it ideal, if LaTex recognized, whether a symbol is in math mode or not and compile it to the "correct" pdf-symbol instead of ignoring it.
    – Sinthoras
    Nov 12, 2022 at 14:00
  • if you input an "a" LaTeX can not guess that you mean a "b". But you can make the input active and define it to do something different in math. (I corrected the 201F to 210F). Nov 12, 2022 at 14:11
8

There is misunderstanding, because we have characters with similar shapes but different meanings in Unicode table.

ħ U+0127  Latin Small Letter H With Stroke
ℏ U+210F  Planck Constant Over Two Pi, \hslash, \let\hbar=\hslash
µ U+00B5  Micro Sign
μ U+03BC  Greek Small Letter Mu        \mu
𝜇 U+1D707 Mathematical Italic Small Mu

The character ħ (U+0127) is one from alphabet of a real language (like é, č, etc.) and it is not intended for math typesetting. You have used it in math mode, so the result is undefined. \hbar is equal to \hslash and it is Planck constant over pi, no letter h with stroke.

The character µ (U+00B5) is micro sign (used for units). It is not intended for math typesetting. You have used it in math mode, so the result is undefined. The \mu is equal to Greek small letter mu. Unicode math in TeX typically sets the \mathcode of this character U+03BC to U+1D707, i.e. this character is printed in italic.

2
  • Yes, there was a misunderstanding, but you explained it well. Thank you! Interestingly, the "Greek Small Letter Mu" only appears in math mode, not in text mode, so the result is exactly the same as the one of "Mathematical Italic Small Mu".
    – Sinthoras
    Nov 12, 2022 at 15:20
  • The default math font is latinmodern-math.otf, which has the MAS Unicode block in it, and therefore \mu. The text font, lmodern font (lmroman12-regular.otf) is Latin.
    – Cicada
    Nov 13, 2022 at 9:15
1

Misunderstanding easily arises.

Visual inspection of the font explains how.

A math font, such as TeX Gyre Pagella - Math, contains all symbols (bold, italic, etc) as defined for the MAS Unicode block:

MAS 1

and

MAS 2

By comparison, a text font, such as TeX Gyre Pagella, would not need the MAS glyphs:

No MAS

The text font will also have different font files for italic, bold, bold italic, etc. The math font will typically be only one font file (with ~1k bold, italic etc symbols in it).

The text font may or may not have Latin and Greek text alphabets in it (TeX Gyre Pagella has both), independent of the MAS, and as regular, italic, bold, etc. Likewise, the math font (TeX Gyre Pagella - Math also has both text Latin and Greek (but as regular only)).

unicode-math package joins all this together (via mapping and ranges), and adds ISO formatting on top.

TGP-M

Consider case2, where the math font is being used in math mode (in blue), and is also being used as the text font in text mode (in red): that is, the MAS glyphs appear in both modes.

So where a glyph comes from, and how it displays in text/math mode, depends on multiple interlocking and overlapping factors.

MWE

\documentclass{article}  
\usepackage{xcolor}
%\usepackage[math-style=ISO, bold-style=ISO]{unicode-math}
\usepackage{unicode-math}
\setmainfont{TexGyrePagella}
\setmathfont{TexGyrePagella-Math}[Colour=blue]
\newfontface\fonttgpm{TexGyrePagella-Math}[Colour=red]
\newcommand\tqbf{The quick brown fox jumps over the lazy dog.}
\newcommand\texta{[Aa] }
\newcommand\textb{\textit{italic} \textbf{bold} \textbf{\textit{bolditalic}} \textsc{Small Caps} }
\newcommand\mas{\texta 𝐀𝐚 𝐴𝑎 𝑨𝒂 𝒜𝒶 𝓐𝓪 𝔄𝔞 𝔸𝕒 𝕬𝖆 𝖠𝖺 𝗔𝗮 𝘈𝘢 𝘼𝙖 𝙰𝚊 𝚪𝛄 𝛤𝛾 𝜞𝜸 𝝘𝝲 𝞒𝞬 𝟎 𝟘 𝟢 𝟬 𝟶}
\newcommand\mymus{µ - μ - 𝛍 𝜇 𝝁 𝝻 𝞵}


\begin{document}

1a. text font = TexGyrePagella (1550 chars) [r,i,b,bi, no MAS]

\noindent
t $\mapsto$ \tqbf

\noindent
t$_2$ $\mapsto$ \textb

\noindent
t $\mapsto$ \mymus ; m $\mapsto$ $\mymus$

\noindent
m $\mapsto$ \mas

\bigskip
1b. math font = TexGyrePagella-Math (4247 chars) [has MAS]

\noindent
t $\mapsto$ \tqbf

\noindent
t$_2$ $\mapsto$ \textb

\noindent
t $\mapsto$ \mymus ; m $\mapsto$ $\mymus$

\noindent
m $\mapsto$ $\mas$

\bigskip
2. math font used as text font = TexGyrePagella-Math [MAS as text, MAS as math]

{\fonttgpm 

\noindent
t $\mapsto$ \tqbf

\noindent
t$_2$ $\mapsto$ \textb

\noindent
t $\mapsto$ \mymus ; m $\mapsto$ $\mymus$

\noindent
m $\mapsto$ \mas 

\noindent
m$_2$ $\mapsto$ $\mas$ 
}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .