summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tagpdf/ex-patch-sectioning-memoir.tex
blob: aefda1cbcb52a1b9d0498bf081a895d1f569fb76 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
% !Mode:: "TeX:DE:UTF-8:Main"
%chapter not correct!!
\documentclass[a4paper,oneside]{memoir}
\settocdepth{subsubsection}
\setsecnumdepth{subsubsection}

\usepackage[english]{babel}


\usepackage{tagpdf}

\tagpdfifpdftexT
 {
  %set language / can also be done with hyperref
  \pdfcatalog{/Lang (en-US)}
  \usepackage[T1]{fontenc}
 }

\tagpdfifluatexT
 {
  %set language / can also be done with hyperref
  \pdfextension catalog{/Lang (en-US)}
  \usepackage{fontspec}
  \usepackage{luacode}
 }


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

\usepackage{lipsum}%\textheight3cm

\usepackage{etoolbox}

\ifdef\cfttocbeforelisthook{
  \appto\cfttocbeforelisthook{\tagstructbegin{tag=TOC}}%\noindent TOC\par}
}{
  \csdef\cfttocbeforelisthook{\tagstructbegin{tag=TOC}}%\noindent TOC\par}
}
\ifdef\cfttocafterlisthook{
  \appto\cfttocafterlisthook{\tagstructend}%\noindent /TOC\par}
}{
  \csdef\cfttocafterlisthook{\tagstructend}%\noindent /TOC\par}
}

\def\M{{\fontsize{3pt}{3pt}\sffamily\selectfont NN}}

%what about unnumbered entries in the toc??????
\appto\cftchapterpresnum{%
     \tagstructbegin{tag=TOCI}% is there a better place? what about unnumbered entries?
     \tagstructbegin{tag=Lbl}%
     \tagmcbegin{tag=Lbl}%
}
\appto\cftchapteraftersnum{%
  \tagmcend
  \tagstructend}

\appto\cftsectionpresnum{%
    \tagstructbegin{tag=TOCI}% is there a better place? what about unnumbered entries?
    \tagstructbegin{tag=Lbl}%
    \tagmcbegin{tag=Lbl}%
}
\appto\cftsectionaftersnum{%
 \tagmcend
 \tagstructend}

\appto\cftsubsectionpresnum{%
    \tagstructbegin{tag=TOCI}% is there a better place? what about unnumbered entries?
    \tagstructbegin{tag=Lbl}%
    \tagmcbegin{tag=Lbl}%
 }
\appto\cftsubsectionaftersnum{%
 \tagmcend
 \tagstructend}
\appto\cftsubsubsectionpresnum{%
    \tagstructbegin{tag=TOCI}% is there a better place? what about unnumbered entries?
    \tagstructbegin{tag=Lbl}%
    \tagmcbegin{tag=Lbl}%
}
\appto\cftsubsubsectionaftersnum{%
 \tagmcend
 \tagstructend}

%begin of entry
\appto\cftchapteraftersnumb{%
     \tagstructbegin{tag=P}%
     \tagmcbegin{tag=P}}
\appto\cftsectionaftersnumb{%
     \tagstructbegin{tag=P}%
     \tagmcbegin{tag=P}}
\appto\cftsubsectionaftersnumb{%
     \tagstructbegin{tag=P}%
     \tagmcbegin{tag=P}}
\appto\cftsubsubsectionaftersnumb{%
     \tagstructbegin{tag=P}%
     \tagmcbegin{tag=P}}

%end of entry
\pretocmd\cftchapterfillnum{%
 \tagmcend
 \tagstructend
}{}{}
\pretocmd\cftsectionfillnum{
 \tagmcend
 \tagstructend}{}{}
\pretocmd\cftsubsectionfillnum{
 \tagmcend
 \tagstructend}{}{}
\pretocmd\cftsubsubsectionfillnum{%
 \tagmcend
 \tagstructend}{}{}


