summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/joinbox/joinbox.tex
blob: bb6d7916ef800938fa56a0a3e7e7328a169a3d51 (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
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
\documentclass[full]{l3doc}
\usepackage[scheme=plain]{ctex}
\usepackage{enumitem}
\usepackage{indentfirst}
\usepackage{titling}
\usepackage{geometry}
\usepackage{fancyvrb-ex}
\usepackage{joinbox}

\IndexPrologue
  {
    \section*{Index}
    \markboth{Index}{Index}
    \addcontentsline{toc}{section}{Index}
    The~italic~numbers~denote~the~pages~where~the~
    corresponding~entry~is~described,~
    numbers~underlined~point~to~the~definition,~
    all~others~indicate~the~places~where~it~is~used.
  }

\newcommand\tikzmark[1]{\tikz \coordinate[overlay, remember picture] (#1);}

\geometry{
  left=4.5cm,
  right=2cm,
  top=2cm,
  bottom=2cm,
}
\hypersetup {
  CJKbookmarks,
  bookmarksopen,
  bookmarksopenlevel=3,
  pdfstartview=FitH,
  pdfinfo = {
   Title = The package joinbox ,
   Subject = A LaTeX3 package ,
   Author = Geng Nan
 }
}

\DoNotIndex{\begin, \end}
\setlength{\parskip}{\medskipamount}
\DeclareDocumentEnvironment { noteen } { +b } {
  \par\textbf{\textsf{NOTE:~}}#1\par
} {}
\DeclareDocumentEnvironment { notezh } { +b } {
  \par\textbf{\textsf{注意:~}}#1\par
} {}

\AtEndDocument{
  \newgeometry{
    left=2cm,
    right=2cm,
    top=2cm,
    bottom=2cm
  }
  \PrintIndex
}

\ExplSyntaxOn
\dim_new:N \l__my_syntax_dim
\box_new:N \g__my_syntax_box
\NewDocumentEnvironment { Syntax } { s }
  {
    \dim_set:Nn \l__my_syntax_dim
      { \textwidth }
    \hbox_gset:Nw \g__my_syntax_box
      \small \ttfamily
      \begin{minipage}[t]{\l__my_syntax_dim}
        \raggedright\obeyspaces\obeylines
  }
  {
      \end{minipage}
    \hbox_gset_end:
    \IfValueF { #1 } { \smallskip }
    \box_use_drop:N \g__my_syntax_box
    \smallskip
  }

\DeclareDocumentEnvironment { Description } { o +b } {
  \hbox_set:Nn \l_tmpa_box { #1 }
  \dim_set:Nn \l_tmpa_dim { \box_wd:N \l_tmpa_box }
  \begin{itemize}[labelwidth=\l_tmpa_dim, align=left]
    #2
  \end{itemize}
} {  }

\keys_define:nn { joinbox/doc } {
  opt  .tl_set:N = \l_opt_tl,
  desc .tl_set:N = \l_desc_tl,
  init .tl_set:N = \l_init_tl,
  init .initial:n = init-none,
}

\box_new:N \l__option_box
\NewDocumentEnvironment { option } { m +b } {
  \keys_set:nn { joinbox/doc } { #1 }
  \hbox_set:Nw \l__option_box
    \small \ttfamily
    \begin{minipage}[t]{\textwidth}
      \obeyspaces\obeylines
      \textcolor{red}{
        \l_opt_tl
        \exp_args:Nx\SpecialOptionIndex{\l_opt_tl}
      }
      {~}\l_desc_tl
      \hfill(
      \tl_if_eq:NnTF \l_init_tl { init-none } { no~value }
        { initially~\texttt{\l_init_tl} }
      )
    \end{minipage}
  \hbox_gset_end:
  \box_use_drop:N \l__option_box
  #2
  \medskip
} {  }

\DeclareDocumentCommand \opt { O{} m }
  { \__codedoc_cmd:no {#1} { #2 } }
\ExplSyntaxOff

\def\vers{\texttt{v1.0.0}
\thanks{\url{https://gitee.com/nwafu_nan/joinbox}}
}

\begin{document}
\title{
  \pkg{joinbox}盒子拼接宏包
  \rlap{\makebox[4cm][r]{
    \normalsize $\Longrightarrow$ \color{red}
    \protect\hyperlink{en}{English Version}
    \protect\hypertarget{zh}{}
  }}
}
\author{\textit{耿楠} \texttt{<nangeng@nwafu.edu.cn>}}
\date{\the\year 年\the\month 月\the\day 日\qquad \vers
}
\maketitle

{\small
\tableofcontents
}
\newpage

\begin{documentation}

\section{引言}

\pkg{joinbox}是一个基于\pkg{l3coffins}用\pkg{expl3}开发的
盒子拼接宏包,它用于实现盒子的垂直或水平拼接。垂直拼接
会以各对象等宽的方式拼接,而水平拼接会以各对象等高的方式
拼接。

该宏包提供了\tn{joinbox}和\tn{joinfigs}两个命令。其中,
\tn{joinbox}用于拼接两个独立对象,\tn{joinfigs}用于拼接
多个图像。这两个命令的不带*(星号)版本用于垂直拼接,而带
*(星号)的版本用于水平拼接。
同时,该宏包还提供了\tn{joinset}命令用于对拼接方式进行设置。

\section{用户接口}

\subsection{\cs{joinbox}拼接两个对象命令}

\begin{function}{\joinbox,\joinbox*}
  \begin{syntax}
    \cs{joinbox} \oarg{拼接方式} \marg{对象1} \marg{对象2}
    \cs{joinbox*} \oarg{拼接方式} \marg{对象1} \marg{对象2}
  \end{syntax}

\end{function}

  用于拼接两个对象。 该命令需要用两个必选参数\marg{对象1}和
  \marg{对象2}指定需要拼接的对象。拼接对象将被置于coffin中,
  然后按需求进行拼接。

  在可选项\oarg{拼接方式}中,可以通过key-value指定输出结果
  基线位置、 输出尺寸(垂直拼接是输出宽度,水平拼接是输出高度)
  和拼接间距。

\subsection{\cs{joinfigs}拼接多个图像命令}

\begin{function}{\joinfigs,\joinfigs*}
  \begin{syntax}
    \cs{joinfigs} \oarg{拼接方式} \marg{文件名称列表}
    \cs{joinfigs*} \oarg{拼接方式} \marg{文件名称列表}
  \end{syntax}

\end{function}

  用于拼接多个图像。该命令需要用一个必选参数\marg{文件名称列表},
  用于指定需要拼接图像,文件名称中可以包含路径,不同文件名称之
  间用英文逗号进行分隔,最少需要有1个图像文件名称。

  在\oarg{拼接方式}可选项中,可以通过key-value指定结果基线位置、
  输出尺寸(垂直拼接是输出宽度,水平拼接是输出调试)、拼接间距。

\subsection{\cs{joinset}}
\begin{function}{\joinset}
  \begin{syntax}
    \cs{joinset} \marg{拼接方式}
  \end{syntax}

\end{function}

  用于通过key-value指定拼接结果中的基线位置、
  输出尺寸(垂直拼接是输出宽度,水平拼接是输出调试)、拼接间距。

\section{拼接方式}

\begin{option}{ opt = baseline, desc = {= \meta{t,vc,H,b}}, init=b }
  设置joinbox或joinfigs拼接结果的输出基线位置,目前支持:
\end{option}\\
\begin{Description}
  \item |t|--- 盒子顶端水平线、
  \item |vc|---盒子水平中心线、
  \item |H|---盒子内容基线、
  \item |b|---盒子底端水平线。
\end{Description}

\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  默认基线\fbox{
    \joinbox{\LaTeX 科技排版}
            {\LaTeX~Typesetting}
  }

  baseline=t\fbox{
    \joinbox[baseline=t]{\LaTeX 科技排版}
                        {\LaTeX~Typesetting}
  }
\end{SideBySideExample}

\bigskip

\begin{option}{ opt = outlen, desc = {= \meta{dim}}, init=0pt }
  设置joinbox或joinfigs拼接结果的输出尺寸,对于垂直拼接,设置
  输出宽度,对于水平拼接,设置输出高度。

  若指定的输出尺寸$\le 0$,则表示使用被拼接对象中的最小尺寸输出。
\end{option}\\
\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  输出宽度\fbox{
    \joinbox[outlen=2cm]{\LaTeX 科技排版}
                        {\LaTeX~Typesetting}
  }

  输出高度\fbox{
    \joinbox*[outlen=0.2cm]{\LaTeX 科技排版}
                        {\LaTeX~Typesetting}
  }
\end{SideBySideExample}

\bigskip

\begin{option}{ opt = sep, desc = {= \meta{dim}}, init=0pt }
  设置拼接对象之间的间距。
\end{option}\\
\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  垂直间距\fbox{
    \joinbox[sep=5pt]{\LaTeX 科技排版}
                  {\LaTeX~Typesetting}
  }

  水平间距\fbox{
    \joinbox*[outlen=0.2cm,sep=5pt]
             {\LaTeX 科技排版}
             {\LaTeX~Typesetting}
  }
\end{SideBySideExample}

\section{嵌套拼接}

可以嵌套使用\tn{joinbox}命令以实现复杂对象拼接。

\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  \joinbox*[outlen=0.04\textheight,sep=-5pt]
        {
          \joinbox[sep=5pt]{\LaTeX 科技排版}
            {\qquad\LaTeX~Typesetting\qquad}
        }{
          \includegraphics[scale=0.2]{expl3}
        }
\end{SideBySideExample}


\section{图像拼接}

\subsection{原始图像}

\begin{center}
  \includegraphics[scale=0.4]{latexframe}\quad
  \includegraphics[scale=0.4]{tl-lion}\quad
  \includegraphics[scale=0.4]{expl3}
\end{center}

\subsection{垂直拼接图像}

\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  \joinfigs[outlen=3cm, sep=5pt]
           {latexframe, tl-lion, expl3}
\end{SideBySideExample}

\subsection{水平拼接图像}

\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  \joinfigs*[outlen=1.3cm, sep=5pt]
           {latexframe, tl-lion, expl3}
\end{SideBySideExample}

\subsection{嵌套拼接图像}

\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  \joinbox*[outlen=0.20\textheight, sep=5pt]
          {
            \joinfigs[outlen=0.25\textwidth]
              {latexframe, tl-lion, expl3}
          }{
            \joinfigs[outlen=0.25\textwidth]
              {expl3, tl-lion, latexframe}
          }
\end{SideBySideExample}

\title{
  \pkg{joinbox} package for Joinning Boxs or Figures
  \rlap{\makebox[2.5cm][r]{
    \normalsize $\Longrightarrow$ \color{red}
    \protect\hyperlink{zh}{中文版本}
    \protect\hypertarget{en}{}
  }}
}
\author{Nan Geng \texttt{<nangeng@nwafu.edu.cn>}}
\date{\today\qquad \vers}
\maketitle

\section{Introduction}

\pkg{joinbox} is a box joinning package based on l3coffins developed with expl3,
which provides the \cs{joinbox} and \cs{joinfigs} macros for vertical or horizontal
joinning of boxes. Different types of joinning can be set up with the options or
\cs{joinset} macro.

Boxes can be joined vertically or horizontally. When using vertical joinning, all
boxes to be joined will keep same width, while when using horizontal joined, all
boxes to be joined will keep same height.

The \cs{joinbox} and \cs{joinfigs} macros without star are used for vertical joinning,
while the \cs{joinbox*} and \cs{joinfigs*} with star are used for horizontal joinning.

\section{Interfaces}

\subsection{\cs{joinbox} for Two Contents Joinning }

\begin{function}{\joinbox,\joinbox*}
  \begin{syntax}
    \cs{joinbox} \oarg{options} \marg{content1} \marg{content2}
    \cs{joinbox*} \oarg{options} \marg{content1} \marg{content2}
  \end{syntax}

\end{function}

  Used to join two contents. It requires two arguments \marg{content1} and
  \marg{content2} to specify the objects to be joined. The contents will
  be placed in the coffin respectively and then joined.

  In the \oarg{options}, the typeout baseline, typeout size
  (vertical joinning is width, horizontal joinning is height), and 
  joinning seperate spacing can be specified with \textit{key-value}.

\subsection{\cs{joinfigs} for Figure Sets Joinning}

\begin{function}{\joinfigs,\joinfigs*}
  \begin{syntax}
    \cs{joinfigs} \oarg{options} \marg{namelist}
    \cs{joinfigs*} \oarg{options} \marg{namelist}
  \end{syntax}

\end{function}

  Used for joinning multiple images. This command requires a argument\marg{namelist}
  to specify the image to be joined. The file name can include a path, 
  and different file names should be separated by commas. 
  At least one image file name is required.

  In the \oarg{options}, the typeout baseline, typeout size
  (vertical joinning is width, horizontal joinning is height), and 
  joinning seperate spacing can be specified with \textit{key-value}.

\subsection{\cs{joinset} for Settings}
\begin{function}{\joinset}
  \begin{syntax}
    \cs{joinset} \marg{options}
  \end{syntax}

\end{function}

  Used to set the typeout baseline, typeout size
  (vertical joinning is width, horizontal joinning is height), and 
  joinning seperate spacing with \textit{key-value}.

\section{Options}

\begin{option}{ opt = baseline, desc = {= \meta{t,vc,H,b}}, init=b }
  Set typeout baseline, currently as follows:
\end{option}\\
\begin{Description}
  \item |t|--- a pole running along the top edge of the bounding box of the coffin;
  \item |vc|---a pole running horizontally through the centre of the coffin half-way between the
bottom and top edges of the bounding box (i.e. the “vertical centre”);
  \item |H|---a pole running along the baseline of the typeset material contained in the coffin;
  \item |b|---a pole running along the bottom edge of the bounding box of the coffin.
\end{Description}

\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  baseline=b\fbox{
    \joinbox{Hello \LaTeX}
            {\LaTeX~Typesetting}
  }

  baseline=t\fbox{
    \joinbox[baseline=t]{Hello \LaTeX}
                        {\LaTeX~Typesetting}
  }
\end{SideBySideExample}

\bigskip

\begin{option}{ opt = outlen, desc = {= \meta{dim}}, init=0pt }
  Used to set typeout size, vertical joinning is width and horizontal joinning is height.

  If $outlen\le 0$,then the typeout size is minimal size of all contents.
\end{option}\\

\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  width: \fbox{
    \joinbox[outlen=2cm]{Hello \LaTeX}
                        {\LaTeX~Typesetting}
  }

  height: \fbox{
    \joinbox*[outlen=0.2cm]{Hello \LaTeX}
                        {\LaTeX~Typesetting}
  }
\end{SideBySideExample}

\bigskip

\begin{option}{ opt = sep, desc = {= \meta{dim}}, init=0pt }
  Used to set joinning seperate spacing.
\end{option}\\
\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  vertical sep: \fbox{
    \joinbox[sep=5pt]{Hello \LaTeX}
                  {\LaTeX~Typesetting}
  }

  horizontal sep: \fbox{
    \joinbox*[outlen=0.2cm,sep=5pt]
             {Hello \LaTeX}
             {\LaTeX~Typesetting}
  }
\end{SideBySideExample}

\section{Nested Joinning}

The \tn{joinbox} can be nested to get complex joinning.

\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  \joinbox*[outlen=0.04\textheight,sep=-5pt]
        {
          \joinbox[sep=5pt]{Hello \LaTeX}
            {\qquad\LaTeX~Typesetting\qquad}
        }{
          \includegraphics[scale=0.2]{expl3}
        }
\end{SideBySideExample}

\section{Figures Joinning}

\subsection{Original}

\begin{center}
  \includegraphics[scale=0.4]{latexframe}\quad
  \includegraphics[scale=0.4]{tl-lion}\quad
  \includegraphics[scale=0.4]{expl3}
\end{center}

\subsection{Vertical Joinning}

\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  \joinfigs[outlen=3cm, sep=5pt]
           {latexframe, tl-lion, expl3}
\end{SideBySideExample}

\subsection{Horizontal Joinning}

\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  \joinfigs*[outlen=1.3cm, sep=5pt]
           {latexframe, tl-lion, expl3}
\end{SideBySideExample}

\subsection{Nested Joinning}

\begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth,gobble=2]
  \joinbox*[outlen=0.20\textheight, sep=5pt]
          {
            \joinfigs[outlen=0.25\textwidth]
              {latexframe, tl-lion, expl3}
          }{
            \joinfigs[outlen=0.25\textwidth]
              {expl3, tl-lion, latexframe}
          }
\end{SideBySideExample}

\end{documentation}


\end{document}