5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{lltjp-geometry}[2014/11/23 Patch to geometry for LuaTeX-ja with vertical writing mode]
7 \RequirePackage{ifluatex}
9 \newdimen\ltj@@geometry@topskip@backup
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}
22 \AtBeginOfPackageFile{geometry}{%
23 \ltj@@geometry@topskip@backup=\topskip
25 \AtEndOfPackageFile{geometry}{%
27 \ifnum\ltjgetparameter{direction}=3 \@ltj@@geometry@tatetrue\fi
29 \if@ltj@@geometry@tate
30 \define@key{Gm}{hdivide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}}%
31 \define@key{Gm}{vdivide}{\Gm@parse@divide{#1}{rmargin}{height}{lmargin}}%
32 \define@key{Gm}{divide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}%
33 \Gm@parse@divide{#1}{rmargin}{height}{lmargin}}%
34 \define@key{Gm}{hmargin}{\Gm@branch{#1}{tmargin}{bmargin}}%
35 \define@key{Gm}{vmargin}{\Gm@branch{#1}{rmargin}{lmargin}}%
36 \define@key{Gm}{margin}{\Gm@branch{#1}{tmargin}{rmargin}%
37 \Gm@branch{#1}{bmargin}{lmargin}}%
38 \def\Gm@detall#1#2#3#4{%
41 \let\Gm@mratio\Gm@hmarginratio
42 \edef\Gm@Dmratio{\if@twoside\Gm@Dhratiotwo\else\Gm@Dhratio\fi}%
44 \let\Gm@mratio\Gm@vmarginratio
45 \edef\Gm@Dmratio{\Gm@Dvratio}%
48 \ifx\Gm@tmargin\@undefined\else\advance\@tempcnta4\relax\fi
49 \ifGm@hbody\advance\@tempcnta2\relax\fi
50 \ifx\Gm@bmargin\@undefined\else\advance\@tempcnta1\relax\fi
53 \ifx\Gm@rmargin\@undefined\else\advance\@tempcnta4\relax\fi
54 \ifGm@vbody\advance\@tempcnta2\relax\fi
55 \ifx\Gm@lmargin\@undefined\else\advance\@tempcnta1\relax\fi
60 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
62 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
64 \Gm@detiiandiii{#2}{#3}{#4}%
66 \ifx\Gm@mratio\@undefined
68 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
70 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
72 \setlength\@tempdimc{\@nameuse{Gm@#4}}%
73 \Gm@detiiandiii{#2}{#3}{#4}%
74 \expandafter\let\csname Gm@#2\endcsname\@undefined
75 \Gm@defbylen{#4}{\@tempdimc}%
77 \Gm@setbyratio[f]{#1}{#4}{#3}%
79 \Gm@detiv{#2}{#3}{#4}{#2}%
80 \or\Gm@detiiandiii{#2}{#3}{#4}%
81 \or\Gm@detiv{#2}{#2}{#4}{#3}%
83 \ifx\Gm@mratio\@undefined
85 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
87 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
89 \setlength\@tempdimc{\@nameuse{Gm@#3}}%
90 \Gm@detiiandiii{#2}{#4}{#3}%
91 \expandafter\let\csname Gm@#2\endcsname\@undefined
92 \Gm@defbylen{#3}{\@tempdimc}%
94 \Gm@setbyratio[b]{#1}{#3}{#4}%
96 \Gm@detiv{#2}{#3}{#4}{#2}%
97 \or\Gm@detiv{#2}{#3}{#4}{#2}%
98 \or\Gm@detiv{#2}{#2}{#3}{#4}%
99 \or\Gm@warning{Over-specification in `#1'-direction.%
100 ^^J\@spaces `#2' (\@nameuse{Gm@#2}) is ignored}%
101 \Gm@detiv{#2}{#3}{#4}{#2}%
104 \ifnum\Gm@cnth<4\let\Gm@tmargin\@undefined\fi
105 \ifodd\Gm@cnth\else\let\Gm@bmargin\@undefined\fi
106 \ifnum\Gm@cntv<4\let\Gm@rmargin\@undefined\fi
107 \ifodd\Gm@cntv\else\let\Gm@lmargin\@undefined\fi
109 \let\Gm@hscale\@undefined
110 \let\Gm@width\@undefined
111 \let\Gm@textwidth\@undefined
114 \let\Gm@vscale\@undefined
115 \let\Gm@height\@undefined
116 \let\Gm@textheight\@undefined
119 \def\Gm@adjustpaper{%
120 \ifdim\paperwidth>\p@\else
121 \PackageError{geometry}{%
122 \string\paperwidth\space(\the\paperwidth) too short}{%
123 Set a paper type (e.g., `a4paper').}%
125 \ifdim\paperheight>\p@\else
126 \PackageError{geometry}{%
127 \string\paperheight\space(\the\paperheight) too short}{%
128 Set a paper type (e.g., `a4paper').}%
131 \setlength\@tempdima{\paperwidth}%
132 \setlength\paperwidth{\paperheight}%
133 \setlength\paperheight{\@tempdima}%
136 \setlength\Gm@layoutwidth{\paperheight}%
137 \setlength\Gm@layoutheight{\paperwidth}%
141 \ifx\Gm@width\@undefined
142 \ifx\Gm@hscale\@undefined
143 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
145 \Gm@defbylen{width}{\Gm@hscale\Gm@layoutwidth}%
148 \ifx\Gm@textwidth\@undefined\else
149 \setlength\@tempdima{\Gm@textwidth}%
151 \advance\@tempdima\Gm@wd@mp
154 \addtolength\@tempdima{\headheight}%
155 \addtolength\@tempdima{\headsep}%
158 \addtolength\@tempdima{\footskip}%
160 \edef\Gm@width{\the\@tempdima}%
164 \ifx\Gm@height\@undefined
165 \ifx\Gm@vscale\@undefined
166 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
168 \Gm@defbylen{height}{\Gm@vscale\Gm@layoutheight}%
171 \setlength\topskip\ltj@@geometry@topskip@backup
172 \ifx\Gm@lines\@undefined\else
173 \setlength\maxdepth{1\Cht}%
174 \setbox\z@=\hbox{\tate% next \ifdim must be executed in tate dir.
175 \ifdim\topskip<\ht\tstrutbox
177 \global\topskip\ht\tstrutbox
178 \PackageWarningNoLine{lltjp-geometry}%
179 {do not worry about `\noexpand\topskip was changed ...'\MessageBreak
181 \PackageWarningNoLine{lltjp-geometry}%
182 {\noexpand\topskip was changed from \the\@tempdima\space
185 \setlength\@tempdima{\baselineskip}%
186 \multiply\@tempdima\Gm@lines
187 \addtolength\@tempdima{\topskip}%
188 \addtolength\@tempdima{-\baselineskip}%
189 \edef\Gm@textheight{\the\@tempdima}%
191 \ifx\Gm@textheight\@undefined\else
192 \edef\Gm@height{\Gm@textheight}%
198 \addtolength\Gm@layoutwidth{-\Gm@bindingoffset}%
201 \Gm@detall{h}{width}{tmargin}{bmargin}%
202 \Gm@detall{v}{height}{rmargin}{lmargin}%
203 \setlength\textwidth{\Gm@width}%
204 \setlength\textheight{\Gm@height}%
205 \setlength\topmargin{\Gm@tmargin}%
206 \setlength\oddsidemargin{\Gm@lmargin}%
207 \addtolength\oddsidemargin{-1\Gm@truedimen in}%
209 \advance\textheight-\Gm@wd@mp
210 \advance\oddsidemargin\Gm@odd@mp
213 \setlength\evensidemargin{\Gm@rmargin}%
214 \addtolength\evensidemargin{-1\Gm@truedimen in}%
216 \advance\evensidemargin\Gm@even@mp
219 \evensidemargin\oddsidemargin
221 \advance\oddsidemargin\Gm@bindingoffset
222 \addtolength\topmargin{-1\Gm@truedimen in}%
224 \addtolength\textwidth{-\headheight}%
225 \addtolength\textwidth{-\headsep}%
227 \addtolength\topmargin{-\headheight}%
228 \addtolength\topmargin{-\headsep}%
231 \addtolength\textwidth{-\footskip}%
234 \setlength\@tempdima{\textheight}%
235 \addtolength\@tempdima{-\topskip}%
237 \@tempcntb\baselineskip
238 \divide\@tempcnta\@tempcntb
239 \setlength\@tempdimb{\baselineskip}%
240 \multiply\@tempdimb\@tempcnta
241 \advance\@tempdima-\@tempdimb
242 \multiply\@tempdima\tw@
243 \ifdim\@tempdima>\baselineskip
244 \addtolength\@tempdimb{\baselineskip}%
246 \addtolength\@tempdimb{\topskip}%
247 \textheight\@tempdimb
249 \advance\oddsidemargin\Gm@layoutvoffset%
250 \advance\evensidemargin\Gm@layoutvoffset%
251 \advance\topmargin\Gm@layouthoffset%
252 \addtolength\Gm@layoutheight{\Gm@bindingoffset}%
253 }% end of \Gm@@process
256 \ProcessOptionsKV[c]{Gm}%
258 \ProcessOptionsKV[p]{Gm}%