Debian Codegraph @

texmf-dist/source/latex/axessibility/axessibility.dtx

raw
1 %
2 % \iffalse meta-comment
3 %
4 %
5 % Copyright (C) 2018, 2019, 2020 by
6 % Anna Capietto, Sandro Coriasco, Boris Doubrov, Alexander Koslovski,
7 % Tiziana Armano, Nadir Murru, Dragan Ahmetovic, Cristian Bernareggi
8 %
9 % Based on accsupp and tagpdf
10 %
11 % This work consists of the main source files axessibility.dtx and axessibility.lua,
12 % and the derived files
13 % axessibility.ins, axessibility.sty, axessibility.pdf, README,
14 % axessibilityExampleSingleLineT.tex, axessibilityExampleSingleLineA.tex,
15 %. axessibilityExampleAlignT.tex, axessibilityExampleAlignA.tex
16 %
17 % This work may be distributed and/or modified under the
18 % conditions of the LaTeX Project Public License, either version 1.3
19 % of this license or (at your option) any later version.
20 % The latest version of this license is in
21 % http://www.latex-project.org/lppl.txt
22 % and version 1.3 or later is part of all distributions of LaTeX
23 % version 2005/12/01 or later.
24 %
25 % This work has the LPPL maintenance status `maintained'.
26 %
27 % The Current Maintainer of this work is
28 % Sandro Coriasco
29 %
30 % \fi
31 %
32 %\iffalse
33 %<*driver>
34 \documentclass{ltxdoc}
35 \usepackage{axessibility}
36 \EnableCrossrefs
37 \CodelineIndex
38 \RecordChanges\begin{document}
39 \title{The \textsf{axessibility} package}
40 \date{January 8, 2020}
41 \author{Dragan Ahmetovic\thanks{Dipartimento di Matematica ``G. Peano'', Universit\`a degli Studi di Torino, 10123, Italy}, Tiziana Armano\footnotemark[1],
42 Cristian Bernareggi\footnotemark[1], Anna Capietto\footnotemark[1], \\
43 Sandro Coriasco\footnotemark[1], Boris Doubrov\thanks{Dual Lab, Ottignies-Louvain-la-Neuve 1340, Belgium}, Alexander Kozlovskiy\footnotemark[2], Nadir Murru\footnotemark[1]
44 %% \\
45 %% $ $
46 %% \\
47 %% Dipartimento di Matematica ``G. Peano''\\Universit\`a degli Studi di Torino \\
48 %% Dual Lab, Ottignies-Louvain-la-Neuve 1340, Belgium
49 %%
50 \\
51 $ $
52 \\
53 \texttt{<anna.capietto at unito.it>,<sandro.coriasco at unito.it>,}\\
54 \texttt{<boris.doubrov at duallab.com>}}
55 %
56 \DocInput{axessibility.dtx }
57 \end{document}
58 %</driver>
59 %\fi
60 %
61 % \changes{v1.0}{2018/07/09}{Initial version}
62 % \changes{v2.0}{2019/01/08}{Added support for environments align, align*, alignat, alignat*, flalign, flalign*, gather, gather*, xalignat, xalignat*, and xxalignat, from the package \textbf{amsmath}}
63 % \changes{v3.0}{2019/xx/yy}{Added option to select between tagging via accsupp or tagpdf packages. Added support for environment multline from the package \textbf{amsmath}. Added option to automatically replace $$ and $$ by \[\] and \(\) in lua mode.}
64 %
65 % \maketitle
66 %
67 %\begin{abstract}
68 %PDF documents containing formulae generated by \LaTeX\
69 % are usually not accessible by assistive technologies for people with special educational needs
70 % and visually impaired people
71 % (i.e., by screen readers and braille displays). The package manages this issue, allowing to create a PDF document where the formulae are read by these assistive technologies, since it automatically generates hidden comments in the PDF document (by means of the /ActualText attribute) in correspondence to each formula. The package does not generate a PDF/UA document.
72 %\end{abstract}
73 %
74 %\tableofcontents
75 %
76 %\section{Introduction}
77 %This package focuses on the specific problem of the accessibility of PDF documents generated by \LaTeX\ for visually impaired people
78 %and people with special educational needs.
79 %When a PDF document is generated starting from \LaTeX, formulae are not accessible by screen readers and braille displays.
80 % They can be made accessible by inserting a hidden comment, i.e., an ActualText, similarly to the case of web pages.
81 % This can be made, e.g., by using the \LaTeX\ package pdfcomment.sty. In any case, this task must be manually performed by the author and it is surely inefficient,
82 % since the author should write the formulae and, in addition, insert a description for each formula.
83 % Note also that the package pdfcomment.sty does not allow to insert special characters like `backslash', `brace', etc, in the comment.
84 % Moreover, with these solutions, the reading is bothered since the screen reader first reads incorrectly the formula and then,
85 % only as a second step, provides the correct comment of the formula.
86 % There are also some \LaTeX\ packages that try to improve the accessibility of PDF documents produced by \LaTeX.
87 % In particular, the packages accsupp.sty, accessibility$\_$meta.sty and tagpdf have
88 % been developed in order to obtain tagged PDF documents. The package accsupp.sty develops some interesting tools for commenting formulae
89 % using also special characters (possibility that is not available, e.g., in the pdfcomment.sty package). The package tagpdf widely
90 % further developed tagging functionalities, along the most recent specifications for PDF documents accessibility. However, all of the
91 % above are not automatized methods,
92 % since the comment and tags must be manually inserted by the author.
93 % The package accessibility$\_$meta.sty is an improved version of the package accessibility.sty.
94 % This package allows the possibility of inserting several tags for sections, links, figures and tables.
95 % However, even if these tags are recognized by the tool for checking tags of Acrobat Reader Pro, they are not always recognized by the screen readers.
96 % Moreover, this package does not manage formulae. Our package automatically produces an ActualText corresponding to the \LaTeX\ commands that generate the formulae.
97 % This ActualText is hidden in the PDF document, but the screen reader reads it without reading any incorrect sequence before.
98 % Additional functionalities, implemented in this version, are available when the typeset is done by means of lua\LaTeX (see below).
99 %
100 %\section{License}
101 %
102 % This work may be distributed and/or modified under the
103 % conditions of the LaTeX Project Public License, either version 1.3
104 % of this license or (at your option) any later version.
105 % The latest version of this license is in
106 % http://www.latex-project.org/lppl.txt
107 % and version 1.3 or later is part of all distributions of LaTeX
108 % version 2005/12/01 or later.
109 %
110 %\section{Prerequisites}
111 %
112 %The package \textbf{axessibility} requires the following packages: \textbf{accsupp, amsmath, amssymb, tagpdf, xstring}.
113 %
114 %\section{Package specification}
115 %
116 %If you use \LaTeX$2_\epsilon$ simply add the following line in the preamble:
117 % \begin{itemize}
118 % \item for the usage based on the \textbf{tagpdf} package,\\
119 %
120 %\indent $\backslash$\textbf{usepackage}$\{$\textbf{axessibility}$\}$\\
121 %
122 % or, equivalently, \\
123 %
124 % $\backslash$\textbf{usepackage[tagpdf]}$\{$\textbf{axessibility}$\}$
125 % \item for the usage based on the \textbf{accsupp} package,\\
126 %
127 % $\backslash$\textbf{usepackage[accsupp]}$\{$\textbf{axessibility}$\}$
128 % \end{itemize}
129 %
130 % \medskip
131 %
132 %\noindent The package includes the following features:
133 %\begin{itemize}
134 %\item In the \textbf{accsupp} version, the commands\\ \\
135 %\indent $\backslash$\textbf{pdfcompresslevel=0} \\
136 %\indent $\backslash$\textbf{pdfoptionpdfminorversion=6} \\ \\
137 % produce an uncompressed PDF document. The command \\ \\
138 %\indent $\backslash$\textbf{BeginAccSupp}
139 %\\ \\
140 %contained in the package \textbf{accsupp}, has been redefined so that the screen readers access the ActualText created by this command.
141 %\item In the \textbf{tagpdf} version, the commands\\ \\
142 %\indent $\backslash$\textbf{tagpdfsetup\{tabsorder=structure,uncompress,activate-all,interwordspace=true\}}\\
143 %$\backslash$\textbf{tagpdfifpdftexT}\\
144 % \textbf{\{}\\
145 % $\backslash$\textbf{pdfcatalog\{/Lang (en-US)\}}\\
146 % $\backslash$\textbf{usepackage[T1]\{fontenc\}}\\
147 % $\backslash$\textbf{input glyphtounicode}\\
148 % $\backslash$\textbf{pdfgentounicode=1}\\
149 % \textbf{\}}\\
150 %$\backslash$\textbf{tagpdfifluatexT}\\
151 % \textbf{\{}\\
152 % $\backslash$\textbf{pdfextension catalog\{/Lang (en-US)\}}\\
153 % $\backslash$\textbf{RequirePackage\{fontspec\}}\\
154 % $\backslash$\textbf{RequirePackage\{luacode\}}\\
155 % $\backslash$\textbf{newfontface$\backslash$zerowidthfont\{freeserif\}}\\
156 %$\backslash$\textbf{directlua\{}\\
157 %\textbf{require("axessibility.lua")}\\
158 %\textbf{\}}\\
159 %\textbf{\}}\\
160 %
161 %produce an uncompressed PDF document, directing appropriately the typesetting, either via pdf\LaTeX\ or lua\LaTeX.
162 %Equations (and other structures) are tagged by means of the commands defined in the \textbf{tagpdf} package, so that
163 %screen readers access the ActualText created by them. When typeset via lua\LaTeX, additional functionalities, implemented
164 %in the file axessibility.lua, can be activated (see Section \ref{sec:extra} below).
165 %\item The new commands \\ \\
166 %\indent $\backslash$\textbf{wrap$\#$1}\\
167 %\indent $\backslash$\textbf{wrapml$\#$1}\\
168 %\indent $\backslash$\textbf{wrapmlstar$\#$1}
169 %\\ \\
170 %allow to store their input into an ActualText in the PDF document (e.g., the \LaTeX\ commands for generating a formula),
171 %for single line and multiple line formulae environments, respectively.
172 %
173 %\item The environments \\ \\
174 %\indent $\backslash$\textbf{begin}$\{$\textbf{equation}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{equation}$\}$ \\
175 %\indent $\backslash$\textbf{begin}$\{$\textbf{equation*}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{equation*}$\}$ \\
176 %\indent $\backslash$[ \dots $\backslash$]\\
177 %\indent $\backslash$( \dots $\backslash$)\\
178 %
179 %have been redefined. In each environment listed above, the command \cs{wrap} is inserted, together with
180 %the command \cs{collect@body}, so that all the content of the environment is automatically stored into an
181 % ActualText in the PDF document. The following multiline formula environments, defined in the \textbf{amsmath} package,\\ \\
182 %\indent $\backslash$\textbf{begin}$\{$\textbf{align}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{align}$\}$ \\
183 %\indent $\backslash$\textbf{begin}$\{$\textbf{align*}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{align*}$\}$ \\
184 %\indent $\backslash$\textbf{begin}$\{$\textbf{alignat}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{alignat}$\}$ \\
185 %\indent $\backslash$\textbf{begin}$\{$\textbf{alignat*}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{alignat*}$\}$ \\
186 %\indent $\backslash$\textbf{begin}$\{$\textbf{flalign}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{flalign}$\}$ \\
187 %\indent $\backslash$\textbf{begin}$\{$\textbf{flalign*}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{flalign*}$\}$ \\
188 %\indent $\backslash$\textbf{begin}$\{$\textbf{gather}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{gather}$\}$ \\
189 %\indent $\backslash$\textbf{begin}$\{$\textbf{gather*}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{gather*}$\}$ \\
190 %\indent $\backslash$\textbf{begin}$\{$\textbf{xalignat}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{xalignat}$\}$ \\
191 %\indent $\backslash$\textbf{begin}$\{$\textbf{xalignat*}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{xalignat*}$\}$ \\
192 %\indent $\backslash$\textbf{begin}$\{$\textbf{xxalignat}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{xxalignat}$\}$ \\
193 %\indent $\backslash$\textbf{begin}$\{$\textbf{multline}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{multline}$\}$ \\
194 %\indent $\backslash$\textbf{begin}$\{$\textbf{multline*}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{multline*}$\}$ \\
195 %
196 % have been similarly redefined, using the commands \cs{wrapml} and \cs{wrapmlstar}.
197 % The content of these environments, too, is now stored into an
198 % ActualText in the PDF document. The support for more multiline environments will be added in future versions of the package.
199 %\end{itemize}
200 %
201 %\section{Usage}\label{sec:usage}
202 %
203 % An author that wants to create an accessible PDF document for visually impaired people, or people with special educational needs,
204 % can add this package and use the above
205 % environments for inserting the formulae. The \LaTeX\ code of the inserted formulae will be added as hidden comments in
206 % correspondence to the location of the formulae in the text. This will allow the user to access the formula code with the screen reader
207 % and with the braille refreshable display. Additionally, the package enables to copy the formula \LaTeX\ code from the PDF reader
208 % and paste it elsewhere (concerning this feature, please see also Section \ref{sec:issues} below).
209 %
210 % Inline and displayed mathematical modes encoded by means of $\$$ and $\$\$$ are not supported by the package. However, external scripts,
211 % or a command \textbf{\textbackslash{}doreplacement\{true\}} when typesetting with lua\LaTeX, implement the automatic replacement of these TeX markers by their LaTeX equivalents $\backslash(\backslash)$ and $\backslash[\backslash]$.
212 % The external scripts are provided as companion software and described in the following section.
213 %
214 %Moreover, provided that also the package
215 % \textbf{eqnalign} is added, the (old) multiline formula environments\\ \\
216 %\indent $\backslash$\textbf{begin}$\{$\textbf{eqnarray}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{eqnarray}$\}$ \\
217 %\indent $\backslash$\textbf{begin}$\{$\textbf{eqnarray*}$\}$ \dots $\backslash$\textbf{end}$\{$\textbf{eqnarray*}$\}$ \\
218 %
219 % \noindent will automatically generate the corresponding hidden ActualText.
220 %
221
222
223 %
224 %\section{External scripts and screen reader integration}\label{sec:extra}
225 %
226 %In addition to the package, we also provide scripts and other resources that complement its functionalities.
227 %
228 %\subsection{Preprocessing scripts}
229 %While we warmly suggest to follow the indications provided in the usage guide (suggested commands and environments), it is also
230 %possible to apply our package to an already existing \LaTeX\ document. In this case, if pdf\LaTeX\ is employed, it is necessary to
231 %preprocess the document in order to replace some of the unsupported commands and environments with the suggested ones. We provide
232 %a preprocessing script to handle some of these cases at our Github repository\footnote{\url{www.integr-abile.unito.it/axessibility/?repository}}. Namely, the underscore characters have to be substituted as indicated above when employing the \textbf{accsupp} mode,
233 % while this is not necessary when the \textbf{tagpdf} mode is selected. $\$$ and $\$\$$ markers must be replaced when typesetting with
234 %pdf\LaTeX\ both in the \textbf{accsupp} and \textbf{tagpdf} mode.
235 %
236 %\subsection{Expansion of user macros}
237 %Note that custom macros used by the author within the formulae are copied as-is into the ActualText in the hidden comment. This macros may bear no meaning for other readers, so it may be more meaningful to expand those macros into the original \LaTeX\ commands. We provide a script that can parse the \LaTeX\ document and replace all the user macros within the formulae with their expanded definitions. You can download this script at our Github repository\footnotemark[\value{footnote}].
238 %
239 %\subsection{Screen reader dictionaries}
240 %\LaTeX\ commands that are included as ActualText in the hidden comments corresponding to formulae may appear awkward when read by the screen reader. We provide dictionaries for JAWS and NVDA screen readers that convert \LaTeX\ commands into natural language. Please note that the braille refreshable display will still show the formulae in their original \LaTeX\ representations. The dictionaries can be downloaded at our Github repository\footnotemark[\value{footnote}].
241 %
242 %\subsection{Automatic replacement of $\$$ and $\$\$$ markers in Lua mode}
243 % Lua mode implements the \LaTeX\ command \textbf{doreplacement} to switch on/off the automatic replacement of $\$$ and $\$\$$ by
244 % \cs{(} \cs{)} and \cs{[} \cs{]} environments, so that external scripts are no longer required.
245 % This option is disabled by default and can be switched on or off by the call
246 % \textbf{\cs{doreplacement}\{true\}} or \textbf{\cs{doreplacement}\{false\}} respectively.
247 % When enabled, the replacement is applied to every input line, which might have undesired effects in verbatim mode or other
248 % environments, where $\$$ and $\$\$$ are used as regular symbols. So, it is recommended to switch off the automatic replacement
249 % functionality in such cases.
250 % The Lua code implementing the replacement is contained in the second main source file axessibility.lua. Please see the comments
251 % within the file itself for further explanations.
252 %
253 %
254 %
255 %\section{Known issues}\label{sec:issues}
256 %
257 %Note that, to preserve the compatibility with Acrobat Reader when employing the \textbf{accsupp} mode, our package discourages
258 %the use of the underscore character ($\_$), which is not correctly read using screen readers in combination with this PDF reader.
259 %Alternatively, we suggest to use the equivalent command \cs{sb}. The underscore character works correctly when the PDF file
260 %is produced in the \textbf{tagpdf} mode.
261 %
262 % The typeset of documents with \textbf{axessibility} by means of lua\LaTeX\ does not work corrrectly when selecting
263 % the \textbf{accsupp} mode.
264 %
265 % The copy and paste feature described in Section \ref{sec:usage} above does not work correctly at times. We observed that
266 % it behaves as expected when the NVDA screenreader is active, while it can produce multiple copies of the formula code
267 % when this software is not running.
268 %
269 % The preprocessing scripts do not cover all the possible character/environment combinations, so some errors can be generated, at times,
270 % when they are employed to perform the underscore, $\$$ and $\$\$$ substitutions.
271
272 %\section{Implementation}
273 %
274
275 % Standard file identification.
276
277 % \begin{macrocode}
278 %
279 \NeedsTeXFormat{LaTeX2e}
280 \ProvidesPackage{axessibility}
281 %[2019/11/01 v3.0: Accessibility support by marked content for inline,
282 % displayed single line, and various displayed multiline formulae]
283
284 %% 'tagpdf' or 'accsupp' option
285 \newif\iftagpdfopt
286
287 \DeclareOption{accsupp}{
288 \tagpdfoptfalse
289 }
290
291 \DeclareOption{tagpdf}{
292 \tagpdfopttrue
293 }
294
295 \ExecuteOptions{tagpdf}
296
297 \ProcessOptions\relax
298
299 \RequirePackage{amsmath}
300 \RequirePackage{amssymb}
301 \RequirePackage{xstring}
302
303 %%%
304 % to avoid errors in if constructs
305 %%%
306 \makeatletter
307 \long\def\@macronestedifalign{
308 \ifingather@
309 \restorealignstate@
310 \egroup
311 \nonumber
312 \ifnum0=`{\fi\iffalse}\fi
313 \else
314 $$%
315 \fi
316 }
317
318 \long\def\@macronestedifmultline{
319 \iftagsleft@ \@xp\lendmultline@ \else \@xp\rendmultline@ \fi
320 }
321 %
322 \makeatother
323 %
324 % \end{macrocode}
325
326
327 % \begin{macrocode}
328 %
329 \iftagpdfopt
330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 % tagpdf option code (default) %
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 %\def\messaggio{option tagpdf} %debug
336 %
337 % \end{macrocode}
338
339 % \noindent Setup of the \textbf{tagpdf} package.
340
341 % \begin{macrocode}
342 %
343 \RequirePackage{tagpdf}
344 \tagpdfsetup{tabsorder=structure,uncompress,activate-all,interwordspace=true}
345 \tagpdfifpdftexT
346 {
347 %set language / can also be done with hyperref
348 \pdfcatalog{/Lang (en-US)}
349 \usepackage[T1]{fontenc}
350 \input glyphtounicode
351 \pdfgentounicode=1
352 }
353 \tagpdfifluatexT
354 {
355 %set language / can also be done with hyperref
356 \pdfextension catalog{/Lang (en-US)}
357 \RequirePackage{fontspec}
358 \RequirePackage{luacode}
359 \newfontface\zerowidthfont{freeserif}
360 \directlua{
361 require("axessibility.lua")
362 }
363 }
364 %
365 % \end{macrocode}
366
367 % \noindent Tokens used for the treatment of multiline formula environments.
368
369 % \begin{macrocode}
370 %
371 \makeatletter
372
373 \newtoks\@mltext
374 \newtoks\@mltexttmp
375
376 %
377 % \end{macrocode}
378
379 % \noindent The command \textbf{\textbackslash{}doreplacmeent} with boolean argument switches on or off $\$$ and $\$\$$ replacement by LaTeX environments \cs{(} \cs{)} and \cs{[} \cs{]}. This command works only in Lua mode and allows to avoid the use of external substitution script. It is switched off by default.
380
381 % \begin{macrocode}
382 %
383 \newcommand{\doreplacement}[1]{
384 \tagpdfifluatexT
385 \directlua { replace_dls_and_double_dls(#1) }
386 }
387 %
388 % \end{macrocode}
389
390 % \noindent Automatic tagging at the document level.
391
392 % \begin{macrocode}
393 %
394 \let\begin@document=\document
395 \let\end@document=\enddocument
396 \renewcommand{\document}{\begin@document\tagstructbegin{tag=Document}}
397 \renewcommand{\enddocument}{\tagstructend\end@document}
398 \makeatother
399 %
400 % \end{macrocode}
401
402
403 % \noindent The next function redefines \cs{(} \cs{)} by means of a (temporary)
404 % math environment that calls the wrapper defined above.
405
406 % \begin{macrocode}
407 %
408 \makeatletter
409 \newenvironment{temp@env}{%
410 \relax\ifmmode\@badmath\else$\fi%
411 \collect@body\wrap}{%
412 \relax\ifmmode\ifinner$\else\@badmath\fi\else \@badmath\fi}
413 \protected\def\(#1\){\begin{temp@env}#1\end{temp@env}}
414 \makeatother
415 %
416 % \end{macrocode}
417
418
419 % \noindent The next command creates a blank space to avoid clash with references (it appears to be a \cs{protect}...).
420 % Refer to https://tex.stackexchange.com/questions/57151/how-do-i-prevent-conflicts-between-accsupp-and-hyperref
421 % for possible handling of such issues.
422
423 % \begin{macrocode}
424 %
425 \newcommand{\auxiliaryspace}{ }
426 %
427 % \end{macrocode}
428
429
430 % \noindent The next one is the actual wrapper. It takes the body of a formula environment and wraps it in the \textbf{tagpdf}
431 % package tagging commands, to make the math-text available in comments.
432 % \cs{detokenize} allows the formula to be parsed and read as a string.
433 % \cs{expandafter} there applies to the token "\{" and allows \cs{detokenize} to be applied
434 % after argument \#1 is passed to the tagging commands.
435
436 % \begin{macrocode}
437 %
438 \makeatletter
439 \long\def\wrap#1{
440 \tagstructbegin{tag=P,alttext-o=\detokenize\expandafter{#1},
441 actualtext-o=\detokenize\expandafter{#1}}
442 \tagmcbegin{tag=P,alttext-o=\detokenize\expandafter{#1},
443 actualtext-o=\detokenize\expandafter{#1}}
444 #1
445 \tagmcend
446 \tagstructend
447 }
448 \makeatother
449 %
450 % \end{macrocode}
451
452 % \noindent The next function redefines \cs{equation} by calling the above wrapper to its argument.
453 % This makes \cs{equation} accessible.
454
455 % \begin{macrocode}
456 %
457 \makeatletter
458 \renewenvironment{equation}{%
459 \incr@eqnum
460 \mathdisplay@push
461 \st@rredfalse \global\@eqnswtrue
462 \mathdisplay{equation}%
463 \collect@body\wrap\auxiliaryspace}{%
464 \endmathdisplay{equation}%
465 \mathdisplay@pop
466 \ignorespacesafterend
467 }
468 \makeatother
469 %
470 % \end{macrocode}
471
472
473 % \noindent The next function redefines \cs{equation*}
474 % by calling the above wrapper to its argument.
475 % This makes \cs{equation*} accessible.
476
477 % \begin{macrocode}
478 %
479 \makeatletter
480 \renewenvironment{equation*}{%
481 \mathdisplay@push
482 \st@rredtrue \global\@eqnswfalse
483 \mathdisplay{equation*}%
484 \collect@body\wrap\auxiliaryspace}{%
485 \endmathdisplay{equation*}%
486 \mathdisplay@pop
487 \ignorespacesafterend
488 }
489 \makeatother
490 %
491 % \end{macrocode}
492
493
494 % \noindent The next function redefines \cs{[} \cs{]},
495 % using the above redefinition of \cs{equation*}.
496
497 % \begin{macrocode}
498 %
499 \makeatletter
500 \protected\def\[#1\]{\begin{equation*}#1\end{equation*}}
501 \makeatother
502 %
503 % \end{macrocode}
504
505
506 % \noindent The next wrappers, similar to the previous one, are used to handle multiline formula environments.
507 % Here some additional step is needed to obtain the desired content, to be stored via the tagging commands.
508
509 % \begin{macrocode}
510 %
511 \makeatletter
512
513 \long\def\wrapml#1{
514 \def\@mltext{\detokenize\expandafter{#1}}
515 \def\@mltexttmp{}
516 \StrBehind[6]{\@mltext}{ }[\@mltexttmp]
517 \StrGobbleRight{\@mltexttmp}{1}[\@mltext]
518 \tagstructbegin{tag=P,alttext-o=\detokenize\expandafter{\@mltext},
519 actualtext-o=\detokenize\expandafter{\@mltext}}
520 \tagmcbegin{tag=P,alttext-o=\detokenize\expandafter{\@mltext},
521 actualtext-o=\detokenize\expandafter{\@mltext}}
522 #1
523 }
524
525 %
526 % This one should be \wrapml parametrized \StrBehind[5]
527 %
528 \long\def\wrapmlstar#1{
529 \def\@mltext{\detokenize\expandafter{#1}}
530 \def\@mltexttmp{}
531 \StrBehind[5]{\@mltext}{ }[\@mltexttmp]
532 \StrGobbleRight{\@mltexttmp}{1}[\@mltext]
533 \tagstructbegin{tag=P,alttext-o=\detokenize\expandafter{\@mltext},
534 actualtext-o=\detokenize\expandafter{\@mltext}}
535 \tagmcbegin{tag=P,alttext-o=\detokenize\expandafter{\@mltext},
536 actualtext-o=\detokenize\expandafter{\@mltext}}
537 #1
538 }
539
540 %
541 % This one should be \wrapml parametrized = \wrapmlstar
542 %
543 \long\def\wrapmlalt#1{
544 \def\@mltext{\detokenize\expandafter{#1}}
545 \def\@mltexttmp{}
546 \StrBehind[5]{\@mltext}{ }[\@mltexttmp]
547 \StrGobbleRight{\@mltexttmp}{1}[\@mltext]
548 \tagstructbegin{tag=P,alttext-o=\detokenize\expandafter{\@mltext},
549 actualtext-o=\detokenize\expandafter{\@mltext}}
550 \tagmcbegin{tag=P,alttext-o=\detokenize\expandafter{\@mltext},
551 actualtext-o=\detokenize\expandafter{\@mltext}}
552 #1
553 }
554
555 \makeatother
556 %
557 % \end{macrocode}
558
559
560 % \noindent The next functions redefine the environments align, align*, alignat, alignat*, flalign, flalign*, gather, gather*,
561 % xalignat, xalignat*, xxalignat, multline, multline*, originally defined in the package \textbf{amsmath}, by calling the
562 % above multiline wrapper to their
563 % argument. The structure, as for the original macros, is essentially the same for all of them.
564
565 % \begin{macrocode}
566 %
567 \makeatletter
568
569 \renewenvironment{align}{%
570 \collect@body\wrapml\auxiliaryspace
571 \start@align\@ne\st@rredfalse\m@ne
572 }{%
573 \math@cr \black@\totwidth@
574 \egroup
575 \@macronestedifalign
576 \ignorespacesafterend
577 \tagmcend
578 \tagstructend
579 }
580
581 \renewenvironment{align*}{%
582 \collect@body\wrapmlstar\auxiliaryspace
583 \start@align\@ne\st@rredtrue\m@ne
584 }{%
585 \endalign
586 }
587
588 \renewenvironment{alignat}{%
589 \collect@body\wrapml\auxiliaryspace\auxiliaryspace
590 \start@align\z@\st@rredfalse
591 }{%
592 \endalign
593 }
594
595 \renewenvironment{alignat*}{%
596 \collect@body\wrapmlstar\auxiliaryspace
597 \start@align\z@\st@rredtrue
598 }{%
599 \endalign
600 }
601
602 \renewenvironment{xalignat}{%
603 \collect@body\wrapmlalt\auxiliaryspace
604 \start@align\@ne\st@rredfalse
605 }{%
606 \endalign
607 }
608
609 \renewenvironment{xalignat*}{%
610 \collect@body\wrapmlstar\auxiliaryspace
611 \start@align\@ne\st@rredtrue
612 }{%
613 \endalign
614 }
615
616 \renewenvironment{xxalignat}{%
617 \collect@body\wrapmlalt\auxiliaryspace
618 \start@align\tw@\st@rredtrue
619 }{%
620 \endalign
621 }
622
623 \renewenvironment{flalign}{%
624 \collect@body\wrapml\auxiliaryspace
625 \start@align\tw@\st@rredfalse\m@ne
626 }{%
627 \endalign
628 }
629
630 \renewenvironment{flalign*}{%
631 \collect@body\wrapmlstar\auxiliaryspace
632 \start@align\tw@\st@rredtrue\m@ne
633 }{%
634 \endalign
635 }
636
637 \renewenvironment{gather}{%
638 \collect@body\wrapmlalt\auxiliaryspace\auxiliaryspace
639 \start@gather\st@rredfalse
640 }{%
641 \math@cr \black@\totwidth@ \egroup
642 $$\ignorespacesafterend
643 \tagmcend
644 \tagstructend
645 }
646
647 \renewenvironment{gather*}{%
648 \collect@body\wrapmlstar\auxiliaryspace\auxiliaryspace
649 \start@gather\st@rredtrue
650 }{%
651 \endgather
652 }
653
654 \renewenvironment{multline}{%
655 \collect@body\wrapmlalt\auxiliaryspace\auxiliaryspace
656 \start@multline\st@rredfalse
657 }{%
658 % \iftagsleft@ \@xp\lendmultline@ \else \@xp\rendmultline@ \fi
659 \@macronestedifmultline
660 \ignorespacesafterend
661 \tagmcend
662 \tagstructend
663 }
664
665 \renewenvironment{multline*}{
666 \collect@body\wrapmlstar\auxiliaryspace\auxiliaryspace
667 \start@multline\st@rredtrue
668 }{
669 \endmultline
670 }
671
672 \makeatother
673 %
674 % \end{macrocode}
675
676 %%%%
677 % End of tagpdf option code
678 %%%%
679
680 % \begin{macrocode}
681 %
682 \else
683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
684 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
685 % accsupp option code %
686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
687 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
688 %\def\messaggio{option accsupp} %debug
689
690 \RequirePackage{accsupp}
691
692 %\RequirePackage{amsmath}
693 %\RequirePackage{amssymb}
694 %\RequirePackage{xstring}
695 % \noindent PDF compression/unicode settings.
696
697
698 \pdfcompresslevel=0
699 \pdfoptionpdfminorversion=6
700 \input{glyphtounicode}
701 \pdfgentounicode=1
702 %
703 % \end{macrocode}
704
705
706 % \noindent Tokens used for the treatment of multiline formula environments.
707
708 % \begin{macrocode}
709 %
710
711 \makeatletter
712
713 \newtoks\@mltext
714 \newtoks\@mltexttmp
715
716 \makeatother
717 %
718 % \end{macrocode}
719
720
721 % \noindent Renewed command \cs{BeginAccSupp}, originally defined in the package \textbf{accsupp},
722 % to add the string \cs{S} before \cs{span}.
723 % This makes the formula readable by screenreading technologies.
724
725 % \begin{macrocode}
726 %
727 \makeatletter
728 \renewcommand*{\BeginAccSupp}[1]{%
729 \begingroup
730 \setkeys{ACCSUPP}{#1}%
731 \edef\ACCSUPP@span{%
732 /S/Span<<%
733 \ifx\ACCSUPP@Lang\relax
734 \else
735 /Lang\ACCSUPP@Lang
736 \fi
737 \ifx\ACCSUPP@Alt\relax
738 \else
739 /Alt\ACCSUPP@Alt
740 \fi
741 \ifx\ACCSUPP@ActualText\relax
742 \else
743 /ActualText\ACCSUPP@ActualText
744 \fi
745 \ifx\ACCSUPP@E\relax
746 \else
747 /E\ACCSUPP@E
748 \fi
749 >>%
750 }%
751 \ACCSUPP@bdc
752 \ACCSUPP@space
753 \endgroup
754 }
755 \makeatother
756 %
757 % \end{macrocode}
758
759
760 % \noindent The next command creates a blank space to avoid clash with references (it appears to be a \cs{protect}...).
761 % Refer to https://tex.stackexchange.com/questions/57151/how-do-i-prevent-conflicts-between-accsupp-and-hyperref
762 % for possible handling of such issues.
763
764 % \begin{macrocode}
765 %
766 \newcommand{\auxiliaryspace}{ }
767 %
768 % \end{macrocode}
769
770
771 % \noindent The next one is the actual wrapper. It takes the body of a formula environment and wraps it in AccSupp
772 % commands, to make the math-text available in comments.
773 % \cs{detokenize} allows the formula to be parsed and read as a string.
774 % \cs{expandafter} there applies to the token "\{" and allows \cs{detokenize} to be applied
775 % after argument \#1 is passed to \cs{BeginAccSupp}.
776
777 % \begin{macrocode}
778 %
779 \makeatletter
780 \long\def\wrap#1{
781 \BeginAccSupp{method=escape,ActualText=\detokenize\expandafter{#1}}
782 #1
783 \EndAccSupp{}%
784 }
785 \makeatother
786 %
787 % \end{macrocode}
788
789
790 % \noindent The next wrapper, similar to the previous one, is used to handle multiline formula environments.
791 % Here some additional step is needed to obtain the desired content, to be stored via \cs{BeginAccSupp}.
792
793 % \begin{macrocode}
794 %
795 \makeatletter
796 \long\def\wrapml#1{
797 \def\@mltext{\detokenize\expandafter{#1}}
798 \def\@mltexttmp{}
799 \StrBehind[5]{\@mltext}{ }[\@mltexttmp]
800 \StrGobbleRight{\@mltexttmp}{1}[\@mltext]
801 %
802 \BeginAccSupp{method=escape,ActualText=\auxiliaryspace\@mltext}
803 #1
804 \EndAccSupp{}%
805 }
806 \makeatother
807 %
808 % \end{macrocode}
809
810
811
812 % \noindent The next function redefines \cs{equation} by calling the above wrapper to its argument.
813 % This makes \cs{equation} accessible.
814
815 % \begin{macrocode}
816 %
817 \makeatletter
818 \renewenvironment{equation}{%
819 \incr@eqnum
820 \mathdisplay@push
821 \st@rredfalse \global\@eqnswtrue
822 \mathdisplay{equation}%
823 \collect@body\wrap\auxiliaryspace}{%
824 \endmathdisplay{equation}%
825 \mathdisplay@pop
826 \ignorespacesafterend
827 }
828 \makeatother
829 %
830 % \end{macrocode}
831
832
833 % \noindent The next function redefines \cs{equation*}
834 % by calling the above wrapper to its argument.
835 % This makes \cs{equation*} accessible.
836
837 % \begin{macrocode}
838 %
839 \makeatletter
840 \renewenvironment{equation*}{%
841 \mathdisplay@push
842 \st@rredtrue \global\@eqnswfalse
843 \mathdisplay{equation*}%
844 \collect@body\wrap\auxiliaryspace}{%
845 \endmathdisplay{equation*}%
846 \mathdisplay@pop
847 \ignorespacesafterend
848 }
849 \makeatother
850 %
851 % \end{macrocode}
852
853
854 % \noindent The next function redefines \cs{[} \cs{]},
855 % using the above redefinition of \cs{equation*}
856
857 % \begin{macrocode}
858 %
859 \makeatletter
860 \protected\def\[#1\]{\begin{equation*}#1\end{equation*}}
861 \makeatother
862 %
863 % \end{macrocode}
864
865
866 % \noindent The next function redefines \cs{(} \cs{)} by means of a (temporary)
867 % math environment that calls the wrapper defined above.
868
869 % \begin{macrocode}
870 %
871 \makeatletter
872 \newenvironment{tempenv}{%
873 \relax\ifmmode\@badmath\else$\fi%
874 \collect@body\wrap}{%
875 \relax\ifmmode\ifinner$\else\@badmath\fi\else \@badmath\fi}
876 \protected\def\(#1\){\begin{tempenv}#1\end{tempenv}}
877 \makeatother
878 %
879 % \end{macrocode}
880
881
882 % \noindent The next functions redefine the environments align, align*, alignat, alignat*, flalign, flalign*, gather, gather*,
883 % xalignat, xalignat*, xxalignat, multline, multline*, originally defined in the package \textbf{amsmath}, by calling the
884 % above multiline wrapper to their
885 % argument. The structure, as for the original macros, is essentially the same for all of them.
886
887 % \begin{macrocode}
888 %
889 \makeatletter
890
891 \renewenvironment{align}{%
892 \collect@body\wrapml\auxiliaryspace
893 \start@align\@ne\st@rredfalse\m@ne
894 }{%
895 \math@cr \black@\totwidth@
896 \egroup
897 \@macronestedifalign
898 \ignorespacesafterend
899 }
900
901 \renewenvironment{align*}{%
902 \collect@body\wrapml\auxiliaryspace
903 \start@align\@ne\st@rredtrue\m@ne
904 }{%
905 \endalign
906 }
907
908 \renewenvironment{alignat}{%
909 \collect@body\wrapml\auxiliaryspace
910 \start@align\z@\st@rredfalse
911 }{%
912 \endalign
913 }
914 \renewenvironment{alignat*}{%
915 \collect@body\wrapml\auxiliaryspace
916 \start@align\z@\st@rredtrue
917 }{%
918 \endalign
919 }
920 \renewenvironment{xalignat}{%
921 \collect@body\wrapml\auxiliaryspace
922 \start@align\@ne\st@rredfalse
923 }{%
924 \endalign
925 }
926 \renewenvironment{xalignat*}{%
927 \collect@body\wrapml\auxiliaryspace
928 \start@align\@ne\st@rredtrue
929 }{%
930 \endalign
931 }
932 \renewenvironment{xxalignat}{%
933 \collect@body\wrapml\auxiliaryspace
934 \start@align\tw@\st@rredtrue
935 }{%
936 \endalign
937 }
938 \renewenvironment{flalign}{%
939 \collect@body\wrapml\auxiliaryspace
940 \start@align\tw@\st@rredfalse\m@ne
941 }{%
942 \endalign
943 }
944
945 \renewenvironment{flalign*}{%
946 \collect@body\wrapml\auxiliaryspace
947 \start@align\tw@\st@rredtrue\m@ne
948 }{%
949 \endalign
950 }
951
952 \renewenvironment{gather}{%
953 \collect@body\wrapml\auxiliaryspace\auxiliaryspace
954 \start@gather\st@rredfalse
955 }{%
956 \math@cr \black@\totwidth@ \egroup
957 $$\ignorespacesafterend
958 }
959
960 \renewenvironment{gather*}{%
961 \collect@body\wrapml\auxiliaryspace\auxiliaryspace
962 \start@gather\st@rredtrue
963 }{%
964 \endgather
965 }
966
967 \renewenvironment{multline}{%
968 \collect@body\wrapml\auxiliaryspace\auxiliaryspace
969 \start@multline\st@rredfalse
970 }{%
971 %\iftagsleft@ \@xp\lendmultline@ \else \@xp\rendmultline@ \fi
972 \@macronestedifmultline
973 \ignorespacesafterend
974 }
975
976 \renewenvironment{multline*}{
977 \collect@body\wrapml\auxiliaryspace\auxiliaryspace
978 \start@multline\st@rredtrue
979 }{
980 \endmultline
981 }
982
983 %%}
984 %%
985 \makeatother
986 %%%%
987 % End of accsupp option code
988 %%%%
989 \fi
990 %
991 % \end{macrocode}
992 %
993 % \noindent
994 % For the automatic $\$$ and $\$\$$ replacement code, please see the second main source file axessibility.lua.
995 %
996 %\section{History}
997 %\noindent \textbf{[2018/07/09: v1.0] }
998 %\begin{itemize}
999 % \item First version (with Michele Berra, Alice Ruighi, and Eugenia Taranto).
1000 %\end{itemize}
1001 %\noindent \textbf{[2019/01/08: v2.0] }
1002 %\begin{itemize}
1003 % \item Added support for environments align, align*, alignat, alignat*, flalign, flalign*, gather, gather*, xalignat, xalignat*, and xxalignat, from the package \textbf{amsmath} (with Michele Berra, Alice Ruighi, and Eugenia Taranto).
1004 %\end{itemize}
1005 %\noindent \textbf{[2020/01/08: v3.0] }
1006 %\begin{itemize}
1007 % \item Added selection option, to choose between tagging via accsupp or tagpdf packages. Added support for environment
1008 % multline and multline* from the package \textbf{amsmath}. Added the second main source file axessibility.lua, containing code
1009 % that can be activated when typesetting with lua\LaTeX.
1010 %\end{itemize}
1011
1012 \endinput
1013 %%
1014 %% End of file `axessibility.sty'.