1

Using unicode-math with LuaTeX. The font Fira Math is missing some glyphs that I use, notably the symbol for \bot. I know that I can grab it from a different font:

\setmathfont[range={"022A5}]{DejaVu Math TeX Gyre}

but that bloats my PDF with yet another font. Alternatively, I can redefine the command \bot:

\AtBeginDocument{\renewcommand{\bot}{\mathord{\perp}}}

but that's exactly the wrong level — a glyph substitution shouldn't require modifying TeX's input syntax. The obvious solution would be to perform the subsitution at the luaotfload level,

  \directlua{
    fonts.handlers.otf.addfeature {
      name = "bottoperp",
      type = "substitute",
      data = {
        [0x22A5] = {0x27C2},
      },
    }
  }
  \setmathfont{Fira Math}[RawFeature=+bottoperp]

but that appears to do nothing.

What is the right way to substitute a glyph with LuaTeX and unicode-math?

8
  • I don't understand what you want. If \perp is the symbol you want, then why don't you use it? Commented Oct 24, 2020 at 22:54
  • \bot is the symbol I want, and it's not in the font.
    – jch
    Commented Oct 24, 2020 at 22:55
  • \perp works fine for me, Commented Oct 24, 2020 at 22:56
  • I has the wrong spacing, compare $x = \bot$ with $x = \perp$. Redefining \bot to {\perp} works fine, due to the extra set of brackets, not sure if it will cause any other trouble.
    – jch
    Commented Oct 24, 2020 at 23:02
  • Well U+22A4 (\bot, UP TACK) is defined as a \mathord in unicode-math, U+27C2 (\perp, PERPENDICULAR) is a \mathrel, so yes their spacing is different, but they have also a different unicode code point and meaning, so if you want U+22A5, then you should get it either from another font, or map it with addfeature, so that the to unicode value is right. Commented Oct 24, 2020 at 23:10

2 Answers 2

2

Instead of using newunicodechar to make the character active, you can adjust the mathcode of \bot to use the glyph for \perp:

\documentclass{article}
\usepackage{unicode-math}

\setmainfont{Fira Sans}
\setmathfont{Fira Math}


\AtBeginDocument{%
  % For U+22A5, use class \mathord (0), family 0 and glyph U+27C2
  \Umathcode"22A5 0 0 "27C2
}

\begin{document}

$a\bot b$ or $a ⊥ b$

$a\perp b$ or $a ⟂ b$

\end{document}

enter image description here

0

Just make active and define it to be \bot, but redefining this one to be {\perp}.

\documentclass{article}
\usepackage{unicode-math}
\usepackage{newunicodechar}

\setmainfont{Fira Sans}
\setmathfont{Fira Math}

% there is no \bot in Fira Sans
\AtBeginDocument{\renewcommand{\bot}{{\perp}}}
\newunicodechar{⊥}{\bot}

\begin{document}

$a\bot b$ or $a ⊥ b$

$a\perp b$ or $a ⟂ b$

\end{document}

enter image description here

The picture shows that (U+22A5) is treated as an ordinary symbol and (U+27C2) as a relation symbol.

8
  • That works around the actual issue, but just like redefining the \bot macro, it's the wrong level — I should be able to substitute a glyph without munging the input syntax.
    – jch
    Commented Oct 25, 2020 at 17:25
  • @jch I'm not sure I understand. Anyway, I added to my example and your doubts should go away.
    – egreg
    Commented Oct 25, 2020 at 20:42
  • Greg, anything can be fixed with TeX macros, that's how we got into the mess we're in. LuaTeX holds the promise of fixing things at the font level when they are font issues, rather than building dozens of font-specific hacks at the TeX macro level, which interact in marvellous ways with the other font-specific hacks.
    – jch
    Commented Oct 25, 2020 at 21:02
  • Is newunicodechar good style in the context of LuaTeX/XeTeX and unicode-math? I had kinda convinced myself that it was only supposed to be used with pdfTeX.
    – Gaussler
    Commented Jul 23, 2021 at 10:22
  • @Gaussler It was born for pdflatex, but extending it to Unicode engines was easy. What it does is to make the character active and to give it a \protected definition.
    – egreg
    Commented Jul 23, 2021 at 10:27

You must log in to answer this question.

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