summaryrefslogtreecommitdiff
path: root/macros/latex-dev/required/latex-lab/latex-lab-minipage.dtx
blob: ffbe5357e766ae1cc49b3ca868b4b2ac08622321 (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
% \iffalse meta-comment
%
%% File: latex-lab-minipage.dtx 
%% 
% Copyright (C) 2023-2024 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-10-30}
\def\ltlabminipageversion{0.81c}
%<*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 best tag minipages and parboxes is still under discussion. 
%  But as they start and contain paragraphs it is clear that 
%  some sockets 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.
%  
%  One of the main problems is how to properly embed them in the
%  surrounding.  When used in normal text (in a paragraph) they
%  typically should close the \texttt{text} structure and reopen one
%  at the end. But when used inside low-level \cs{vbox} or \cs{hbox}
%  this is often wrong. The code uses now there two sockets
%  \texttt{tagsupport/parbox/before} and
%  \texttt{tagsupport/parbox/after} which can be set to noop, if
%  necessary.
%  
%    \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 use sockets for the tag support code, as there will be cases where we want
% to exchange the content or disable it.
%    \begin{macrocode}
\socket_new:nn {tagsupport/minipage/before}{0}
\socket_new:nn {tagsupport/minipage/after} {0}
\socket_new:nn {tagsupport/parbox/before}  {0}
\socket_new:nn {tagsupport/parbox/after}{0}
%    \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 socket
%    \begin{macrocode}
  \socket_use:n{tagsupport/minipage/before}% new
  \setbox\@tempboxa\vbox\bgroup
    \color@begingroup
      \hsize\@tempdima
      \textwidth\hsize \columnwidth\hsize
      \@parboxrestore
      \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@
      \socket_assign_plug:nn{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}
  \socket_use:n{tagsupport/minipage/after} %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}%
  \socket_use:n{tagsupport/parbox/before}
  \@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%
  \socket_use:n{tagsupport/parbox/after}
  }
%    \end{macrocode}
%
% \subsection{Tagging commands}
% 
%    \begin{macrocode}
\tl_new:N  \l__ltboxes_tag_tl
\tl_set:Nn \l__ltboxes_tag_tl {Div}
\socket_new_plug:nnn{tagsupport/minipage/before}{tag/dflt}
  {
%    \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}
  }
%    \end{macrocode}
% similar for the other sockets:
%    \begin{macrocode}
\socket_new_plug:nnn{tagsupport/minipage/after}{tag/dflt}
  {\tag_struct_end:\tag_struct_begin:n{tag=\l__tag_para_tag_tl}\tag_mc_begin_pop:n{}}
  
\socket_new_plug:nnn{tagsupport/parbox/before}{tag/dflt}
  {\tag_mc_end_push:\tag_struct_end:\tag_struct_begin:n{tag=\l__ltboxes_tag_tl}}
  
\socket_new_plug:nnn{tagsupport/parbox/after}{tag/dflt}
  {\tag_struct_end:\tag_struct_begin:n{tag=\l__tag_para_tag_tl}\tag_mc_begin_pop:n{}}
%    \end{macrocode}
% Activate the default tagging plug
%    \begin{macrocode}
\socket_assign_plug:nn{tagsupport/minipage/before}{tag/dflt}
\socket_assign_plug:nn{tagsupport/minipage/after} {tag/dflt}
\socket_assign_plug:nn{tagsupport/parbox/before}  {tag/dflt}
\socket_assign_plug:nn{tagsupport/parbox/after}   {tag/dflt}
%    \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}