\makeatletter
\patchcmd\cftchapterformatpnum{\cftchapterpagefont #1}{%
  %\llap{\M pnum}%
  \tagstructbegin{tag=Reference}%
   \tagmcbegin{tag=Reference}
  \cftchapterpagefont #1%
  %\rlap{\M pnum}%
  \tagmcend
  \tagstructend
  \tagstructend %for /TOCI. is there a better place?
}{}{}
\patchcmd\cftsectionformatpnum{\@nameuse{cftsectionpagefont}#1}{%
  %\llap{\M pnum}%
  \tagstructbegin{tag=Reference}%
   \tagmcbegin{tag=Reference}
   \@nameuse{cftsectionpagefont}#1%
  %\rlap{\M pnum}%
  \tagmcend
 \tagstructend
 \tagstructend %for /TOCI. is there a better place?
}{}{\typeout{patch failed}}
\patchcmd\cftsubsectionformatpnum{\@nameuse{cftsubsectionpagefont}#1}{%
  %\llap{\M}%
  \tagstructbegin{tag=Reference}%
   \tagmcbegin{tag=Reference}
   \@nameuse{cftsubsectionpagefont}#1%
  %\rlap{\M}%
   \tagmcend
  \tagstructend
  \tagstructend %for /TOCI. is there a better place?
}{}{\typeout{patch failed}}

\patchcmd\cftsubsubsectionformatpnum{\@nameuse{cftsubsubsectionpagefont}#1}{%
  %\llap{\M}%
  \tagstructbegin{tag=Reference}%
   \tagmcbegin{tag=Reference}
   \@nameuse{cftsubsubsectionpagefont}#1%
  %\rlap{\M}%
   \tagmcend
  \tagstructend
  \tagstructend %for /TOCI. is there a better place?
}{}{\typeout{patch failed}}


% section is typeset using \M@sect
\ExplSyntaxOn
\prop_new:N   \g_tag_section_level_prop
\prop_put:Nnn \g_tag_section_level_prop {chapter}{H1}
\prop_put:Nnn \g_tag_section_level_prop {section}{H2}
\prop_put:Nnn \g_tag_section_level_prop {Starredsection}{H2}
\prop_put:Nnn \g_tag_section_level_prop {subsection}{H3}
\prop_put:Nnn \g_tag_section_level_prop {subsubsection}{H4}
\prop_put:Nnn \g_tag_section_level_prop {paragraph}{H5}
\ExplSyntaxOff
\patchcmd\M@sect{#9\@@par}{%
 %this place could be used for something between number and text
  #9%
     \tagmcend
     \tagstructend
  \@@par%
}{}{}

% section* use \@ssect, but memoir redefines it a little before
% calling the kernel version

\ExplSyntaxOn
\patchcmd\@ssect{\@mem@old@ssect{#1}{#2}{#3}{#4}{#5}}{%
  \@mem@old@ssect{#1}{#2}{#3}{#4}{%
  \tagstructbegin{tag=H2}% how to get level???
  \tagmcbegin    {tag=H2}% how to get level???
   #5
  \tagmcend
  \tagstructend}%
}{}{}

% section numbers are typeset using \@seccntformat


\pretocmd\@seccntformat{%
 \tagstructbegin{tag=\prop_item:Nn\g_tag_section_level_prop{#1}}%
 \tagmcbegin    {tag=\prop_item:Nn\g_tag_section_level_prop{#1}}
}{}{}
\ExplSyntaxOff
% could be used to insert something after the number ...
%\patchcmd\@seccntformat{\endcsname}{%
%  \endcsname\rlap{\M}%
%}{}{}

\renewcommand{\cftdot}{\tagmcbegin{artifact}.\tagmcend}

\makeatother
 % I don't want to handle header/footer now
\pagestyle{empty}
\makeevenfoot{plain}{}{}{}
\makeoddfoot{plain}{}{}{}


%% missing yet: chapter titles
\begin{document}

\tagstructbegin{tag=Document}

\tableofcontents*

\chapter{Test chapter}

\section{Test section}

 \tagstructbegin{tag=P}
   \tagmcbegin{tag=P}
test
   \tagmcend
 \tagstructend


\subsection{Test subsection}

 \tagstructbegin{tag=P}
   \tagmcbegin{tag=P}
test
   \tagmcend
 \tagstructend

\subsubsection{Test subsubsection}

 \tagstructbegin{tag=P}
   \tagmcbegin{tag=P}
test
   \tagmcend
 \tagstructend

\section*{Starred section}

\tagstructend
\end{document}