-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonecell.dtx
364 lines (357 loc) · 10.5 KB
/
onecell.dtx
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
% \iffalse meta-comment
%
% File: onecell.dtx Copyright (C) 2017-2019 Jonathan P. Spratte
%
% 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
%
% ------------------------------------------------------------------------------
%
%<*driver>
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
\expandafter\begingroup
\fi
\input l3docstrip.tex
\askforoverwritefalse
\preamble
--------------------------------------------------------------
onecell -- place contents into a single cell
E-mail: [email protected]
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
--------------------------------------------------------------
Copyright (C) 2017-2019 Jonathan P. Spratte
This work 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:
http://www.latex-project.org/lppl.txt
This work is "maintained" (as per LPPL maintenance status) by
Jonathan P. Spratte.
This work consists of the file onecell.dtx
and the derived files onecell.ins,
onecell.pdf and
onecell.sty.
\endpreamble
% stop docstrip adding \endinput
\postamble
\endpostamble
\generate{\file{onecell.sty}{\from{onecell.dtx}{pkg}}}
\ifx\fmtname\nameofplainTeX
\expandafter\endbatchfile
\else
\expandafter\endgroup
\fi
%</driver>
%
%<*driver|pkg>
\RequirePackage{xparse,array,l3keys2e}
%</driver|pkg>
%
%<*driver>
\ProvidesFile{onecell.dtx}[2019/02/03 Place contents into a single cell]
\documentclass{l3doc}
\usepackage{enumitem}
\newenvironment{options}
{\begin{description}[style=nextline,font=\normalfont\ttfamily]}
{\end{description}}
\begin{document}
\DocInput{onecell.dtx}
\end{document}
%</driver>
%
%<*pkg>
\ProvidesExplPackage
{onecell} {2019/02/03}
{v0.2} {Place contents into a single cell}
%</pkg>
% \fi
%
% \title{The \pkg{onecell} package}
% \author{Jonathan P. Spratte\thanks{E-mail: [email protected]}}
% \date{Released 2019/02/03}
% \maketitle
% \tableofcontents
%
% \begin{documentation}
%
% \section{Introduction}
%
% This is a package to put many cells into a single one inside of a
% \env{tabular} environment. Its purpose is similar to that of \pkg{makecell}
% but should be more versatile in using different column specifiers and more
% than one column. It is in no way meant to supersede \pkg{makecell}.
%
% It is written as a docstrip file: executing |latex onecell.dtx| generates the
% \file{onecell.sty} file and typesets this documentation; execute
% |tex onecell.dtx| to only generate \file{onecell.sty}.
%
% \section{Documentation}
%
% \subsection{Column Specifier}
%
% \begin{function}{\onecellCycle}
% This column specifier cycles the column specifiers behind it until every
% used column is defined. It must be preceded by at least one valid column
% specifier. If it is already defined when the package tries to define it an
% error message is displayed. The definition is omitted and the column
% specifier doesn't get used automatically.
% \end{function}
%
% \subsection{Macros}
%
% \begin{function}{\onecell}
% \begin{syntax}
% \cs{onecell}\meta{*}\meta{!}\oarg{columns}\oarg{alignment}\marg{contents}
% \end{syntax}
% This command is the actual macro typesetting \meta{contents} as one cell.
% For this a \env{tabular} environment is used. By default you can use any
% number of rows and columns in \meta{contents} without taking care. This is
% done using |\onecellCycle|. As a side effect, this would also cycle over
% |@{}| at the end of the column specifications. Because of this, by default
% there is no such code to prevent the leading and trailing |\tabcolsep| but a
% |\hspace*{-\tabcolsep}| before and after the \env{tabular}.
%
% If |*| is given those |\hspace*{-\tabcolsep}|s are not used.
% If you specify \meta{columns} what in fact is used is
% \texttt{\{\meta{columns}\cs{onecellCycle}\meta{columns}\}}. The default is
% also used if you give an empty argument. The package default is |c|.
% Using |!| results in the literal interpretation of \meta{columns} so without
% adding |\onecellCycle| to it.
% Finally the \meta{alignment} is the vertical alignment which is directly
% given to \env{tabular}.
% \end{function}
%
% \begin{function}{\onecellOptions}
% \begin{syntax}
% \cs{onecellOptions}\marg{options}
% \end{syntax}
% Lets you change the default behaviour of \cs{onecell}. You can specify any
% options listed in \autoref{sec:options}.
% \end{function}
%
% \subsection{Options}\label{sec:options}
%
% The package knows the following options (as key=value syntax):
% \begin{options}
% \item[col\textit{umns}=\meta{tl}]
% sets the default column specifier used. Package default is |c|. Both |col|
% and |columns| will work.
% \item[align=\meta{tl}]
% sets the default vertical alignment. Package default is |c|.
% \item[pad=\meta{choice}]
% is a choice key. Known choices are:
% \begin{options}
% \item[remove]
% surrounding space is removed using |\hspace*{-\labelsep}|. This is the
% package default.
% \item[leave]
% surrounding space is not removed.
% \end{options}
% The optional |*| for \cs{onecell} always sets the opposite of the defined
% |pad| key.
% \item[repeat=\meta{bool}]
% is a boolean key. If it is set to true, the specified \meta{columns} to
% \cs{onecell} are repeated using the \cs{onecellCycle} column specifier.
% The optional |!| for \cs{onecell} always sets the opposite of the defined
% |repeat|. Package default is |true|.
% \item[default]
% reverts every other key to the package default.
% \end{options}
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{Implementation}
%
% \begin{macrocode}
%<*pkg>
% \end{macrocode}
%
% \begin{macrocode}
%<@@=onecell>
% \end{macrocode}
%
% \begin{macrocode}
\ExplSyntaxOn
% \end{macrocode}
%
% \subsection{Variables}
%
% \begin{variable}{\l_onecell_align_tl}
% Stores the default vertical alignment.
% \begin{macrocode}
\tl_new:N \l_onecell_align_tl
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_onecell_columns_tl}
% Stores the default column specifiers (without \cs{onecellCycle} and the
% repetition).
% \begin{macrocode}
\tl_new:N \l_onecell_columns_tl
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\g_@@_column_already_defined_bool}
% Set to true if \cs{onecellCycle} was already defined.
% \begin{macrocode}
\bool_new:N \g_@@_column_already_defined_bool
% \end{macrocode}
% \end{variable}
%
% \subsection{Messages}
%
% \begin{macrocode}
\msg_new:nnn { onecell } { unknown_key }
{ The~key~#1~is~unknown~and~therefore~ignored! }
% \end{macrocode}
%
% \begin{macrocode}
\msg_new:nnnn { onecell } { column_already_defined }
{ The~column~specifier~'\string\onecellCycle'~is~already~defined. }
{
The~package~will~set~the~key~'repeat'~and~its~package~default~to~false.\\
See~the~documentation~for~what~that~implies.
}
% \end{macrocode}
%
% \subsection{Column specifier}
%
% \begin{macro}{\onecellCycle}
% Code from \url{https://tex.stackexchange.com/a/358114/117050}
% \begin{macrocode}
\ifcsname NC@find@\string\onecellCycle\endcsname
\msg_error:nn { onecell } { column_already_defined }
\bool_gset_true:N \g_@@_column_already_defined_bool
\else
\newcolumntype{\onecellCycle}{!{\d@llarend&\span\@gobbletwo}}
\fi
% \end{macrocode}
% \end{macro}
%
% \subsection{Options and configuration}
%
% \begin{macrocode}
\keys_define:nn { onecell }
{
,col .tl_set_x:N = \l_onecell_columns_tl
,col .value_required:n = true
,columns .meta:n = { col = #1 }
,align .tl_set_x:N = \l_onecell_align_tl
,pad .choice:
,pad / remove .code:n =
\cs_set_eq:NN \@@_starred:Nn \IfBooleanF
,pad / leave .code:n =
\cs_set_eq:NN \@@_starred:Nn \IfBooleanT
,pad .value_required:n = true
,repeat .choice:
,repeat / true .code:n =
\cs_set_protected:Nn \@@_processor_excl:n
{ \def\ProcessedArgument{##1} }
,repeat / false .code:n =
\cs_set_eq:NN \@@_processor_excl:n \ReverseBoolean
,repeat .default:n = true
,unknown .code:n = {
\msg_error:nnx { onecell } { unknown_key } { \l_keys_key_tl }
}
}
% \end{macrocode}
%
% \begin{macrocode}
\bool_if:NTF \g_@@_column_already_defined_bool
{
\keys_define:nn { onecell } {
,default .meta:n = {
,col = c
,align = c
,pad = remove
,repeat = false
}
,default .value_forbidden:n = true
}
}
{
\keys_define:nn { onecell } {
,default .meta:n = {
,col = c
,align = c
,pad = remove
,repeat = true
}
,default .value_forbidden:n = true
}
}
% \end{macrocode}
%
% \begin{macrocode}
\keys_set:nn { onecell } { default }
% \end{macrocode}
%
% \begin{macrocode}
\ProcessKeysOptions { onecell }
% \end{macrocode}
%
% \subsection{Macros}
%
% \subsubsection{User level}
%
% \begin{macro}{\onecell}
% \begin{macrocode}
\NewDocumentCommand{\onecell}
{
s
>{ \@@_processor_excl:n }t!
>{ \@@_processor_Optional_O:Vn \l_onecell_columns_tl }O{}
O{\l_onecell_align_tl}
+m
}{{
\@@_starred:Nn{#1}{\hspace*{-\tabcolsep}}
\cs_set_protected_nopar:Nn \@@_tabular: { \begin{tabular}[#4] }
\IfBooleanTF { #2 }
{ \@@_tabular: { #3 } }
{ \@@_tabular: { #3 \onecellCycle #3 } }
#5%
\end{tabular}
\@@_starred:Nn{#1}{\hspace*{-\tabcolsep}}
}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\onecellOptions}
% \begin{macrocode}
\NewDocumentCommand{\onecellOptions}{ +m }
{ \keys_set:nn { onecell } { #1 } }
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Auxiliary}
%
% \begin{macro}{\@@_processor_Optional_O:nn, \@@_processor_Optional_O:Vn}
% \begin{macrocode}
\cs_new_protected:Npn \@@_processor_Optional_O:nn #1 #2
{
\tl_if_empty:nTF { #2 }
{ \def\ProcessedArgument{#1} }
{ \def\ProcessedArgument{#2} }
}
\cs_generate_variant:Nn \@@_processor_Optional_O:nn { Vn }
% \end{macrocode}
% \end{macro}
%
% \end{implementation}
%
% \PrintIndex
%
% \begin{macrocode}
\ExplSyntaxOff
% \end{macrocode}
%
% \begin{macrocode}
%</pkg>
% \end{macrocode}