summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tagpdf/ex-patch-list.tex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-01-14 03:01:14 +0000
committerNorbert Preining <norbert@preining.info>2022-01-14 03:01:14 +0000
commit45623da68203ac8d7aa04b779a6ed65c92c3f866 (patch)
tree151ca3ede3ee826360d4b32c0029cfc106346ec9 /macros/latex/contrib/tagpdf/ex-patch-list.tex
parentee3f9ca89b21a2174f7e427d9d48247b1912e130 (diff)
CTAN sync 202201140301
Diffstat (limited to 'macros/latex/contrib/tagpdf/ex-patch-list.tex')
-rw-r--r--macros/latex/contrib/tagpdf/ex-patch-list.tex101
1 files changed, 53 insertions, 48 deletions
diff --git a/macros/latex/contrib/tagpdf/ex-patch-list.tex b/macros/latex/contrib/tagpdf/ex-patch-list.tex
index d6485c86fe..30448c6a80 100644
--- a/macros/latex/contrib/tagpdf/ex-patch-list.tex
+++ b/macros/latex/contrib/tagpdf/ex-patch-list.tex
@@ -1,24 +1,25 @@
% !Mode:: "TeX:DE:UTF-8:Main"
-%This example shows how one can patch lists command
-%it is based on enumitem
+% This example shows how one can patch lists command
+% it is based on enumitem
-%It uses a command to end \item (\meti). It is perhaps possible to hide this command
-% inside \item/end{list}, but with nested list it is not so easy.
+% Pay attention to casing. Li/LI, Lbody/Lbody are different.
-% not really up-to-date, with paratagging one could simplify things.
+% It doesn't test nesting!
+
+% We are using \DocumentMetadata
+% This requires a new pdfmanagement and/or latex-dev!
+% Older systems should use \DeclareDocumentMetadata
+\IfFormatAtLeastTF{2022-06-01}{}
+ {\RequirePackage{pdfmanagement-testphase}}
+\DocumentMetadata{pdfversion=1.7,uncompress,testphase=tagpdf}
-% Pay attention to casing. Li/LI, Lbody/Lbody are different.
-%no page break involved. So the example works in lua and generic mode
-\RequirePackage{pdfmanagement-testphase}
-\DeclareDocumentMetadata{pdfversion=1.7,uncompress}
\documentclass{scrbook}
\usepackage[english]{babel}
-\usepackage{tagpdf}
\usepackage{iftex}
-\iftutex
+\ifluatex
\usepackage{fontspec}
\usepackage{luacode}
\else
@@ -27,49 +28,53 @@
-\tagpdfsetup{tabsorder=structure,
- activate,
- }
+\tagpdfsetup
+ {
+ tabsorder=structure,
+ }
\usepackage{lipsum}%\textheight3cm
\usepackage{enumitem,xpatch}
-\makeatletter
+% At first we add to the begin/end hooks the structure commands.
+% To avoid problems with nested paragraphs we force a new paragraph for now.
+% Real code should avoid that!
+\AddToHook{env/itemize/begin}{\par\tagstructbegin{tag=L}}%\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}}
+\AddToHook{env/enumerate/end}{\par\tagstructend\tagstructend\tagstructend}%LBody,LI,L
+\AddToHook{env/description/begin}{\par\tagstructbegin{tag=L}}
+\AddToHook{env/description/end}{\par\tagstructend\tagstructend\tagstructend}%LBody,LI,L
+\makeatletter
+\ExplSyntaxOn
+%We detect is this is the first or a follow up item where we have to end a structure first:
\newcommand\tag@enit@format@preset[1]{%
- \tagstructbegin{tag=LI}%
- \tagstructbegin{tag=Lbl}%
- \tagmcbegin{tag=Lbl}%
- #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{tag=Lbl}
+ #1
\tagmcend
- \tagstructend %end Lbl
- \tagstructbegin{tag=LBody}}
-
-\newcommand\meti{% end of \item
- \tagstructend %end of LBody
- \tagstructend %end of LI
-}
+ \tagstructend
+ \tagstructbegin{tag=LBody}
+ }
+
+\ExplSyntaxOff
\xpatchcmd\enit@preset{\@firstofone}{\tag@enit@format@preset}{}{\fail}
+%close mc from paratagging and reopen ...
+\xpatchcmd\@item{\box\@labels}{\tagmcend \box\@labels \tagmcbegin{tag=P}}{}{\fail}
-\setlist{
- before*=\tagstructbegin{tag=L},
- after*={\tagstructend}}
-
-% keys that overwrite \enit@format must be patched, eg like the follow
-% the font key should be patched in a similar way
-\enitkv@key{enumitem}{format}{%
- \def\enit@format{%
- \tagstructbegin{tag=LI}%
- \tagstructbegin{tag=Lbl}%
- \tagmcbegin{tag=Lbl}%
- #1\tagmcend}}
\makeatother
-% marking of the text inside the list can not be handled automatically -- one doesn't know the type
-% we use simple P here
-\newcommand\TAGP{\tagstructbegin{tag=P}\tagmcbegin{tag=P}}
-\newcommand\PGAT{\tagmcend\tagstructend}
+
+
\begin{document}
%I don't want to handle pagestyles, so set everything to empty:
@@ -78,18 +83,18 @@
\begin{itemize}
-\item \TAGP Ducks say quack\PGAT\meti
-\item \TAGP Marmots say something Parmotlike\PGAT\meti
+\item Ducks say quack
+\item Marmots say something Parmotlike
\end{itemize}
\begin{enumerate}
-\item \TAGP The highest pass is the Col de l'Iseran.\PGAT\meti
-\item \TAGP The second highest pass is the Passo dello Stelvio.\PGAT\meti
+\item The highest pass is the Col de l'Iseran.
+\item The second highest pass is the Passo dello Stelvio.
\end{enumerate}
\begin{description}
-\item[ducks] \TAGP yellow\PGAT\meti
-\item[marmots] \TAGP brown\PGAT\meti
+\item[ducks] yellow
+\item[marmots] brown
\end{description}