OSDN Git Service

ebe3e84cf022cf71926c280a13f7320aedd063a1
[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/22 Patch to geometry for LuaTeX-ja with vertical writing mode]
7 \RequirePackage{luatexja}
8 \RequirePackage{filehook}
9
10 \AtEndOfPackageFile{geometry}{%
11 \ifnum\ltjgetparameter{direction}=3%
12 \define@key{Gm}{hdivide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}}%
13 \define@key{Gm}{vdivide}{\Gm@parse@divide{#1}{rmargin}{height}{lmargin}}%
14 \define@key{Gm}{divide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}%
15   \Gm@parse@divide{#1}{rmargin}{height}{lmargin}}%
16 \define@key{Gm}{hmargin}{\Gm@branch{#1}{tmargin}{bmargin}}%
17 \define@key{Gm}{vmargin}{\Gm@branch{#1}{rmargin}{lmargin}}%
18 \define@key{Gm}{margin}{\Gm@branch{#1}{tmargin}{rmargin}%
19   \Gm@branch{#1}{bmargin}{lmargin}}%
20 \def\Gm@detall#1#2#3#4{%
21   \@tempcnta\z@
22   \if#1h
23     \let\Gm@mratio\Gm@hmarginratio
24     \edef\Gm@Dmratio{\if@twoside\Gm@Dhratiotwo\else\Gm@Dhratio\fi}%
25   \else
26     \let\Gm@mratio\Gm@vmarginratio
27     \edef\Gm@Dmratio{\Gm@Dvratio}%
28   \fi
29   \if#1h
30     \ifx\Gm@tmargin\@undefined\else\advance\@tempcnta4\relax\fi
31     \ifGm@hbody\advance\@tempcnta2\relax\fi
32     \ifx\Gm@bmargin\@undefined\else\advance\@tempcnta1\relax\fi
33     \Gm@cnth\@tempcnta
34   \else
35     \ifx\Gm@rmargin\@undefined\else\advance\@tempcnta4\relax\fi
36     \ifGm@vbody\advance\@tempcnta2\relax\fi
37     \ifx\Gm@lmargin\@undefined\else\advance\@tempcnta1\relax\fi
38     \Gm@cntv\@tempcnta
39   \fi
40   \ifcase\@tempcnta
41     \if#1h
42       \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
43     \else
44       \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
45     \fi
46     \Gm@detiiandiii{#2}{#3}{#4}%
47   \or
48     \ifx\Gm@mratio\@undefined
49       \if#1h
50         \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
51       \else
52         \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
53       \fi
54       \setlength\@tempdimc{\@nameuse{Gm@#4}}%
55       \Gm@detiiandiii{#2}{#3}{#4}%
56       \expandafter\let\csname Gm@#2\endcsname\@undefined
57       \Gm@defbylen{#4}{\@tempdimc}%
58     \else
59       \Gm@setbyratio[f]{#1}{#4}{#3}%
60     \fi
61     \Gm@detiv{#2}{#3}{#4}{#2}%
62   \or\Gm@detiiandiii{#2}{#3}{#4}%
63   \or\Gm@detiv{#2}{#2}{#4}{#3}%
64   \or
65     \ifx\Gm@mratio\@undefined
66       \if#1h
67         \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
68       \else
69         \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
70       \fi
71       \setlength\@tempdimc{\@nameuse{Gm@#3}}%
72       \Gm@detiiandiii{#2}{#4}{#3}%
73       \expandafter\let\csname Gm@#2\endcsname\@undefined
74       \Gm@defbylen{#3}{\@tempdimc}%
75     \else
76       \Gm@setbyratio[b]{#1}{#3}{#4}%
77     \fi
78     \Gm@detiv{#2}{#3}{#4}{#2}%
79   \or\Gm@detiv{#2}{#3}{#4}{#2}%
80   \or\Gm@detiv{#2}{#2}{#3}{#4}%
81   \or\Gm@warning{Over-specification in `#1'-direction.%
82                   ^^J\@spaces `#2' (\@nameuse{Gm@#2}) is ignored}%
83     \Gm@detiv{#2}{#3}{#4}{#2}%
84   \else\fi}%
85 \def\Gm@clean{%
86   \ifnum\Gm@cnth<4\let\Gm@tmargin\@undefined\fi
87   \ifodd\Gm@cnth\else\let\Gm@bmargin\@undefined\fi
88   \ifnum\Gm@cntv<4\let\Gm@rmargin\@undefined\fi
89   \ifodd\Gm@cntv\else\let\Gm@lmargin\@undefined\fi
90   \ifGm@hbody\else
91     \let\Gm@hscale\@undefined
92     \let\Gm@width\@undefined
93     \let\Gm@textwidth\@undefined
94   \fi
95   \ifGm@vbody\else
96     \let\Gm@vscale\@undefined
97     \let\Gm@height\@undefined
98     \let\Gm@textheight\@undefined
99   \fi
100   }%
101 \def\Gm@adjustpaper{%
102   \ifdim\paperwidth>\p@\else
103     \PackageError{geometry}{%
104     \string\paperwidth\space(\the\paperwidth) too short}{%
105     Set a paper type (e.g., `a4paper').}%
106   \fi
107   \ifdim\paperheight>\p@\else
108     \PackageError{geometry}{%
109     \string\paperheight\space(\the\paperheight) too short}{%
110     Set a paper type (e.g., `a4paper').}%
111   \fi
112   \ifGm@swap@papersize
113     \setlength\@tempdima{\paperwidth}%
114     \setlength\paperwidth{\paperheight}%
115     \setlength\paperheight{\@tempdima}%
116   \fi
117   \ifGm@layout\else
118     \setlength\Gm@layoutwidth{\paperheight}%
119     \setlength\Gm@layoutheight{\paperwidth}%
120   \fi}%
121 \def\Gm@adjustbody{
122   \ifGm@hbody
123     \ifx\Gm@width\@undefined
124       \ifx\Gm@hscale\@undefined
125         \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
126       \else
127         \Gm@defbylen{width}{\Gm@hscale\Gm@layoutwidth}%
128       \fi
129     \fi
130     \ifx\Gm@textwidth\@undefined\else
131       \setlength\@tempdima{\Gm@textwidth}%
132       \ifGm@includemp
133         \advance\@tempdima\Gm@wd@mp
134       \fi
135       \ifGm@includehead
136         \addtolength\@tempdima{\headheight}%
137         \addtolength\@tempdima{\headsep}%
138       \fi
139       \ifGm@includefoot
140         \addtolength\@tempdima{\footskip}%
141       \fi
142       \edef\Gm@width{\the\@tempdima}%
143     \fi
144   \fi
145   \ifGm@vbody
146     \ifx\Gm@height\@undefined
147       \ifx\Gm@vscale\@undefined
148         \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
149       \else
150         \Gm@defbylen{height}{\Gm@vscale\Gm@layoutheight}%
151       \fi
152     \fi
153     \ifx\Gm@lines\@undefined\else
154       \ifdim\topskip<\ht\strutbox
155         \setlength\@tempdima{\topskip}%
156         \setlength\topskip{\ht\strutbox}%
157         \Gm@warning{\noexpand\topskip was changed from \the\@tempdima\space
158         to \the\topskip}%
159       \fi
160       \setlength\@tempdima{\baselineskip}%
161       \multiply\@tempdima\Gm@lines
162       \addtolength\@tempdima{\topskip}%
163       \addtolength\@tempdima{-\baselineskip}%
164       \edef\Gm@textheight{\the\@tempdima}%
165     \fi
166     \ifx\Gm@textheight\@undefined\else
167       \edef\Gm@height{\the\textheight}%
168     \fi
169   \fi}%
170 \def\Gm@@process{%
171   \Gm@expandlengths
172   \Gm@adjustpaper
173   \addtolength\Gm@layoutwidth{-\Gm@bindingoffset}%
174   \Gm@adjustmp
175   \Gm@adjustbody
176   \Gm@detall{h}{width}{tmargin}{bmargin}%
177   \Gm@detall{v}{height}{rmargin}{lmargin}%
178   \setlength\textwidth{\Gm@width}%
179   \setlength\textheight{\Gm@height}%
180   \setlength\topmargin{\Gm@tmargin}%
181   \setlength\oddsidemargin{\Gm@lmargin}%
182   \addtolength\oddsidemargin{-1\Gm@truedimen in}%
183   \ifGm@includemp
184     \advance\textheight-\Gm@wd@mp
185     \advance\oddsidemargin\Gm@odd@mp
186   \fi
187   \if@mparswitch
188     \setlength\evensidemargin{\Gm@rmargin}%
189     \addtolength\evensidemargin{-1\Gm@truedimen in}%
190     \ifGm@includemp
191       \advance\evensidemargin\Gm@even@mp
192     \fi
193   \else
194     \evensidemargin\oddsidemargin
195   \fi
196   \advance\oddsidemargin\Gm@bindingoffset
197   \addtolength\topmargin{-1\Gm@truedimen in}%
198   \ifGm@includehead
199     \addtolength\textwidth{-\headheight}%
200     \addtolength\textwidth{-\headsep}%
201   \else
202     \addtolength\topmargin{-\headheight}%
203     \addtolength\topmargin{-\headsep}%
204   \fi
205   \ifGm@includefoot
206     \addtolength\textwidth{-\footskip}%
207   \fi
208   \ifGm@heightrounded
209     \setlength\@tempdima{\textheight}%
210     \addtolength\@tempdima{-\topskip}%
211     \@tempcnta\@tempdima
212     \@tempcntb\baselineskip
213     \divide\@tempcnta\@tempcntb
214     \setlength\@tempdimb{\baselineskip}%
215     \multiply\@tempdimb\@tempcnta
216     \advance\@tempdima-\@tempdimb
217     \multiply\@tempdima\tw@
218     \ifdim\@tempdima>\baselineskip
219       \addtolength\@tempdimb{\baselineskip}%
220     \fi
221     \addtolength\@tempdimb{\topskip}%
222     \textheight\@tempdimb
223   \fi
224   \advance\oddsidemargin\Gm@layoutvoffset%
225   \advance\evensidemargin\Gm@layoutvoffset%
226   \advance\topmargin\Gm@layouthoffset%
227   \addtolength\Gm@layoutheight{\Gm@bindingoffset}%
228 }% end of \Gm@@process
229 \Gm@initall
230 \Gm@processconfig
231 \ProcessOptionsKV[c]{Gm}%
232 \Gm@setdefaultpaper
233 \ProcessOptionsKV[p]{Gm}%
234 \Gm@process
235 \fi}
236 \endinput