OSDN Git Service

Improved the patch for [t]ascmac.sty.
[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 \newdimen\ltj@@geometry@topskip@backup
10 \newif\if@ltj@@geometry@tate
11 \@ltj@@geometry@tatefalse
12 \ifluatex\else % pTeX
13   \@ltj@@geometry@tatetrue
14 \def \AtBeginDvi #1{%
15   \global \setbox \@begindvibox
16     \vbox{\yoko\unvbox \@begindvibox #1}%
17 }
18 \fi
19
20 \RequirePackage{filehook}
21
22 \AtBeginOfPackageFile{geometry}{%
23   \ltj@@geometry@topskip@backup=\topskip
24 }
25 \AtEndOfPackageFile{geometry}{%
26 \ifluatex
27   \ifnum\ltjgetparameter{direction}=3 \@ltj@@geometry@tatetrue\fi
28 \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{%
39   \@tempcnta\z@
40   \if#1h
41     \let\Gm@mratio\Gm@hmarginratio
42     \edef\Gm@Dmratio{\if@twoside\Gm@Dhratiotwo\else\Gm@Dhratio\fi}%
43   \else
44     \let\Gm@mratio\Gm@vmarginratio
45     \edef\Gm@Dmratio{\Gm@Dvratio}%
46   \fi
47   \if#1h
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
51     \Gm@cnth\@tempcnta
52   \else
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
56     \Gm@cntv\@tempcnta
57   \fi
58   \ifcase\@tempcnta
59     \if#1h
60       \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
61     \else
62       \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
63     \fi
64     \Gm@detiiandiii{#2}{#3}{#4}%
65   \or
66     \ifx\Gm@mratio\@undefined
67       \if#1h
68         \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
69       \else
70         \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
71       \fi
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}%
76     \else
77       \Gm@setbyratio[f]{#1}{#4}{#3}%
78     \fi
79     \Gm@detiv{#2}{#3}{#4}{#2}%
80   \or\Gm@detiiandiii{#2}{#3}{#4}%
81   \or\Gm@detiv{#2}{#2}{#4}{#3}%
82   \or
83     \ifx\Gm@mratio\@undefined
84       \if#1h
85         \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
86       \else
87         \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
88       \fi
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}%
93     \else
94       \Gm@setbyratio[b]{#1}{#3}{#4}%
95     \fi
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}%
102   \else\fi}%
103 \def\Gm@clean{%
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
108   \ifGm@hbody\else
109     \let\Gm@hscale\@undefined
110     \let\Gm@width\@undefined
111     \let\Gm@textwidth\@undefined
112   \fi
113   \ifGm@vbody\else
114     \let\Gm@vscale\@undefined
115     \let\Gm@height\@undefined
116     \let\Gm@textheight\@undefined
117   \fi
118   }%
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').}%
124   \fi
125   \ifdim\paperheight>\p@\else
126     \PackageError{geometry}{%
127     \string\paperheight\space(\the\paperheight) too short}{%
128     Set a paper type (e.g., `a4paper').}%
129   \fi
130   \ifGm@swap@papersize
131     \setlength\@tempdima{\paperwidth}%
132     \setlength\paperwidth{\paperheight}%
133     \setlength\paperheight{\@tempdima}%
134   \fi
135   \ifGm@layout\else
136     \setlength\Gm@layoutwidth{\paperheight}%
137     \setlength\Gm@layoutheight{\paperwidth}%
138   \fi}%
139 \def\Gm@adjustbody{
140   \ifGm@hbody
141     \ifx\Gm@width\@undefined
142       \ifx\Gm@hscale\@undefined
143         \Gm@defbylen{width}{\Gm@Dhscale\Gm@layoutwidth}%
144       \else
145         \Gm@defbylen{width}{\Gm@hscale\Gm@layoutwidth}%
146       \fi
147     \fi
148     \ifx\Gm@textwidth\@undefined\else
149       \setlength\@tempdima{\Gm@textwidth}%
150       \ifGm@includemp
151         \advance\@tempdima\Gm@wd@mp
152       \fi
153       \ifGm@includehead
154         \addtolength\@tempdima{\headheight}%
155         \addtolength\@tempdima{\headsep}%
156       \fi
157       \ifGm@includefoot
158         \addtolength\@tempdima{\footskip}%
159       \fi
160       \edef\Gm@width{\the\@tempdima}%
161     \fi
162   \fi
163   \ifGm@vbody
164     \ifx\Gm@height\@undefined
165       \ifx\Gm@vscale\@undefined
166         \Gm@defbylen{height}{\Gm@Dvscale\Gm@layoutheight}%
167       \else
168         \Gm@defbylen{height}{\Gm@vscale\Gm@layoutheight}%
169       \fi
170     \fi
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
176           \@tempdima\topskip
177           \global\topskip\ht\tstrutbox
178           \PackageWarningNoLine{lltjp-geometry}%
179            {do not worry about  `\noexpand\topskip was changed ...'\MessageBreak
180               warning above}
181           \PackageWarningNoLine{lltjp-geometry}%
182             {\noexpand\topskip was changed from \the\@tempdima\space
183               to \the\topskip}
184         \fi}%
185       \setlength\@tempdima{\baselineskip}%
186       \multiply\@tempdima\Gm@lines
187       \addtolength\@tempdima{\topskip}%
188       \addtolength\@tempdima{-\baselineskip}%
189       \edef\Gm@textheight{\the\@tempdima}%
190     \fi
191     \ifx\Gm@textheight\@undefined\else
192       \edef\Gm@height{\Gm@textheight}%
193     \fi
194   \fi}%
195 \def\Gm@@process{%
196   \Gm@expandlengths
197   \Gm@adjustpaper
198   \addtolength\Gm@layoutwidth{-\Gm@bindingoffset}%
199   \Gm@adjustmp
200   \Gm@adjustbody
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}%
208   \ifGm@includemp
209     \advance\textheight-\Gm@wd@mp
210     \advance\oddsidemargin\Gm@odd@mp
211   \fi
212   \if@mparswitch
213     \setlength\evensidemargin{\Gm@rmargin}%
214     \addtolength\evensidemargin{-1\Gm@truedimen in}%
215     \ifGm@includemp
216       \advance\evensidemargin\Gm@even@mp
217     \fi
218   \else
219     \evensidemargin\oddsidemargin
220   \fi
221   \advance\oddsidemargin\Gm@bindingoffset
222   \addtolength\topmargin{-1\Gm@truedimen in}%
223   \ifGm@includehead
224     \addtolength\textwidth{-\headheight}%
225     \addtolength\textwidth{-\headsep}%
226   \else
227     \addtolength\topmargin{-\headheight}%
228     \addtolength\topmargin{-\headsep}%
229   \fi
230   \ifGm@includefoot
231     \addtolength\textwidth{-\footskip}%
232   \fi
233   \ifGm@heightrounded
234     \setlength\@tempdima{\textheight}%
235     \addtolength\@tempdima{-\topskip}%
236     \@tempcnta\@tempdima
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}%
245     \fi
246     \addtolength\@tempdimb{\topskip}%
247     \textheight\@tempdimb
248   \fi
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
254 \Gm@initall
255 \Gm@processconfig
256 \ProcessOptionsKV[c]{Gm}%
257 \Gm@setdefaultpaper
258 \ProcessOptionsKV[p]{Gm}%
259 \Gm@process
260 \fi}
261 \endinput