Debian Codegraph @

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