Debian Codegraph @

texmf-dist/source/latex/latex-lab/latex-lab-mathtools.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: latex-lab-mathtools.dtx
4 %
5 % Copyright (C) 2022-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 \def\ltlabmathtoolsdate{2025-06-18}
22 \def\ltlabmathtoolsversion{0.80c}
23 %<*driver>
24 \DocumentMetadata{tagging=on,pdfstandard=ua-2}
25 \documentclass[kernel]{l3doc}
26 \usepackage{latex-lab-testphase-l3doc}
27 \EnableCrossrefs
28 \CodelineIndex
29 \begin{document}
30 \DocInput{latex-lab-mathtools.dtx}
31 \end{document}
32 %</driver>
33 %
34 % \fi
35 %
36 %
37 % \title{The \texttt{latex-lab-mathtools} code\thanks{}}
38 % \author{\LaTeX{} Project}
39 % \date{v\ltlabmathtoolsversion\ \ltlabmathtoolsdate}
40 % \maketitle
41 %
42 % \newcommand\fmi[1]{\begin{quote} TODO: \itshape #1\end{quote}}
43 % \newcommand\NEW[1]{\marginpar{\mbox{}\hfill\fbox{New: #1}}}
44 % \providecommand\class[1]{\texttt{#1.cls}}
45 % \providecommand\pkg[1]{\texttt{#1}}
46 % \providecommand\hook[1]{\texttt{#1}}
47 %
48 % \begin{abstract}
49 % \end{abstract}
50 %
51 % \tableofcontents
52 %
53 % \section{Introduction}
54 %
55 % This file implements adaptions to the \pkg{mathtools} package needed for
56 % the tagging project.
57 %
58 % \MaybeStop{\setlength\IndexMin{200pt} \PrintIndex }
59 %
60 % \section{The Implementation}
61 %
62 % \begin{macrocode}
63 %<@@=math>
64 % \end{macrocode}
65 %
66 % \begin{macrocode}
67 %<*kernel>
68 % \end{macrocode}
69 %
70 % \subsection{File declaration}
71 % \begin{macrocode}
72 \ProvidesFile{latex-lab-mathtools.ltx}
73 [2024-07-13 v0.1a mathtools adaptions]
74 % \end{macrocode}
75 % \subsection{Tagpdf support}
76 % To make the code independent from tagging being loaded and active
77 % we load the \pkg{tagpdf-base} package:
78 %
79 % \begin{macrocode}
80 \RequirePackage{tagpdf-base}
81 % \end{macrocode}
82 %
83 % \subsection{\cs{shortintertext}}
84 % Similar to the \cs{intertext} command from amsmath,
85 % \cs{shortintertext} errors with active tagging as it is processed twice
86 % which leads to duplicated structures.
87 % The fix is similar but is complicated as \pkg{mathtools} defines two version (and
88 % an additional \cs{intertext} version) and package options to switch between the variants.
89 %
90 % At first we redefine all the internal commands
91 % \begin{macrocode}
92 \ExplSyntaxOn
93 \tl_new:N\l_@@_mathtools_init_tl
94 \cs_if_eq:NNTF\intertext@ \MT_intertext:
95 {
96 \tl_set:Nn \l_@@_mathtools_init_tl {\MT_orig_intertext_false:}
97 }
98 {
99 \tl_set:Nn \l_@@_mathtools_init_tl {\MT_orig_intertext_true:}
100 }
101 % \end{macrocode}
102 %
103 % \begin{macrocode}
104 \cs_if_eq:NNTF\shortintertext@ \MT_shortintertext:n
105 {
106 \tl_put_right:Nn \l_@@_mathtools_init_tl
107 {\MT_orig_shortintertext_false:}
108 }
109 {
110 \tl_put_right:Nn \l_@@_mathtools_init_tl
111 {\MT_orig_shortintertext_true:}
112 }
113 % \end{macrocode}
114 %
115 % \begin{macrocode}
116 \def\MT_intertext: {%
117 \def\intertext##1{%
118 \ifvmode\else\\\@empty\fi
119 \noalign{%
120 \penalty\postdisplaypenalty\vskip\belowdisplayskip
121 \vskip-\lineskiplimit % CCS
122 \vskip\normallineskiplimit % CCS
123 \vskip\l_MT_above_intertext_sep
124 \vbox{%
125 % \end{macrocode}
126 % Stop tagging when measuring:
127 % \begin{macrocode}
128 \ifmeasuring@\tag_suspend:n{\measuring}\fi
129 \normalbaselines
130 \ifdim
131 \ifdim\@totalleftmargin=\z@
132 \linewidth
133 \else
134 -\maxdimen
135 \fi
136 =\columnwidth
137 \else \parshape\@ne \@totalleftmargin \linewidth
138 \fi
139 % \end{macrocode}
140 % End the previous mc:
141 % \begin{macrocode}
142 \tag_mc_end_push:
143 % \end{macrocode}
144 % We are already in a par so we change now to Span:
145 % \begin{macrocode}
146 \tagpdfsetup{para/tag=Span}
147 \noindent\ignorespaces##1\par
148 % \end{macrocode}
149 % Restart the MC
150 % \begin{macrocode}
151 \tag_mc_begin_pop:n{}}%
152 \penalty\predisplaypenalty\vskip\abovedisplayskip%
153 \vskip-\lineskiplimit % CCS
154 \vskip\normallineskiplimit % CCS
155 \vskip\l_MT_below_intertext_sep
156 }%
157 }%
158 \MH_let:NwN \shortintertext \shortintertext@
159 }
160 % \end{macrocode}
161 % \begin{macrocode}
162 \def\MT_orig_shortintertext:n #1{%
163 \ifvmode\else\\\@empty\fi
164 \noalign{%
165 \penalty\postdisplaypenalty\vskip\abovedisplayshortskip
166 \vbox{%
167 \ifmeasuring@\tag_suspend:n{\measuring}\fi
168 \normalbaselines
169 \MH_if_dim:w
170 \MH_if_dim:w \@totalleftmargin=\z@
171 \linewidth
172 \MH_else:
173 -\maxdimen
174 \MH_fi:
175 =\columnwidth
176 \MH_else:
177 \parshape\@ne \@totalleftmargin \linewidth
178 \MH_fi:
179 \tag_mc_end_push:
180 \tagpdfsetup{para/tag=Span}
181 \tagpdfparaOn
182 \noindent\ignorespaces#1\par
183 \tag_mc_begin_pop:n{}}
184 \penalty\predisplaypenalty\vskip\abovedisplayshortskip%
185 }%
186 }
187 % \end{macrocode}
188 %
189 % \begin{macrocode}
190 \def\MT_shortintertext:n #1{%
191 \ifvmode\else\\\@empty\fi
192 \noalign{%
193 \penalty\postdisplaypenalty\vskip\abovedisplayshortskip
194 \vskip-\lineskiplimit
195 \vskip\normallineskiplimit
196 \vskip\l_MT_above_shortintertext_sep
197 \vbox{%
198 \ifmeasuring@\tag_suspend:n{\measuring}\fi
199 \normalbaselines
200 \MH_if_dim:w
201 \MH_if_dim:w \@totalleftmargin=\z@
202 \linewidth
203 \MH_else:
204 -\maxdimen
205 \MH_fi:
206 =\columnwidth
207 \MH_else:
208 \parshape\@ne \@totalleftmargin \linewidth
209 \MH_fi:
210 \tag_mc_end_push:
211 \tagpdfsetup{para/tag=P}
212 % \end{macrocode}
213 % Why is it needed to enable paratagging??
214 % \begin{macrocode}
215 \tagpdfparaOn
216 \noindent\ignorespaces#1\par
217 \tag_mc_begin_pop:n{}}%
218 \penalty\predisplaypenalty\vskip\abovedisplayshortskip%
219 \vskip-\lineskiplimit
220 \vskip\normallineskiplimit
221 \vskip\l_MT_below_shortintertext_sep
222 }%
223 }
224 % \end{macrocode}
225 % see https://github.com/latex3/tagging-project/issues/734. The multlined environment
226 % still creates a few unneeded structure, perhaps triggered by empty tags.
227 % \begin{macrocode}
228 \renewcommand*\MT_mult_internal:n [1]{
229 \MH_if_boolean:nF {outer_mult}{\alignedspace@left} %<-- requires amsmath 2016/11/05
230 \MT_next:
231 \bgroup
232 \Let@
233 \def\l_MT_multline_lastline_fint{0 }
234 \chardef\dspbrk@context\@ne \restore@math@cr
235 \MH_let:NwN \math@cr@@\MT_mult_mathcr_atat:w
236 \MH_let:NwN \shoveleft\MT_shoveleft:wn
237 \MH_let:NwN \shoveright\MT_shoveright:wn
238 \spread@equation
239 \MH_set_boolean_F:n {mult_firstline}
240 \MT_measure_mult:n {#1}
241 \MH_if_dim:w \l_MT_multwidth_dim<\l_MT_multline_measure_fdim
242 \MH_setlength:dn \l_MT_multwidth_dim{\l_MT_multline_measure_fdim}
243 \fi
244 \MH_set_boolean_T:n {mult_firstline}
245 \MH_if_num:w \l_MT_multline_lastline_fint=\@ne
246 \MH_let:NwN \math@cr@@ \MT_mult_firstandlast_mathcr:w
247 \MH_fi:
248 \ialign\bgroup
249 \hfil\strut@$\m@th\displaystyle{}##
250 \UseTaggingSocket{math/luamml/save/nNn}{ {} \displaystyle {mtd}}
251 $
252 \UseTaggingSocket{math/luamml/mtable/finalizecol}{last}
253 \hfil
254 \crcr
255 \hfilneg
256 #1
257 }
258 % \end{macrocode}
259 % end hook
260 % \begin{macrocode}
261 \l_@@_mathtools_init_tl
262 \ExplSyntaxOff
263 % \end{macrocode}
264 %
265 % \begin{macrocode}
266 %</kernel>
267 % \end{macrocode}
268 %
269 % \Finale
270 %