OSDN Git Service

lltjp-geometry,sty: fix showframe on pTeX etc.
[luatex-ja/luatexja.git] / src / patches / lltjp-geometry.sty
1 %
2 % lltjp-geometry.sty
3 %
4
5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{lltjp-geometry}[2014/11/23 Patch to geometry for LuaTeX-ja with vertical writing mode]
7 \RequirePackage{ifluatex}
8
9 \newif\if@ltj@@geometry@tate
10 \@ltj@@geometry@tatefalse
11 \ifluatex\else % pTeX
12   \@ltj@@geometry@tatetrue
13 \def \AtBeginDvi #1{%
14   \global \setbox \@begindvibox
15     \vbox{\yoko\unvbox \@begindvibox #1}%
16 }
17 \fi
18
19 \RequirePackage{filehook}
20
21 \AtBeginOfPackageFile{geometry}{%
22   \edef\Gm@ltj@topskip{\the\topskip}
23   \edef\Gm@ltj@headsep{\the\headsep}
24   \edef\Gm@ltj@footskip{\the\footskip}
25 }
26 \AtEndOfPackageFile{geometry}{%
27 \ifluatex
28   \ifnum\ltjgetparameter{direction}=3 \@ltj@@geometry@tatetrue\fi
29 \fi
30 \if@ltj@@geometry@tate
31
32 % `h', `v' は「水平」「垂直」を意味するが:
33 % ユーザー側では「紙の物理的な水平方向」「物理的な垂直方向」を,
34 % しかしパッケージ内部処理では「字送り方向」「行送り方向」を表す.
35 % そのため,key-value interface 内で h, v の交換を行う必要がある.
36
37 \define@key{Gm}{vdivide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}}%
38 \define@key{Gm}{hdivide}{\Gm@parse@divide{#1}{lmargin}{height}{rmargin}}%
39 \define@key{Gm}{divide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}%
40   \Gm@parse@divide{#1}{lmargin}{height}{rmargin}}%
41 \define@key{Gm}{vmargin}{\Gm@branch{#1}{tmargin}{bmargin}}%
42 \define@key{Gm}{hmargin}{\Gm@branch{#1}{lmargin}{rmargin}}%
43 \define@key{Gm}{margin}{\Gm@branch{#1}{tmargin}{lmargin}%
44   \Gm@branch{#1}{bmargin}{rmargin}}%
45 \define@key{Gm}{headsep}{\Gm@defbylen{ltj@headsep}{#1}}%
46 \define@key{Gm}{footskip}{\Gm@defbylen{ltj@footskip}{#1}}%
47 \define@key{Gm}{vmarginratio}{\edef\Gm@hmarginratio{#1}}%
48 \define@key{Gm}{hmarginratio}{\edef\Gm@vmarginratio{#1}}%
49
50 % \@mparswitch は傍注の出力位置を左右ページで変えるスイッチだが,
51 % geometry.sty はこれを左右ページのレイアウトを変えるか否かの判定にも使っている.
52 % 縦組クラスの場合は \@mparswitch は常に偽でないとおかしなことになるので
53 % \@mparswitch -> \Gm@ltj@layoutswitch と名称変更する.
54
55 \newif\ifGm@ltj@layoutswitch
56 \let\Gm@ltj@layoutswitch\@mparswitch
57 \@mparswitchfalse
58 \define@key{Gm}{twoside}[true]{\Gm@doifelse{twoside}{#1}%
59   {\@twosidetrue\Gm@ltj@layoutswitchtrue}{\@twosidefalse\Gm@ltj@layoutswitchfalse}}%
60 \define@key{Gm}{asymmetric}[true]{\Gm@doifelse{asymmetric}{#1}%
61   {\@twosidetrue\Gm@ltj@layoutswitchfalse}{}}%
62
63   \def\Gm@Dhratio{2:3}% = top:bottom default
64   \def\Gm@Dvratio{1:1}% = left:right default for oneside
65   \def\Gm@Dvratiotwo{2:3}% = inner:outer default for twoside.
66
67 % save length
68 \def\Gm@save{%
69   \Gm@savelength{paperwidth}%
70   \Gm@savelength{paperheight}%
71   \Gm@savelength{textwidth}%
72   \Gm@savelength{textheight}%
73   \Gm@savelength{evensidemargin}%
74   \Gm@savelength{oddsidemargin}%
75   \Gm@savelength{topmargin}%
76   \Gm@savelength{headheight}%
77   %\Gm@savelength{headsep}%
78   \Gm@savelength{topskip}%
79   %\Gm@savelength{footskip}%
80   \Gm@savelength{baselineskip}%
81   \Gm@savelength{marginparwidth}%
82   \Gm@savelength{marginparsep}%
83   \Gm@savelength{columnsep}%
84   \Gm@savelength{hoffset}%
85   \Gm@savelength{voffset}
86   \Gm@savelength{Gm@layoutwidth}%
87   \Gm@savelength{Gm@layoutheight}%
88   \Gm@savelength{Gm@layouthoffset}%
89   \Gm@savelength{Gm@layoutvoffset}%
90   \Gm@saveboolean{@twocolumn}%
91   \Gm@saveboolean{@twoside}%
92   \Gm@saveboolean{Gm@ltj@layoutswitch}%
93   \Gm@saveboolean{@reversemargin}}%
94
95 % frame
96 \ifluatex
97   \def\Gm@pageframe@cmd{\vb@xt@\z@}
98 \else
99   \def\Gm@pageframe@cmd{\vb@xt@\z@\bgroup\yoko\aftergroup\egroup}
100 \fi
101 \renewcommand*{\Gm@pageframes}{%
102   \Gm@pageframe@cmd{%
103    \ifGm@showcrop
104     \vb@xt@\z@{\vskip-1\Gm@truedimen in\vskip\Gm@layoutvoffset%
105      \hb@xt@\z@{\hskip-1\Gm@truedimen in\hskip\Gm@layouthoffset%
106       \vb@xt@\Gm@layoutheight{%
107        \let\protect\relax
108        \hb@xt@\Gm@layoutwidth{\Gm@cropmark(-1,1,-3,3)\hfil\Gm@cropmark(1,1,3,3)}%
109        \vfil
110        \hb@xt@\Gm@layoutwidth{\Gm@cropmark(-1,-1,-3,-3)\hfil\Gm@cropmark(1,-1,3,-3)}}%
111      \hss}%
112     \vss}%
113    \fi%
114    \ifGm@showframe
115     \if@twoside
116      \ifodd\count\z@
117        \let\@themargin\oddsidemargin
118      \else
119        \let\@themargin\evensidemargin
120      \fi
121     \fi
122     \moveright\@themargin%
123     \vb@xt@\z@{%
124      \vskip\topmargin\vb@xt@\z@{\vss\Gm@hrule}%
125      \vskip\headheight\vb@xt@\z@{\vss\Gm@hruled}%
126      \vskip\headsep\vb@xt@\z@{\vss\Gm@hrule}%
127      \if@reversemargin\vb@xt@\z@{%
128        \vss\vb@xt@\z@{\vss\Gm@hrule}%
129        \vskip\marginparwidth\vb@xt@\z@{\vss\Gm@hrule}%
130        \vskip\marginparsep
131      }\fi
132      \hb@xt@\textwidth{\llap{\Gm@vrule}\hfil\Gm@vrule}%
133      \vb@xt@\z@{\vss\Gm@hruled}%
134      \unless\if@reversemargin\vb@xt@\z@{%
135        \vskip\marginparsep\vb@xt@\z@{\vss\Gm@hrule}%
136        \vskip\marginparwidth\vb@xt@\z@{\vss\Gm@hruled}%
137      }\fi%
138      \vskip\footskip\vb@xt@\z@{\vss\Gm@hruled}%
139      \vss}%
140     \fi%
141   }}
142 \def\Gm@detall#1#2#3#4{%
143   \@tempcnta\z@
144   \if#1h
145     \let\Gm@mratio\Gm@hmarginratio
146     \edef\Gm@Dmratio{\if@twoside\Gm@Dhratiotwo\else\Gm@Dhratio\fi}%
147   \else
148     \let\Gm@mratio\Gm@vmarginratio
149     \edef\Gm@Dmratio{\Gm@Dvratio}%
150   \fi
151   \if#1h
152     \ifx\Gm@tmargin\@undefined\else\advance\@tempcnta4\relax\fi
153     \ifGm@hbody\advance\@tempcnta2\relax\fi
154     \ifx\Gm@bmargin\@undefined\else\advance\@tempcnta1\relax\fi
155     \Gm@cnth\@tempcnta
156   \else
157     \ifx\Gm@rmargin\@undefined\else\advance\@tempcnta4\relax\fi
158     \ifGm@vbody\advance\@tempcnta2\relax\fi
159     \ifx\Gm@lmargin\@undefined\else\advance\@tempcnta1\relax\fi
160     \Gm@cntv\@tempcnta
161   \fi
162   \ifcase\@tempcnta
163     \if#1h
164       \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
165     \else
166       \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
167     \fi
168     \Gm@detiiandiii{#2}{#3}{#4}%
169   \or
170     \ifx\Gm@mratio\@undefined
171       \if#1h
172         \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
173       \else
174         \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
175       \fi
176       \setlength\@tempdimc{\@nameuse{Gm@#4}}%
177       \Gm@detiiandiii{#2}{#3}{#4}%
178       \expandafter\let\csname Gm@#2\endcsname\@undefined
179       \Gm@defbylen{#4}{\@tempdimc}%
180     \else
181       \Gm@setbyratio[f]{#1}{#4}{#3}%
182     \fi
183     \Gm@detiv{#2}{#3}{#4}{#2}%
184   \or\Gm@detiiandiii{#2}{#3}{#4}%
185   \or\Gm@detiv{#2}{#2}{#4}{#3}%
186   \or
187     \ifx\Gm@mratio\@undefined
188       \if#1h
189         \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
190       \else
191         \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
192       \fi
193       \setlength\@tempdimc{\@nameuse{Gm@#3}}%
194       \Gm@detiiandiii{#2}{#4}{#3}%
195       \expandafter\let\csname Gm@#2\endcsname\@undefined
196       \Gm@defbylen{#3}{\@tempdimc}%
197     \else
198       \Gm@setbyratio[b]{#1}{#3}{#4}%
199     \fi
200     \Gm@detiv{#2}{#3}{#4}{#2}%
201   \or\Gm@detiv{#2}{#3}{#4}{#2}%
202   \or\Gm@detiv{#2}{#2}{#3}{#4}%
203   \or\Gm@warning{Over-specification in `#1'-direction.%
204                   ^^J\@spaces `#2' (\@nameuse{Gm@#2}) is ignored}%
205     \Gm@detiv{#2}{#3}{#4}{#2}%
206   \else\fi}%
207 \def\Gm@clean{%
208   \ifnum\Gm@cnth<4\let\Gm@tmargin\@undefined\fi
209   \ifodd\Gm@cnth\else\let\Gm@bmargin\@undefined\fi
210   \ifnum\Gm@cntv<4\let\Gm@rmargin\@undefined\fi
211   \ifodd\Gm@cntv\else\let\Gm@lmargin\@undefined\fi
212   \ifGm@hbody\else
213     \let\Gm@hscale\@undefined
214     \let\Gm@width\@undefined
215     \let\Gm@textwidth\@undefined
216   \fi
217   \ifGm@vbody\else
218     \let\Gm@vscale\@undefined
219     \let\Gm@height\@undefined
220     \let\Gm@textheight\@undefined
221   \fi
222   }%
223 \def\Gm@adjustpaper{%
224   \ifdim\paperwidth>\p@\else
225     \PackageError{geometry}{%
226     \string\paperwidth\space(\the\paperwidth) too short}{%
227     Set a paper type (e.g., `a4paper').}%
228   \fi
229   \ifdim\paperheight>\p@\else
230     \PackageError{geometry}{%
231     \string\paperheight\space(\the\paperheight) too short}{%
232     Set a paper type (e.g., `a4paper').}%
233   \fi
234   \ifGm@swap@papersize
235     \setlength\@tempdima{\paperwidth}%
236     \setlength\paperwidth{\paperheight}%
237     \setlength\paperheight{\@tempdima}%
238   \fi
239   \ifGm@layout\else
240     \setlength\Gm@layoutwidth{\paperheight}%
241     \setlength\Gm@layoutheight{\paperwidth}%
242   \fi}%
243 \def\Gm@adjustbody{
244   \ifGm@hbody
245     \ifx\Gm@width\@undefined
246       \ifx\Gm@hscale\@undefined
247         \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
248       \else
249         \Gm@defbylen{width}{\Gm@hscale\Gm@layoutwidth}%
250       \fi
251     \fi
252     \ifx\Gm@textwidth\@undefined\else
253       \setlength\@tempdima{\Gm@textwidth}%
254       \ifGm@includemp
255         \advance\@tempdima\Gm@wd@mp
256       \fi
257       \ifGm@includehead
258         \addtolength\@tempdima{\headheight}%
259         \addtolength\@tempdima{\headsep}%
260       \fi
261       \ifGm@includefoot
262         \addtolength\@tempdima{\footskip}%
263       \fi
264       \edef\Gm@width{\the\@tempdima}%
265     \fi
266   \fi
267   \ifGm@vbody
268     \ifx\Gm@height\@undefined
269       \ifx\Gm@vscale\@undefined
270         \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
271       \else
272         \Gm@defbylen{height}{\Gm@vscale\Gm@layoutheight}%
273       \fi
274     \fi
275     \setlength\topskip\Gm@ltj@topskip
276     \ifx\Gm@lines\@undefined\else
277       \setlength\maxdepth{1\Cht}%
278       \setbox\z@=\hbox{\tate% next \ifdim must be executed in tate dir.
279         \ifdim\topskip<\ht\tstrutbox
280           \@tempdima\topskip
281           \global\topskip\ht\tstrutbox
282           \PackageWarningNoLine{lltjp-geometry}%
283            {do not worry about  `\noexpand\topskip was changed ...'\MessageBreak
284               warning above}
285           \PackageWarningNoLine{lltjp-geometry}%
286             {\noexpand\topskip was changed from \the\@tempdima\space
287               to \the\topskip}
288         \fi}%
289       \setlength\@tempdima{\baselineskip}%
290       \multiply\@tempdima\Gm@lines
291       \addtolength\@tempdima{\topskip}%
292       \addtolength\@tempdima{-\baselineskip}%
293       \edef\Gm@textheight{\the\@tempdima}%
294     \fi
295     \ifx\Gm@textheight\@undefined\else
296       \edef\Gm@height{\Gm@textheight}%
297     \fi
298   \fi}%
299
300 \def\Gm@adjustmp{%%%% TODO %%%%%%%
301   \ifGm@includemp
302     \@tempdimb\marginparwidth
303     \advance\@tempdimb\marginparsep
304     \Gm@wd@mp\@tempdimb
305     \Gm@odd@mp\z@
306     \Gm@even@mp\z@
307     \if@twocolumn
308       \Gm@wd@mp2\@tempdimb
309       \Gm@odd@mp\@tempdimb
310       \Gm@even@mp\@tempdimb
311     \else
312       \if@reversemargin
313         \Gm@odd@mp\@tempdimb
314         \if@mparswitch\else
315           \Gm@even@mp\@tempdimb
316         \fi
317       \else
318         \if@mparswitch
319           \Gm@even@mp\@tempdimb
320         \fi
321       \fi
322     \fi
323   \fi}%
324 \def\Gm@@process{%
325   \Gm@expandlengths
326   \Gm@adjustpaper
327   \addtolength\Gm@layoutwidth{-\Gm@bindingoffset}%
328   \Gm@adjustmp
329   \Gm@adjustbody
330   \Gm@detall{h}{width}{tmargin}{bmargin}%
331   \Gm@detall{v}{height}{lmargin}{rmargin}%
332   \setlength\textwidth{\Gm@width}%
333   \setlength\textheight{\Gm@height}%
334   \setlength\headsep{\Gm@ltj@headsep}%
335   \setlength\footskip{\Gm@ltj@footskip}%
336   \setlength\topmargin{\Gm@tmargin}%
337   \setlength\oddsidemargin{\Gm@lmargin}%
338   \addtolength\oddsidemargin{-1\Gm@truedimen in}%
339   \ifGm@ltj@layoutswitch
340     \setlength\evensidemargin{\Gm@rmargin}%
341     \addtolength\evensidemargin{-1\Gm@truedimen in}%
342   \else
343     \evensidemargin\oddsidemargin
344   \fi
345   \advance\oddsidemargin\Gm@bindingoffset
346   \addtolength\topmargin{-1\Gm@truedimen in}%
347   \ifGm@includehead
348     \addtolength\textwidth{-\headheight}%
349     \addtolength\textwidth{-\headsep}%
350   \else
351     \addtolength\topmargin{-\headheight}%
352     \addtolength\topmargin{-\headsep}%
353   \fi
354   \ifGm@includefoot
355     \addtolength\textwidth{-\footskip}%
356   \fi
357   \ifGm@includemp
358     \advance\textwidth-\Gm@wd@mp
359     \if@reversemargin
360       \advance\headsep\Gm@wd@mp
361     \else
362       \advance\footskip\Gm@wd@mp
363     \fi
364   \fi
365   \ifGm@heightrounded
366     \setlength\@tempdima{\textheight}%
367     \addtolength\@tempdima{-\topskip}%
368     \@tempcnta\@tempdima
369     \@tempcntb\baselineskip
370     \divide\@tempcnta\@tempcntb
371     \setlength\@tempdimb{\baselineskip}%
372     \multiply\@tempdimb\@tempcnta
373     \advance\@tempdima-\@tempdimb
374     \multiply\@tempdima\tw@
375     \ifdim\@tempdima>\baselineskip
376       \addtolength\@tempdimb{\baselineskip}%
377     \fi
378     \addtolength\@tempdimb{\topskip}%
379     \textheight\@tempdimb
380   \fi
381   \advance\oddsidemargin\Gm@layoutvoffset%
382   \advance\evensidemargin\Gm@layoutvoffset%
383   \advance\topmargin\Gm@layouthoffset%
384   \addtolength\Gm@layoutheight{\Gm@bindingoffset}%
385 }% end of \Gm@@process
386
387 % log
388 \def\Gm@logcontent#1{%
389   *geometry* verbose mode - [ #1 ] result:^^J%
390   \ifGm@pass * pass: disregarded the geometry package!^^J%
391   \else
392   * driver: \if\Gm@driver<none>\else\Gm@driver\fi^^J%
393   * paper: \ifx\Gm@paper\@undefined<default>\else\Gm@paper\fi^^J%
394   * layout: \ifGm@layout<custom>\else<same size as paper>\fi^^J%
395   \ifGm@layout
396   * layout(width,height): (\the\Gm@layoutwidth,\the\Gm@layoutheight)^^J%
397   \fi
398   * layoutoffset:(h,v)=(\the\Gm@layouthoffset,\the\Gm@layoutvoffset)^^J%
399   \@ifundefined{Gm@lines}{}{* lines: \Gm@lines^^J}%
400   \@ifundefined{Gm@hmarginratio}{}{* hratio: \Gm@hmarginratio^^J}%
401   \@ifundefined{Gm@vmarginratio}{}{* vratio: \Gm@vmarginratio^^J}%
402   \ifdim\Gm@bindingoffset=\z@\else
403   * bindingoffset: \the\Gm@bindingoffset^^J\fi
404   * modes: %
405    \Gm@showbool{landscape}%
406    \Gm@showbool{includehead}%
407    \Gm@showbool{includefoot}%
408    \Gm@showbool{includemp}%
409    \if@twoside twoside\space\fi%
410    \ifGm@ltj@layoutswitch\else\if@twoside asymmetric\space\fi\fi%
411    \Gm@showbool{heightrounded}%
412    \ifx\Gm@truedimen\@empty\else truedimen\space\fi%
413    \Gm@showbool{showframe}%
414    \Gm@showbool{showcrop}%
415   ^^J%
416   * h-part:(L,W,R)=(\Gm@lmargin, \Gm@height, \Gm@rmargin)^^J%
417   * v-part:(T,H,B)=(\Gm@tmargin, \Gm@width, \Gm@bmargin)^^J%
418   \fi
419   \Gm@showdim{\paperwidth}%
420   \Gm@showdim{\paperheight}%
421   \Gm@showdim{\textwidth}%
422   \Gm@showdim{\textheight}%
423   \Gm@showdim{\oddsidemargin}%
424   \Gm@showdim{\evensidemargin}%
425   \Gm@showdim{\topmargin}%
426   \Gm@showdim{\headheight}%
427   \Gm@showdim{\headsep}%
428   \Gm@showdim{\topskip}%
429   \Gm@showdim{\footskip}%
430   \Gm@showdim{\marginparwidth}%
431   \Gm@showdim{\marginparsep}%
432   \Gm@showdim{\columnsep}%
433   * \string\skip\string\footins=\the\skip\footins^^J%
434   \Gm@showdim{\hoffset}%
435   \Gm@showdim{\voffset}%
436   \Gm@showdim{\mag}%
437   * \string\@twocolumn\if@twocolumn true\else false\fi^^J%
438   * \string\@twoside\if@twoside true\else false\fi^^J%
439   * \string\@mparswitch\if@mparswitch true\else false\fi^^J%
440   * \string\@reversemargin\if@reversemargin true\else false\fi^^J%
441   * (1in=72.27pt=25.4mm, 1cm=28.453pt)^^J}%
442
443
444 \Gm@initall
445 \Gm@processconfig
446 \ProcessOptionsKV[c]{Gm}%
447 \Gm@setdefaultpaper
448 \ProcessOptionsKV[p]{Gm}%
449 \Gm@process
450 \fi}
451 \endinput