summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tagpdf/tagpdfdocu-patches.sty
blob: 3ad0e3de74648028bce0ed9b9f6cda4eeec6213c (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
%\RequirePackage[enable-debug]{expl3}[2018/06/14]
\ProvidesExplPackage {tagpdfdocu-patches} {2023-01-24} {0.98b}
 {patches/commands for the tagpdf documentation}
\RequirePackage{etoolbox,xpatch}

% latex-lab experiments
\providecommand\tagtool[1]{}
%vLogos

\ExplSyntaxOn
\DeclareRobustCommand\TeX{
  \leavevmode
  \tag_mc_end_push:
   \tag_struct_begin:n{tag=Span,alt=TeX,actualtext=TeX}
    \tagmcbegin{}
     T\kern-.1667em\lower.5ex\hbox{E}\kern-.05emX\@ %changed from -.125em
    \tagmcend
   \tag_struct_end:
  \tag_mc_begin_pop:n{}}
\DeclareRobustCommand{\LaTeX}{
        \leavevmode
        \tag_mc_end_push:
        \tag_struct_begin:n{tag=Span,alt=LaTeX,actualtext=LaTeX}
        \tagmcbegin{}
        L\kern-.25em % %changed from -0.36em
        \sbox\z@ T%
         \vbox to\ht\z@{\hbox{\check@mathfonts
                              \fontsize\sf@size\z@
                              \math@fontsfalse\selectfont
                              A}%
                        \vss}%
        \kern-.1em % %changed from 0.15em
        T\kern-.1667em\lower.5ex\hbox{E}\kern-.05emX\@ %changed from -0.125
        \tagmcend
        \tag_struct_end:
        \tag_mc_begin_pop:n{}    
  }
% textbf

\AddToHook{cmd/textbf/before}
  {\leavevmode\tag_mc_end_push:\tag_struct_begin:n{tag=Strong}\tagmcbegin{}}

\AddToHook{cmd/textbf/after}
  {\tag_mc_end:\tag_struct_end:\tag_mc_begin_pop:n{}}

% emph
\AddToHook{cmd/emph/before}
  {\leavevmode\tag_mc_end_push:\tag_struct_begin:n{tag=Em}\tagmcbegin{}}

\AddToHook{cmd/emph/after}
  {\tag_mc_end:\tag_struct_end:\tag_mc_begin_pop:n{}}
  
  
\newcommand\minisec[1]{%
    \if@noskipsec \leavevmode \fi
    \par
    \@afterindentfalse
    \if@nobreak
      \everypar{}%
    \else
      \addpenalty\@secpenalty\addvspace{1.5ex}%
    \fi
  {\tagpdfsetup{paratag=H10}\parindent \z@    
   \setlength{\parfillskip}{\z@ plus 1fil}%
    \raggedright\normalfont\bfseries\nobreak
    \nobreak\interlinepenalty \@M #1\par\nobreak%
  }\nobreak
  \@afterheading
}                    


      
%%%%
%% Lists
%% patches enumitem internals!
%%%%
\tagpdfsetup
  {
     newattribute =
        {itemize}{/O /List /ListNumbering/Unordered},
     newattribute =
        {enumerate}{/O /List /ListNumbering/Ordered},        
     newattribute =
        {description}{/O /List /ListNumbering/Description},            
  }
\AddToHook{env/itemize/begin}{\par\tagstructbegin{tag=L,attribute-class=itemize}}%\par is needed to close the paragraph before.
\AddToHook{env/itemize/end}{\par\tagstructend\tagstructend\tagstructend}%LBody,LI,L
\AddToHook{env/enumerate/begin}{\par\tagstructbegin{tag=L,attribute-class=enumerate}}
\AddToHook{env/enumerate/end}{\par\tagstructend\tagstructend\tagstructend}%LBody,LI,L
\AddToHook{env/description/begin}{\par\tagstructbegin{tag=L,attribute-class=description}}
\AddToHook{env/description/end}{\par\tagstructend\tagstructend\tagstructend}%LBody,LI,L

\newcommand\tag@enit@format@preset[1]{%
 \str_if_eq:eeTF { \prop_item:cn { g__tag_struct_\g__tag_struct_stack_current_tl _prop }{S} }{/L}
  {
   %\typeout{BEGIN~OF~LIST}
  }
  {%\typeout{NEXT ITEM}
   \tagstructend\tagstructend} % for the LBody/LI
  \tagstructbegin{tag=LI}
  \tagstructbegin{tag=Lbl}
  \tagmcbegin{}
    #1
  \tagmcend
  \tagstructend
  \tagstructbegin{tag=LBody}
  }

\ExplSyntaxOff
\xpatchcmd\enit@preset{\@firstofone}{\tag@enit@format@preset}{}{\fail}
%close mc from paratagging and reopen ...
% this disturbs someone docCommand which has then a MC outside a P.
\xpatchcmd\@item{\box\@labels}{\tagmcend \box\@labels \tagmcbegin{tag=P}}{}{\fail}
\ExplSyntaxOn

% keys that overwrite \enit@format must be patched, eg like the follow
% the font key should be patched in a similar way
\enitkv@key{}{format}{% new enumitem don't use first argument
  \def\enit@format{%
   \tagstructbegin{tag=LI}%
   \tagstructbegin{tag=Lbl}%
   \tagmcbegin{}%
   #1\tagmcend}}


% listings + verbatim
% the paragraph code could create span around the lines ...
% we use Code for every line.

\AddToHook{env/lstlisting/begin}{\tagpdfsetup{paratag=Code}}
\AddToHook{env/lstlisting/end}{}

\AddToHook{env/verbatim/begin}{\tagpdfsetup{paratag=Code}}
\AddToHook{env/verbatim/end}{}

\AddToHook{env/docCommand/begin}{\tagstructbegin{tag=P}\tagpdfsetup{paratag=Code}}
\AddToHook{env/docCommand/end}  {\tagstructend}

% ======== marginnote ==========
% TODO marginnote has a bug (a \par is missing) so it messes up tagging.
% but currently unneeded as we marked them up as artifacts anyway as they don't contain
% meaningful contents

\NewDocumentCommand\sidenote{m}
 {
   \tag_mc_artifact_group_begin:n{notype}\tagpdfparaOff\marginnote{#1}\tag_mc_artifact_group_end:
 }

% ======== tikzpicture ==========
% TODO this needs some investigation: it messes up the stack if one add paraOff

\AddToHook{env/tikzpicture/begin}{}

%======== tcolorbox ========
% We switch of paratagging at the begin and reenable it locally in before upper.
% the before upper setting is dangerous as it can be overwritten by
% users. So a more stable hook is needed.
%\AddToHook{env/tcolorbox/begin}{\tagpdfparaOff}
%\AddToHook{env/docCommand/begin}{\tagpdfparaOff}
%\tcbset{before~upper=\tagpdfparaOn}
\AddToHook{env/tcolorbox/begin}{\tagpdfparaOff \tcbset{before~upper=\tagpdfparaOn}}
\AddToHook{env/docCommand/begin}{\tagpdfparaOff \tcbset{before~upper=\tagpdfparaOn}}
\ExplSyntaxOff
% ======= footnote ========
% done in testphase code

% ======= bibliography ========
% biblatex. Creates some empty mc-chunks.
% no internal patches, but redefining begentry/finentry is not safe.
% better hook is needed.

\newbibmacro*{begentry}{\tagstructbegin{tag=BibEntry}\tagmcbegin{}}
\newbibmacro*{finentry}{\finentry\tagmcend\tagstructend}

% ====== hyperref ========
% this should probably go into tagpdf, but it is related to
% problem of pdf strings and context ....

\AddToHook{package/hyperref/after}
 {%
  \pdfstringdefDisableCommands{%
   \let\tagstructbegin\@gobble
   \let\tagmcbegin\@gobble
   \let\tagmcend\relax
   \let\tagstructend\relax
 }}{}


%====== pictures ========
% PAC3 complained that the BBox is missing, so we are cheating for now
% and add a fix size.
\tagpdfsetup
  {
     newattribute =
        {bbox}{/O /Layout /BBox [0 0 100 100]}
  }

\endinput