summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/tagpdf/tagpdfdocu-patches.sty
blob: 6ae5840b113fa13d265cf5e94d2d60b053e1be1f (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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
%\RequirePackage[enable-debug]{expl3}[2018/06/14]
\ProvidesExplPackage {tagpdfdocu-patches} {2024-08-02} {0.99d}
 {patches/commands for the tagpdf documentation}
\RequirePackage{etoolbox,xpatch}

%Logos
% only spacing changes:
\ExplSyntaxOn
\DeclareRobustCommand\TeX{
  \leavevmode
     T\kern-.1667em\lower.5ex\hbox{E}\kern-.05emX\@ %changed from -.125em
   }
\DeclareRobustCommand{\LaTeX}{
        \leavevmode
        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
    }
  
% minisec, correct tagging is still unclear.  
\newcommand\minisec[1]{%
    \if@noskipsec \leavevmode \fi
    \par
    \@afterindentfalse
    \if@nobreak
      \everypar{}%
    \else
      \addpenalty\@secpenalty\addvspace{1.5ex}%
    \fi
  {\tagpdfsetup{para/maintag=P,para/tag=Strong}\parindent \z@    
   \setlength{\parfillskip}{\z@ plus 1fil}%
    \raggedright\normalfont\bfseries\nobreak
    \nobreak\interlinepenalty \@M #1\par\nobreak%
  }\nobreak
  \@afterheading
}                    

% listings. Unclear how to make it work for the original lstlisting, so we make a 
% copy taglstlisting for now
\DeclareInstance{blockenv}{lstlisting}{display}
{
  env-name       = lstlisting,
  tag-name       = verbatim,
  tag-class      = ,
  tagging-recipe = standard,
  inner-level-counter  = ,
  level-increase = false,
  setup-code     = ,
  block-instance = displayblock ,
  inner-instance = ,
  final-code     =  \tl_set:Nn \l__tag_para_main_tag_tl {codeline}\tagtool{paratag=Code},
}

\lstnewenvironment{taglstlisting}[2][]{%
     \UseInstance{blockenv}{lstlisting} {}
     \lst@TestEOLChar{#2}%
     \lstset{#1}%
     \csname\@lst @SetFirstNumber\endcsname%
   }{%
     \@nobreakfalse
     \csname\@lst @SaveFirstNumber\endcsname%
     \endblockenv
   }
      
% ======== marginnote ==========
% 2024-03-23 currently marginnote is no longer used, we use marginpar
% 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
%\renewcommand*{\mn@parboxrestore}{\tagpdfparaOff}%

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

\ExplSyntaxOff

%======== 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.
% we force also a \par and add a div structure, to avoid clashes with the block
% tagging code. This needs revisiting!

\AddToHook{env/tcolorbox/before}{\par\tagstructbegin{tag=Div}}
\AddToHook{env/tcolorbox/begin}{\tagpdfparaOff \tcbset{before upper=\tagpdfparaOn}}
\AddToHook{env/tcolorbox/after}{\par\tagstructend}

% ========= doc Commands from tcolorbox
% Not sure if this is generally usable but one must avoid tagstop if there can
% be a pagebreak 
\DeclareInstance{blockenv}{docCommand}{display}
{
  env-name       = docCommand,
  tag-name       = Div,
  tag-class      = ,
  tagging-recipe = standalone,
  inner-level-counter  = ,
  level-increase = false,
  setup-code     = ,
  block-instance = displayblock ,
}

\RenewDocumentEnvironment{tcb@manual@entry}{}
    {\UseInstance{blockenv}{docCommand} 
      {tag-name=Div,
       leftmargin=\kvtcb@doc@left,
       rightmargin=\kvtcb@doc@right,
       }%
     \tagtool{para=false}% 
     \AssignSocketPlug{tagsupport/minipage/before}{noop}
     \AssignSocketPlug{tagsupport/minipage/after}{noop}      
     \AssignSocketPlug{tagsupport/parbox/before}{noop}
     \AssignSocketPlug{tagsupport/parbox/after}{noop}  
    }   
    {\endblockenv } 

\tcbset{
 doc head command=
   {before upper=\tagstructbegin{tag=Code}\tagmcbegin{},
    after upper=\tagmcend\tagstructend},
 }
 
 

% ======= footnote ========
% done in testphase code

% ====== 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
 }}{}

%====== tikz picture =======
% first draft to tag. The main problem is to handle paragraphs. One 
\ExplSyntaxOn
\cs_new_protected:Npn\__tag_tikz_savepos:n #1
 {
  \tex_savepos:D 
  \tikz@resetexpandcount%
  \tikz@scan@one@point\pgfutil@firstofone(current~bounding~box.north~east)\relax
  \pgf@pos@transform{\pgf@x}{\pgf@y}%
  \property_record:nn{#1}{xpos,ypos,abspage}
  \property_record:nn{#1-tr}{pgfx,pgfy}
  \tikz@scan@one@point\pgfutil@firstofone(current~bounding~box.south~west)\relax
  \pgf@pos@transform{\pgf@x}{\pgf@y}%
  \property_record:nn{#1-bl}{pgfx,pgfy}
  \tex_savepos:D 
 }
\cs_generate_variant:Nn \__tag_tikz_savepos:n {e}
 
\NewProperty{pgfx}{now}{0}
 {
   \dim_compare:nNnTF {\dim_abs:n {\pgf@x}} > {15999pt} 
    { 0 }
    { \dim_to_decimal_in_sp:n{\pgf@x} } 
 }  
\NewProperty{pgfy}{now}{0}
 {
   \dim_compare:nNnTF {\dim_abs:n {\pgf@y}} > {15999pt} 
    { 0 }
    { \dim_to_decimal_in_sp:n{\pgf@y} } 
 }  

\cs_new_protected:Npn \__tag_tikz_getbbox:
 {
   \int_gincr:N\g__tag_graphic_int
   \tl_set:Ne\l__tag_graphic_currentlabel_tl {__tag_graphic_\int_use:N \g__tag_graphic_int}
   \tl_gset:Ne\g__tag_graphic_lx_tl
     {
       \dim_to_decimal_in_bp:n 
         {   \property_ref:een {\l__tag_graphic_currentlabel_tl}{xpos}{0}sp 
           + \property_ref:een {\l__tag_graphic_currentlabel_tl-bl}{pgfx}{0}sp  
         }
     }  
   \tl_gset:Ne\g__tag_graphic_ly_tl
        {
          \dim_to_decimal_in_bp:n 
            { \property_ref:een {\l__tag_graphic_currentlabel_tl}{ypos}{0}sp 
              + \property_ref:een {\l__tag_graphic_currentlabel_tl-bl}{pgfy}{0}sp
            }
        } 
   \tl_gset:Ne\g__tag_graphic_ux_tl
     {
       \dim_to_decimal_in_bp:n 
         {   \property_ref:een {\l__tag_graphic_currentlabel_tl}{xpos}{0}sp 
           + \property_ref:een {\l__tag_graphic_currentlabel_tl-tr}{pgfx}{0}sp  
         }
     }
   \tl_gset:Ne\g__tag_graphic_uy_tl
     {
       \dim_to_decimal_in_bp:n 
         {   \property_ref:een {\l__tag_graphic_currentlabel_tl}{ypos}{0}sp 
           + \property_ref:een {\l__tag_graphic_currentlabel_tl-tr}{pgfy}{0}sp  
         }
     }  
  }

\cs_new_protected:Npn \__tag_graphic_tikz_begin_picture:
 {
  \tag_mc_end_push:
  \bool_if:NTF \l__tag_graphic_artifact_bool
   { \tagmcbegin{artifact} }
   {   
     \__tag_tikz_getbbox:
     \tagstructbegin{tag=Figure,alt=\l__tag_graphic_alt_tl}\tagmcbegin{}
     \__tag_prop_gput:cne
         { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop }
         { A } 
         {
           << 
             /O /Layout /BBox~
             [
              \g__tag_graphic_lx_tl\c_space_tl
              \g__tag_graphic_ly_tl\c_space_tl
              \g__tag_graphic_ux_tl\c_space_tl
              \g__tag_graphic_uy_tl
             ]
           >>   
         }
    \bool_if:NT\l__tag_graphic_debug_bool
     {
       \__tag_graphic_show_bbox:VVVVne
        \g__tag_graphic_lx_tl
        \g__tag_graphic_ly_tl
        \g__tag_graphic_ux_tl
        \g__tag_graphic_uy_tl
        {red}
        {\int_use:N\g__tag_graphic_int}
      }
    }      
    \SuspendTagging{tikz}      
  }

\cs_new_protected:Npn \__tag_graphic_tikz_end_picture:
 {
   \ResumeTagging{tikz}\tagmcend
   \bool_if:NF \l__tag_graphic_artifact_bool
     {
       \tagstructend
       \__tag_tikz_savepos:e {__tag_graphic_\int_use:N \g__tag_graphic_int}
     }
   \tag_mc_begin_pop:n{}
 }
 
\tikzset
 {
   every~picture/.style=
    {
     artifact,
     execute~at~begin~picture=\__tag_graphic_tikz_begin_picture:, 
     execute~at~end~picture=\__tag_graphic_tikz_end_picture:
    }
 }
\AddToHook{env/tikzpicture/before}{\leavevmode} 
 
\tikzset
 {
   alt/.code= 
     {
       \bool_set_false:N \l__tag_graphic_artifact_bool
       \tl_set:Nn \l__tag_graphic_alt_tl{#1}
     } 
 } 
\tikzset
 {
   artifact/.code= 
    \bool_set_true:N \l__tag_graphic_artifact_bool
 } 

\ExplSyntaxOff





\endinput