5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{lltjp-geometry}[2014/11/23 Patch to geometry for LuaTeX-ja with vertical writing mode]
7 \RequirePackage{ifluatex}
9 \newif\if@ltj@@geometry@tate
10 \@ltj@@geometry@tatefalse
12 \@ltj@@geometry@tatetrue
14 \global \setbox \@begindvibox
15 \vbox{\yoko\unvbox \@begindvibox #1}%
19 \RequirePackage{filehook}
22 \AtEndOfPackageFile{geometry}{%
24 \ifnum\ltjgetparameter{direction}=3 \@ltj@@geometry@tatetrue\fi
26 \typeout{\meaning\if@ltj@@geometry@tate}
27 \if@ltj@@geometry@tate
28 \define@key{Gm}{hdivide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}}%
29 \define@key{Gm}{vdivide}{\Gm@parse@divide{#1}{rmargin}{height}{lmargin}}%
30 \define@key{Gm}{divide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}%
31 \Gm@parse@divide{#1}{rmargin}{height}{lmargin}}%
32 \define@key{Gm}{hmargin}{\Gm@branch{#1}{tmargin}{bmargin}}%
33 \define@key{Gm}{vmargin}{\Gm@branch{#1}{rmargin}{lmargin}}%
34 \define@key{Gm}{margin}{\Gm@branch{#1}{tmargin}{rmargin}%
35 \Gm@branch{#1}{bmargin}{lmargin}}%
36 \def\Gm@detall#1#2#3#4{%
39 \let\Gm@mratio\Gm@hmarginratio
40 \edef\Gm@Dmratio{\if@twoside\Gm@Dhratiotwo\else\Gm@Dhratio\fi}%
42 \let\Gm@mratio\Gm@vmarginratio
43 \edef\Gm@Dmratio{\Gm@Dvratio}%
46 \ifx\Gm@tmargin\@undefined\else\advance\@tempcnta4\relax\fi
47 \ifGm@hbody\advance\@tempcnta2\relax\fi
48 \ifx\Gm@bmargin\@undefined\else\advance\@tempcnta1\relax\fi
51 \ifx\Gm@rmargin\@undefined\else\advance\@tempcnta4\relax\fi
52 \ifGm@vbody\advance\@tempcnta2\relax\fi
53 \ifx\Gm@lmargin\@undefined\else\advance\@tempcnta1\relax\fi
58 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
60 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
62 \Gm@detiiandiii{#2}{#3}{#4}%
64 \ifx\Gm@mratio\@undefined
66 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
68 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
70 \setlength\@tempdimc{\@nameuse{Gm@#4}}%
71 \Gm@detiiandiii{#2}{#3}{#4}%
72 \expandafter\let\csname Gm@#2\endcsname\@undefined
73 \Gm@defbylen{#4}{\@tempdimc}%
75 \Gm@setbyratio[f]{#1}{#4}{#3}%
77 \Gm@detiv{#2}{#3}{#4}{#2}%
78 \or\Gm@detiiandiii{#2}{#3}{#4}%
79 \or\Gm@detiv{#2}{#2}{#4}{#3}%
81 \ifx\Gm@mratio\@undefined
83 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
85 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
87 \setlength\@tempdimc{\@nameuse{Gm@#3}}%
88 \Gm@detiiandiii{#2}{#4}{#3}%
89 \expandafter\let\csname Gm@#2\endcsname\@undefined
90 \Gm@defbylen{#3}{\@tempdimc}%
92 \Gm@setbyratio[b]{#1}{#3}{#4}%
94 \Gm@detiv{#2}{#3}{#4}{#2}%
95 \or\Gm@detiv{#2}{#3}{#4}{#2}%
96 \or\Gm@detiv{#2}{#2}{#3}{#4}%
97 \or\Gm@warning{Over-specification in `#1'-direction.%
98 ^^J\@spaces `#2' (\@nameuse{Gm@#2}) is ignored}%
99 \Gm@detiv{#2}{#3}{#4}{#2}%
102 \ifnum\Gm@cnth<4\let\Gm@tmargin\@undefined\fi
103 \ifodd\Gm@cnth\else\let\Gm@bmargin\@undefined\fi
104 \ifnum\Gm@cntv<4\let\Gm@rmargin\@undefined\fi
105 \ifodd\Gm@cntv\else\let\Gm@lmargin\@undefined\fi
107 \let\Gm@hscale\@undefined
108 \let\Gm@width\@undefined
109 \let\Gm@textwidth\@undefined
112 \let\Gm@vscale\@undefined
113 \let\Gm@height\@undefined
114 \let\Gm@textheight\@undefined
117 \def\Gm@adjustpaper{%
118 \ifdim\paperwidth>\p@\else
119 \PackageError{geometry}{%
120 \string\paperwidth\space(\the\paperwidth) too short}{%
121 Set a paper type (e.g., `a4paper').}%
123 \ifdim\paperheight>\p@\else
124 \PackageError{geometry}{%
125 \string\paperheight\space(\the\paperheight) too short}{%
126 Set a paper type (e.g., `a4paper').}%
129 \setlength\@tempdima{\paperwidth}%
130 \setlength\paperwidth{\paperheight}%
131 \setlength\paperheight{\@tempdima}%
134 \setlength\Gm@layoutwidth{\paperheight}%
135 \setlength\Gm@layoutheight{\paperwidth}%
139 \ifx\Gm@width\@undefined
140 \ifx\Gm@hscale\@undefined
141 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
143 \Gm@defbylen{width}{\Gm@hscale\Gm@layoutwidth}%
146 \ifx\Gm@textwidth\@undefined\else
147 \setlength\@tempdima{\Gm@textwidth}%
149 \advance\@tempdima\Gm@wd@mp
152 \addtolength\@tempdima{\headheight}%
153 \addtolength\@tempdima{\headsep}%
156 \addtolength\@tempdima{\footskip}%
158 \edef\Gm@width{\the\@tempdima}%
162 \ifx\Gm@height\@undefined
163 \ifx\Gm@vscale\@undefined
164 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
166 \Gm@defbylen{height}{\Gm@vscale\Gm@layoutheight}%
169 \ifx\Gm@lines\@undefined\else
170 \setlength\maxdepth{1\Cht}%
171 \setlength\topskip{.5\maxdepth}%
172 \ifdim\topskip<\ht\tstrutbox
173 \setlength\@tempdima{\topskip}%
174 \setlength\topskip{\ht\tstrutbox}%
175 \Gm@warning{\noexpand\topskip was changed from \the\@tempdima\space
178 \setlength\@tempdima{\baselineskip}%
179 \multiply\@tempdima\Gm@lines
180 \addtolength\@tempdima{\topskip}%
181 \addtolength\@tempdima{-\baselineskip}%
182 \edef\Gm@textheight{\the\@tempdima}%
184 \ifx\Gm@textheight\@undefined\else
185 \edef\Gm@height{\Gm@textheight}%
191 \addtolength\Gm@layoutwidth{-\Gm@bindingoffset}%
194 \Gm@detall{h}{width}{tmargin}{bmargin}%
195 \Gm@detall{v}{height}{rmargin}{lmargin}%
196 \setlength\textwidth{\Gm@width}%
197 \setlength\textheight{\Gm@height}%
198 \setlength\topmargin{\Gm@tmargin}%
199 \setlength\oddsidemargin{\Gm@lmargin}%
200 \addtolength\oddsidemargin{-1\Gm@truedimen in}%
202 \advance\textheight-\Gm@wd@mp
203 \advance\oddsidemargin\Gm@odd@mp
206 \setlength\evensidemargin{\Gm@rmargin}%
207 \addtolength\evensidemargin{-1\Gm@truedimen in}%
209 \advance\evensidemargin\Gm@even@mp
212 \evensidemargin\oddsidemargin
214 \advance\oddsidemargin\Gm@bindingoffset
215 \addtolength\topmargin{-1\Gm@truedimen in}%
217 \addtolength\textwidth{-\headheight}%
218 \addtolength\textwidth{-\headsep}%
220 \addtolength\topmargin{-\headheight}%
221 \addtolength\topmargin{-\headsep}%
224 \addtolength\textwidth{-\footskip}%
227 \setlength\@tempdima{\textheight}%
228 \addtolength\@tempdima{-\topskip}%
230 \@tempcntb\baselineskip
231 \divide\@tempcnta\@tempcntb
232 \setlength\@tempdimb{\baselineskip}%
233 \multiply\@tempdimb\@tempcnta
234 \advance\@tempdima-\@tempdimb
235 \multiply\@tempdima\tw@
236 \ifdim\@tempdima>\baselineskip
237 \addtolength\@tempdimb{\baselineskip}%
239 \addtolength\@tempdimb{\topskip}%
240 \textheight\@tempdimb
242 \advance\oddsidemargin\Gm@layoutvoffset%
243 \advance\evensidemargin\Gm@layoutvoffset%
244 \advance\topmargin\Gm@layouthoffset%
245 \addtolength\Gm@layoutheight{\Gm@bindingoffset}%
246 }% end of \Gm@@process
249 \ProcessOptionsKV[c]{Gm}%
251 \ProcessOptionsKV[p]{Gm}%