Skip to content

Commit

Permalink
Improve footnotes and adapt Ref to changes in tagpdf (#1475)
Browse files Browse the repository at this point in the history
* adapt ref handling to tagpdf 0.99f

* update version, remove message

* correct command name syntax

* simplify Ref code after tagpdf update

* store also structure number of Sect

* correct and improve footnotes in longtable

* update changes.txt and version

* use @@ tag

* document need of +0
  • Loading branch information
u-fischer authored Sep 26, 2024
1 parent f008dc9 commit 780e846
Show file tree
Hide file tree
Showing 31 changed files with 1,855 additions and 147 deletions.
7 changes: 7 additions & 0 deletions required/latex-lab/changes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2024-09-24 Ulrike Fischer <[email protected]>
* latex-lab-sec.dtx,latex-lab-footnotes.dtx:
correct and improve footnotes in longtable

2024-09-24 Ulrike Fischer <[email protected]>
* latex-lab-toc.dtx,latex-lab-footnotes.dtx: adapt Ref handling to tagpdf 0.99f

2024-09-18 Ulrike Fischer <[email protected]>
* latex-lab-amsmath.dtx,latex-lab-graphic.dtc,
latex-lab-marginpar.dtx,latex-lab-math.dtx,latex-lab-mathtools.dtx,
Expand Down
28 changes: 15 additions & 13 deletions required/latex-lab/latex-lab-footnotes.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
%
% for those people who are interested or want to report an issue.
%
\def\ltlabfootnotedate{2024-07-27}
\def\ltlabfootnoteversion{0.8e}
\def\ltlabfootnotedate{2024-09-24}
\def\ltlabfootnoteversion{0.8f}

%<*driver>
\documentclass{l3doc}
Expand Down Expand Up @@ -1953,10 +1953,7 @@
% \begin{macrocode}
\cs_new_protected:Npn \@@_gput_ref:nn #1 #2 %#1 the structure number receiving the ref #2
{
\tag_if_active:T
{
\tag_struct_gput:nne {#1}{ref}{\tag_struct_object_ref:e { #2 }}
}
\tag_struct_gput:nnn {#1}{ref_num}{#2}
}
\cs_new_protected:Npn \fnote_gput_refs:nn #1 #2 % pair of numbers
{
Expand All @@ -1967,11 +1964,7 @@
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
\tl_new:N \l_@@_dflt_struct_tl
\tl_set:Nn \l_@@_dflt_struct_tl {2}
% \end{macrocode}
% kernel hooks for taggin
% kernel hooks for tagging
% this sets the structure around the whole text
%
%
Expand All @@ -1981,14 +1974,23 @@
{
\tag_mc_end_push:
% \end{macrocode}
% test if a footnote is allowed, if not move up to the document structure.
% test if a footnote is allowed, if not move up to the next sect or
% the document structure.
% \begin{macrocode}
\tag_check_child:nnTF {FENote}{pdf2}
{
\tag_struct_begin:n { tag=footnote }
}
{
\tag_struct_begin:n { tag=footnote,parent=\l_@@_dflt_struct_tl }
\tag_struct_begin:n
{
tag=footnote,
% \end{macrocode}
% We add 0 for now to ensure to get a number even if the sec code is not loaded
% or if the seq is empty (which it shouldn't unless there is an coding error)
% \begin{macrocode}
parent=\int_max:nn{2}{\tag_get:n{current_Sect}+0}
}
}
% \end{macrocode}
% Store the current structure number for labels.
Expand Down
140 changes: 76 additions & 64 deletions required/latex-lab/latex-lab-sec.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
%
% for those people who are interested or want to report an issue.
%
\def\ltlabsecdate{2024-09-18}
\def\ltlabsecversion{0.84d}
\def\ltlabsecdate{2024-09-24}
\def\ltlabsecversion{0.84e}
%<*driver>
\documentclass[kernel]{l3doc}
\EnableCrossrefs
Expand Down Expand Up @@ -227,129 +227,140 @@
%
% \begin{macrocode}
%<*package>
%<@@=tag>
% \end{macrocode}
% \subsubsection{Tagging commands}
%
%
% \begin{variable}{\g__tag_sec_stack_seq}
% The stack holds the tag and the level.
% \begin{variable}{\g_@@_sec_stack_seq}
% The stack holds the tag, the level and the structure number.
% \begin{macrocode}
\seq_new:N \g__tag_sec_stack_seq
\seq_gpush:Nn\g__tag_sec_stack_seq {{Document}{-100}}
\seq_new:N \g_@@_sec_stack_seq
\seq_gpush:Nn\g_@@_sec_stack_seq {{Document}{-100}{2}}
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l__tag_sec_Sect_bool}
% \begin{macro}{\@@_get_data_current_Sect:}
% This allows to retrieve the number of the current Sect structure (or
% Document if we are outside any Sect) with |\tag_get:n{current_Sect}|
% \begin{macrocode}
\cs_new:Npn \@@_get_data_current_Sect:
{
\exp_last_unbraced:Ne\use_iii:nnn{\seq_item:Nn\g_@@_sec_stack_seq{1}}
}
% \end{macrocode}
% \end{macro}
% \begin{variable}{\l_@@_sec_Sect_bool}
% This boolean controls if a Sect structure is opened.
% \begin{macrocode}
\bool_new:N \l__tag_sec_Sect_bool
\bool_set_true:N\l__tag_sec_Sect_bool
\bool_new:N \l_@@_sec_Sect_bool
\bool_set_true:N\l_@@_sec_Sect_bool
% \end{macrocode}
% \end{variable}

%
% \begin{macro}{\__tag_sec_begin:nn}
%
% \begin{macro}{\@@_sec_begin:nn}
% This starts a sectioning structure.
% Currently the tag is fix, either Sect or Part, depending on the level,
% but this will perhaps change. The second argument is currently unused.
% \begin{macrocode}
\cs_new_protected:Npn\__tag_sec_begin:nn #1 #2 %#1 level #2 keyval
\cs_new_protected:Npn\@@_sec_begin:nn #1 #2 %#1 level #2 keyval
{
\tag_struct_begin:n
{
tag= {\int_compare:nNnTF {#1}={-1}{Part}{Sect}}
,#2
}
\seq_gpush:Ne \g__tag_sec_stack_seq {{\g__tag_struct_tag_tl}{\int_eval:n{#1}}}
\seq_gpush:Ne \g_@@_sec_stack_seq
{{\g_@@_struct_tag_tl}{\int_eval:n{#1}}{\g_@@_struct_stack_current_tl}}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\__tag_sec_end:n}
% \begin{macro}{\@@_sec_end:n}
% \begin{macrocode}
\msg_new:nnn { tag } {wrong-sect-nesting}
{
The~structure~#1~can~not~be~closed.\\
It~is~not~equal~to~the~current~structure~#2~on~the~main~stack
}

\cs_new_protected:Npn\__tag_sec_end:n #1 % #1 level
\cs_new_protected:Npn\@@_sec_end:n #1 % #1 level
{
\seq_get:NN \g__tag_sec_stack_seq \l__tag_tmpa_tl
\int_compare:nNnT {#1}<{\exp_last_unbraced:NV\use_ii:nn\l__tag_tmpa_tl+1}
\seq_get:NN \g_@@_sec_stack_seq \l_@@_tmpa_tl
\int_compare:nNnT {#1}<{\exp_last_unbraced:NV\use_ii:nnn\l_@@_tmpa_tl+1}
{
\seq_get:NN\g__tag_struct_tag_stack_seq \l__tag_tmpb_tl
\seq_get:NN\g_@@_struct_tag_stack_seq \l_@@_tmpb_tl
\exp_args:Nee
\tl_if_eq:nnTF
{\exp_last_unbraced:NV\use_i:nn\l__tag_tmpa_tl}
{\exp_last_unbraced:NV\use_i:nn\l__tag_tmpb_tl}
{\exp_last_unbraced:NV\use_i:nnn\l_@@_tmpa_tl}
{\exp_last_unbraced:NV\use_i:nn\l_@@_tmpb_tl}
{
\seq_gpop:NN \g__tag_sec_stack_seq \l__tag_tmpa_tl
\seq_gpop:NN \g_@@_sec_stack_seq \l_@@_tmpa_tl
\tag_struct_end:
\__tag_sec_end:n {#1}
\@@_sec_end:n {#1}
}
{
\msg_warning:nnee {tag}{wrong-sect-nesting}
{ \exp_last_unbraced:NV\use_i:nn \l__tag_tmpa_tl }
{ \exp_last_unbraced:NV\use_i:nn \l__tag_tmpb_tl }
{ \exp_last_unbraced:NV\use_i:nnn \l_@@_tmpa_tl }
{ \exp_last_unbraced:NV\use_i:nn \l_@@_tmpb_tl }
}
}
}
% \end{macrocode}
% \end{macro}

% \begin{macro}{\__tag_tool_para_split:}
% \begin{macro}{\@@_tool_para_split:}
% Runin-sectioning command must separate the heading from the following text.
%
% \begin{macrocode}
\cs_new_protected:Npn \__tag_tool_para_split:
\cs_new_protected:Npn \@@_tool_para_split:
{
\tag_mc_end:
\tag_struct_end:
\tag_struct_begin:n{tag=\l__tag_para_tag_default_tl}
\tag_struct_begin:n{tag=\l_@@_para_tag_default_tl}
\tag_mc_begin:n{}
\__tag_setup_restore_para_default:
\@@_setup_restore_para_default:
}
% \end{macrocode}
% \end{macro}

% \begin{macro}{\__tag_setup_restore_para_default:}
% \begin{macro}{\@@_setup_restore_para_default:}
% We change the para tagging in the sectioning code.
% This here restores the default. Currently it only resets the
% the tag, but perhaps more will be needed later.
% \begin{macrocode}
\cs_new_protected:Npn \__tag_setup_restore_para_default:
\cs_new_protected:Npn \@@_setup_restore_para_default:
{
\tl_set:Nn \l__tag_para_main_tag_tl {text-unit}
\tl_set_eq:NN\l__tag_para_tag_tl\l__tag_para_tag_default_tl
\tl_set:Nn \l_@@_para_main_tag_tl {text-unit}
\tl_set_eq:NN\l_@@_para_tag_tl\l_@@_para_tag_default_tl
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\__tag_sec_end_display:}
% \begin{macro}{\@@_sec_end_display:}
% \begin{macrocode}
\cs_new_protected:Npn \__tag_sec_end_display:
\cs_new_protected:Npn \@@_sec_end_display:
{
\tag_struct_end: %P = Hn
\__tag_setup_restore_para_default:
\@@_setup_restore_para_default:
}
% \end{macrocode}
% \end{macro}
%
% Open sec structures should be closed at the end of the document. This should
% be done before tagpdf closes the Document structure.
% \begin{macrocode}
\hook_gput_code:nnn{tagpdf/finish/before}{tagpdf/sec}{\__tag_sec_end:n{-10}}
\hook_gput_code:nnn{tagpdf/finish/before}{tagpdf/sec}{\@@_sec_end:n{-10}}
\hook_gset_rule:nnnn {tagpdf/finish/before}{tagpdf/sec}{before}{tagpdf}
% \end{macrocode}
%
% The commands \cs{mainmatter}, \cs{backmatter}, \cs{frontmatter} and
% \cs{appendix} close all \texttt{Sect} and \texttt{Part} structures.
% \begin{macrocode}
\AddToHook{cmd/frontmatter/before}{\__tag_sec_end:n{-10}}
\AddToHook{cmd/mainmatter/before} {\__tag_sec_end:n{-10}}
\AddToHook{cmd/backmatter/before} {\__tag_sec_end:n{-10}}
\AddToHook{cmd/appendix/before} {\__tag_sec_end:n{-10}}
\AddToHook{cmd/frontmatter/before}{\@@_sec_end:n{-10}}
\AddToHook{cmd/mainmatter/before} {\@@_sec_end:n{-10}}
\AddToHook{cmd/backmatter/before} {\@@_sec_end:n{-10}}
\AddToHook{cmd/appendix/before} {\@@_sec_end:n{-10}}
% \end{macrocode}
%
% \subsection{Tagging tools}
Expand All @@ -368,10 +379,10 @@
{
,sec-start-part .code:n =
{
\bool_if:NT\l__tag_sec_Sect_bool
\bool_if:NT\l_@@_sec_Sect_bool
{
\__tag_sec_end:n {-1}
\__tag_sec_begin:nn{-1}{tag=Part}
\@@_sec_end:n {-1}
\@@_sec_begin:nn{-1}{tag=Part}
}
\tag_struct_begin:n{tag=part,title=#1}
% \end{macrocode}
Expand All @@ -382,43 +393,43 @@
% all slightly different in the standard classes. So this is delayed
% to the time when sectioning commands are redefined with templates.
% \begin{macrocode}
\tl_set:Nn\l__tag_para_main_tag_tl {NonStruct}
\tl_set:Nn\l__tag_para_tag_tl {Span}
\tl_set:Nn\l_@@_para_main_tag_tl {NonStruct}
\tl_set:Nn\l_@@_para_tag_tl {Span}
}
,sec-stop-part .code:n = {\__tag_sec_end_display:}
,sec-stop-part .code:n = {\@@_sec_end_display:}
,sec-start-chapter .code:n =
{
\bool_if:NT\l__tag_sec_Sect_bool
\bool_if:NT\l_@@_sec_Sect_bool
{
\__tag_sec_end:n {0}
\__tag_sec_begin:nn{0}{tag=Sect}
\@@_sec_end:n {0}
\@@_sec_begin:nn{0}{tag=Sect}
}
\tag_struct_begin:n{tag=chapter,title=#1}
% \end{macrocode}
% similar to part we remap to NonStruct for now ...
% \begin{macrocode}
\tl_set:Nn\l__tag_para_main_tag_tl {NonStruct}
\tl_set:Nn\l__tag_para_tag_tl {Span}
\tl_set:Nn\l_@@_para_main_tag_tl {NonStruct}
\tl_set:Nn\l_@@_para_tag_tl {Span}
}
,sec-stop-chapter .meta:n = { sec-stop-part}
,sec-start .code:n = % #1 is a name like "section"
{
\bool_if:NT\l__tag_sec_Sect_bool
\bool_if:NT\l_@@_sec_Sect_bool
{
\__tag_sec_end:n {\cs_if_exist_use:c{toclevel@#1}+0}
\__tag_sec_begin:nn {\cs_if_exist_use:c{toclevel@#1}+0}{tag=Sect}
\@@_sec_end:n {\cs_if_exist_use:c{toclevel@#1}+0}
\@@_sec_begin:nn {\cs_if_exist_use:c{toclevel@#1}+0}{tag=Sect}
}
\tl_set:Nn\l__tag_para_tag_tl{#1}
\tl_set:Nn\l_@@_para_tag_tl{#1}
}
,sec-start .value_required:n = true
,sec-split-para .code:n = {\__tag_tool_para_split:}
,restore-para .code:n = {\__tag_setup_restore_para_default:}
,sec-split-para .code:n = {\@@_tool_para_split:}
,restore-para .code:n = {\@@_setup_restore_para_default:}
,sec-stop .code:n =
{
\par\__tag_sec_end:n {\cs_if_exist_use:c{toclevel@#1}+0}
\par\@@_sec_end:n {\cs_if_exist_use:c{toclevel@#1}+0}
}
,sec-stop .value_required:n = true
,sec-add-grouping .bool_set:N = \l__tag_sec_Sect_bool
,sec-add-grouping .bool_set:N = \l_@@_sec_Sect_bool
}
% \end{macrocode}
%
Expand Down Expand Up @@ -669,8 +680,8 @@
% \begin{macrocode}
\cs_new_protected:Npn \@kernel@tag@hangfrom #1
{
\tagstructbegin{tag=\l__tag_para_tag_tl}
\cs_if_exist_use:N \__tag_gincr_para_begin_int:
\tagstructbegin{tag=\l_@@_para_tag_tl}
\cs_if_exist_use:N \@@_gincr_para_begin_int:
\tagstructbegin{tag=Lbl}
\setbox\@tempboxa
\hbox
Expand All @@ -680,7 +691,7 @@
% \begin{macrocode}
\bool_lazy_and:nnT
{\tag_if_active_p:}
{\g__tag_mode_lua_bool}
{\g_@@_mode_lua_bool}
{\tagmcbegin{tag=Lbl}}
{#1}
}
Expand Down Expand Up @@ -715,6 +726,7 @@
% \cs{@sect} is only changed to replace the hyperref patches
% and to use the new \cs{@kernel@tag@hangfrom} and \cs{@kernel@tag@svsec}
% \begin{macrocode}
%<@@=>
\def\@sect#1#2#3#4#5#6[#7]#8{%
\ifnum #2>\c@secnumdepth
\def\@svsec{\@hyp@section@target@nnn{[section]}{}{#3}}
Expand All @@ -727,7 +739,7 @@
\@tempskipa #5\relax
\ifdim \@tempskipa>\z@
\begingroup
\tagtool{para-flattened=true} % or \bool_set_true\l__tag_para_flattened_bool
\tagtool{para-flattened=true} % or \bool_set_true\l_@@_para_flattened_bool
#6{%
\ifnum #2>\c@secnumdepth
\@hangfrom {\hskip #3\relax\@svsec}%
Expand Down
Loading

0 comments on commit 780e846

Please sign in to comment.