summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tagpdf/ex-patch-list.tex
blob: f3f149b20ce7ce313b7fa123838fc32284765422 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
% !Mode:: "TeX:DE:UTF-8:Main"

%This example shows how one can patch lists command
%it is based on enumitem

%It uses a command to end \item (\meti). It is perhaps possible to hide this command
% inside \item/end{list}, but with nested list it is not so easy.

% Pay attention to casing. Li/LI, Lbody/Lbody are different.
%no page break involved. So the example works in lua and generic mode
\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{pdfversion=1.7,lang=en-UK,uncompress}

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage{tagpdf}

\tagpdfifpdftexT
 {
  \usepackage[T1]{fontenc}
 }

\tagpdfifluatexT
 {
  \usepackage{fontspec}
  \usepackage{luacode}
 }


\tagpdfsetup{tabsorder=structure,
             activate-all,
             }

\usepackage{lipsum}%\textheight3cm

\usepackage{enumitem,xpatch}

\makeatletter

\newcommand\tag@enit@format@preset[1]{%
  \tagstructbegin{tag=LI}%
  \tagstructbegin{tag=Lbl}%
  \tagmcbegin{tag=Lbl}%
  #1%
  \tagmcend
  \tagstructend %end Lbl
  \tagstructbegin{tag=LBody}}

\newcommand\meti{% end of \item
 \tagstructend %end of LBody
 \tagstructend %end of LI
}

\xpatchcmd\enit@preset{\@firstofone}{\tag@enit@format@preset}{}{\fail}

\setlist{
    before*=\tagstructbegin{tag=L},
    after*={\tagstructend}}

% keys that overwrite \enit@format must be patched, eg like the follow
% the font key should be patched in a similar way
\enitkv@key{enumitem}{format}{%
  \def\enit@format{%
   \tagstructbegin{tag=LI}%
   \tagstructbegin{tag=Lbl}%
   \tagmcbegin{tag=Lbl}%
   #1\tagmcend}}
\makeatother
% marking of the text inside the list can not be handled automatically -- one doesn't know the type
% we use simple P here
\newcommand\TAGP{\tagstructbegin{tag=P}\tagmcbegin{tag=P}}
\newcommand\PGAT{\tagmcend\tagstructend}

\begin{document}
%I don't want to handle pagestyles, so set everything to empty:
\pagestyle{empty}\renewcommand\chapterpagestyle{empty}

\tagstructbegin{tag=Document}

\begin{itemize}
\item \TAGP Ducks say quack\PGAT\meti
\item \TAGP Marmots say something Parmotlike\PGAT\meti
\end{itemize}

\begin{enumerate}
\item \TAGP The highest pass is the Col de l'Iseran.\PGAT\meti
\item \TAGP The second highest pass is the Passo dello Stelvio.\PGAT\meti
\end{enumerate}

\begin{description}
\item[ducks] \TAGP yellow\PGAT\meti
\item[marmots] \TAGP brown\PGAT\meti
\end{description}

\tagstructend   %Document
\end{document}