unicode-math icon indicating copy to clipboard operation
unicode-math copied to clipboard

\DeclareMathSymbol

Open eg9 opened this issue 7 years ago • 3 comments
trafficstars

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}
screen shot 2018-07-29 at 16 37 31

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.

eg9 avatar Jul 29 '18 14:07 eg9

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.

wspr avatar Jul 29 '18 15:07 wspr

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…)

wspr avatar Jul 30 '18 09:07 wspr