5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{lltjp-geometry}[2020/02/25 Patch to geometry for LuaTeX-ja with vertical writing mode]
8 \ifdefined\if@ltj@@geometry@tate\expandafter\endinput\fi
9 \newif\if@ltj@@geometry@tate
10 \newif\if@ltj@@geometry@forceoff
11 \@ltj@@geometry@tatefalse
12 \@ltj@@geometry@forceofffalse
13 \DeclareOption{force}{\@ltj@@geometry@tatetrue}
14 \DeclareOption{disable}{\@ltj@@geometry@forceofftrue}
18 \RequirePackage{ifluatex}
20 \ifdefined\luatexjaLoaded\else
21 \PackageError{lltjp-geometry}{%
22 lltjp-geometry does not work without luatexja.
27 \global \setbox \@begindvibox
28 \vbox{\yoko\unvbox \@begindvibox #1}%
32 \RequirePackage{filehook}
33 \RequirePackage{etoolbox}
34 \newif\ifGm@ltj@layoutswitch
35 \let\orig@PackageWarningNoLine=\PackageWarningNoLine
36 % define ifGm@swap@papersize if it is undefined
37 \expandafter\newif\csname ifGm@swap@papersize\endcsname
39 \AtBeginOfPackageFile{geometry}{%
40 \edef\Gm@ltj@topskip{\the\topskip}
41 \edef\Gm@ltj@headsep{\the\headsep}
42 \edef\Gm@ltj@footskip{\the\footskip}
44 \ifnum\ltjgetparameter{direction}=3 \@ltj@@geometry@tatetrue\fi
46 \@gobble\iftrue\csname iftdir\endcsname\@ltj@@geometry@tatetrue\fi
48 \csname tl_if_in:NnT\endcsname\@begindocumenthook{\tate}{\@ltj@@geometry@tatetrue}
49 \if@ltj@@geometry@tate
50 \if@ltj@@geometry@forceoff
51 \@ltj@@geometry@tatefalse
53 \let\PackageWarningNoLine\@gobbletwo% 警告抑止
58 \AtEndOfPackageFile{geometry}{%
59 \let\PackageWarningNoLine=\orig@PackageWarningNoLine
60 \if@ltj@@geometry@tate
61 \let\PackageWarningNoLine=\orig@PackageWarningNoLine
65 % * pTeX, LuaTeX ともに truedimen が正しく動作しない
66 % * pTeX resetpaper が正しく動作しない
68 % `h', `v' は「水平」「垂直」を意味するが:
69 % ユーザー側では「紙の物理的な水平方向」「物理的な垂直方向」を,
70 % しかしパッケージ内部処理では「字送り方向」「行送り方向」を表す.
71 % そのため,key-value interface 内で h, v の交換を行う必要がある.
73 % twoside 指定時は,lmargin は小口側,rmargin はノド側の余白を指す.
74 % また,bindingoffset 偶数ページを右に,奇数ページを左にずらす.
75 \define@key{Gm}{hdivide}{\Gm@parse@divide{#1}{lmargin}{height}{rmargin}}%
77 \define@key{Gm}{vscale}{\Gm@hbodytrue\edef\Gm@hscale{#1}}%
78 \define@key{Gm}{hscale}{\Gm@vbodytrue\edef\Gm@vscale{#1}}%
79 \define@key{Gm}{vdivide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}}%
80 \define@key{Gm}{divide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}%
81 \Gm@parse@divide{#1}{lmargin}{height}{rmargin}}%
82 \define@key{Gm}{vmargin}{\Gm@branch{#1}{tmargin}{bmargin}}%
83 \define@key{Gm}{hmargin}{\Gm@branch{#1}{lmargin}{rmargin}}%
84 \define@key{Gm}{margin}{\Gm@branch{#1}{tmargin}{lmargin}%
85 \Gm@branch{#1}{bmargin}{rmargin}}%
86 \define@key{Gm}{headsep}{\Gm@defbylen{ltj@headsep}{#1}}%
87 \define@key{Gm}{footskip}{\Gm@defbylen{ltj@footskip}{#1}}%
88 \let\KV@Gm@foot\KV@Gm@footskip
89 \define@key{Gm}{vmarginratio}{\edef\Gm@hmarginratio{#1}}%
90 \define@key{Gm}{hmarginratio}{\edef\Gm@vmarginratio{#1}}%
91 \define@key{Gm}{nohead}[true]{\Gm@doifelse{nohead}{#1}%
92 {\Gm@setlength\headheight\z@\Gm@defbylen{ltj@headsep}\z@}{}}%
93 \define@key{Gm}{nofoot}[true]{\Gm@doifelse{nofoot}{#1}%
94 {\Gm@defbylen{ltj@footskip}\z@}{}}%
95 \define@key{Gm}{noheadfoot}[true]{\Gm@doifelse{noheadfoot}{#1}%
96 {\Gm@setlength\headheight\z@\Gm@defbylen{ltj@headsep}\z@
97 \Gm@defbylen{ltj@footskip}\z@}{}}%
98 \define@key{Gm}{layoutwidth}{\Gm@layouttrue\Gm@setlength\Gm@layoutheight{#1}}%
99 \define@key{Gm}{layoutheight}{\Gm@layouttrue\Gm@setlength\Gm@layoutwidth{#1}}%
100 \define@key{Gm}{layoutsize}{\Gm@branch{#1}{layoutwidth}{layoutheight}}%
101 \define@key{Gm}{layout}{\Gm@layouttrue\@nameuse{Gm@#1}{Gm@layout}%
102 \Gm@setlength\@tempdima{\Gm@layoutheight}%
103 \Gm@setlength\Gm@layoutheight{\Gm@layoutwidth}%
104 \Gm@setlength\Gm@layoutwidth{\@tempdima}%
107 % \@mparswitch は傍注の出力位置を左右ページで変えるスイッチだが,
108 % geometry.sty はこれを左右ページのレイアウトを変えるか否かの判定にも使っている.
109 % 縦組クラスの場合は \@mparswitch は常に偽でないとおかしなことになるので
110 % \@mparswitch -> \Gm@ltj@layoutswitch と名称変更する.
112 \let\Gm@ltj@layoutswitch\@mparswitch
114 \define@key{Gm}{twoside}[true]{\Gm@doifelse{twoside}{#1}%
115 {\@twosidetrue\Gm@ltj@layoutswitchtrue}{\@twosidefalse\Gm@ltj@layoutswitchfalse}}%
116 \define@key{Gm}{asymmetric}[true]{\Gm@doifelse{asymmetric}{#1}%
117 {\@twosidetrue\Gm@ltj@layoutswitchfalse}{}}%
119 % includemp 指定時は,\headsep (if reversemp || twocolumn) や,
120 % \footskip (if !reversemp || twocolumn) を傍注幅だけ増加させる.
123 \def\Gm@Dhratio{2:3}% = top:bottom default
124 \def\Gm@Dvratio{1:1}% = left:right default for oneside
125 \def\Gm@Dvratiotwo{3:2}% = inner:outer default for twoside.
127 % geometry.sty ロード時に landscape オプションが指定されていた場合,
128 % それによって用紙サイズの縦横が入れ替わってしまっているので補正する.
129 \setlength\@tempdima{\paperwidth}%
130 \setlength\paperwidth{\paperheight}%
131 \setlength\paperheight{\@tempdima}%
136 \Gm@savelength{paperwidth}%
137 \Gm@savelength{paperheight}%
138 \Gm@savelength{textwidth}%
139 \Gm@savelength{textheight}%
140 \Gm@savelength{evensidemargin}%
141 \Gm@savelength{oddsidemargin}%
142 \Gm@savelength{topmargin}%
143 \Gm@savelength{headheight}%
144 %\Gm@savelength{headsep}%
145 \Gm@savelength{topskip}%
146 %\Gm@savelength{footskip}%
147 \Gm@savelength{baselineskip}%
148 \Gm@savelength{marginparwidth}%
149 \Gm@savelength{marginparsep}%
150 \Gm@savelength{columnsep}%
151 \Gm@savelength{hoffset}%
152 \Gm@savelength{voffset}
153 \Gm@savelength{Gm@layoutwidth}%
154 \Gm@savelength{Gm@layoutheight}%
155 \Gm@savelength{Gm@layouthoffset}%
156 \Gm@savelength{Gm@layoutvoffset}%
157 \Gm@saveboolean{@twocolumn}%
158 \Gm@saveboolean{@twoside}%
159 \Gm@saveboolean{Gm@ltj@layoutswitch}%
160 \Gm@saveboolean{@reversemargin}}%
164 \def\Gm@pageframe@cmd{\vb@xt@\z@}
166 \def\Gm@pageframe@cmd{\vb@xt@\z@\bgroup\yoko\aftergroup\egroup}
168 \renewcommand*{\Gm@pageframes}{%
171 \vb@xt@\z@{\vskip-1\Gm@truedimen in\vskip\Gm@layoutvoffset%
172 \hb@xt@\z@{\hskip-1\Gm@truedimen in\hskip\Gm@layouthoffset%
173 \vb@xt@\Gm@layoutwidth{%
175 \hb@xt@\Gm@layoutheight{\Gm@cropmark(-1,1,-3,3)\hfil\Gm@cropmark(1,1,3,3)}%
177 \hb@xt@\Gm@layoutheight{\Gm@cropmark(-1,-1,-3,-3)\hfil\Gm@cropmark(1,-1,3,-3)}}%
184 \let\@themargin\oddsidemargin
186 \let\@themargin\evensidemargin
189 \moveright\@themargin%
191 \vskip\topmargin\vb@xt@\z@{\vss\Gm@hrule}%
192 \vskip\headheight\vb@xt@\z@{\vss\Gm@hruled}%
193 \vskip\headsep\vb@xt@\z@{\vss\Gm@hrule}%
194 \if@reversemargin\vb@xt@\z@{%
195 \vss\vb@xt@\z@{\vss\Gm@hrule}%
196 \vskip\marginparwidth\vb@xt@\z@{\vss\Gm@hrule}%
199 \hb@xt@\textwidth{\llap{\Gm@vrule}\hfil\Gm@vrule}%
200 \vb@xt@\z@{\vss\Gm@hruled}%
201 \unless\if@reversemargin\vb@xt@\z@{%
202 \vskip\marginparsep\vb@xt@\z@{\vss\Gm@hrule}%
203 \vskip\marginparwidth\vb@xt@\z@{\vss\Gm@hruled}\vss%
205 \vskip\footskip\vb@xt@\z@{\vss\Gm@hruled}%
209 \def\Gm@detall#1#2#3#4{%
212 \let\Gm@mratio\Gm@hmarginratio
213 \edef\Gm@Dmratio{\Gm@Dhratio}%
215 \let\Gm@mratio\Gm@vmarginratio
216 \edef\Gm@Dmratio{\if@twoside\Gm@Dvratiotwo\else\Gm@Dvratio\fi}%
219 \ifx\Gm@tmargin\@undefined\else\advance\@tempcnta4\relax\fi
220 \ifGm@hbody\advance\@tempcnta2\relax\fi
221 \ifx\Gm@bmargin\@undefined\else\advance\@tempcnta1\relax\fi
224 \ifx\Gm@lmargin\@undefined\else\advance\@tempcnta4\relax\fi
225 \ifGm@vbody\advance\@tempcnta2\relax\fi
226 \ifx\Gm@rmargin\@undefined\else\advance\@tempcnta1\relax\fi
231 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
233 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
235 \Gm@detiiandiii{#2}{#3}{#4}%
237 \ifx\Gm@mratio\@undefined
239 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
241 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
243 \setlength\@tempdimc{\@nameuse{Gm@#4}}%
244 \Gm@detiiandiii{#2}{#3}{#4}%
245 \expandafter\let\csname Gm@#2\endcsname\@undefined
246 \Gm@defbylen{#4}{\@tempdimc}%
248 \Gm@setbyratio[f]{#1}{#4}{#3}%
250 \Gm@detiv{#2}{#3}{#4}{#2}%
251 \or\Gm@detiiandiii{#2}{#3}{#4}%
252 \or\Gm@detiv{#2}{#2}{#4}{#3}%
254 \ifx\Gm@mratio\@undefined
256 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
258 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
260 \setlength\@tempdimc{\@nameuse{Gm@#3}}%
261 \Gm@detiiandiii{#2}{#4}{#3}%
262 \expandafter\let\csname Gm@#2\endcsname\@undefined
263 \Gm@defbylen{#3}{\@tempdimc}%
265 \Gm@setbyratio[b]{#1}{#3}{#4}%
267 \Gm@detiv{#2}{#3}{#4}{#2}%
268 \or\Gm@detiv{#2}{#3}{#4}{#2}%
269 \or\Gm@detiv{#2}{#2}{#3}{#4}%
270 \or\Gm@warning{Over-specification in `#1'-direction.%
271 ^^J\@spaces `#2' (\@nameuse{Gm@#2}) is ignored}%
272 \Gm@detiv{#2}{#3}{#4}{#2}%
275 \ifnum\Gm@cnth<4\let\Gm@tmargin\@undefined\fi
276 \ifodd\Gm@cnth\else\let\Gm@bmargin\@undefined\fi
277 \ifnum\Gm@cntv<4\let\Gm@lmargin\@undefined\fi
278 \ifodd\Gm@cntv\else\let\Gm@rmargin\@undefined\fi
280 \let\Gm@hscale\@undefined
281 \let\Gm@width\@undefined
282 \let\Gm@textwidth\@undefined
285 \let\Gm@vscale\@undefined
286 \let\Gm@height\@undefined
287 \let\Gm@textheight\@undefined
290 \def\Gm@adjustpaper{%
291 \ifdim\paperwidth>\p@\else
292 \PackageError{geometry}{%
293 \string\paperwidth\space(\the\paperwidth) too short}{%
294 Set a paper type (e.g., `a4paper').}%
296 \ifdim\paperheight>\p@\else
297 \PackageError{geometry}{%
298 \string\paperheight\space(\the\paperheight) too short}{%
299 Set a paper type (e.g., `a4paper').}%
302 \setlength\@tempdima{\paperwidth}%
303 \setlength\paperwidth{\paperheight}%
304 \setlength\paperheight{\@tempdima}%
307 \setlength\Gm@layoutwidth{\paperheight}%
308 \setlength\Gm@layoutheight{\paperwidth}%
312 \ifx\Gm@width\@undefined
313 \ifx\Gm@hscale\@undefined
314 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
316 \Gm@defbylen{width}{\Gm@hscale\Gm@layoutwidth}%
319 \ifx\Gm@textwidth\@undefined\else
320 \setlength\@tempdima{\Gm@textwidth}%
322 \advance\@tempdima\Gm@wd@mp
325 \addtolength\@tempdima{\headheight}%
326 \addtolength\@tempdima{\headsep}%
329 \addtolength\@tempdima{\footskip}%
331 \edef\Gm@width{\the\@tempdima}%
335 \ifx\Gm@height\@undefined
336 \ifx\Gm@vscale\@undefined
337 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
339 \Gm@defbylen{height}{\Gm@vscale\Gm@layoutheight}%
342 \setlength\topskip\Gm@ltj@topskip
343 \ifx\Gm@lines\@undefined\else
344 \@tempdima=\f@size\p@ \@tempdima=.5\@tempdima
346 \advance\@tempdima\ltjgetparameter{talbaselineshift}%
348 \advance\@tempdima\tbaselineshift
350 \ifdim\maxdepth<\@tempdima
351 \PackageWarningNoLine{lltjp-geometry}%
352 {\noexpand\maxdepth was changed from \the\maxdepth\space
356 \setbox\z@=\hbox{\tate% next \ifdim must be executed in tate dir.
357 \ifdim\topskip<\ht\tstrutbox
359 \global\topskip\ht\tstrutbox
360 \PackageWarningNoLine{lltjp-geometry}%
361 {\noexpand\topskip was changed from \the\@tempdima\space
364 \setlength\@tempdima{\baselineskip}%
365 \multiply\@tempdima\Gm@lines
366 \addtolength\@tempdima{\topskip}%
367 \addtolength\@tempdima{-\baselineskip}%
368 \edef\Gm@textheight{\the\@tempdima}%
370 \ifx\Gm@textheight\@undefined\else
371 \edef\Gm@height{\Gm@textheight}%
377 \@tempdimb\marginparwidth
378 \advance\@tempdimb\marginparsep
387 \addtolength\Gm@layoutheight{-\Gm@bindingoffset}%
390 \Gm@detall{h}{width}{tmargin}{bmargin}%
391 \Gm@detall{v}{height}{lmargin}{rmargin}%
392 \setlength\textwidth{\Gm@width}%
393 \setlength\textheight{\Gm@height}%
394 \setlength\headsep{\Gm@ltj@headsep}%
395 \setlength\footskip{\Gm@ltj@footskip}%
396 \setlength\topmargin{\Gm@tmargin}%
397 \setlength\oddsidemargin{\Gm@lmargin}%
398 \addtolength\oddsidemargin{-1\Gm@truedimen in}%
399 \ifGm@ltj@layoutswitch
400 \setlength\evensidemargin{\Gm@rmargin}%
401 \addtolength\evensidemargin{-1\Gm@truedimen in}%
403 \evensidemargin\oddsidemargin
405 \advance\evensidemargin\Gm@bindingoffset
406 \addtolength\topmargin{-1\Gm@truedimen in}%
408 \addtolength\textwidth{-\headheight}%
409 \addtolength\textwidth{-\headsep}%
411 \addtolength\topmargin{-\headheight}%
412 \addtolength\topmargin{-\headsep}%
415 \addtolength\textwidth{-\footskip}%
418 \advance\textwidth-\Gm@wd@mp
420 \advance\headsep.5\Gm@wd@mp
421 \advance\footskip.5\Gm@wd@mp
422 \else\if@reversemargin
423 \advance\headsep\Gm@wd@mp
425 \advance\footskip\Gm@wd@mp
429 \setlength\@tempdima{\textheight}%
430 \addtolength\@tempdima{-\topskip}%
432 \@tempcntb\baselineskip
433 \divide\@tempcnta\@tempcntb
434 \setlength\@tempdimb{\baselineskip}%
435 \multiply\@tempdimb\@tempcnta
436 \advance\@tempdima-\@tempdimb
437 \multiply\@tempdima\tw@
438 \ifdim\@tempdima>\baselineskip
439 \addtolength\@tempdimb{\baselineskip}%
441 \addtolength\@tempdimb{\topskip}%
442 \textheight\@tempdimb
444 \advance\oddsidemargin\Gm@layouthoffset%
445 \advance\evensidemargin\Gm@layouthoffset%
446 \advance\topmargin\Gm@layoutvoffset%
447 \addtolength\Gm@layoutheight{\Gm@bindingoffset}%
448 }% end of \Gm@@process
450 \def\Gm@logcontent#1{%
451 *geometry* verbose mode - [ #1 ] result:^^J%
452 \ifGm@pass * pass: disregarded the geometry package!^^J%
454 * driver: \if\Gm@driver<none>\else\Gm@driver\fi^^J%
455 * paper: \ifx\Gm@paper\@undefined<default>\else\Gm@paper\fi^^J%
456 * layout: \ifGm@layout<custom>\else<same size as paper>\fi^^J%
458 * layout(width,height): (\the\Gm@layoutwidth,\the\Gm@layoutheight)^^J%
460 * layoutoffset:(h,v)=(\the\Gm@layouthoffset,\the\Gm@layoutvoffset)^^J%
461 \@ifundefined{Gm@lines}{}{* lines: \Gm@lines^^J}%
462 \@ifundefined{Gm@hmarginratio}{}{* hratio: \Gm@hmarginratio^^J}%
463 \@ifundefined{Gm@vmarginratio}{}{* vratio: \Gm@vmarginratio^^J}%
464 \ifdim\Gm@bindingoffset=\z@\else
465 * bindingoffset: \the\Gm@bindingoffset^^J\fi
467 \Gm@showbool{landscape}%
468 \Gm@showbool{includehead}%
469 \Gm@showbool{includefoot}%
470 \Gm@showbool{includemp}%
471 \if@twoside twoside\space\fi%
472 \ifGm@ltj@layoutswitch\else\if@twoside asymmetric\space\fi\fi%
473 \Gm@showbool{heightrounded}%
474 \ifx\Gm@truedimen\@empty\else truedimen\space\fi%
475 \Gm@showbool{showframe}%
476 \Gm@showbool{showcrop}%
478 * h-part:(L,W,R)=(\Gm@lmargin, \Gm@height, \Gm@rmargin)^^J%
479 * v-part:(T,H,B)=(\Gm@tmargin, \Gm@width, \Gm@bmargin)^^J%
481 \Gm@showdim{\paperwidth}%
482 \Gm@showdim{\paperheight}%
483 \Gm@showdim{\textwidth}%
484 \Gm@showdim{\textheight}%
485 \Gm@showdim{\oddsidemargin}%
486 \Gm@showdim{\evensidemargin}%
487 \Gm@showdim{\topmargin}%
488 \Gm@showdim{\headheight}%
489 \Gm@showdim{\headsep}%
490 \Gm@showdim{\topskip}%
491 \Gm@showdim{\footskip}%
492 \Gm@showdim{\marginparwidth}%
493 \Gm@showdim{\marginparsep}%
494 \Gm@showdim{\columnsep}%
495 * \string\skip\string\footins=\the\skip\footins^^J%
496 \Gm@showdim{\hoffset}%
497 \Gm@showdim{\voffset}%
499 * \string\@twocolumn\if@twocolumn true\else false\fi^^J%
500 * \string\@twoside\if@twoside true\else false\fi^^J%
501 * \string\@mparswitch\if@mparswitch true\else false\fi^^J%
502 * \string\@reversemargin\if@reversemargin true\else false\fi^^J%
503 * (1in=72.27pt=25.4mm, 1cm=28.453pt)^^J}%
508 \ProcessOptionsKV[c]{Gm}%
510 \ProcessOptionsKV[p]{Gm}%