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}
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}{lmargin}{width}{rmargin}%
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{%
23 \let\Gm@mratio\Gm@hmarginratio
24 \edef\Gm@Dmratio{\if@twoside\Gm@Dhratiotwo\else\Gm@Dhratio\fi}%
26 \let\Gm@mratio\Gm@vmarginratio
27 \edef\Gm@Dmratio{\Gm@Dvratio}%
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
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
42 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
44 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
46 \Gm@detiiandiii{#2}{#3}{#4}%
48 \ifx\Gm@mratio\@undefined
50 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
52 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
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}%
59 \Gm@setbyratio[f]{#1}{#4}{#3}%
61 \Gm@detiv{#2}{#3}{#4}{#2}%
62 \or\Gm@detiiandiii{#2}{#3}{#4}%
63 \or\Gm@detiv{#2}{#2}{#4}{#3}%
65 \ifx\Gm@mratio\@undefined
67 \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
69 \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
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}%
76 \Gm@setbyratio[b]{#1}{#3}{#4}%
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}%
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
91 \let\Gm@hscale\@undefined
92 \let\Gm@width\@undefined
93 \let\Gm@textwidth\@undefined
96 \let\Gm@vscale\@undefined
97 \let\Gm@height\@undefined
98 \let\Gm@textheight\@undefined
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').}%
107 \ifdim\paperheight>\p@\else
108 \PackageError{geometry}{%
109 \string\paperheight\space(\the\paperheight) too short}{%
110 Set a paper type (e.g., `a4paper').}%
113 \setlength\@tempdima{\paperwidth}%
114 \setlength\paperwidth{\paperheight}%
115 \setlength\paperheight{\@tempdima}%
118 \setlength\Gm@layoutwidth{\paperheight}%
119 \setlength\Gm@layoutheight{\paperwidth}%
124 \addtolength\Gm@layoutwidth{-\Gm@bindingoffset}%
127 \Gm@detall{h}{width}{tmargin}{bmargin}%
128 \Gm@detall{v}{height}{rmargin}{lmargin}%
129 \setlength\textwidth{\Gm@width}%
130 \setlength\textheight{\Gm@height}%
131 \setlength\topmargin{\Gm@tmargin}%
132 \setlength\oddsidemargin{\Gm@lmargin}%
133 \addtolength\oddsidemargin{-1\Gm@truedimen in}%
135 \advance\textheight-\Gm@wd@mp
136 \advance\oddsidemargin\Gm@odd@mp
139 \setlength\evensidemargin{\Gm@rmargin}%
140 \addtolength\evensidemargin{-1\Gm@truedimen in}%
142 \advance\evensidemargin\Gm@even@mp
145 \evensidemargin\oddsidemargin
147 \advance\oddsidemargin\Gm@bindingoffset
148 \addtolength\topmargin{-1\Gm@truedimen in}%
150 \addtolength\textwidth{-\headheight}%
151 \addtolength\textwidth{-\headsep}%
153 \addtolength\topmargin{-\headheight}%
154 \addtolength\topmargin{-\headsep}%
157 \addtolength\textwidth{-\footskip}%
160 \setlength\@tempdima{\textheight}%
161 \addtolength\@tempdima{-\topskip}%
163 \@tempcntb\baselineskip
164 \divide\@tempcnta\@tempcntb
165 \setlength\@tempdimb{\baselineskip}%
166 \multiply\@tempdimb\@tempcnta
167 \advance\@tempdima-\@tempdimb
168 \multiply\@tempdima\tw@
169 \ifdim\@tempdima>\baselineskip
170 \addtolength\@tempdimb{\baselineskip}%
172 \addtolength\@tempdimb{\topskip}%
173 \textheight\@tempdimb
175 \advance\oddsidemargin\Gm@layoutvoffset%
176 \advance\evensidemargin\Gm@layoutvoffset%
177 \advance\topmargin\Gm@layouthoffset%
178 \addtolength\Gm@layoutheight{\Gm@bindingoffset}%
179 }% end of \Gm@@process
182 \ProcessOptionsKV[c]{Gm}%
184 \ProcessOptionsKV[p]{Gm}%