summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tagpdf/tagpdf-roles.dtx
blob: 920c6345ca84c9c6d9b8f4a21f7a887fc298a548 (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
% \iffalse meta-comment
%
%% File: tagpdf-roles.dtx
%
% Copyright (C) 2019 Ulrike Fischer
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version.  The latest version
% of this license is in the file
%
%    https://www.latex-project.org/lppl.txt
%
% This file is part of the "tagpdf bundle" (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% -----------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
%    https://github.com/u-fischer/tagpdf
%
% for those people who are interested.
%
% \fi
%
%    \begin{macrocode}
%<@@=tag>
%<*roles>
\ProvidesExplPackage {tagpdf-roles-code} {2021/02/23} {0.80}
 {part of tagpdf - code related to roles and structure names}

\@@_seq_new:N     \g_@@_role_tags_seq  %to get names from numbers
\@@_prop_new:N    \g_@@_role_tags_prop %to get numbers from names

%The list of standard adobe tags.
\clist_const:Nn \c_@@_role_sttags_clist
  {%possible root elements
    Document,   %A complete document. This is the root element of any structure tree containing
                %multiple parts or multiple articles.
    Part,       %A large-scale division of a document.
    Art,        %A relatively self-contained body of text constituting a single narrative or exposition
    %subelements
    Sect,       %A container for grouping related content elements.
    Div,        %A generic block-level element or group of elements
    BlockQuote, %A portion of text consisting of one or more paragraphs attributed to someone other
                %than the author of the  surrounding text.
    Caption,    %A brief portion of text describing a table or figure.
    TOC,        %A list made up of table of contents item entries (structure tag TOCI; see below)
                %and/or other nested table of contents entries
    TOCI,       %An individual member of a table of contents. This entry's children can be any of
                %the following structure  tags:
                %Lbl,Reference,NonStruct,P,TOC
    Index,
    NonStruct,  %probably not needed
    H,
    H1,
    H2,
    H3,
    H4,
    H5,
    H6,
    P,
    L,           %list
    LI,          %list item (around label and list item body)
    Lbl,         %list label
    LBody,       %list item body
    Table,
    TR,          %table row
    TH,          %table header cell
    TD,          %table data cell
    THead,       %table header (n rows)
    TBody,       %table rows
    TFoot,       %table footer
    Span,        %generic inline marker
    Quote,       %inline quote
    Note,        % footnote, endnote. Lbl can be child
    Reference,   % A citation to content elsewhere in the document.
    BibEntry,    %bibentry
    Code,        %
    Link,        %
    Annot,
    Figure,
    Formula,
    Form,
    Artifact
  }

% get tag name from number: \seq_item:Nn \g_@@_role_tags_seq { n }
%\seq_gset_from_clist:NN \g_@@_role_tags_seq \c_@@_role_tags_clist

\clist_map_inline:Nn \c_@@_role_sttags_clist
  {
    \@@_seq_gput_right:Nn \g_@@_role_tags_seq { #1 }
  }


% get tag number from name: \prop_item:Nn \g_@@_role_tags_prop { name }
\int_step_inline:nnnn { 1 }{ 1 }{ \seq_count:N \g_@@_role_tags_seq }
  {
    \@@_prop_gput:Nxn \g_@@_role_tags_prop
      {
        \seq_item:Nn \g_@@_role_tags_seq  { #1 }
      }
      { #1 }
  }

\cs_new:Nn \@@_role_get_tag_from_index:nn
  {
    \@@_seq_item:cn { #1_seq } { #2 }
  }

\cs_new:Nn \@@_role_get_index_from_tag:nn
  {
    \@@_prop_item:cn { #1_prop } { #2 }
  }

% new tags and the rolemap

\@@_prop_new:N \g_@@_role_rolemap_prop

\cs_new_protected:Nn \@@_role_add_tag:nn %new name, reference to old
  {
    \@@_seq_gput_right:Nn \g_@@_role_tags_seq { #1 }
    \@@_prop_gput:Nnx \g_@@_role_tags_prop    { #1 }
      {
        \seq_count:N \g_@@_role_tags_seq
      }
    \@@_check_add_tag_role:nn {#1}{#2}
    \tl_if_empty:nF { #2 }
      {
        \@@_prop_gput:Nnn \g_@@_role_rolemap_prop
          { #1 } { #2 }
      }
  }

\cs_generate_variant:Nn \@@_role_add_tag:nn {xx}

\keys_define:nn { @@ / setup }
  {
    add-new-tag .code:n =
     {
       \seq_set_split:Nnn \l_tmpa_seq { / } {#1/}
       \@@_role_add_tag:xx
         {
           \seq_item:Nn \l_tmpa_seq {1}
         }
         {
           \seq_item:Nn \l_tmpa_seq {2}
         }
     }
  }


%</roles>
%    \end{macrocode}