Debian Codegraph @

texmf-dist/source/latex/flexipage/flexipage.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2022 by <+author+> <<+email+>>
4 % ---------------------------------------------------------------------------
5 % This work may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either version 1.3
7 % of this license or (at your option) any later version.
8 % The latest version of this license is in
9 % http://www.latex-project.org/lppl.txt
10 % and version 1.3 or later is part of all distributions of LaTeX
11 % version 2005/12/01 or later.
12 %
13 % This work has the LPPL maintenance status `maintained'.
14 %
15 % The Current Maintainer of this work is <+maintainer+>.
16 %
17 % This work consists of the files flexipage.dtx and flexipage.ins
18 % and the derived filebase flexipage.sty.
19 %
20 % \fi
21 %
22 % \iffalse
23 %<*driver>
24 \ProvidesFile{flexipage.dtx}
25 %</driver>
26 %<package>\NeedsTeXFormat{LaTeX2e}[2020/10/01]
27 %<package>\ProvidesPackage{flexipage}
28 %<*package>
29 % [2022/07/09 1.00 Easy page geometry]
30 % [2022/10/01 1.01 First Page different footer]
31 [2023/03/17 1.02 Fixed bug re fixed page sizes]
32 %</package>
33 %
34 %<*driver>
35 \documentclass{ltxdoc}
36 \usepackage{xspace}
37 \usepackage{tikz,amsmath, amssymb,bm,color}
38 \usetikzlibrary{shapes,arrows}
39 \usetikzlibrary{calc}
40 \EnableCrossrefs
41 \CodelineIndex
42 \RecordChanges
43 \begin{document}
44 \voffset = -45pt
45 \textheight=210mm
46 \DocInput{flexipage.dtx}
47 \PrintChanges
48 % \PrintIndex
49 \end{document}
50 %</driver>
51 % \fi
52 %
53 %
54 %
55 % \CharacterTable
56 % {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
57 % 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
58 % Digits \0\1\2\3\4\5\6\7\8\9
59 % Exclamation \! Double quote \" Hash (number) \#
60 % Dollar \$ Percent \% Ampersand \&
61 % Acute accent \' Left paren \( Right paren \)
62 % Asterisk \* Plus \+ Comma \,
63 % Minus \- Point \. Solidus \/
64 % Colon \: Semicolon \; Less than \<
65 % Equals \= Greater than \> Question mark \?
66 % Commercial at \@ Left bracket \[ Backslash \\
67 % Right bracket \] Circumflex \^ Underscore \_
68 % Grave accent \` Left brace \{ Vertical bar \|
69 % Right brace \} Tilde \~}
70 %
71 %
72 % \changes{<+version+>}{<+date+>}{Converted to DTX file}
73 %
74 % \DoNotIndex{\newcommand,\newenvironment}
75 %
76 %
77 % \providecommand*{\url}{\texttt}
78 % \providecommand\lgtarg[1]{{\ttfamily<}\meta{#1}{\ttfamily>}}
79 % \GetFileInfo{flexipage.dtx}
80 %
81 % \title{The \textsf{flexipage} package}
82 % \author{Anton Vrba\\\small%
83 % Home Page: \url{https://github.com/anton-vrba/flexipage} }
84 % \date{\fileversion~from \filedate\\}
85 %
86 %
87 % \maketitle
88 %
89 % \begin{abstract}
90 % \noindent The package flexipage allows easy page layout if marginalia is required.
91 % Mid document changes are possible such as: new marginal width, full width text,
92 % and landscape text without marginal. Partners well with the package \textsf{sidenotesplus}.
93 % The package also aids the layout for book printing, allowing for binding corrections
94 % and adding page bleed, if required,
95 % \end{abstract}
96 %
97 %
98 %
99 % \noindent The aim is an easy to use the page geometry setup,
100 % and allow mid-document changes such as from portrait
101 % to landscape, or change the text body width to marginalia width ratio.
102 % The philosophy is simple, easy to understand options quickly set up the page geometry:
103 % \begin{enumerate}
104 % \item |pageheight| and |pagewidth| of final document, default inherited.
105 % \item Defines page margins |inner|, |outer|, |top| and |bot|. Inner refers to the binding
106 % that is the left side margin of on odd pages in |twoside| documents, or
107 % of pages in |oneside| documents. Page margins surround the printable area.
108 % Default for all |36pt|, or |0.5in|.
109 % \item Add a |binding| correction, default |9pt|.
110 % \item Add an |outerbleed|, increases the papersize by adding a bleed area to the
111 % non bound margins. For the seldom requirement an |innerbleed| adds to the
112 % paperwidth on the inner side.
113 % Refer to your publisher. Default for both |0pt|.
114 % \item Divide the remaining printable area into a vertical |grid|, default |12|.
115 % \item Insert a |marginparsep| (default |3ex|) at the |margingrid| position
116 % counting from the outer edge; 0 is for no
117 % marginalia, 1 is a narrow marginal note area, and 4 is a marginal note area
118 % of one halve the width of the text body area's width when |grid=12|.
119 % The marginal area is placed by the outer edge.
120 % \item The \LaTeX\xspace |headsep|, |headheight| and |footskip| dimension
121 % can also be passed as options, otherwise default to class values.
122 % \item As a visual guide, the option |show| frames the page geometry in the output
123 % \end{enumerate}
124 %
125 % \footnotesize
126 % \noindent \begin{tikzpicture}
127 %
128 % \draw [fill=yellow!30] (-4,4.4) node (v1) {} rectangle (3,-4.2);
129 % \draw[fill=white] (-3.8,4.2) rectangle (2.8,-4);
130 % \draw [color=green, fill=green!20 ] (-2.8,3.6) rectangle (2.2,-3.4);%
131 % \draw [fill=orange!10] (-2.8,3.6) rectangle (0.8,3.4);
132 % \draw [fill=orange!10] (1,3) rectangle (2.2,-2.8);
133 % \draw [fill=orange!10](-2.8,3) rectangle (0.8,-2.8);
134 % \draw [fill=violet!10] (-3.8,-4.2) rectangle (v1);
135
136 % \draw [loosely dashed, blue] (-3.4,4.2) -- (-3.4,-4);
137 % \draw (-2.8,-3.4) -- (0.8,-3.4);
138 % \draw [loosely dashed] (1.8,3) -- (1.8,-2.8);
139 % \draw [loosely dashed] (1.4,3) -- (1.4,-2.8);
140 % \draw [loosely dashed] (0.4,3) -- (0.4,-2.8);
141 % \draw [loosely dashed] (0,3) -- (0,-2.8);
142 % \draw [loosely dashed] (-0.4,3) -- (-0.4,-2.8);
143 % \draw [loosely dashed] (-0.8,3) -- (-0.8,-2.8);
144 % \draw [loosely dashed] (-1.2,3) -- (-1.2,-2.8);
145 % \draw [loosely dashed] (-1.6,3) -- (-1.6,-2.8);
146 % \draw [loosely dashed](-2,3) -- (-2,-2.8);
147 % \draw [loosely dashed](-2.4,3) -- (-2.4,-2.8);
148 % \node at (-1.2,3.5) {Header};
149 % \node at (-0.9,0.3) {Text Body};
150 % \node [rotate=90] at (1.6,0.3) {Marginal};
151 % \node [text width=65mm, right ] at (3.5,0.1)
152 % {\small The basic paper geometry for book printing is illustrated to the left.
153 % This for odd page numbers, the recto page. The even pages mirror this geometry
154 % to maintain verso--recto symmetry.
155 % The final page size is the white area. The yellow outer coloured area is the
156 % |outerbleed| and the violet colored area on the left is the |innerbleed|, these
157 % are trimmed and discarded. Please refer to your publisher if needed.
158 %
159 % ~~~The green area is the text block containing the text body, the marginal,
160 % the header and footer and is defined by the margins |top|,
161 % |outer| and |bottom| to the trimmed paper's edge.
162 % The inner side (left) vertical dot-dashed line represents the |binding| correction and the |inner|
163 % margin is defined from this line.
164 %
165 % ~~~Here the illustrated text width plus the marginal width are divided into 12 equal |grid=12| divisions
166 % with the marginal takin 3 of them, defined by |marginalgrid=3|.
167 % .};
168 % \node at (-1.2,-3.3) {Footer};
169 % \end{tikzpicture}\small
170 % \\ Also refer to:
171 % \url{https://www.overleaf.com/learn/latex/Single\_sided\_and\_double\_sided\_documents}
172 % \normalsize
173 %
174 % \section{Usage}
175 % \subsection{Document preamble}
176 % \small
177 % \begin{verbatim}
178 % \PassOptionsToPackage{
179 % % a4paper , % or another recognised paper size
180 % % paperheight = , % inherits from class
181 % % paperwidth = , % inherits from class
182 % % inner = , % default 36pt or 0.5in
183 % % outer = , % 36pt or 0.5in
184 % % top = , % 36pt or 0.5in
185 % % bot = , % 36pt or 0.5in
186 % % binding = , % 9pt or 0.125in
187 % % outerbleed = , % 0pt, but check with your printer
188 % % innerbleed = , % 0pt, but check with your printer
189 % % grid = , % 12 it is just a number
190 % % marginalgrid = , % 3 it is just a number
191 % % marginparsep = , % 3ex, if using sidenotesplus change to 4 or 5ex
192 % % headsep = , % inherits from class
193 % % headheight = , % inherits from class
194 % % footskip= , % inherits from class
195 % % extrafirstfoot= , % 0pt, first page extra footer, reduces textheight
196 % % show , % a switch to show frames around the printable areas.
197 % % fancyhdrOff , % Do not use the fancyhdr package
198 % % NoFixMargin % a possible future requirement
199 % }{flexipage}
200 % \usepackage{flexipage}
201 % \end{verbatim}
202 % \normalsize\vspace{-20pt}
203 %
204 % \paragraph{Known Issue:} If using the option |show| and the package \textsf{xcolor}
205 % is loaded later with options, an error will occur. The reason
206 % is that when option |show| is specified the package \textsf{eso-pic} is loaded
207 % which in turns loads \textsf{xcolor} without options. Remedy, load \textsf{xcolor}
208 % with options before loading \textsf{flexipage}
209 %
210 % If the option |extrafirstfoot| is used, and |show| is used then the frames for the
211 % first page do not show the effect of |extrafirstfoot|.
212 %
213 % \paragraph{Marginalia Position Issue:} When doing mid document changes to |\textwidth|
214 % and |\marginparwidth| then |\marginpar{content}| renders the marginalia to the correct
215 % width but places it at the old position. A patch is provided here
216 % to correct this issue. Should this ever be fixed in the
217 % latex base software then the |NoFixMargin| option would be required.
218 %
219 % \paragraph{Using \textsf{fancyhdr} package} By default the \textsf{fancyhdr} package
220 % is loaded and the |\headerlength| is set to span the page, that is it overhangs the
221 % text body. The advantage here is that the header has the same format throughout
222 % the document if mid-document layout changes are made. If no such changes are
223 % made then use the |fancyhdrOff| and load \textsf{fancyhdr} in your preamble. Now
224 % the header does not overhang the text body and is as shown in the previous illustration.
225 %
226 %
227 % The following paper sizes are recognised:
228 %
229 % ~
230 %
231 % \begin{tabular}{rlp{2ex}rl}
232 % \multicolumn{2}{c}{Standard Paper} & &\multicolumn{2}{c}{Standard Book} \\
233 % a4paper &210$\times$297mm & & US-Trade &6$\times$9in \\
234 % a5paper &148$\times$210mm & & UK-B-Format &135$\times$210mm \\
235 % b4paper &250$\times$353mm & & US-B-Format &129$\times$198mm \\
236 % b5paper &176$\times$250mm & & UK-Royal &156$\times$234mm \\
237 % c4paper &229$\times$324mm & & Quarto &9.5$\times$12in \\
238 % c5paper &162$\times$229mm & & Octavo &6$\times$9in \\
239 % b4jpaper &257$\times$364mm & & CrownQuarto &189$\times$246mm \\
240 % b5jpaper &182$\times$257mm & & Demi &138$\times$216mm \\
241 % letterpaper &8.5$\times$11in \\
242 % legalpaper &8.5$\times$14in \\
243 % executivepaper &7.25$\times$10.5in \\
244 % \end{tabular}
245
246 %
247 %\subsection{User Interfaces}
248 %
249 %
250 % \DescribeMacro{\NewMarginPage} Changes text--marginal ratio.
251 % |\NewMarginPage|\oarg{g}\lgtarg{parsep}\marg{m}
252 % where optionally the grid count is reset to |grid|=\textit{g}, and marginal width is
253 % determined by |marginalgrid|=\textit{m}. The ratio of the lengths |\textwidth|
254 % to |\marginparwidth| is $g-m$ to $n$. The second option changes the |\parsep| length.
255 %
256 %
257 % \DescribeMacro{\NewFullPage} Continues the document with a new page without margins,
258 % and is equivalent to |\NewMarginPage|\marg{0}
259 %
260 %
261 %
262 % \DescribeMacro{\OldMarginPage}
263 % \DescribeMacro{\ResetFlexiPage} After |\NewMarginPage| or |\NewFullPage| revert to
264 % the previous page geometry, these are not stacked. |\ResetFlexiPage| reverts to the layout specified in
265 % the initial options
266 %
267 %
268 %
269 %
270 % \DescribeEnv{Landscape}
271 % \DescribeEnv{landscape}
272 % These two environments provide landscape layouts. The big |Landscape| provides
273 % full text block landscape. The small |landscape| environments respects the
274 % portrait orientated marginal space which now is white space. Do not use
275 % marginalia in landscape mode.
276 %
277 % \DescribeMacro{\Landscape}
278 % \DescribeMacro{\endLandscape}
279 % \DescribeMacro{\landscape}
280 % \DescribeMacro{\endlandscape} Alternatives to |\begin{Landscape}| $\cdots$ $\cdots$ |\end{Landscape}|
281 % %
282 %
283 % \section{Implementation}
284 %
285 % \iffalse
286 %<*package>
287 % \fi
288 %
289 % \begin{macrocode}
290 \RequirePackage{xparse} % new LaTeX3 syntax to define macros and environments
291 \RequirePackage{l3keys2e} % nice way for option processing
292 \RequirePackage{calc} % length manipulation
293 \RequirePackage{fp} % floating point calculation
294 \RequirePackage{ifoddpage}
295 \RequirePackage{graphics} % provides landscaping
296 \RequirePackage{mparhack} % not needed here, but the user certainly needs it.
297 \RequirePackage{etoolbox} % provides \patchcmd
298 % ****** \RequirePackage{eso-pic} only loaded later if option show is specified
299 \newlength{\fleximarginparsep}
300 \newlength{\flx@paperheight}
301 \newlength{\flx@paperwidth}
302 \newlength{\flx@temp}
303 \newlength{\flx@LSfix}
304 \setlength{\flx@LSfix}{0pt}
305 \newlength{\flx@lsfix}
306 \setlength{\flx@lsfix}{0pt}
307 \newlength{\flx@textheigt}
308 \newlength{\flx@orgtextwidth}
309 \newlength{\flx@oldparsep}
310 \newlength{\flx@oparsep}
311 \newlength{\flx@binding}
312 \newlength{\marginparsepodd}
313 \newlength{\marginparsepeven}
314 \newlength{\flx@inner}
315 \newlength{\flx@outer}
316 \newlength{\flx@top}
317 \newlength{\flx@bot}
318 \newlength{\flx@parsep}
319 \newlength{\flx@printarea}
320 \newlength{\flx@outerbleed}
321 \newlength{\flx@innerbleed}
322 \newlength{\flx@extrafirstfoot}
323 \setlength{\flx@extrafirstfoot} {0pt}
324 \setlength{\flx@binding} {9pt}
325 \setlength{\flx@inner} {36pt}
326 \setlength{\flx@outer} {36pt}
327 \setlength{\flx@top} {36pt}
328 \setlength{\flx@bot} {45pt}
329 \setlength{\flx@parsep}{3ex}
330 \setlength{\flx@outerbleed} {0pt}
331 \setlength{\flx@innerbleed} {0pt}
332 \FPset\flx@m{3}
333 \FPset\flx@g{12}
334 \newif\ifSF@frame\SF@framefalse
335 \newif\ifFix@Margin\Fix@Margintrue
336 \newif\ifUse@fancyhdr\Use@fancyhdrtrue
337 % \end{macrocode}
338 %
339 %
340 %
341 % \begin{macrocode}
342 \setlength{\flx@paperheight}{\paperheight}
343 \setlength{\flx@paperwidth}{\paperwidth}
344
345 \NewDocumentCommand \flx@setpapersize {o o m}{
346 \setlength{\flx@paperheight}{#2#3}
347 \setlength{\flx@paperwidth}{#1#3}
348 }
349
350
351 \ExplSyntaxOn
352 \keys_define:nn { flexiprint }
353 {
354 binding .code:n = \setlength{\flx@binding}{#1},
355 inner .code:n = \setlength{\flx@inner}{#1},
356 outer .code:n = \setlength{\flx@outer}{#1},
357 top .code:n = \setlength{\flx@top}{#1},
358 bot .code:n = \setlength{\flx@bot}{#1},
359 marginparsep .code:n = \setlength{\flx@parsep}{#1},
360 paperheight .code:n = \setlength{\flx@paperheight}{#1},
361 paperwidth .code:n = \setlength{\flx@paperwidth}{#1},
362 outerbleed .code:n = \setlength{\flx@outerbleed}{#1},
363 innerbleed .code:n = \setlength{\flx@innerbleed}{#1},
364 grid .code:n = \FPset\flx@g{#1},
365 marginalgrid .code:n = \FPset\flx@m{#1} ,
366 show .code:n = \SF@frametrue ,
367 NoFixMargin .code:n = \Fix@Marginfalse ,
368 headsep .code:n = \setlength{\headsep}{#1},
369 headheight .code:n = \setlength{\headheight}{#1},
370 footskip .code:n = \setlength{\footskip}{#1},
371 extrafirstfoot .code:n = \setlength{\flx@extrafirstfoot}{#1},
372 fancyhdrOff .code:n = \Use@fancyhdrfalse,
373 a4paper .code:n = \flx@setpapersize[210][297]{mm},
374 a5paper .code:n = \flx@setpapersize[148][210]{mm},
375 b4paper .code:n = \flx@setpapersize[250][353]{mm},
376 b5paper .code:n = \flx@setpapersize[176][250]{mm},
377 c4paper .code:n = \flx@setpapersize[229][324]{mm},
378 c5paper .code:n = \flx@setpapersize[162][229]{mm},
379 b4jpaper .code:n = \flx@setpapersize[257][364]{mm},
380 b5jpaper .code:n = \flx@setpapersize[182][257]{mm},
381 letterpaper .code:n = \flx@setpapersize[8.5][11]{in},
382 legalpaper .code:n = \flx@setpapersize[8.5][14]{in},
383 executivepaper .code:n = \flx@setpapersize[7.25][10.5]{in},
384 10x8paper .code:n = \flx@setpapersize[8][10]{in},
385 US-Trade .code:n = \flx@setpapersize[6][9]{in},
386 UK-B-Format .code:n = \flx@setpapersize[135][210]{mm},
387 US-B-Format .code:n = \flx@setpapersize[129][198]{mm},
388 UK-Royal .code:n = \flx@setpapersize[156][234]{mm},
389 Quarto .code:n = \flx@setpapersize[9.5][12]{in},
390 Octavo .code:n = \flx@setpapersize[6][9]{in},
391 CrownQuarto .code:n = \flx@setpapersize[189][246]{mm},
392 Demi .code:n = \flx@setpapersize[138][216]{mm},
393 }
394 \ProcessKeysOptions { flexiprint }
395
396 \DeclareExpandableDocumentCommand{\IfNoValueOrEmptyTF}{ m m m }
397 {
398 \IfNoValueTF{#1}
399 {#2}
400 {\tl_if_empty:nTF {#1} {#2} {#3}}
401 }
402 \ExplSyntaxOff
403
404 \FPset\flx@oldg{\flx@g}
405 \FPset\flx@oldm{\flx@m}
406 \FPset\flx@og{\flx@g}
407 \FPset\flx@om{\flx@m}
408 \setlength{\flx@oparsep}{\flx@parsep}
409 \ifUse@fancyhdr
410 \RequirePackage{fancyhdr}
411 \pagestyle{fancy}
412 \fi
413
414 \setlength{\flx@oldparsep}{\flx@parsep}
415 \setlength{\flx@oparsep}{\flx@parsep}
416 \addtolength{\flx@binding}{\flx@innerbleed}
417 \global\hoffset=0pt
418 \global\voffset=0pt
419
420 % \end{macrocode}
421 %
422 % \begin{macro}{\flx@setpagevertical}
423 % \begin{macrocode}
424 \NewDocumentCommand \flx@setpagevertical {} {
425 \setlength{\flx@temp}{\flx@paperwidth+\flx@innerbleed+\flx@outerbleed}
426 \global\paperwidth=\flx@temp
427
428 \setlength{\flx@temp}{\flx@paperheight+2\flx@outerbleed}
429 \global\paperheight=\flx@temp
430
431 \setlength{\flx@temp}{\flx@top+\flx@outerbleed-72pt}
432 \setlength{\topmargin}{\flx@temp}
433
434 \setlength{\flx@temp}{\paperheight - \flx@top %
435 - \headheight - \headsep -\footskip - \flx@bot - 2\flx@outerbleed}
436 \setlength{\flx@textheigt}{\flx@temp}
437 \setlength{\textheight}{\flx@textheigt-\flx@extrafirstfoot}
438 %******************************************************************
439 }
440 % \end{macrocode}
441 % \end{macro}
442 %
443 % \begin{macrocode}
444 \flx@setpagevertical
445 \AddToHook{shipout/firstpage}{%
446 \global\textheight=\flx@textheigt
447 }
448
449
450
451 \newlength{\flx@linewidth}
452 % \end{macrocode}
453 %
454 % \begin{macro}{\flx@setpage}
455 % \begin{macrocode}
456
457 \NewDocumentCommand \flx@setpage {} {
458 \FPifgt\flx@m0\relax\else\setlength{\flx@parsep}{0pt}\fi
459 \setlength{\flx@temp}{\flx@binding+\flx@inner-72pt}
460 \global\oddsidemargin=\flx@temp
461
462 \setlength{\flx@linewidth}{\paperwidth-\oddsidemargin-\flx@outer-72pt-\flx@outerbleed}
463 \ifUse@fancyhdr
464 \setlength{\headwidth}{\flx@linewidth}
465 \fi
466 \setlength{\flx@printarea}{\flx@linewidth-\flx@parsep}
467 \FPsub\flx@t\flx@g\flx@m
468 \setlength{\flx@temp}{\flx@printarea * \real{\flx@t}/\real{\flx@g} }
469 \global\textwidth=\flx@temp
470
471 \setlength{\flx@temp}{\flx@printarea * \real{\flx@m}/\real{\flx@g} }
472 \global\marginparwidth=\flx@temp
473 \global\marginparsep=\flx@parsep
474 \if@twoside
475 \setlength{\flx@temp}{\flx@outer+\marginparwidth+\marginparsep-1in+\flx@outerbleed}
476 \global\evensidemargin=\flx@temp
477 \else
478 \global\evensidemargin=\oddsidemargin
479 \fi
480 \global\fleximarginparsep=\marginparsep
481 \global\hsize=\textwidth
482 }
483 % \end{macrocode}
484 % \end{macro}
485 %
486 % \begin{macrocode}
487 \flx@setpage
488 \flx@orgtextwidth=\textwidth
489 \FPset\flx@oldg\flx@g
490 \FPset\flx@oldm\flx@m
491 \setlength{\flx@oparsep}{\flx@parsep}
492 \setlength{\flx@oldparsep}{\flx@parsep}
493 % \end{macrocode}
494 %
495 %
496 % \begin{macro}{\NewMarginPage}
497 % \begin{macrocode}
498 \NewDocumentCommand \NewMarginPage {o d<> m} {
499 \FPset\flx@oldg\flx@g
500 \FPset\flx@oldm\flx@m
501 \setlength{\flx@oldparsep}{\flx@parsep}
502 \ResetFlexiPage
503 \IfNoValueOrEmptyTF{#2}{\relax}{\setlength{\flx@parsep}{#2} }
504 \IfNoValueOrEmptyTF{#1}{\relax}{\FPset\flx@g{#1}}
505 \FPset\flx@m{#3}
506 \flx@setpage
507 \flx@marginparcorrection
508 }
509 % \end{macrocode}
510 % \end{macro}
511 %
512 %
513 % \begin{macro}{\OldMarginPage}
514 % \begin{macrocode}
515 \NewDocumentCommand \OldMarginPage {} {
516 \FPset\flx@m\flx@oldm
517 \FPset\flx@g\flx@oldg
518 \flx@ResetFlexiPage
519 \setlength{\flx@parsep}{\flx@oldparsep}
520 \flx@setpage
521 \flx@marginparcorrection
522 }
523 % \end{macrocode}
524 % \end{macro}
525 %
526 %
527 % \begin{macro}{\NewFullPage}
528 % \begin{macrocode}
529 \NewDocumentCommand \NewFullPage {}{
530 \FPset\flx@oldg\flx@g
531 \FPset\flx@oldm\flx@m
532 \setlength{\flx@oldparsep}{\flx@parsep}
533 \flx@ResetFlexiPage
534 \FPset\flx@m{0}
535 \setlength{\flx@parsep}{0pt}
536 \flx@setpage
537 }
538 % \end{macrocode}
539 % \end{macro}
540 %
541 %
542 % \begin{macro}{\ResetFlexiPage}
543 % \begin{macrocode}
544 \NewDocumentCommand \ResetFlexiPage{} {
545 \FPset\flx@oldg\flx@g
546 \FPset\flx@oldm\flx@m
547 \flx@ResetFlexiPage
548 }
549 % \end{macrocode}
550 % \end{macro}
551 %
552 %
553 % \begin{macro}{\flx@ResetFlexiPage}
554 % \begin{macrocode}
555 \NewDocumentCommand \flx@ResetFlexiPage{} {
556 \clearpage
557 \FPset\flx@g\flx@og
558 \FPset\flx@m\flx@om
559 \setlength{\flx@parsep}{\flx@oparsep}
560 \flx@setpage
561 \flx@marginparcorrection
562 }
563 % \end{macrocode}
564 % \end{macro}%
565 %
566 % \begin{macro}{\Landscape}
567 % \begin{macrocode}
568 \NewDocumentCommand \Landscape {}
569 % \end{macrocode}
570 % \end{macro}
571 %
572 % \begin{macrocode}
573 {
574 \FPset\flx@oldm\flx@m
575 \FPset\flx@oldg\flx@g
576 \setlength{\flx@oldparsep}{\flx@parsep}
577 \clearpage
578 \setlength{\flx@LSfix}{\textheight-\flx@linewidth}
579 \FPset\flx@m{0}
580 \setlength{\flx@parsep}{0ex}
581 \flx@setpage
582 \flx@landscape
583 }
584 % \end{macrocode}
585 %
586 % \begin{macro}{\endLandscape}
587 % \begin{macrocode}
588 \NewDocumentCommand \endLandscape {}
589 {
590 \flx@endlandscape
591 \FPset\flx@m\flx@oldm
592 \FPset\flx@g\flx@oldg
593 \setlength{\flx@parsep}{\flx@oldparsep}
594 \flx@setpage
595 \setlength{\flx@LSfix}{0pt}
596 \flx@marginparcorrection
597 }
598 % \end{macrocode}
599 % \end{macro}
600 %
601 %
602 % \begin{macro}{\landscape}
603 % \begin{macrocode}
604 \NewDocumentCommand \landscape {}
605 % \end{macrocode}
606 % \end{macro}
607 %
608 % \begin{macrocode}
609 {
610 \FPset\flx@oldm\flx@m
611 \FPset\flx@oldg\flx@g
612 \setlength{\flx@oldparsep}{\flx@parsep}
613 \clearpage
614 \setlength{\flx@LSfix}{\textheight-\textwidth}
615 \FPset\flx@m{0}
616 \setlength{\flx@parsep}{0ex}
617 \flx@landscape
618 }
619 % \end{macrocode}
620 %
621 % \begin{macro}{\endlandscape}
622 % \begin{macrocode}
623 \NewDocumentCommand \endlandscape {}
624 {
625 \flx@endlandscape
626 \FPset\flx@m\flx@oldm
627 \FPset\flx@g\flx@oldg
628 \setlength{\flx@parsep}{\flx@oldparsep}
629 \flx@setpage
630 \setlength{\flx@LSfix}{0pt}
631 \flx@marginparcorrection
632 }
633 % \end{macrocode}
634 % \end{macro}
635 %
636 %
637 % If the page layout includes a marginal these lscape.sty package
638 % respect these
639 %
640 %
641 % \begin{macrocode}
642 %
643
644 \def\flx@LS@rot{%
645 \setbox\@outputbox\vbox{\hbox{\rotatebox{90}{\box\@outputbox}}}}
646
647 \def\flx@landscape{%
648 \let\flx@LS@makecol=\@makecol
649 \let\flx@LS@makefcolumn=\@makefcolumn
650 \clearpage
651 \begingroup
652 \global\vsize=\textwidth
653 \global\hsize=\textheight
654 \linewidth=\hsize
655 \columnwidth=\hsize
656 \@colroom=\vsize
657 \textheight=\vsize
658 \@colht=\vsize
659 \def\@makecol{\flx@LS@makecol\flx@LS@rot}%
660 \def\@makefcolumn##1{\flx@LS@makefcolumn{##1}\flx@LS@rot}}
661
662 \def\flx@endlandscape{%
663 \clearpage
664 \endgroup
665 \global\@colht=\textheight
666 \global\vsize=\textheight
667 \global\@colroom=\textheight}
668 %
669 % \end{macrocode}
670 %
671 %
672 %
673 % \begin{macro}{\flx@marginparcorrection }
674 %
675 % Mid-document changes to textwidth are not communicated the LaTeX marginpar
676 % routines hence the patch to correct the odd-side marginparsep.
677 %
678 % lifted from https://tex.stackexchange.com/questions/174605
679 %
680 % % \end{macro}
681 %
682 %
683 % \begin{macrocode}
684 \NewDocumentCommand\flx@marginparcorrection{}{
685 \ifFix@Margin
686 \setlength{\marginparsepodd}{\marginparsep-\flx@orgtextwidth+\textwidth}
687 \setlength{\marginparsepeven}{\marginparsep}
688 \patchcmd{\@addmarginpar}%In this command
689 {\mph@orig@addmarginpar}%...replace this...
690 {\if@twoside\ifodd\c@page\relax%...with this
691 \marginparsep=\marginparsepodd%Page isodd
692 \else%twoside and eveb
693 \marginparsep=\marginparsepeven%Page iseven
694 \fi
695 \else% oneside
696 \marginparsep=\marginparsepodd
697 \fi
698 \mph@orig@addmarginpar}
699 {}%success
700 {\message{Error! Couldn't hook into command %failure
701 `\string\@addmarginpar'}} %end patch command
702
703 {
704 \def\patcherr{%
705 \message{Error!Couldn't hook into command`\string\@mn@@@marginnote'}}
706 \def\patchok{%
707 \let\patcherr\relax%Only display error if first patch fails
708 \patch%Now patch again.
709 }
710 \def\patch{
711 \patchcmd{\@mn@@@marginnote}%In this command
712 {\kern\marginparsep}%...replace this...
713 {\ifx\@mn@currpage\relax\else%...with this
714 \if@twoside\ifodd\@mn@currpage\relax
715 \kern\marginparsepodd%Page is odd
716 \else
717 \kern\marginparsepeven
718 \fi
719 \else% one side
720 \kern\marginparsepodd
721 \fi
722 \fi}
723 {\message{Patched!}\patchok}%success(recurse)
724 {\patcherr}%fail
725 }
726 \message{Patching`\string\@mn@@@marginnote`!}
727 \patch
728 \global\let\@mn@@@marginnote\@mn@@@marginnote%Makepatch global
729 }
730 \fi
731 }
732 % \end{macrocode}
733 %
734 %
735 % The package showframe.sty is adapted and localised
736 %
737 %
738 % \begin{macrocode}
739 \ifSF@frame\RequirePackage{eso-pic}\fi % so that below code can draw frames
740
741 \ifSF@frame\AddToShipoutPictureBG{\flx@ShowFramePicture}\fi
742
743 \newcommand*\flx@framecolor{\color{green}}
744 \newcommand*\flx@frameline{.8pt}
745 \newdimen\SF@tempdima
746
747 \newcommand\flx@ShowFramePicture{%
748 \begingroup
749 \color{orange}\linethickness{\flx@frameline}%
750 \if@twoside
751 \ifodd\c@page
752 \AtPageUpperLeft{%
753 \put(\flx@innerbleed,-\paperheight+\flx@outerbleed){%
754 \framebox(\paperwidth-\flx@outerbleed-\flx@innerbleed,\paperheight-2\flx@outerbleed){}}}%
755 \else
756 \AtPageUpperLeft{%
757 \put(\flx@outerbleed,-\paperheight+\flx@outerbleed){%
758 \framebox(\paperwidth-\flx@outerbleed-\flx@innerbleed,\paperheight-2\flx@outerbleed){}}}%
759 \fi
760 \else
761 \AtPageUpperLeft{%
762 \put(\flx@innerbleed,-\paperheight+\flx@outerbleed){%
763 \framebox(\paperwidth-\flx@outerbleed-\flx@innerbleed,\paperheight-2\flx@outerbleed){}}}%
764 \fi
765 \flx@framecolor\linethickness{\flx@frameline}%
766 \AtTextLowerLeft{%
767 \put(0,-\flx@LSfix){\framebox(\textwidth,\textheight+\flx@LSfix){}}}%
768
769 \ifUse@fancyhdr
770 \if@twoside
771 \ifodd\c@page
772 \AtPageUpperLeft{%
773 \put(\flx@inner+\flx@binding,-\flx@outerbleed-\flx@top-\headheight){%
774 \framebox(\flx@linewidth,\headheight){}}}%
775 \AtPageUpperLeft{%
776 \put(\flx@inner+\flx@binding,%
777 -\flx@outerbleed-\flx@top-\headheight-\headsep-\textheight%
778 -\footskip -\flx@LSfix){%
779 \line(1,0){\flx@linewidth}}}%
780 \else
781 \AtPageUpperLeft{%
782 \put(\flx@outer+\flx@outerbleed,-\flx@outerbleed-\flx@top-\headheight){%
783 \framebox(\flx@linewidth,\headheight){}}}%
784 \AtPageUpperLeft{%
785 \put(\flx@outer+\flx@outerbleed,%
786 -\flx@outerbleed-\flx@top-\headheight-\headsep-\textheight%
787 -\footskip -\flx@LSfix){%
788 \line(1,0){\flx@linewidth}}}%
789
790 \fi
791 \else
792 \AtPageUpperLeft{%
793 \put(\flx@inner+\flx@binding,-\flx@outerbleed-\flx@top-\headheight){%
794 \framebox(\flx@linewidth,\headheight){}}}%
795 \AtPageUpperLeft{%
796 \put(\flx@inner+\flx@binding,%
797 -\flx@outerbleed-\flx@top-\headheight-\headsep-\textheight%
798 -\footskip -\flx@LSfix){%
799 \line(1,0){\flx@linewidth}}}%
800 \fi
801 %
802 \else
803 \AtTextUpperLeft{%
804 \put(0,\headsep){%
805 \framebox(\textwidth,\headheight){}}}%
806 \AtTextLowerLeft{%
807 \put(0,-\footskip-\flx@LSfix){%
808 \line(1,0){\textwidth}}}%
809 \fi
810 %
811 \FPifgt\flx@m 0{%
812 \AtTextLowerLeft{%
813 \SF@tempdima=\textwidth\advance\SF@tempdima\marginparsep%
814 \if@twoside
815 \ifodd\c@page\else
816 \if@mparswitch
817 \SF@tempdima=-\marginparsep\advance\SF@tempdima-\marginparwidth
818 \fi
819 \fi
820 \fi
821 \put(\SF@tempdima,0)%
822 {\framebox(\marginparwidth,\textheight){}}%
823 }%
824 }\fi
825 \endgroup
826 }
827 % \end{macrocode}
828 %
829 %
830 % \iffalse
831 %</package>
832 % \fi
833 %
834 % \Finale
835 \endinput