summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/adjmulticol/adjmulticol.dtx
blob: 12c5e4ca73d51bdea43a884853ae9bc9458b5bc1 (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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
% \iffalse
%
%% Copyright 2020, Boris Veytsman <borisv@lk.net>
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3 of this license or (at your option) any 
%% later version.
%% The latest version of the license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2003/06/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Boris Veytsman
%%
%% This work consists of the file adjmulticol.dtx and the
%% derived file adjmulticol.sty,
%%
%%
%% Since this package is based on the multicol package, 
%% Copyright 1989-2005 Frank Mittelbach, the following additional 
%% condition is added to the licensing terms.  The term ``multicol''
%% here should be interpreted as ``multicol and/or adjmulticol'' 
%% package, as appropriate.
%%
%%  In addition to the terms of LPPL any distributed version
%%  (unchanged or modified) of multicol has to keep the statement
%%  about the moral obligation for using multicol. In case of major
%%  changes where this would not be appropriate the author of the
%%  changed version should contact the copyright holder.
%%
%%
%%  Moral obligation for using multicol:
%%  ------------------------------------
%%
%%  Users of multicol who wish to include or use multicol or a modified
%%  version in a proprietary and commercially market product are asked
%%  under certain conditions (see below) for the payment of a license
%%  fee.  The size of this fee is to be determined, in each instance,
%%  by the commercial user, depending on his/her judgment of the value of
%%  multicol for his/her product.
%%
%%
%%  The conditions for this are as follows:
%%
%%   The producer of a proprietary and commercially market product
%%   that involves typesetting using multicol is asked to determine
%%   the value of a license fee for using multicol if
%%
%%   - the product is a document and the producer has decided to
%%     include multicol to typeset (parts of) the document or has
%%     directed the author of the document to include multicol (for
%%     example, by providing a class file to be used by the author)
%%
%%   - the product is a LaTeX class or package that includes multicol
%%
%%
%%   There is no moral obligation in case
%%
%%   - the product is a document but producer has not directed
%%     the author to include multicol (in that case the moral obligation
%%     lies with the author of the document)
%%
%%   - the product does not involve typesetting, e.g., consists, for
%%     example, of distributing multicol and its documentation.
%%
%%   - the product is not proprietary, i.e., is made available as free
%%     software itself (which doesn't prohibit its commercial marketing)
%%
%%   - multicol is used for non-commercial purposes
%%
%%
%% Determinating a license fee might result in a license fee of zero
%% (i.e., no payment) in case a producer has determined that the use
%% of multicol has no enhancing effect on the product. This is a
%% plausible scenario, i.e., in the above two cases the producer is
%% only asked to evaluate the value of multicol for the product
%% not for the payment of a license fee per se (which might or might
%% not follow from this evaluation).
%%
%% The license fee, if any, can be payed either to the LaTeX3 fund
%% (see ltx3info.txt in the base LaTeX distribution) or to the author of
%% the program who can be contacted at
%%
%%     Frank.Mittelbach@latex-project.org
%%
%<*gobble> 
% \fi
% \CheckSum{184}
%
%
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~} 
%
%\iffalse
%    \begin{macrocode}
\documentclass{ltxdoc}
\usepackage[breaklinks,colorlinks,linkcolor=black,citecolor=black,
            pagecolor=black,urlcolor=black]{hyperref}
\usepackage{breakurl,adjmulticol}
\PageIndex
\CodelineIndex
\RecordChanges
\EnableCrossrefs
\begin{document}
  \DocInput{adjmulticol.dtx}
\end{document}
%    \end{macrocode}
%</gobble> 
% \fi
% \MakeShortVerb{|}
% \GetFileInfo{adjmulticol.sty}
% 
% \title{Adjusting Margins for Multicolumn and Unicolumn
% Output\thanks{\copyright Boris Veytsman, 2020} \thanks{Note: This
% package is released under terms which affect its use in commercial
% applications. Please see the details at the top of the source file}} 
% \author{Boris Veytsman}
% \date{\filedate, \fileversion}
% \maketitle
%
% \begin{abstract}
%   This package provides an extension of the \textsf{multicol}
%   package~\cite{Mittelbach06:Multicol} with the option to change the
%   margins for multicolumn and unicolumn layout.  The package understands the
%   difference between the even and odd margins for two side printing.
% \end{abstract}
%
% \tableofcontents
%
% \clearpage
%
%\section{Introduction}
%\label{sec:intro}
%
%
% One of the common requests from the book designers is the
% possibility to change the margins of the text in the midddle of the
% page.  The standard \LaTeX{} |list| environment does exactly this.
% Thus it is not surprising that many packages creatively use this
% tool to change the layout.  An example is the \textsf{changepage}
% package~\cite{Wilson09:Changepage}. Unfortunately this approach has
% a seriour drawback:  a list sets the margins globally.  If the
% material is split between the pages, the margins on the first page
% are repeated on all the subsequent pages.  While this is fine for
% one-side printing, it leads to a catastrophe for the two-sided
% one, as can be seen from the following example (provided by Ivo
% Welch):
% \begin{verbatim}
% \documentclass{book}
% \usepackage{lipsum,multicol}
% \evensidemargin=1.5in
% \oddsidemargin=-3em
% \textwidth=5in
%
% \newenvironment{chmargin}[2]{%
%   \begin{list}{}{\topsep0pt\partopsep0pt\itemsep0pt\parsep\parskip%
%       \listparindent\parindent\itemindent\parindent
%       \leftmargin#1\rightmargin#2\relax}\item}%
%   {\end{list}}
%
% \begin{document}
%
% \chapter{Show}
% \section{Normal}
% \marginpar{I need a lot of outer margin space in the normal text.}
% \lipsum[1-10]
% \begin{chmargin}{0pt}{-160pt}
%   \section{End of Chapter Meterial}
%   \textbf{Now I want to use the outer margin because I need width.}
%   \lipsum[11-16]
%   \fbox{\textbf{\Large Darn---it extends into the inner spine margin now.}}
%   \lipsum[17-40]
% \end{chmargin}
%
% \end{document}
% \end{verbatim}
% 
%
%  To remedy this problem, we need a completely different approach: we
%  need to change the output routine.  This is done in this package.
%
%  Since the text with the special layout is often typeset in the
%  multicolumn mode, we load the \textsf{multicol}
%  package~\cite{Mittelbach06:Multicol} and patch it to provide two
%  changes:
%  \begin{enumerate}
%  \item Margins changes, persistent over the pages.
%  \item The possibility of an one-column ``multicolumn'' layout.  Of
%    course, this layout does not make sense in the context of the
%    original \textsf{multicol} package, but is useful when the
%    margins are changed.
%  \end{enumerate}
%  
%  Note that since this package uses the \textsf{multicol} package, it
%  inherits its special moral obligation for the commercial users.
%  Please see the source file for the details.
%
%  This file was commissioned for by Prof.~Ivo Welch,
%  \url{http://www.ivo-welch.info/}.   He also provided sample files
%  and patiently tested it.
%
%\section{User Interface}
%\label{sec:interface}
%
% The installation of the class follows the usual
% practice~\cite{TeXFAQ} for \LaTeX{} packages:
% \begin{enumerate}
% \item Run \textsf{latex} on |adjmulticol.ins|.  This will produce the file
% |adjmulticol.sty|.
% \item Put the file |adjmulticol.sty| to
% the place where \LaTeX{} can find them (see
% \cite{TeXFAQ} or the documentation for your \TeX{}
% system).\label{item:install} 
% \item Update the database of file names.  Again, see \cite{TeXFAQ}
% or the documentation for your \TeX{} system for the system-specific
% details.\label{item:update}
% \item The file |adjmulticol.pdf| provides the documentation for the
% package (this is the file you are probably reading now).
% \end{enumerate}
% As an alternative to items~\ref{item:install} and~\ref{item:update}
% you can just put the files in the working directory where your
% |.tex| file is.
% 
% 
%
% To use this package, add to the preamble of your document
% the line |\usepackage{adjmulticol}|.
% 
% The package provides two new environments for adjusted multicolumn
% layout. 
%
% \DescribeEnv{adjmulticols}
% The environment |adjmulticols| is similar to the environment
% |multicols|, but it has three mandatory arguments instead of one:
% \begin{quote}
%   |\begin{adjmulticols}|\marg{number}\marg{inner margin}\marg{outer
%   margin}\\
% \meta{text}\\
% |\end{adjmulticols}|
% \end{quote}
% For example,
% \begin{verbatim}
%  \begin{adjmulticols}{2}{12pt}{-1in}
%     Text Text Text
% \end{adjmulticols}
% \end{verbatim}
% Here \meta{number} is the number of columns.  Unlike |multicols|,
% |adjmulticols| environment allows this number to be 1.  
%
% The \meta{inner margin} and \meta{outer margin} are calculated from
% the current text area margins, so negative values mean the extension
% of the text area.  In one-sided printing \meta{inner margin} is the
% left margin, and \meta{outer margin} is the right margin.  You
% probably would not want to use this package for one-sided printing,
% since in this case \textsf{changepage}
% package~\cite{Wilson09:Changepage} works fine.  In two-sided
% printing \meta{inner margin} is the margin on the spine side of the
% page, and \meta{outer margin} is the margin on the other side.
%
% You can use the optional arguments of the |multicols| environment.
% Note that the argument of the first optional argument, the header text
% spread over all columns, is typeset with the \emph{normal} margins.
% If you want to change margins for the header too, you may want to
% use one-column |adjmulticols| environment instead.
%
% \DescribeEnv{adjmulticols*}
% The starred version of the environment, |adjmulticols*| is similar
% to the |multicols*| environment: it does not balance the columns on
% the last page.
%
%
%
%\StopEventually{\clearpage
% \bibliography{adjmulticol}
% \bibliographystyle{unsrt}}
%
% \clearpage
% 
% \section{Implementation}
% \label{sec:implementation}
% 
%
%\subsection{Declarations}
%\label{sec:decl}
% 
%  We start with declaration, who we are:
%
%
%    \begin{macrocode}
%<style>\NeedsTeXFormat{LaTeX2e}
%<*gobble>
\ProvidesFile{adjmulticol.dtx}
%</gobble>
%<style>\ProvidesPackage{adjmulticol}
%<*style>
[2020/03/06 v1.2 Adjusted margins for multicolumn layout]
%    \end{macrocode}
%
%
%\subsection{Options}
%\label{sec:options}
%
% All options are sent to |multicols|:
%    \begin{macrocode}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{multicol}}
\ProcessOptions\relax
%    \end{macrocode}
% 
%
%\subsection{Loading Packages}
%\label{sec:loading}
%
% We use |multicol| to get all the code from it:
%    \begin{macrocode}
\RequirePackage{multicol}
%    \end{macrocode}
%
%
%\subsection{Registers}
%\label{sec:registers}
%
% \begin{macro}{\adjmc@inner}
%   Inner margin delta:  left on odd pages, right on even pages for
%   two-sided typesetting, and left for one-sided typesetting.
%    \begin{macrocode}
\newdimen\adjmc@inner
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\adjmc@outer}
%   Outer margin delta: right on odd pages, left on even pages, and
%   right for two-sided typesetting
%    \begin{macrocode}
\newdimen\adjmc@outer
%    \end{macrocode}   
% \end{macro}
%
%
% \begin{macro}{\adjmc@saved@leftmargin}
%   We save the value of |\multicol@leftmargin| between the calls in
%   the register |\adjmc@savedleftmargin|:
%    \begin{macrocode}
\newdimen\adjmc@saved@leftmargin
%    \end{macrocode}
%   
% \end{macro}
%
%\subsection{Starting Environment}
%\label{sec:start}
%  
% \begin{macro}{\adjmulticols}
%   We have three mandatory arguments instead of one for |multicols|:
%   the number of columns, the left margin delta and the right margin
%   delta:
%    \begin{macrocode}
\def\adjmulticols#1#2#3{\col@number#1\relax
  \def\@tempa{#2}%
  \ifx\@tempa\@empty\adjmc@inner\z@\else\adjmc@inner#2\fi
  \def\@tempa{#3}%
  \ifx\@tempa\@empty\adjmc@outer\z@\else\adjmc@outer#3\fi
%    \end{macrocode}
%   The standard |multicols| have the minimum of two columns.  We, of
%   course, want to consider one column layout too:
%    \begin{macrocode}
  \ifnum\col@number<\@ne
     \PackageWarning{adjmulticol}%
      {Using `\number\col@number'
       columns doesn't seem a good idea.^^J
       I therefore use one columns instead}%
     \col@number\@ne\fi
  \ifnum\col@number>10
     \PackageError{adjmulticol}%
      {Too many columns}%
      {Current implementation doesn't
       support more than 10 columns.%
       \MessageBreak
       I therefore use 10 columns instead}%
     \col@number10 \fi
%    \end{macrocode}
%
%  
%   As in the standard package we redefine the footnote making command:
%    \begin{macrocode}
     \ifx\@footnotetext\mult@footnotetext\else
       \let\orig@footnotetext\@footnotetext
       \let\@footnotetext\mult@footnotetext
     \fi
%    \end{macrocode}
%   And look for the optional arguments
%    \begin{macrocode}
  \@ifnextchar[\adjmult@cols{\adjmult@cols[]}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\adjmult@cols}
%   Looking for the second optional argument.  Note that we use
%   |\premulticols| for the default:
%    \begin{macrocode}
\def\adjmult@cols[#1]{\@ifnextchar[%
  {\adjmult@@cols{#1}}%
  {\adjmult@@cols{#1}[\premulticols]}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\adjmult@@cols}
%   And now we are gathered all arguments:
%    \begin{macrocode}
\def\adjmult@@cols#1[#2]{%
%    \end{macrocode}
%  The macro |\prepare@multicols| uses the current value of
%  |\linewidth|.  We do not change his, but rather change |\linewidth|:
%    \begin{macrocode}
    \advance\linewidth by -\adjmc@inner\relax
    \advance\linewidth by -\adjmc@outer\relax
%    \end{macrocode}
% Then we redefine the output routines:
%    \begin{macrocode}
\let\page@sofar=\adjmc@page@sofar
%    \end{macrocode}
% and start the standard multicols:
%    \begin{macrocode}
   \mult@@cols#1[#2]}
%    \end{macrocode}
% \end{macro}
% 
%
% 
% \begin{macro}{\set@mult@vsize}
% \changes{v1.1}{2013/01/20}{Redefined macro}
% The formula for |\vsize| in multicols seem to work only for
% column number above 2.  Here we add special case of 1.
%    \begin{macrocode}
\def\set@mult@vsize#1{%
    \vsize\@colroom
    \@tempdima\baselineskip
    \advance\@tempdima-\topskip
    \advance\vsize\@tempdima
    \vsize\col@number\vsize
    \advance\vsize-\@tempdima
    \ifnum\col@number>1\relax
    \advance\vsize\col@number\baselineskip
    \else
    \advance\vsize-2\baselineskip
    \fi
    #1\advance\vsize
        \c@collectmore\baselineskip}
%    \end{macrocode}
% \end{macro}
%
%\subsection{Ending Environment}
%\label{sec:end}
%
% \begin{macro}{\endadjmulticols}
% \changes{v1.2}{2020/03/06}{Redefined macro}
%   Here we use the standard environment end.  Note that it uses
%   |\@checkend|, so we need to redefine it to fool the
%   check.  We need to do it globally to work inside a box too.  
%    \begin{macrocode}
\def\endadjmulticols{%
  \global\let\@ADJMC@checkend\@checkend
  \gdef\@checkend##1{}%
  \endmulticols
  \global\let\@checkend\@ADJMC@checkend}
%    \end{macrocode}   
% \end{macro}
%
%
%
%\subsection{Output Routines}
%\label{sec:output}
%
% \begin{macro}{\adjmc@page@sofar@orig}
%   First, we save the original declaration of |\page@sofar|:
%    \begin{macrocode}
\let\adjmc@page@sofar@orig=\page@sofar
%    \end{macrocode}
%   
% \end{macro}
%
%
% \begin{macro}{\adjmc@page@sofar}
%   We redefine |\page@sofar| to change the margins and allow for
%  one-column output:
%    \begin{macrocode}
\def\adjmc@page@sofar{%
%    \end{macrocode}
%  If we have one column, the standard mechanisms leave empty space
%  instead of the first column.  Ok, we use the fact that there is a
%  copy of the first column in |\mult@firstbox|\dots
%    \begin{macrocode}
  \ifnum\col@number=\@ne
  \setbox\mult@rightbox\box\mult@firstbox
  \fi
%    \end{macrocode}
% We redefine |\multicol@leftmargin| to introduce the shift of the
% box.  We save the old code in |\adjmc@saved@leftmargin|
%    \begin{macrocode}
   \adjmc@saved@leftmargin=\multicol@leftmargin
   \if@twoside
      \ifodd\c@page
        \advance\multicol@leftmargin by \adjmc@inner\relax
     \else
        \advance \multicol@leftmargin by \adjmc@outer\relax
    \fi
   \else
      \advance \multicol@leftmargin by \adjmc@inner\relax
  \fi
%    \end{macrocode}
% Then we invoke the original |\page@sofar| and restore the margin:
%    \begin{macrocode}
   \adjmc@page@sofar@orig
   \multicol@leftmargin=\adjmc@saved@leftmargin}
%    \end{macrocode}
%   
% \end{macro}
% 
%
%\subsection{Not Balancing Columns}
%\label{sec:not_balance}
%
% The starred versions do not balance the columns.
%
% \begin{macro}{\adjmulticols*}
%   This follows the code of the \textsf{multicols} package:
%    \begin{macrocode}
\newenvironment{adjmulticols*}{%
   \ifinner
     \PackageWarning{multicol}%
       {multicols* inside a box does
        not make sense.\MessageBreak
        Going to balance anyway}%
   \else
     \let\balance@columns@out
         \multi@column@out
   \fi
   \adjmulticols}{%
   \vfill
  \endadjmulticols}
%    \end{macrocode}
%   
% \end{macro}
%
%
%\subsection{Ending the Style}
%\label{sec:end}
%
%
%
%    \begin{macrocode}
%</style>
%    \end{macrocode}
%\Finale
%\clearpage
%
%\PrintChanges
%\clearpage
%\PrintIndex
%
\endinput