Debian Codegraph @

texmf-dist/source/latex-dev/latex-lab/latex-lab-unicode-math.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: latex-lab-unicode-math.dtx
4 %
5 % Copyright (C) 2024-2026 The LaTeX Project
6 %
7 % It may be distributed and/or modified under the conditions of the
8 % LaTeX Project Public License (LPPL), either version 1.3c of this
9 % license or (at your option) any later version. The latest version
10 % of this license is in the file
11 %
12 % https://www.latex-project.org/lppl.txt
13 %
14 %
15 % The latex-lab bundle is developed in the LaTeX2e GitHub.
16 % Issues may be reported at
17 %
18 % https://github.com/latex3/latex2e/issues
19 %
20 %<*driver>
21 \DocumentMetadata{tagging=on,pdfstandard=ua-2}
22 \documentclass[kernel]{l3in2edoc}
23
24 \EnableCrossrefs
25 \CodelineIndex
26 \begin{document}
27 \DocInput{latex-lab-unicode-math.dtx}
28 \end{document}
29 %</driver>
30 %
31 % \fi
32 %
33 %
34 % \title{The \texttt{latex-lab-unicode-math} code\thanks{}}
35 % \author{\LaTeX{} Project}
36 %
37 % \maketitle
38 %
39 % \newcommand\fmi[1]{\begin{quote} TODO: \itshape #1\end{quote}}
40 % \newcommand\NEW[1]{\marginpar{\mbox{}\hfill\fbox{New: #1}}}
41 % \providecommand\class[1]{\texttt{#1.cls}}
42 % \providecommand\pkg[1]{\texttt{#1}}
43 % \providecommand\hook[1]{\texttt{#1}}
44 %
45 % \begin{abstract}
46 % \end{abstract}
47 %
48 % \tableofcontents
49 %
50 % \section{Introduction}
51 %
52 % This file implements temporary adaptations to the \pkg{unicode-math} package needed for
53 % the tagging project.
54 %
55 % \MaybeStop{\setlength\IndexMin{200pt} \PrintIndex }
56 %
57 % \section{The Implementation}
58 %
59 % \begin{macrocode}
60 %<@@=math>
61 % \end{macrocode}
62 %
63 % \begin{macrocode}
64 %<*kernel>
65 % \end{macrocode}
66 %
67 % \subsection{File declaration}
68 % \begin{macrocode}
69 \ProvidesExplFile
70 {latex-lab-unicode-math.ltx}
71 {2026-01-16}
72 {0.1f}
73 {unicode-math adaptions}
74 % \end{macrocode}
75 % \subsection{Sockets}
76 % Unicode glyphs like a root sign should be marked as artifacts to avoid duplication
77 % in derivation if mathml structure elements are used. This is done with a luamml socket
78 % \texttt{math/luamml/artifact} which is declared in \texttt{lttagging} and
79 % whose plug is defined in \pkg{luamml}.
80 %
81 % \subsection{Delimiters}
82 %
83 % Extensible delimiters set with \cs{bigl}, \cs{Bigl}, etc.\ use boxes in their
84 % definitions. This gives wrong structure elements if used with luamml.
85 % We therefore redefine the internal amsmath command
86 % to make use of the luatex primitive.
87 % \changes{v0.1b}{2025-02-10}{redefine \cs{bBigg@}}
88 % \changes{v0.1e}{2025-06-30}{redefine \cs{bBigg@}, tagging issue#757}
89 % \changes{v0.1f}{2025-12-16}{add support for lua-unicode-math, tagging issue#1137}
90 % \begin{macro}{\bBigg@}
91 % \begin{macrocode}
92 \def\bBigg@#1#2
93 {{\ensuremath
94 {
95 \Uvextensible height~#1~ \dimexpr0.5\big@size\relax ~ depth ~#1~
96 \dimexpr0.5\big@size\relax~ axis~exact~#2
97 }
98 }}
99 % \end{macrocode}
100 % \end{macro}
101 %
102 % \subsection{varlim-commands}
103 %
104 % The commands \cs{varinjlim}, \cs{varliminf}, \cs{varprojlim} and \cs{varlimisup}
105 % use boxes that confuse luamml. We redefine them to use luatex primitives. This slightly
106 % changes the look!
107 % \changes{0.1d}{2025-05-25}{add missing \cs{mathop}}
108 % \begin{macrocode}
109 \protected\def\varinjlim
110 {\mathop{\Udelimiterunder 0 "2192 {\qopname\relax o{\luamml_ignore:\mathstrut lim}}}}
111 \protected\def\varprojlim
112 {\mathop{\Udelimiterunder 0 "2190 {\qopname\relax o{\luamml_ignore:\mathstrut lim}}}}
113 \protected\def\varlimsup
114 {\mathop{\overline{\qopname\relax o{\luamml_ignore:\mathstrut lim}}}}
115 \protected\def\varliminf
116 {\mathop{\underline{\qopname\relax o{lim}}}}
117 % \end{macrocode}
118 %
119 % \subsection{Roots}
120 % Roots have two problems in tagging: At first, if mathml structure elements are
121 % used, the root symbol is given twice: as Unicode char and through the \texttt{msqrt}
122 % or \texttt{mroot} mathml structure element. In derivation this leads to duplications.
123 % The glyph should be tagged as artifact in this case.
124 % At second, in some cases complicated box constructions instead of the
125 % luatex primitives are used which leads to wrong tagging.
126 % We redefine \cs{sqrtsign} and add the artifact socket for the first problem.
127 %
128 % TODO: A root with empty argument should be tagged differently.
129 % \begin{macrocode}
130 \AtBeginDocument
131 {
132 \@ifpackageloaded{unicode-math}
133 {
134 \cs_gset_protected_nopar:Npn \sqrtsign
135 {
136 \tag_socket_use:n {math/luamml/artifact}
137 \tex_Uradical:D \symoperators "0221A\scan_stop:
138 }
139 }
140 {
141 \cs_gset_protected_nopar:Npn \sqrtsign
142 {
143 \tag_socket_use:n {math/luamml/artifact}
144 \tex_Uradical:D \symlummain "0221A\scan_stop:
145 }
146 \cs_gset_protected_nopar:Npn \root #1 \of
147 {
148 \tag_socket_use:n {math/luamml/artifact}
149 \tex_Uroot:D \symlummain "0221A~ { #1 }
150 }
151 }
152 }
153 % \end{macrocode}
154 % TODO: Tagging of \verb+\sqrt[\leftroot{-2}\uproot{2}\beta]{y}+ is currently incorrect,
155 % but setting \cs{Umathradicaldegreeraise} and \cs{Umathradicaldegreeafter} does not
156 % work, so another solution must be found (or a warning must be issued).
157 % \begin{macrocode}
158 \cs_set_nopar:Npn \plainroot@ #1 \of #2
159 {
160 \bool_if:nTF
161 {
162 \__um_int_if_zero_p:n \uproot@ && \__um_int_if_zero_p:n \leftroot@
163 }
164 {
165 \tag_socket_use:n {math/luamml/artifact}
166 \tex_Uroot:D \c__um_radical_sqrt_tl { #1 } { #2 }
167 }
168 {
169 \hbox_set:Nn \rootbox
170 {
171 \c_math_toggle_token \m@th
172 \scriptscriptstyle { #1 }
173 \c_math_toggle_token
174 }
175 \mathchoice
176 { \r@@@@t \displaystyle { #2 } }
177 { \r@@@@t \textstyle { #2 } }
178 { \r@@@@t \scriptstyle { #2 } }
179 { \r@@@@t \scriptscriptstyle { #2 } }
180 }
181 \c_group_end_token
182 }
183 % \end{macrocode}
184 % \subsection{Fractions}
185 % Similar to roots in fractions the rule must be marked as artifact.
186 % \begin{macrocode}
187 \DeclareRobustCommand {\frac}[2]
188 {{\tag_socket_use:n{math/luamml/artifact}\Ustack{\begingroup#1\endgroup\@@@@over#2}}}
189 % \end{macrocode}
190 % \begin{macrocode}
191 %</kernel>
192 % \end{macrocode}
193 %
194 % \Finale
195 %