unicode-math
unicode-math copied to clipboard
\DeclareMathSymbol
Description
There is no public interface for defining new math symbols, maybe taken from the PUA of some font.
Check/indicate
- [x] Relevant for XeTeX
- [x] Relevant for LuaTeX
- [x] Issue tracker has been searched for similar issues?
- [x] Reference: https://tex.stackexchange.com/questions/439477/h
Minimal example demonstrating the issue
\documentclass{article}
\usepackage{unicode-math}
% define a font with a NFSS family name
\newfontfamily{\libertine}{Linux Libertine O}[NFSSFamily=libertine]
% declare it as a math symbo font
\DeclareSymbolFont{libertine}{TU}{libertine}{m}{n}
% declare the symbol
\Umathchardef\penguin="3 \symlibertine "E000
\begin{document}
$a\penguin b$
\end{document}
Further details
unicode-math has \__um_set_mathchar:NNnn that could fill the bill, weren't it private. I guess that redefining \DeclareSymbolFont like
\DeclareDocumentCommand{\DeclareMathSymbol}{mmmm}
{
\__um_set_mathchar:NNnn #1 #2 { #3 } { #4 }
}
should also work for standard fonts. Indeed, this appears to work:
\documentclass{article}
\usepackage{unicode-math}
\ExplSyntaxOn
\DeclareDocumentCommand{\DeclareMathSymbol}{mmmm}
{
\__um_set_mathchar:NNnn #1 #2 { #3 } { #4 }
}
\ExplSyntaxOff
% define a font with a NFSS family name
\newfontfamily{\libertine}{Linux Libertine O}[NFSSFamily=libertine]
% declare it as a math symbo font
\DeclareSymbolFont{libertine}{TU}{libertine}{m}{n}
% declare the symbol
\DeclareMathSymbol\penguin{\mathrel}{libertine}{"E000}
% another test
\DeclareSymbolFont{test}{OT1}{cmr}{m}{n}
\DeclareMathSymbol\foo{\mathbin}{test}{`f}
\begin{document}
$a\penguin b\foo c$
\end{document}
Well, there is a small problem: the legacy \DeclareMathSymbol command also accepts a number in the second argument, so possibly \__um_set_mathchar:NNnn should be \__um_set_mathchar:Nnnn, with a test for the first argument to be a single control sequence.
Thanks Enrico — that's a good suggestion. In my "original design" of the package I didn't anticipate new symbols in PUA, etc., but that was clearly short-sighted.
As suggested in tex.sx chat, I think the most viable approach first up is to extend 2e — I’ll write something and suggest it to Frank. (In fact, I may already have something in umath2e that never got finished…)