Debian Codegraph @

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

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