summaryrefslogtreecommitdiff
path: root/macros/latex-dev/required/latex-lab/latex-lab-minipage.dtx
blob: bbd40a3c520d6bb8e540697e03744b9b1a2b57c1 (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
% \iffalse meta-comment
%
%% File: latex-lab-minipage.dtx (C) Copyright 2023 LaTeX Project
%
% 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
%
%
% The development version of the bundle can be found below
%
%    https://github.com/latex3/latex2e/required/latex-lab
%
% for those people who are interested or want to report an issue.
%
\def\ltlabminipagedate{2023-08-20}
\def\ltlabminipageversion{0.81b}
%<*driver>
\documentclass{l3doc}
\EnableCrossrefs
\CodelineIndex
\begin{document}
  \DocInput{latex-lab-minipage.dtx}
\end{document}
%</driver>
%
% \fi
%
%
% \title{The \textsf{latex-lab-minipage} package\\
% Changes related to the tagging of minipage and parbox}
% \author{\LaTeX{} Project\thanks{Initial implementation done by Ulrike Fischer}}
% \date{v\ltlabminipageversion\ \ltlabminipagedate}
%
% \maketitle
%
% \newcommand{\xt}[1]{\textsl{\textsf{#1}}}
% \newcommand{\TODO}[1]{\textbf{[TODO:} #1\textbf{]}}
% \newcommand{\docclass}{document class \marginpar{\raggedright document class
% customizations}}
%
% \providecommand\hook[1]{\texttt{#1}}
%
% \begin{abstract}
% \end{abstract}
% 
% \section{Introduction}
% 
%  How to tag minipages and parboxes is still under discussion. 
%  But as they start and contain paragraphs it is clear that 
%  hooks are needed to interrupt and restart the tagging. 
%  
%  The tagging added is currently quite simple minded. See the todo-testfiles and the
%  code comments for some open points. 
%  
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% \section{Implementation}
%    \begin{macrocode}
\ProvidesExplPackage {latex-lab-testphase-minipage} 
  {\ltlabminipagedate} {\ltlabminipageversion}
  {Code related to the tagging of minipages and parboxes}
%    \end{macrocode}
% As minipage uses a socket from the footnote code we must load the OR-code:
%    \begin{macrocode}
\RequirePackage{latex-lab-testphase-new-or-1}
\RequirePackage{latex-lab-testphase-new-or-2}
%    \end{macrocode}
%  

% \subsection{Provide the kernel hooks}
% [kernel?]
% We need to check/set the status before the
% initial \cs{leavevmode} to decide how to handle the structure. 
% Perhaps the same command will work for both?
%    \begin{macrocode}
\def\@kernel@init@minipage{}
\def\@kernel@init@parbox{}
%    \end{macrocode}
% We need a few hooks.
%    \begin{macrocode}
\def\@kernel@before@minipage{}
\def\@kernel@after@minipage{}
\def\@kernel@before@parbox{}
\def\@kernel@after@parbox{}
%    \end{macrocode}
%
% \subsection{Patch minipage}
% [kernel?]
% The begin hook is inserted in \cs{@iiiminipage}
%    \begin{macrocode}
\def\@iiiminipage#1#2[#3]#4{%
%    \end{macrocode}
% Before switching to hmode we insert a hook. It is currently unused
% but could for example check if we are in vmode and change the following
% paragraph tag. 
%    \begin{macrocode}
  \@kernel@init@minipage
  \leavevmode 
  \@pboxswfalse
  \setlength\@tempdima{#4}%
  \def\@mpargs{{#1}{#2}[#3]{#4}}%
%    \end{macrocode}
% insert the hook
%    \begin{macrocode}
  \@kernel@before@minipage% new
  \setbox\@tempboxa\vbox\bgroup
    \color@begingroup
      \hsize\@tempdima
      \textwidth\hsize \columnwidth\hsize
      \@parboxrestore
      \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@
      \AssignSocketPlug{fntext/process}{mp}%
      \let\@listdepth\@mplistdepth \@mplistdepth\z@
      \@minipagerestore
      \@setminipage}
%    \end{macrocode}
%  And a hook at the end
%    \begin{macrocode}
\def\endminipage{%
    \par
    \unskip
    \ifvoid\@mpfootins\else
      \vskip\skip\@mpfootins
      \normalcolor
      \footnoterule
      \unvbox\@mpfootins
    \fi
    \@minipagefalse   %% added 24 May 89
  \color@endgroup
  \egroup
%    \end{macrocode}
% as the parbox command is called, we must prevent that it adds its additional
% tagging commands:
%    \begin{macrocode}
  \tag_stop:n{minipage}
  \expandafter\@iiiparbox\@mpargs{\unvbox\@tempboxa}%
  \tag_start:n{minipage}
  \@kernel@after@minipage%new end ...
  }
%    \end{macrocode}
%
% And similar for \cs{parbox}
%    \begin{macrocode}
\long\def\@iiiparbox#1#2[#3]#4#5{%
  \@kernel@init@parbox
  \leavevmode
  \@pboxswfalse
  \setlength\@tempdima{#4}%
  \@kernel@before@parbox% new
  \@begin@tempboxa\vbox{\hsize\@tempdima\@parboxrestore#5\@@par}%
    \ifx\relax#2\else
      \setlength\@tempdimb{#2}%
      \edef\@parboxto{to\the\@tempdimb}%
    \fi
    \if#1b\vbox
    \else\if #1t\vtop
    \else\ifmmode\vcenter
    \else\@pboxswtrue $\vcenter
    \fi\fi\fi
    \@parboxto{\let\hss\vss\let\unhbox\unvbox
       \csname bm@#3\endcsname}%
    \if@pboxsw \m@th$\fi
  \@end@tempboxa%
  \@kernel@after@parbox%new end
  }
%    \end{macrocode}
%
% \subsection{Tagging commands}
% 
%    \begin{macrocode}
\tl_new:N  \l__ltboxes_tag_tl
\tl_set:Nn \l__ltboxes_tag_tl {Div}
\cs_set_protected:Npn\@kernel@before@minipage
  {
%    \end{macrocode}
% As there was a \cs{leavevmode} before that is a P/text open that we have to close.
%    \begin{macrocode}
    \tag_mc_end_push:\tag_struct_end:
%    \end{macrocode}
% TODO: the P can be further up, we need a proper method to test and handle this. 
%    \begin{macrocode}   
    \tag_struct_begin:n{tag=\l__ltboxes_tag_tl}}
\cs_set_protected:Npn\@kernel@after@minipage
  {\tag_struct_end:\tag_struct_begin:n{tag=\l__tag_para_tag_tl}\tag_mc_begin_pop:n{}}
\cs_set_protected:Npn\@kernel@before@parbox
  {\tag_mc_end_push:\tag_struct_end:\tag_struct_begin:n{tag=\l__ltboxes_tag_tl}}
\cs_set_protected:Npn\@kernel@after@parbox
  {\tag_struct_end:\tag_struct_begin:n{tag=\l__tag_para_tag_tl}\tag_mc_begin_pop:n{}}
%    \end{macrocode}
%    \begin{macrocode}
%</package>  
%    \end{macrocode}

%    \begin{macrocode}
%<*latex-lab>
\ProvidesFile{minipage-latex-lab-testphase.ltx}
        [\ltlabminipagedate\space v\ltlabminipageversion 
         code related to the tagging of minipage and parbox]
\RequirePackage{latex-lab-testphase-minipage}
%</latex-lab>
%    \end{macrocode}