Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 %% File: latex-lab-text.dtx (C) Copyright 2023-2025 LaTeX Project
4 %
5 % It may be distributed and/or modified under the conditions of the
6 % LaTeX Project Public License (LPPL), either version 1.3c of this
7 % license or (at your option) any later version. The latest version
8 % of this license is in the file
9 %
10 % https://www.latex-project.org/lppl.txt
11 %
12 %
13 % The latex-lab bundle is developed in the LaTeX2e GitHub.
14 % Issues may be reported at
15 %
16 % https://github.com/latex3/latex2e/issues
17 %
18 \def\ltlabtextdate{2026-04-27}
19 \def\ltlabtextversion{0.85g}
20
21 %<*driver>
22 \DocumentMetadata{tagging=on,pdfstandard=ua-2}
23 \documentclass[kernel]{l3in2edoc}
24
25 % for the phoneme argument
26 \usepackage{fontspec}
27 \setmonofont{NewCMMono10-Book.otf}
28
29 %\DeclareUnicodeCharacter{02C8}{\texttt{\textquotesingle}}
30 %\DeclareUnicodeCharacter{02D0}{\texttt{:}}
31 %\DeclareUnicodeCharacter{025B}{$\epsilon$}
32
33 \EnableCrossrefs
34 \CodelineIndex
35 \begin{document}
36 \DocInput{latex-lab-text.dtx}
37 \end{document}
38 %</driver>
39 %
40 % \fi
41 %
42 % \title{The \textsf{latex-lab-text} package\\
43 % Changes and additions to the kernel related to the tagging of various small text commands}
44 % \author{\LaTeX{} Project\thanks{Initial implementation done by Ulrike Fischer}}
45 % \date{v\ltlabtextversion\ \ltlabtextdate}
46 %
47 % \maketitle
48 %
49 % \newcommand{\xt}[1]{\textsl{\textsf{#1}}}
50 % \newcommand{\TODO}[1]{\textbf{[TODO:} #1\textbf{]}}
51 % \newcommand{\docclass}{document class \marginpar{\raggedright document class
52 % customizations}}
53 %
54 % \providecommand\hook[1]{\texttt{#1}}
55 %
56 % \begin{abstract}
57 % \end{abstract}
58 %
59 % \section{Introduction}
60 %
61 % This module contains small changes to improve the tagging of
62 % (inline) text commands.
63 %
64 % While the tagging of the \LaTeX{} logo is quite straightforward, tagging of
65 % \cs{emph} as \texttt{EM} can have unwanted side-effect as both tags are inline tags
66 % and so not every inner
67 % structure is allowed. Probably both commands will need an optional argument or a
68 % starred variant which suppress the tagging.
69 %
70 % \section{Implementation}
71 % \begin{macrocode}
72 %<*package>
73 %<@@=tag>
74 % \end{macrocode}
75 % \begin{macrocode}
76 \ProvidesExplPackage {latex-lab-testphase-text} {\ltlabtextdate} {\ltlabtextversion}
77 {Code related to the tagging of various small text commands}
78 % \end{macrocode}
79
80 % \subsection{The \LaTeX\ and \TeX\ logo}
81 % This uses the generic hooks, so that it catches also other definitions.
82 % For \cs{LaTeX} we stop tagging to avoid that the inner \cs{TeX} leads to a double tagging.
83 % \begin{macrocode}
84 \AddToHook{cmd/LaTeX/before}
85 {
86 \mode_leave_vertical:
87 \UseTaggingSocket{inline/begin}
88 {tag=\UseStructureName{span},actualtext=LaTeX,phoneme=[ˈlaːtɛx]}
89 \tag_suspend:n{\LaTeX}
90 }
91 \AddToHook{cmd/LaTeX/after}
92 {
93 \tag_resume:n{\LaTeX}
94 \UseTaggingSocket{inline/end}
95 }
96 \AddToHook{cmd/TeX/before}
97 {
98 \mode_leave_vertical:
99 \UseTaggingSocket{inline/begin}
100 {tag=\UseStructureName{span},actualtext=TeX}
101 }
102 \AddToHook{cmd/TeX/after}
103 {
104 \UseTaggingSocket{inline/end}
105 }
106 % \end{macrocode}
107 %
108 % \subsection{Emphasizing}
109 % We tag \cs{emph} but leave commands like \cs{textbf} alone, as it is not
110 % clear if they always have a semantic meaning.
111 % \begin{macrocode}
112 \AddToHook{cmd/emph/before}
113 {
114 \mode_leave_vertical:
115 \UseTaggingSocket{inline/begin}
116 {tag=\UseStructureName{text/emph}}
117 }
118
119 \AddToHook{cmd/emph/after}
120 {
121 \UseTaggingSocket{inline/end}
122 }
123 % \end{macrocode}
124 %
125 %\subsection{\cs{textsuperscript} and \cs{textsubscript}}
126 % \begin{macrocode}
127 \sys_if_engine_luatex:TF
128 {
129 \cs_new:Npn \@@_space_ignore:n #1 {\tag_spacechar_off:#1\tag_spacechar_on:}
130 }
131 {
132 \cs_set_eq:NN \@@_space_ignore:n \use:n
133 }
134 \protected\def\@textsuperscript#1%
135 {%
136 \check@mathfonts
137 \leavevmode
138 \begingroup
139 \UseTaggingSocket{inline/begin}{tag=\UseStructureName{span},attribute-class=sup}
140 \sbox\z@{\fontsize\sf@size\sf@size#1}%
141 \raise\dimexpr\textsuperscript@offset\relax\box\z@
142 \UseTaggingSocket{inline/end}
143 \@@_space_ignore:n{\textsuperscript@space}
144 \endgroup
145 }
146 \protected\def\@textsubscript#1%
147 {%
148 \check@mathfonts
149 \leavevmode
150 \begingroup
151 \UseTaggingSocket{inline/begin}{tag=\UseStructureName{span},attribute-class=sub}
152 \sbox\z@{\fontsize\sf@size\sf@size#1}%
153 \lower\dimexpr\textsubscript@offset\relax\box\z@
154 \UseTaggingSocket{inline/end}
155 \@@_space_ignore:n{\textsuperscript@space}
156 \endgroup
157 }
158 % \end{macrocode}
159 % \subsection{\cs{mbox}}
160 % When used in math and when luamml is active \cs{mbox} has to be correctly annoted.
161 % For this we add a socket that luamml can activate.
162 % We test for the socket until 2025-06-01.
163 % \changes{v0.85c}{2024-12-03}{Add luamml socket to \cs{mbox}}
164 % \begin{macrocode}
165 \DeclareRobustCommand\mbox[1]
166 {
167 \leavevmode
168 \tag_socket_use:nnn {math/luamml/hbox}
169 {}{ \hbox{#1} }
170 }
171 % \end{macrocode}
172 % And the same for \cs{makebox}
173 % \begin{macrocode}
174 \long\def\@imakebox[#1][#2]#3{%
175 \tag_socket_use:nnn {math/luamml/hbox}{}
176 {
177 \@begin@tempboxa\hbox{#3}%
178 \setlength\@tempdima{#1}% support calc
179 \hb@xt@\@tempdima{%
180 \expandafter\ifx\csname bm@#2\endcsname\relax
181 \bm@c
182 \@latex@warning{Unexpected~alignment~#2}%
183 \else
184 \csname bm@#2\endcsname
185 \fi}%
186 \@end@tempboxa
187 }}
188 % \end{macrocode}
189 %
190 % \subsection{phantom commands}
191 %
192 % In text mode we do not want the content of a phantom command to create a structure,
193 % so we suspend tagging
194 % \changes{0.85d}{2025-01-27}{Suspend tagging in \cs{makeph@nt}}
195 % TODO: consider if it makes sense to set measuring to true instead.
196 % \cs{mathsm@sh} is redefined in latex-lab-math.
197 % \begin{macro}[no-user-doc]{\makeph@nt}
198 % \begin{macrocode}
199 \def\makeph@nt#1{%
200 \setbox\z@\hbox
201 {\SuspendTagging{\makeph@nt}%
202 \color@begingroup#1\color@endgroup\ResumeTagging{\makeph@nt}}\finph@nt}
203 % \end{macrocode}
204 % \end{macro}
205 %
206 %
207 % \begin{macro}[no-user-doc]{\@kernel@mathph@nt,\mathph@nt}
208 % \begin{macrocode}
209 \def\@kernel@mathph@nt#1#2{%
210 \setbox\z@\hbox{\SuspendTagging{\mathph@nt}$\m@th#1{#2}$\ResumeTagging{\mathph@nt}}\finph@nt}
211 \def\mathph@nt#1#2
212 {
213 \setbox \z@ = \hbox {
214 $
215 \m@th
216 #1
217 {
218 % nested phantoms should not be processed by luamml
219 \let\mathph@nt\@kernel@mathph@nt
220 #2
221 }
222 \UseTaggingSocket{math/luamml/save/nNn}{{mathphant} #1 {mphantom}}
223 $
224 }
225 \UseTaggingSocket{math/luamml/finph@nt}{}{\finph@nt}
226 }
227 % \end{macrocode}
228 % \end{macro}
229 % \subsection{The \cs{verb} command}
230 %
231 % \begin{macrocode}
232 \def\verb{\relax\ifmmode\hbox\else\leavevmode\null\fi
233 \bgroup
234 \UseTaggingSocket{inline/begin}{tag=\UseStructureName{text/verb}}%
235 \verb@eol@error \let\do\@makeother \dospecials
236 \verbatim@font\@noligs
237 \language\l@nohyphenation
238 \@ifstar\@sverb\@verb}
239 \def\verb@egroup{\global\let\verb@balance@group\@empty\UseTaggingSocket{inline/end}\egroup}
240 % \end{macrocode}
241 % \begin{macrocode}
242 %</package>
243 % \end{macrocode}