5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{lltjp-geometry}[2018/01/19 Patch to geometry for LuaTeX-ja with vertical writing mode]
7 \ifdefined\if@ltj@@geometry@tate\expandafter\endinput\fi
8 \newif\if@ltj@@geometry@tate
9 \newif\if@ltj@@geometry@forceoff
10 \@ltj@@geometry@tatefalse
11 \@ltj@@geometry@forceofffalse
12 \DeclareOption{force}{\@ltj@@geometry@tatetrue}
13 \DeclareOption{disable}{\@ltj@@geometry@forceofftrue}
17 \RequirePackage{ifluatex}
19 \ifdefined\luatexjaLoaded\else
20 \PackageError{lltjp-geometry}{%
21 lltjp-geometry does not work without luatexja.
26 \global \setbox \@begindvibox
27 \vbox{\yoko\unvbox \@begindvibox #1}%
31 \RequirePackage{filehook}
32 \RequirePackage{etoolbox}
33 \newif\ifGm@ltj@layoutswitch
34 \let\orig@PackageWarningNoLine=\PackageWarningNoLine
35 % define ifGm@swap@papersize if it is undefined
36 \expandafter\newif\csname ifGm@swap@papersize\endcsname
38 \AtBeginOfPackageFile{geometry}{%
39 \edef\Gm@ltj@topskip{\the\topskip}
40 \edef\Gm@ltj@headsep{\the\headsep}
41 \edef\Gm@ltj@footskip{\the\footskip}
43 \ifnum\ltjgetparameter{direction}=3 \@ltj@@geometry@tatetrue\fi
45 \@gobble\iftrue\csname iftdir\endcsname\@ltj@@geometry@tatetrue\fi
47 \patchcmd\@begindocumenthook{\tate}{\tate}{\@ltj@@geometry@tatetrue}{}%
48 \if@ltj@@geometry@tate
49 \if@ltj@@geometry@forceoff
50 \@ltj@@geometry@tatefalse
52 \let\PackageWarningNoLine\@gobbletwo% 警告抑止
56 \AtEndOfPackageFile{geometry}{%
57 \let\PackageWarningNoLine=\orig@PackageWarningNoLine
58 \if@ltj@@geometry@tate
59 \let\PackageWarningNoLine=\orig@PackageWarningNoLine
63 % * pTeX, LuaTeX ともに truedimen が正しく動作しない
64 % * pTeX resetpaper が正しく動作しない
66 % `h', `v' は「水平」「垂直」を意味するが:
67 % ユーザー側では「紙の物理的な水平方向」「物理的な垂直方向」を,
68 % しかしパッケージ内部処理では「字送り方向」「行送り方向」を表す.
69 % そのため,key-value interface 内で h, v の交換を行う必要がある.
71 % twoside 指定時は,lmargin は小口側,rmargin はノド側の余白を指す.
72 % また,bindingoffset 偶数ページを右に,奇数ページを左にずらす.
73 \define@key{Gm}{hdivide}{\Gm@parse@divide{#1}{lmargin}{height}{rmargin}}%
75 \define@key{Gm}{vscale}{\Gm@hbodytrue\edef\Gm@hscale{#1}}%
76 \define@key{Gm}{hscale}{\Gm@vbodytrue\edef\Gm@vscale{#1}}%
77 \define@key{Gm}{vdivide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}}%
78 \define@key{Gm}{divide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}%
79 \Gm@parse@divide{#1}{lmargin}{height}{rmargin}}%
80 \define@key{Gm}{vmargin}{\Gm@branch{#1}{tmargin}{bmargin}}%
81 \define@key{Gm}{hmargin}{\Gm@branch{#1}{lmargin}{rmargin}}%
82 \define@key{Gm}{margin}{\Gm@branch{#1}{tmargin}{lmargin}%
83 \Gm@branch{#1}{bmargin}{rmargin}}%
84 \define@key{Gm}{headsep}{\Gm@defbylen{ltj@headsep}{#1}}%
85 \define@key{Gm}{footskip}{\Gm@defbylen{ltj@footskip}{#1}}%
86 \let\KV@Gm@foot\KV@Gm@footskip
87 \define@key{Gm}{vmarginratio}{\edef\Gm@hmarginratio{#1}}%
88 \define@key{Gm}{hmarginratio}{\edef\Gm@vmarginratio{#1}}%
89 \define@key{Gm}{nohead}[true]{\Gm@doifelse{nohead}{#1}%
90 {\Gm@setlength\headheight\z@\Gm@defbylen{ltj@headsep}\z@}{}}%
91 \define@key{Gm}{nofoot}[true]{\Gm@doifelse{nofoot}{#1}%
92 {\Gm@defbylen{ltj@footskip}\z@}{}}%
93 \define@key{Gm}{noheadfoot}[true]{\Gm@doifelse{noheadfoot}{#1}%
94 {\Gm@setlength\headheight\z@\Gm@defbylen{ltj@headsep}\z@
95 \Gm@defbylen{ltj@footskip}\z@}{}}%
96 \define@key{Gm}{layoutwidth}{\Gm@layouttrue\Gm@setlength\Gm@layoutheight{#1}}%
97 \define@key{Gm}{layoutheight}{\Gm@layouttrue\Gm@setlength\Gm@layoutwidth{#1}}%
98 \define@key{Gm}{layoutsize}{\Gm@branch{#1}{layoutwidth}{layoutheight}}%
99 \define@key{Gm}{layout}{\Gm@layouttrue\@nameuse{Gm@#1}{Gm@layout}%
100 \Gm@setlength\@tempdima{\Gm@layoutheight}%
101 \Gm@setlength\Gm@layoutheight{\Gm@layoutwidth}%
102 \Gm@setlength\Gm@layoutwidth{\@tempdima}%
105 % \@mparswitch は傍注の出力位置を左右ページで変えるスイッチだが,
106 % geometry.sty はこれを左右ページのレイアウトを変えるか否かの判定にも使っている.
107 % 縦組クラスの場合は \@mparswitch は常に偽でないとおかしなことになるので
108 % \@mparswitch -> \Gm@ltj@layoutswitch と名称変更する.
110 \let\Gm@ltj@layoutswitch\@mparswitch
112 \define@key{Gm}{twoside}[true]{\Gm@doifelse{twoside}{#1}%
113 {\@twosidetrue\Gm@ltj@layoutswitchtrue}{\@twosidefalse\Gm@ltj@layoutswitchfalse}}%
114 \define@key{Gm}{asymmetric}[true]{\Gm@doifelse{asymmetric}{#1}%
115 {\@twosidetrue\Gm@ltj@layoutswitchfalse}{}}%
117 % includemp 指定時は,\headsep (if reversemp || twocolumn) や,
118 % \footskip (if !reversemp || twocolumn) を傍注幅だけ増加させる.
121 \def\Gm@Dhratio{2:3}% = top:bottom default
122 \def\Gm@Dvratio{1:1}% = left:right default for oneside
123 \def\Gm@Dvratiotwo{3:2}% = inner:outer default for twoside.
125 % geometry.sty ロード時に landscape オプションが指定されていた場合,
126 % それによって用紙サイズの縦横が入れ替わってしまっているので補正する.
127 \setlength\@tempdima{\paperwidth}%
128 \setlength\paperwidth{\paperheight}%
129 \setlength\paperheight{\@tempdima}%
134 \Gm@savelength{paperwidth}%
135 \Gm@savelength{paperheight}%
136 \Gm@savelength{textwidth}%
137 \Gm@savelength{textheight}%
138 \Gm@savelength{evensidemargin}%
139 \Gm@savelength{oddsidemargin}%
140 \Gm@savelength{topmargin}%
141 \Gm@savelength{headheight}%
142 %\Gm@savelength{headsep}%
143 \Gm@savelength{topskip}%
144 %\Gm@savelength{footskip}%
145 \Gm@savelength{baselineskip}%
146 \Gm@savelength{marginparwidth}%
147 \Gm@savelength{marginparsep}%
148 \Gm@savelength{columnsep}%
149 \Gm@savelength{hoffset}%
150 \Gm@savelength{voffset}
151 \Gm@savelength{Gm@layoutwidth}%
152 \Gm@savelength{Gm@layoutheight}%
153 \Gm@savelength{Gm@layouthoffset}%
154 \Gm@savelength{Gm@layoutvoffset}%
155 \Gm@saveboolean{@twocolumn}%
156 \Gm@saveboolean{@twoside}%
157 \Gm@saveboolean{Gm@ltj@layoutswitch}%
158 \Gm@saveboolean{@reversemargin}}%
162 \def\Gm@pageframe@cmd{\vb@xt@\z@}
164 \def\Gm@pageframe@cmd{\vb@xt@\z@\bgroup\yoko\aftergroup\egroup}
166 \renewcommand*{\Gm@pageframes}{%
169 \vb@xt@\z@{\vskip-1\Gm@truedimen in\vskip\Gm@layoutvoffset%
170 \hb@xt@\z@{\hskip-1\Gm@truedimen in\hskip\Gm@layouthoffset%
171 \vb@xt@\Gm@layoutwidth{%
173 \hb@xt@\Gm@layoutheight{\Gm@cropmark(-1,1,-3,3)\hfil\Gm@cropmark(1,1,3,3)}%
175 \hb@xt@\Gm@layoutheight{\Gm@cropmark(-1,-1,-3,-3)\hfil\Gm@cropmark(1,-1,3,-3)}}%
182 \let\@themargin\oddsidemargin
184 \let\@themargin\evensidemargin
187 \moveright\@themargin%
189 \vskip\topmargin\vb@xt@\z@{\vss\Gm@hrule}%
190 \vskip\headheight\vb@xt@\z@{\vss\Gm@hruled}%
191 \vskip\headsep\vb@xt@\z@{\vss\Gm@hrule}%
192 \if@reversemargin\vb@xt@\z@{%
193 \vss\vb@xt@\z@{\vss\Gm@hrule}%
194 \vskip\marginparwidth\vb@xt@\z@{\vss\Gm@hrule}%
197 \hb@xt@\textwidth{\llap{\Gm@vrule}\hfil\Gm@vrule}%
198 \vb@xt@\z@{\vss\Gm@hruled}%
199 \unless\if@reversemargin\vb@xt@\z@{%
200 \vskip\marginparsep\vb@xt@\z@{\vss\Gm@hrule}%
201 \vskip\marginparwidth\vb@xt@\z@{\vss\Gm@hruled}\vss%
203 \vskip\footskip\vb@xt@\z@{\vss\Gm@hruled}%
207 \def\Gm@detall#1#2#3#4{%
210 \let\Gm@mratio\Gm@hmarginratio
211 \edef\Gm@Dmratio{\Gm@Dhratio}%
213 \let\Gm@mratio\Gm@vmarginratio
214 \edef\Gm@Dmratio{\if@twoside\Gm@Dvratiotwo\else\Gm@Dvratio\fi}%
217 \ifx\Gm@tmargin\@undefined\else\advance\@tempcnta4\relax\fi
218 \ifGm@hbody\advance\@tempcnta2\relax\fi
219 \ifx\Gm@bmargin\@undefined\else\advance\@tempcnta1\relax\fi
222 \ifx\Gm@lmargin\@undefined\else\advance\@tempcnta4\relax\fi
223 \ifGm@vbody\advance\@tempcnta2\relax\fi
224 \ifx\Gm@rmargin\@undefined\else\advance\@tempcnta1\relax\fi
229 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
231 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
233 \Gm@detiiandiii{#2}{#3}{#4}%
235 \ifx\Gm@mratio\@undefined
237 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
239 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
241 \setlength\@tempdimc{\@nameuse{Gm@#4}}%
242 \Gm@detiiandiii{#2}{#3}{#4}%
243 \expandafter\let\csname Gm@#2\endcsname\@undefined
244 \Gm@defbylen{#4}{\@tempdimc}%
246 \Gm@setbyratio[f]{#1}{#4}{#3}%
248 \Gm@detiv{#2}{#3}{#4}{#2}%
249 \or\Gm@detiiandiii{#2}{#3}{#4}%
250 \or\Gm@detiv{#2}{#2}{#4}{#3}%
252 \ifx\Gm@mratio\@undefined
254 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
256 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
258 \setlength\@tempdimc{\@nameuse{Gm@#3}}%
259 \Gm@detiiandiii{#2}{#4}{#3}%
260 \expandafter\let\csname Gm@#2\endcsname\@undefined
261 \Gm@defbylen{#3}{\@tempdimc}%
263 \Gm@setbyratio[b]{#1}{#3}{#4}%
265 \Gm@detiv{#2}{#3}{#4}{#2}%
266 \or\Gm@detiv{#2}{#3}{#4}{#2}%
267 \or\Gm@detiv{#2}{#2}{#3}{#4}%
268 \or\Gm@warning{Over-specification in `#1'-direction.%
269 ^^J\@spaces `#2' (\@nameuse{Gm@#2}) is ignored}%
270 \Gm@detiv{#2}{#3}{#4}{#2}%
273 \ifnum\Gm@cnth<4\let\Gm@tmargin\@undefined\fi
274 \ifodd\Gm@cnth\else\let\Gm@bmargin\@undefined\fi
275 \ifnum\Gm@cntv<4\let\Gm@lmargin\@undefined\fi
276 \ifodd\Gm@cntv\else\let\Gm@rmargin\@undefined\fi
278 \let\Gm@hscale\@undefined
279 \let\Gm@width\@undefined
280 \let\Gm@textwidth\@undefined
283 \let\Gm@vscale\@undefined
284 \let\Gm@height\@undefined
285 \let\Gm@textheight\@undefined
288 \def\Gm@adjustpaper{%
289 \ifdim\paperwidth>\p@\else
290 \PackageError{geometry}{%
291 \string\paperwidth\space(\the\paperwidth) too short}{%
292 Set a paper type (e.g., `a4paper').}%
294 \ifdim\paperheight>\p@\else
295 \PackageError{geometry}{%
296 \string\paperheight\space(\the\paperheight) too short}{%
297 Set a paper type (e.g., `a4paper').}%
300 \setlength\@tempdima{\paperwidth}%
301 \setlength\paperwidth{\paperheight}%
302 \setlength\paperheight{\@tempdima}%
305 \setlength\Gm@layoutwidth{\paperheight}%
306 \setlength\Gm@layoutheight{\paperwidth}%
310 \ifx\Gm@width\@undefined
311 \ifx\Gm@hscale\@undefined
312 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
314 \Gm@defbylen{width}{\Gm@hscale\Gm@layoutwidth}%
317 \ifx\Gm@textwidth\@undefined\else
318 \setlength\@tempdima{\Gm@textwidth}%
320 \advance\@tempdima\Gm@wd@mp
323 \addtolength\@tempdima{\headheight}%
324 \addtolength\@tempdima{\headsep}%
327 \addtolength\@tempdima{\footskip}%
329 \edef\Gm@width{\the\@tempdima}%
333 \ifx\Gm@height\@undefined
334 \ifx\Gm@vscale\@undefined
335 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
337 \Gm@defbylen{height}{\Gm@vscale\Gm@layoutheight}%
340 \setlength\topskip\Gm@ltj@topskip
341 \ifx\Gm@lines\@undefined\else
342 \@tempdima=\f@size\p@ \@tempdima=.5\@tempdima
344 \advance\@tempdima\ltjgetparameter{talbaselineshift}%
346 \advance\@tempdima\tbaselineshift
348 \ifdim\maxdepth<\@tempdima
349 \PackageWarningNoLine{lltjp-geometry}%
350 {\noexpand\maxdepth was changed from \the\maxdepth\space
354 \setbox\z@=\hbox{\tate% next \ifdim must be executed in tate dir.
355 \ifdim\topskip<\ht\tstrutbox
357 \global\topskip\ht\tstrutbox
358 \PackageWarningNoLine{lltjp-geometry}%
359 {\noexpand\topskip was changed from \the\@tempdima\space
362 \setlength\@tempdima{\baselineskip}%
363 \multiply\@tempdima\Gm@lines
364 \addtolength\@tempdima{\topskip}%
365 \addtolength\@tempdima{-\baselineskip}%
366 \edef\Gm@textheight{\the\@tempdima}%
368 \ifx\Gm@textheight\@undefined\else
369 \edef\Gm@height{\Gm@textheight}%
375 \@tempdimb\marginparwidth
376 \advance\@tempdimb\marginparsep
385 \addtolength\Gm@layoutheight{-\Gm@bindingoffset}%
388 \Gm@detall{h}{width}{tmargin}{bmargin}%
389 \Gm@detall{v}{height}{lmargin}{rmargin}%
390 \setlength\textwidth{\Gm@width}%
391 \setlength\textheight{\Gm@height}%
392 \setlength\headsep{\Gm@ltj@headsep}%
393 \setlength\footskip{\Gm@ltj@footskip}%
394 \setlength\topmargin{\Gm@tmargin}%
395 \setlength\oddsidemargin{\Gm@lmargin}%
396 \addtolength\oddsidemargin{-1\Gm@truedimen in}%
397 \ifGm@ltj@layoutswitch
398 \setlength\evensidemargin{\Gm@rmargin}%
399 \addtolength\evensidemargin{-1\Gm@truedimen in}%
401 \evensidemargin\oddsidemargin
403 \advance\evensidemargin\Gm@bindingoffset
404 \addtolength\topmargin{-1\Gm@truedimen in}%
406 \addtolength\textwidth{-\headheight}%
407 \addtolength\textwidth{-\headsep}%
409 \addtolength\topmargin{-\headheight}%
410 \addtolength\topmargin{-\headsep}%
413 \addtolength\textwidth{-\footskip}%
416 \advance\textwidth-\Gm@wd@mp
418 \advance\headsep.5\Gm@wd@mp
419 \advance\footskip.5\Gm@wd@mp
420 \else\if@reversemargin
421 \advance\headsep\Gm@wd@mp
423 \advance\footskip\Gm@wd@mp
427 \setlength\@tempdima{\textheight}%
428 \addtolength\@tempdima{-\topskip}%
430 \@tempcntb\baselineskip
431 \divide\@tempcnta\@tempcntb
432 \setlength\@tempdimb{\baselineskip}%
433 \multiply\@tempdimb\@tempcnta
434 \advance\@tempdima-\@tempdimb
435 \multiply\@tempdima\tw@
436 \ifdim\@tempdima>\baselineskip
437 \addtolength\@tempdimb{\baselineskip}%
439 \addtolength\@tempdimb{\topskip}%
440 \textheight\@tempdimb
442 \advance\oddsidemargin\Gm@layouthoffset%
443 \advance\evensidemargin\Gm@layouthoffset%
444 \advance\topmargin\Gm@layoutvoffset%
445 \addtolength\Gm@layoutheight{\Gm@bindingoffset}%
446 }% end of \Gm@@process
448 \def\Gm@logcontent#1{%
449 *geometry* verbose mode - [ #1 ] result:^^J%
450 \ifGm@pass * pass: disregarded the geometry package!^^J%
452 * driver: \if\Gm@driver<none>\else\Gm@driver\fi^^J%
453 * paper: \ifx\Gm@paper\@undefined<default>\else\Gm@paper\fi^^J%
454 * layout: \ifGm@layout<custom>\else<same size as paper>\fi^^J%
456 * layout(width,height): (\the\Gm@layoutwidth,\the\Gm@layoutheight)^^J%
458 * layoutoffset:(h,v)=(\the\Gm@layouthoffset,\the\Gm@layoutvoffset)^^J%
459 \@ifundefined{Gm@lines}{}{* lines: \Gm@lines^^J}%
460 \@ifundefined{Gm@hmarginratio}{}{* hratio: \Gm@hmarginratio^^J}%
461 \@ifundefined{Gm@vmarginratio}{}{* vratio: \Gm@vmarginratio^^J}%
462 \ifdim\Gm@bindingoffset=\z@\else
463 * bindingoffset: \the\Gm@bindingoffset^^J\fi
465 \Gm@showbool{landscape}%
466 \Gm@showbool{includehead}%
467 \Gm@showbool{includefoot}%
468 \Gm@showbool{includemp}%
469 \if@twoside twoside\space\fi%
470 \ifGm@ltj@layoutswitch\else\if@twoside asymmetric\space\fi\fi%
471 \Gm@showbool{heightrounded}%
472 \ifx\Gm@truedimen\@empty\else truedimen\space\fi%
473 \Gm@showbool{showframe}%
474 \Gm@showbool{showcrop}%
476 * h-part:(L,W,R)=(\Gm@lmargin, \Gm@height, \Gm@rmargin)^^J%
477 * v-part:(T,H,B)=(\Gm@tmargin, \Gm@width, \Gm@bmargin)^^J%
479 \Gm@showdim{\paperwidth}%
480 \Gm@showdim{\paperheight}%
481 \Gm@showdim{\textwidth}%
482 \Gm@showdim{\textheight}%
483 \Gm@showdim{\oddsidemargin}%
484 \Gm@showdim{\evensidemargin}%
485 \Gm@showdim{\topmargin}%
486 \Gm@showdim{\headheight}%
487 \Gm@showdim{\headsep}%
488 \Gm@showdim{\topskip}%
489 \Gm@showdim{\footskip}%
490 \Gm@showdim{\marginparwidth}%
491 \Gm@showdim{\marginparsep}%
492 \Gm@showdim{\columnsep}%
493 * \string\skip\string\footins=\the\skip\footins^^J%
494 \Gm@showdim{\hoffset}%
495 \Gm@showdim{\voffset}%
497 * \string\@twocolumn\if@twocolumn true\else false\fi^^J%
498 * \string\@twoside\if@twoside true\else false\fi^^J%
499 * \string\@mparswitch\if@mparswitch true\else false\fi^^J%
500 * \string\@reversemargin\if@reversemargin true\else false\fi^^J%
501 * (1in=72.27pt=25.4mm, 1cm=28.453pt)^^J}%
506 \ProcessOptionsKV[c]{Gm}%
508 \ProcessOptionsKV[p]{Gm}%