latex3 / unicode-math

XeLaTeX/LuaLaTeX package for using unicode/OpenType maths fonts
http://ctan.org/pkg/unicode-math
LaTeX Project Public License v1.3c
245 stars 29 forks source link

\DeclareMathSymbol #485

Open eg9 opened 6 years ago

eg9 commented 6 years ago

Description

There is no public interface for defining new math symbols, maybe taken from the PUA of some font.

Check/indicate

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.

wspr commented 6 years ago

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 commented 6 years ago

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