1

I have hundreds of lines of code of the form

\Umathcode`a = 0 \symwmb "1D4B6

and

\Umathcode"03B1 = 0 \symrmtl "0000B

where, in the latter case, there is a counterpart \def\alpha{^^^^03b1}, within commands of the type in David Carlisle's answer in Greek letters within \mathsf, \mathsfit, \mathbfsf, and \mathbfsfit without using unicode-math that map character codes to characters in various fonts. Since I am reusing the Latin and Greek alphabets in several such commands, it occurs to me that it should be possible to create several globally-defined comma-separated \clists from LaTeX 3 code that is available in xparse (actually, from what I have read, \seqs may be more versatile in this case) and reuse them. So I need to write a command of the form

\MapCodes{LatinLower}{\symYYYY}{1D486, 1D487, 1D488, ... 1D4CF}

that can be called from within each of the \symXXXX commands in like those in David's answer to my previous question that would then execute this sequence of commands within the scope of the calling command. Here, LatinLower is a list or sequence containing the Latin lowercase letters and could be globally defined, \symYYYY is the font declared with DeclareSymbolFont{YYYY}{TU}{<NFSS family>}{m}{n}, and the last argument is the list of slot numbers for the particular font which correspond to the lowercase characters desired.

I am pretty certain this is doable, but I am a newbie to LaTeX 3 and learn most easily by example anyway, so I can either spend all day trying to figure this out from interface3.pdf or just ask and learn from the answers. I hope I have adequately explained what I am trying to accomplish.

  • despite @egreg deleting his answer i'd go that way, there are only 24 "holes" for out of order characters so fixing them is less work than making explicit lists for all the alphabets – David Carlisle Jul 22 '23 at 21:34
  • if you do want two lists see for example \seq_map_pairwise_function:NNN ⟨seq1⟩ ⟨seq2⟩ ⟨function ⟩ note the mapping is specified by unicode, it does not depend on the font – David Carlisle Jul 22 '23 at 21:38
  • It must surely be easier to use unicode-math which already implements ths, then patch mtpro back – David Carlisle Jul 22 '23 at 21:40
  • @DavidCarlisle Yes, I liked @egreg 's answer and got it to work. It is certainly best for the Latin alphabet. I was still curious about my original question thinking that was a functionality that I would need sooner or later (that is, pairing lists). I found \seq_map_pairwise_function and got it to work for Greek. – Mike Pugh Jul 22 '23 at 22:21

1 Answers1

1

You can define sequences for the blocks and use \seq_map_pairwise_function:NNN.

Here I use just a short example. Use numeric codes (with the appropriate prefix).

\documentclass{article}
\usepackage{fontspec}

\newfontfamily{\StixTwoMath}{STIXTwoMath-Regular.otf}[ NFSSFamily=stix, Script=Math, Scale=MatchLowercase ]

\DeclareSymbolFont{stix}{TU}{stix}{m}{n}

\ExplSyntaxOn

\NewDocumentCommand{\defineblock}{mm} {% #1 = block name, #2 = clist \seq_gclear_new:c { g_pugh_math_block_#1_seq } \seq_gset_from_clist:cn { g_pugh_math_block_#1_seq } { #2 } }

\NewDocumentCommand{\definecodes}{mmm} {% #1 = block name, #2 = math family, #3 = clist __pugh_math_definecodes:nnn { #1 } { #2 } { #3 } }

\seq_new:N \l__pugh_math_temp_seq \tl_new:N \l__pugh_math_family_tl

\cs_new_protected:Nn __pugh_math_definecodes:nnn { \seq_set_from_clist:Nn \l__pugh_math_temp_seq { #3 } \tl_set:Nn \l__pugh_math_family_tl { #2 } \seq_map_pairwise_function:cNN { g_pugh_math_block_#1_seq } % the block \l__pugh_math_temp_seq % the codes __pugh_math_assigncode:nn }

\cs_new_protected:Nn __pugh_math_assigncode:nn { \Umathcode #1 = 0 ~ \use:c { sym \l__pugh_math_family_tl } #2 \scan_stop: }

\ExplSyntaxOff

\defineblock{LowerLatin}{a,b,`c}

\definecodes{LowerLatin}{stix}{"1D482,"1D483,"1D484}

\begin{document}

$abc+d$

\end{document}

Since I just specified a to c, only those characters receive a special \Umathcode.

enter image description here

egreg
  • 1,121,712
  • Right. I actually meant to explicitly mention the possibility that the characters are not sequentially located within the font. Blackboard characters for example often have C, N, P, Q, R, and Z separated from the rest of the alphabet. So I wanted to cover both cases. – Mike Pugh Jul 22 '23 at 15:40
  • Oh, but you are referring to the character codes, not the font slots. So, right, this should work. – Mike Pugh Jul 22 '23 at 15:43
  • But I also want to work with the Greek alphabet, which has common variants noncontiguous with the usual characters, even though they have common character codes. I modified the original question since it might also be an issue. – Mike Pugh Jul 22 '23 at 15:47
  • @MikePugh The new version should be like you want. – egreg Jul 22 '23 at 22:19
  • Perfect! Thank you, again! – Mike Pugh Jul 23 '23 at 00:38