1

I specifically want "⦂" (U2982, Z NOTATION TYPE COLON) to appear as a colon with mathrel spacing (or better yet, the way amsmath redefines \colon)

But redefining \typecolon with \AtBeginDocument doesn't work. I have also tried using lower level unicode-math commands. A MWE containing my attempts follows:

%!TEX program = lualatex

\documentclass{article}
\usepackage[math-style=ISO, partial=upright]{unicode-math}
\setmathfont{LibertinusMath-Regular.otf}

\AtBeginDocument{
  \let\typecolon\colon % fails
% \renewcommand{\typecolon}{\nobreak\mskip2mu\mathpunct{}\nonscript
% \mkern-\thinmuskip{:}\mskip6muplus1mu\relax} % fails
}

% \ExplSyntaxOn
% \AtBeginDocument{
  % \__um_process_symbol_noparse:nnn {"02982}{:}{\mathrel} % fails
  % \__um_process_symbol_noparse:nnn {"02982}{\colon}{\mathrel} % fails
  % \__um_remap_symbol:nnn {\`⦂} {\mathrel} {"02236} % fails
  % \__um_remap_symbol:nnn {\typecolon} {\mathrel} {"02236} % fails
% }
% \ExplSyntaxOff


\begin{document}

With explicit symbol: $f ⦂ A → B.$

With \verb|\symbol|: $f \symbol{"02982} A → B.$

With \verb|\typecolon|: $f \typecolon A → B.$

\end{document}

Which results in enter image description here

My assumption was that unicode-math defines the bare unicode character is defined as an ‘active character’ which expands to \typecolon, as per unicode-math-table.tex but, obviously, I'm wrong or redefining \typecolon would work.

What is the correct approach here? And where is my misunderstanding? Thanks in advance for all replies.


Version details:

I am using LuaLaTeX with unicode-math:

>_ lualatex --version                       
This is LuaHBTeX, Version 1.14.0 (TeX Live 2022/dev/Debian) […]

Specifically, that which is packaged with Ubuntu 22.04.

5
  • Same question as 1 2 . (also almost same as 3 but that one redefines a "commonly used" one) -- maybe there are something-else to be said here regarding why the __um ones doesn't work but... because they're "low level" what do you expect...
    – user202729
    Commented Jun 13, 2022 at 8:30
  • @user202729; Thanks for your insight. I was hoping that the tooling the modern engines and unicode-math (U-M) would provide a 'higher level' way of doing it. I worried something like the lowercase trick may actually interfere. The U-M package does the task en masse, and I want to comport with it. As for my expectations with __um functions, they've been used to good effect, so I expected they might work. They're not part of the public interface but that doesn't mean they're not useful, right?
    – Timtro
    Commented Jun 13, 2022 at 13:43
  • first, it's about the mathcode change and the definition in this case, not the lowercase part -- the lowercase part itself cannot interfere if you understand TeX sufficiently deeply. -- By the way, for the documentation of "internal commands" to see what they does, go to ctan.org/pkg/unicode-math and click "documentation of the source code".
    – user202729
    Commented Jun 13, 2022 at 14:26
  • 1
    For reference: also same question as 4
    – user202729
    Commented Jun 13, 2022 at 14:43
  • 1
    Actually, thinking about it, unicode-math works by loading fonts that happens to "already have" these characters in the correct position instead of using mathcode 8000, so there might not be any such convenient functions inside.
    – user202729
    Commented Jun 13, 2022 at 14:46

2 Answers 2

3

Assigning a \mathcode of "8000 makes a character “math active”. When used in math mode, such a 〈character〉 is replaced by an active character token having the original character code (TeXbook p. 289). Therefore, we only have to assign the appropriate \mathcode and make it so that the active behaves as \colon.

% Tested with LuaTeX and XeTeX
\documentclass{article}
\usepackage[math-style=ISO, partial=upright]{unicode-math}
\setmainfont{STIX-Regular.otf}  % to show the ⦂ in horizontal mode
\setmathfont{LibertinusMath-Regular.otf}

% In LuaTeX, \letcharcode`⦂=\colon can replace the following line (Marcel Krüger's hint)
\begingroup \lccode`~=`⦂ \lowercase{\endgroup\def~}{\colon}
\AtBeginDocument{\mathcode`⦂="8000\relax}

\begin{document}

With \verb|\colon|: $f \colon A → B$.

With explicit symbol: $f ⦂ A → B$.

With \verb|\symbol|: $f \symbol{"02982} A → B$.

“⦂” is still “\symbol{"02982}” (\verb|\symbol{"02982}|) in horizontal mode.

\end{document}

enter image description here

In math mode, \symbol{"02982} is also replaced by the active , because it expands to \char"02982\relax, and \char"02982 is a 〈character〉 that is treated in the same way in math mode as -with-catcode-12 (TeXbook p. 289).

5
  • Thanks for your thoughtful and erudite answer. I am waiting down the clock on the customary 24-hours before accepting. I wanted to ask about your reference to Marcel Krüger: where is his hint? I also wanted to note that I was hoping for something higher-level, making use of unicode-math's machinery. I was wondering if you had thoughts on weather that would even be worth the bother.
    – Timtro
    Commented Jun 13, 2022 at 14:07
  • 1
    Marcel's hint was in a comment here that he deleted after I incorporated the suggestion in my answer. I don't know if there is a way specifically using unicode-math; I'm certainly not an expert regarding this package.
    – frougon
    Commented Jun 13, 2022 at 14:17
  • RE: Krüger's comment: Oh, okay. I was wondering what I missed. I think what's still nagging me is why \AtBeginDocument{\let\typecolon\colon} doesn't work, as it does here for \setminus. But I think that's a new question at this point.
    – Timtro
    Commented Jun 13, 2022 at 14:25
  • @Timtro Well redefining commands like that doesn't seem like "public API" anyway. If it works it's probably by accident.
    – user202729
    Commented Jun 13, 2022 at 14:29
  • 1
    @Timtro In the question you linked to, the math expression uses \setminus. The fact that \let\setminus\smallsetminus has an effect on uses of \setminus is not surprising. But this doesn't magically make $A ⧵ B$ work with e.g. Latin Modern Math, which doesn't have U+29F5 (). In the same way, \let\typecolon\colon affects uses of \typecolon but not those of (unless special measures have been taken for , of course).
    – frougon
    Commented Jun 13, 2022 at 15:00
1

Just to point out the "internal unicode-math API" option, which the OP appears to prefer:

\documentclass{article}
\usepackage[math-style=ISO, partial=upright]{unicode-math}
\setmainfont{STIX-Regular.otf}
\setmathfont{LibertinusMath-Regular.otf}

\ExplSyntaxOn
\AtBeginDocument{
 \__um_mathactive_remap:nn {"2982} {\colon}
}
\ExplSyntaxOff

\begin{document}

With \verb|\colon|: $f \colon A → B$.

With explicit symbol: $f ⦂ A → B$.

With \verb|\symbol|: $f \symbol{"02982} A → B$.

“⦂” is still “\symbol{"02982}” (\verb|\symbol{"02982}|) in horizontal mode.
% MWE copied from the other answer, I don't actually have the fonts to test but testing with default font works well
\end{document}

In some other versions I think you need to drop the first __? as expected of an internal API.

There's also the \__um_map_char_single:nn and such under section "15.1   Mapping 'naked' math characters" in unicode-math-code.pdf but the documentation is a bit dense...

4
  • 1
    People should be aware that macros explicitly marked as private are likely to change in incompatible ways (which includes disappearing altogether...).
    – frougon
    Commented Jun 13, 2022 at 15:04
  • Thanks for finding __um_mathactive_remap:nn. I did look through the code documentation but missed it. Looking at the source, it unsurprisingly does (from first impression) more or less what @frougon does in his answer!
    – Timtro
    Commented Jun 13, 2022 at 15:06
  • @frougon RE: explicitly private macros: that's actually a really good (and now obvious) point that I hadn't considered. In my mind, relying on U-M was somehow improving portability and robustness by pushing the responsibility of maintenance to these packages. But I see it's much the opposite, after reading comments in the U-M code about the uncertainty of implementation.
    – Timtro
    Commented Jun 13, 2022 at 15:11
  • 1
    The leading double underscore is precisely this: “not part of the public API”. Other than that, yes, \__um_mathactive_remap:nn does essentially the same as my code (the only difference being that the temporary macro \__um_tmp: whose meaning is assigned to the active character is \protected... which wouldn't bring anything in our case, because my answer doesn't make active [would be catcode 13, not 12]).
    – frougon
    Commented Jun 13, 2022 at 15:16

You must log in to answer this question.

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