5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{lltjp-geometry}[2016/10/06 Patch to geometry for LuaTeX-ja with vertical writing mode]
7 \RequirePackage{ifluatex}
9 \ifdefined\if@ltj@@geometry@tate\expandafter\endinput\fi
10 \newif\if@ltj@@geometry@tate
11 \@ltj@@geometry@tatefalse
13 \@ltj@@geometry@tatetrue
15 \global \setbox \@begindvibox
16 \vbox{\yoko\unvbox \@begindvibox #1}%
20 \RequirePackage{filehook}
21 \RequirePackage{etoolbox}
22 \newif\ifGm@ltj@layoutswitch
23 \let\orig@PackageWarningNoLine=\PackageWarningNoLine
24 % define ifGm@swap@papersize if it is undefined
25 \expandafter\newif\csname ifGm@swap@papersize\endcsname
27 \AtBeginOfPackageFile{geometry}{%
28 \edef\Gm@ltj@topskip{\the\topskip}
29 \edef\Gm@ltj@headsep{\the\headsep}
30 \edef\Gm@ltj@footskip{\the\footskip}
32 \ifnum\ltjgetparameter{direction}=3 \@ltj@@geometry@tatetrue\fi
34 \if@ltj@@geometry@tate
35 \let\PackageWarningNoLine\@gobbletwo% 警告抑止
38 \AtEndOfPackageFile{geometry}{%
39 \let\PackageWarningNoLine=\orig@PackageWarningNoLine
40 \if@ltj@@geometry@tate
41 \let\PackageWarningNoLine=\orig@PackageWarningNoLine
45 % * pTeX, LuaTeX ともに truedimen が正しく動作しない
46 % * pTeX resetpaper が正しく動作しない
48 % `h', `v' は「水平」「垂直」を意味するが:
49 % ユーザー側では「紙の物理的な水平方向」「物理的な垂直方向」を,
50 % しかしパッケージ内部処理では「字送り方向」「行送り方向」を表す.
51 % そのため,key-value interface 内で h, v の交換を行う必要がある.
53 % twoside 指定時は,lmargin は小口側,rmargin はノド側の余白を指す.
54 % また,bindingoffset 偶数ページを右に,奇数ページを左にずらす.
55 \define@key{Gm}{hdivide}{\Gm@parse@divide{#1}{lmargin}{height}{rmargin}}%
57 \define@key{Gm}{vscale}{\Gm@hbodytrue\edef\Gm@hscale{#1}}%
58 \define@key{Gm}{hscale}{\Gm@vbodytrue\edef\Gm@vscale{#1}}%
59 \define@key{Gm}{vdivide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}}%
60 \define@key{Gm}{divide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}%
61 \Gm@parse@divide{#1}{lmargin}{height}{rmargin}}%
62 \define@key{Gm}{vmargin}{\Gm@branch{#1}{tmargin}{bmargin}}%
63 \define@key{Gm}{hmargin}{\Gm@branch{#1}{lmargin}{rmargin}}%
64 \define@key{Gm}{margin}{\Gm@branch{#1}{tmargin}{lmargin}%
65 \Gm@branch{#1}{bmargin}{rmargin}}%
66 \define@key{Gm}{headsep}{\Gm@defbylen{ltj@headsep}{#1}}%
67 \define@key{Gm}{footskip}{\Gm@defbylen{ltj@footskip}{#1}}%
68 \let\KV@Gm@foot\KV@Gm@footskip
69 \define@key{Gm}{vmarginratio}{\edef\Gm@hmarginratio{#1}}%
70 \define@key{Gm}{hmarginratio}{\edef\Gm@vmarginratio{#1}}%
71 \define@key{Gm}{nohead}[true]{\Gm@doifelse{nohead}{#1}%
72 {\Gm@setlength\headheight\z@\Gm@defbylen{ltj@headsep}\z@}{}}%
73 \define@key{Gm}{nofoot}[true]{\Gm@doifelse{nofoot}{#1}%
74 {\Gm@defbylen{ltj@footskip}\z@}{}}%
75 \define@key{Gm}{noheadfoot}[true]{\Gm@doifelse{noheadfoot}{#1}%
76 {\Gm@setlength\headheight\z@\Gm@defbylen{ltj@headsep}\z@
77 \Gm@defbylen{ltj@footskip}\z@}{}}%
78 \define@key{Gm}{layoutwidth}{\Gm@layouttrue\Gm@setlength\Gm@layoutheight{#1}}%
79 \define@key{Gm}{layoutheight}{\Gm@layouttrue\Gm@setlength\Gm@layoutwidth{#1}}%
80 \define@key{Gm}{layoutsize}{\Gm@branch{#1}{layoutwidth}{layoutheight}}%
81 \define@key{Gm}{layout}{\Gm@layouttrue\@nameuse{Gm@#1}{Gm@layout}%
82 \Gm@setlength\@tempdima{\Gm@layoutheight}%
83 \Gm@setlength\Gm@layoutheight{\Gm@layoutwidth}%
84 \Gm@setlength\Gm@layoutwidth{\@tempdima}%
87 % \@mparswitch は傍注の出力位置を左右ページで変えるスイッチだが,
88 % geometry.sty はこれを左右ページのレイアウトを変えるか否かの判定にも使っている.
89 % 縦組クラスの場合は \@mparswitch は常に偽でないとおかしなことになるので
90 % \@mparswitch -> \Gm@ltj@layoutswitch と名称変更する.
92 \let\Gm@ltj@layoutswitch\@mparswitch
94 \define@key{Gm}{twoside}[true]{\Gm@doifelse{twoside}{#1}%
95 {\@twosidetrue\Gm@ltj@layoutswitchtrue}{\@twosidefalse\Gm@ltj@layoutswitchfalse}}%
96 \define@key{Gm}{asymmetric}[true]{\Gm@doifelse{asymmetric}{#1}%
97 {\@twosidetrue\Gm@ltj@layoutswitchfalse}{}}%
99 % includemp 指定時は,\headsep (if reversemp || twocolumn) や,
100 % \footskip (if !reversemp || twocolumn) を傍注幅だけ増加させる.
103 \def\Gm@Dhratio{2:3}% = top:bottom default
104 \def\Gm@Dvratio{1:1}% = left:right default for oneside
105 \def\Gm@Dvratiotwo{3:2}% = inner:outer default for twoside.
107 % geometry.sty ロード時に landscape オプションが指定されていた場合,
108 % それによって用紙サイズの縦横が入れ替わってしまっているので補正する.
109 \setlength\@tempdima{\paperwidth}%
110 \setlength\paperwidth{\paperheight}%
111 \setlength\paperheight{\@tempdima}%
116 \Gm@savelength{paperwidth}%
117 \Gm@savelength{paperheight}%
118 \Gm@savelength{textwidth}%
119 \Gm@savelength{textheight}%
120 \Gm@savelength{evensidemargin}%
121 \Gm@savelength{oddsidemargin}%
122 \Gm@savelength{topmargin}%
123 \Gm@savelength{headheight}%
124 %\Gm@savelength{headsep}%
125 \Gm@savelength{topskip}%
126 %\Gm@savelength{footskip}%
127 \Gm@savelength{baselineskip}%
128 \Gm@savelength{marginparwidth}%
129 \Gm@savelength{marginparsep}%
130 \Gm@savelength{columnsep}%
131 \Gm@savelength{hoffset}%
132 \Gm@savelength{voffset}
133 \Gm@savelength{Gm@layoutwidth}%
134 \Gm@savelength{Gm@layoutheight}%
135 \Gm@savelength{Gm@layouthoffset}%
136 \Gm@savelength{Gm@layoutvoffset}%
137 \Gm@saveboolean{@twocolumn}%
138 \Gm@saveboolean{@twoside}%
139 \Gm@saveboolean{Gm@ltj@layoutswitch}%
140 \Gm@saveboolean{@reversemargin}}%
144 \def\Gm@pageframe@cmd{\vb@xt@\z@}
146 \def\Gm@pageframe@cmd{\vb@xt@\z@\bgroup\yoko\aftergroup\egroup}
148 \renewcommand*{\Gm@pageframes}{%
151 \vb@xt@\z@{\vskip-1\Gm@truedimen in\vskip\Gm@layoutvoffset%
152 \hb@xt@\z@{\hskip-1\Gm@truedimen in\hskip\Gm@layouthoffset%
153 \vb@xt@\Gm@layoutwidth{%
155 \hb@xt@\Gm@layoutheight{\Gm@cropmark(-1,1,-3,3)\hfil\Gm@cropmark(1,1,3,3)}%
157 \hb@xt@\Gm@layoutheight{\Gm@cropmark(-1,-1,-3,-3)\hfil\Gm@cropmark(1,-1,3,-3)}}%
164 \let\@themargin\oddsidemargin
166 \let\@themargin\evensidemargin
169 \moveright\@themargin%
171 \vskip\topmargin\vb@xt@\z@{\vss\Gm@hrule}%
172 \vskip\headheight\vb@xt@\z@{\vss\Gm@hruled}%
173 \vskip\headsep\vb@xt@\z@{\vss\Gm@hrule}%
174 \if@reversemargin\vb@xt@\z@{%
175 \vss\vb@xt@\z@{\vss\Gm@hrule}%
176 \vskip\marginparwidth\vb@xt@\z@{\vss\Gm@hrule}%
179 \hb@xt@\textwidth{\llap{\Gm@vrule}\hfil\Gm@vrule}%
180 \vb@xt@\z@{\vss\Gm@hruled}%
181 \unless\if@reversemargin\vb@xt@\z@{%
182 \vskip\marginparsep\vb@xt@\z@{\vss\Gm@hrule}%
183 \vskip\marginparwidth\vb@xt@\z@{\vss\Gm@hruled}\vss%
185 \vskip\footskip\vb@xt@\z@{\vss\Gm@hruled}%
189 \def\Gm@detall#1#2#3#4{%
192 \let\Gm@mratio\Gm@hmarginratio
193 \edef\Gm@Dmratio{\Gm@Dhratio}%
195 \let\Gm@mratio\Gm@vmarginratio
196 \edef\Gm@Dmratio{\if@twoside\Gm@Dvratiotwo\else\Gm@Dvratio\fi}%
199 \ifx\Gm@tmargin\@undefined\else\advance\@tempcnta4\relax\fi
200 \ifGm@hbody\advance\@tempcnta2\relax\fi
201 \ifx\Gm@bmargin\@undefined\else\advance\@tempcnta1\relax\fi
204 \ifx\Gm@lmargin\@undefined\else\advance\@tempcnta4\relax\fi
205 \ifGm@vbody\advance\@tempcnta2\relax\fi
206 \ifx\Gm@rmargin\@undefined\else\advance\@tempcnta1\relax\fi
211 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
213 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
215 \Gm@detiiandiii{#2}{#3}{#4}%
217 \ifx\Gm@mratio\@undefined
219 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
221 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
223 \setlength\@tempdimc{\@nameuse{Gm@#4}}%
224 \Gm@detiiandiii{#2}{#3}{#4}%
225 \expandafter\let\csname Gm@#2\endcsname\@undefined
226 \Gm@defbylen{#4}{\@tempdimc}%
228 \Gm@setbyratio[f]{#1}{#4}{#3}%
230 \Gm@detiv{#2}{#3}{#4}{#2}%
231 \or\Gm@detiiandiii{#2}{#3}{#4}%
232 \or\Gm@detiv{#2}{#2}{#4}{#3}%
234 \ifx\Gm@mratio\@undefined
236 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
238 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
240 \setlength\@tempdimc{\@nameuse{Gm@#3}}%
241 \Gm@detiiandiii{#2}{#4}{#3}%
242 \expandafter\let\csname Gm@#2\endcsname\@undefined
243 \Gm@defbylen{#3}{\@tempdimc}%
245 \Gm@setbyratio[b]{#1}{#3}{#4}%
247 \Gm@detiv{#2}{#3}{#4}{#2}%
248 \or\Gm@detiv{#2}{#3}{#4}{#2}%
249 \or\Gm@detiv{#2}{#2}{#3}{#4}%
250 \or\Gm@warning{Over-specification in `#1'-direction.%
251 ^^J\@spaces `#2' (\@nameuse{Gm@#2}) is ignored}%
252 \Gm@detiv{#2}{#3}{#4}{#2}%
255 \ifnum\Gm@cnth<4\let\Gm@tmargin\@undefined\fi
256 \ifodd\Gm@cnth\else\let\Gm@bmargin\@undefined\fi
257 \ifnum\Gm@cntv<4\let\Gm@lmargin\@undefined\fi
258 \ifodd\Gm@cntv\else\let\Gm@rmargin\@undefined\fi
260 \let\Gm@hscale\@undefined
261 \let\Gm@width\@undefined
262 \let\Gm@textwidth\@undefined
265 \let\Gm@vscale\@undefined
266 \let\Gm@height\@undefined
267 \let\Gm@textheight\@undefined
270 \def\Gm@adjustpaper{%
271 \ifdim\paperwidth>\p@\else
272 \PackageError{geometry}{%
273 \string\paperwidth\space(\the\paperwidth) too short}{%
274 Set a paper type (e.g., `a4paper').}%
276 \ifdim\paperheight>\p@\else
277 \PackageError{geometry}{%
278 \string\paperheight\space(\the\paperheight) too short}{%
279 Set a paper type (e.g., `a4paper').}%
282 \setlength\@tempdima{\paperwidth}%
283 \setlength\paperwidth{\paperheight}%
284 \setlength\paperheight{\@tempdima}%
287 \setlength\Gm@layoutwidth{\paperheight}%
288 \setlength\Gm@layoutheight{\paperwidth}%
292 \ifx\Gm@width\@undefined
293 \ifx\Gm@hscale\@undefined
294 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
296 \Gm@defbylen{width}{\Gm@hscale\Gm@layoutwidth}%
299 \ifx\Gm@textwidth\@undefined\else
300 \setlength\@tempdima{\Gm@textwidth}%
302 \advance\@tempdima\Gm@wd@mp
305 \addtolength\@tempdima{\headheight}%
306 \addtolength\@tempdima{\headsep}%
309 \addtolength\@tempdima{\footskip}%
311 \edef\Gm@width{\the\@tempdima}%
315 \ifx\Gm@height\@undefined
316 \ifx\Gm@vscale\@undefined
317 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
319 \Gm@defbylen{height}{\Gm@vscale\Gm@layoutheight}%
322 \setlength\topskip\Gm@ltj@topskip
323 \ifx\Gm@lines\@undefined\else
324 \@tempdima=\f@size\p@ \@tempdima=.5\@tempdima
326 \advance\@tempdima\ltjgetparameter{talbaselineshift}%
328 \advance\@tempdima\tbaselineshift
330 \ifdim\maxdepth<\@tempdima
331 \PackageWarningNoLine{lltjp-geometry}%
332 {\noexpand\maxdepth was changed from \the\maxdepth\space
336 \setbox\z@=\hbox{\tate% next \ifdim must be executed in tate dir.
337 \ifdim\topskip<\ht\tstrutbox
339 \global\topskip\ht\tstrutbox
340 \PackageWarningNoLine{lltjp-geometry}%
341 {\noexpand\topskip was changed from \the\@tempdima\space
344 \setlength\@tempdima{\baselineskip}%
345 \multiply\@tempdima\Gm@lines
346 \addtolength\@tempdima{\topskip}%
347 \addtolength\@tempdima{-\baselineskip}%
348 \edef\Gm@textheight{\the\@tempdima}%
350 \ifx\Gm@textheight\@undefined\else
351 \edef\Gm@height{\Gm@textheight}%
357 \@tempdimb\marginparwidth
358 \advance\@tempdimb\marginparsep
367 \addtolength\Gm@layoutheight{-\Gm@bindingoffset}%
370 \Gm@detall{h}{width}{tmargin}{bmargin}%
371 \Gm@detall{v}{height}{lmargin}{rmargin}%
372 \setlength\textwidth{\Gm@width}%
373 \setlength\textheight{\Gm@height}%
374 \setlength\headsep{\Gm@ltj@headsep}%
375 \setlength\footskip{\Gm@ltj@footskip}%
376 \setlength\topmargin{\Gm@tmargin}%
377 \setlength\oddsidemargin{\Gm@lmargin}%
378 \addtolength\oddsidemargin{-1\Gm@truedimen in}%
379 \ifGm@ltj@layoutswitch
380 \setlength\evensidemargin{\Gm@rmargin}%
381 \addtolength\evensidemargin{-1\Gm@truedimen in}%
383 \evensidemargin\oddsidemargin
385 \advance\evensidemargin\Gm@bindingoffset
386 \addtolength\topmargin{-1\Gm@truedimen in}%
388 \addtolength\textwidth{-\headheight}%
389 \addtolength\textwidth{-\headsep}%
391 \addtolength\topmargin{-\headheight}%
392 \addtolength\topmargin{-\headsep}%
395 \addtolength\textwidth{-\footskip}%
398 \advance\textwidth-\Gm@wd@mp
400 \advance\headsep.5\Gm@wd@mp
401 \advance\footskip.5\Gm@wd@mp
402 \else\if@reversemargin
403 \advance\headsep\Gm@wd@mp
405 \advance\footskip\Gm@wd@mp
409 \setlength\@tempdima{\textheight}%
410 \addtolength\@tempdima{-\topskip}%
412 \@tempcntb\baselineskip
413 \divide\@tempcnta\@tempcntb
414 \setlength\@tempdimb{\baselineskip}%
415 \multiply\@tempdimb\@tempcnta
416 \advance\@tempdima-\@tempdimb
417 \multiply\@tempdima\tw@
418 \ifdim\@tempdima>\baselineskip
419 \addtolength\@tempdimb{\baselineskip}%
421 \addtolength\@tempdimb{\topskip}%
422 \textheight\@tempdimb
424 \advance\oddsidemargin\Gm@layouthoffset%
425 \advance\evensidemargin\Gm@layouthoffset%
426 \advance\topmargin\Gm@layoutvoffset%
427 \addtolength\Gm@layoutheight{\Gm@bindingoffset}%
428 }% end of \Gm@@process
430 \def\Gm@logcontent#1{%
431 *geometry* verbose mode - [ #1 ] result:^^J%
432 \ifGm@pass * pass: disregarded the geometry package!^^J%
434 * driver: \if\Gm@driver<none>\else\Gm@driver\fi^^J%
435 * paper: \ifx\Gm@paper\@undefined<default>\else\Gm@paper\fi^^J%
436 * layout: \ifGm@layout<custom>\else<same size as paper>\fi^^J%
438 * layout(width,height): (\the\Gm@layoutwidth,\the\Gm@layoutheight)^^J%
440 * layoutoffset:(h,v)=(\the\Gm@layouthoffset,\the\Gm@layoutvoffset)^^J%
441 \@ifundefined{Gm@lines}{}{* lines: \Gm@lines^^J}%
442 \@ifundefined{Gm@hmarginratio}{}{* hratio: \Gm@hmarginratio^^J}%
443 \@ifundefined{Gm@vmarginratio}{}{* vratio: \Gm@vmarginratio^^J}%
444 \ifdim\Gm@bindingoffset=\z@\else
445 * bindingoffset: \the\Gm@bindingoffset^^J\fi
447 \Gm@showbool{landscape}%
448 \Gm@showbool{includehead}%
449 \Gm@showbool{includefoot}%
450 \Gm@showbool{includemp}%
451 \if@twoside twoside\space\fi%
452 \ifGm@ltj@layoutswitch\else\if@twoside asymmetric\space\fi\fi%
453 \Gm@showbool{heightrounded}%
454 \ifx\Gm@truedimen\@empty\else truedimen\space\fi%
455 \Gm@showbool{showframe}%
456 \Gm@showbool{showcrop}%
458 * h-part:(L,W,R)=(\Gm@lmargin, \Gm@height, \Gm@rmargin)^^J%
459 * v-part:(T,H,B)=(\Gm@tmargin, \Gm@width, \Gm@bmargin)^^J%
461 \Gm@showdim{\paperwidth}%
462 \Gm@showdim{\paperheight}%
463 \Gm@showdim{\textwidth}%
464 \Gm@showdim{\textheight}%
465 \Gm@showdim{\oddsidemargin}%
466 \Gm@showdim{\evensidemargin}%
467 \Gm@showdim{\topmargin}%
468 \Gm@showdim{\headheight}%
469 \Gm@showdim{\headsep}%
470 \Gm@showdim{\topskip}%
471 \Gm@showdim{\footskip}%
472 \Gm@showdim{\marginparwidth}%
473 \Gm@showdim{\marginparsep}%
474 \Gm@showdim{\columnsep}%
475 * \string\skip\string\footins=\the\skip\footins^^J%
476 \Gm@showdim{\hoffset}%
477 \Gm@showdim{\voffset}%
479 * \string\@twocolumn\if@twocolumn true\else false\fi^^J%
480 * \string\@twoside\if@twoside true\else false\fi^^J%
481 * \string\@mparswitch\if@mparswitch true\else false\fi^^J%
482 * \string\@reversemargin\if@reversemargin true\else false\fi^^J%
483 * (1in=72.27pt=25.4mm, 1cm=28.453pt)^^J}%
488 \ProcessOptionsKV[c]{Gm}%
490 \ProcessOptionsKV[p]{Gm}%