X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fpatches%2Flltjp-geometry.sty;h=43a175e09ba046ffe7d98814a66240f8d42b3782;hb=36574439c76cf41604fb48e2ce82a2949bae864d;hp=46ee0e4f031b099a0794146e3f8e8adf4212f16e;hpb=ffeb994448f6eb4d7a07ff1cfba552dae3625819;p=luatex-ja%2Fluatexja.git diff --git a/src/patches/lltjp-geometry.sty b/src/patches/lltjp-geometry.sty index 46ee0e4..43a175e 100644 --- a/src/patches/lltjp-geometry.sty +++ b/src/patches/lltjp-geometry.sty @@ -3,13 +3,26 @@ % \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{lltjp-geometry}[2014/11/23 Patch to geometry for LuaTeX-ja with vertical writing mode] -\RequirePackage{ifluatex} - +\ProvidesPackage{lltjp-geometry}[2020/02/25 Patch to geometry for LuaTeX-ja with vertical writing mode] +\RequirePackage{expl3} +\ifdefined\if@ltj@@geometry@tate\expandafter\endinput\fi \newif\if@ltj@@geometry@tate +\newif\if@ltj@@geometry@forceoff \@ltj@@geometry@tatefalse -\ifluatex\else % pTeX - \@ltj@@geometry@tatetrue +\@ltj@@geometry@forceofffalse +\DeclareOption{force}{\@ltj@@geometry@tatetrue} +\DeclareOption{disable}{\@ltj@@geometry@forceofftrue} + +\ProcessOptions\relax + +\RequirePackage{ifluatex} +\ifluatex + \ifdefined\luatexjaLoaded\else + \PackageError{lltjp-geometry}{% + lltjp-geometry does not work without luatexja. + }{} +\fi +\else % pTeX \def \AtBeginDvi #1{% \global \setbox \@begindvibox \vbox{\yoko\unvbox \@begindvibox #1}% @@ -17,30 +30,192 @@ \fi \RequirePackage{filehook} +\RequirePackage{etoolbox} +\newif\ifGm@ltj@layoutswitch +\let\orig@PackageWarningNoLine=\PackageWarningNoLine +% define ifGm@swap@papersize if it is undefined +\expandafter\newif\csname ifGm@swap@papersize\endcsname - -\AtEndOfPackageFile{geometry}{% +\ExplSyntaxOn +\AtBeginOfPackageFile{geometry}{% + \edef\Gm@ltj@topskip{\the\topskip} + \edef\Gm@ltj@headsep{\the\headsep} + \edef\Gm@ltj@footskip{\the\footskip} \ifluatex \ifnum\ltjgetparameter{direction}=3 \@ltj@@geometry@tatetrue\fi +\else + \@gobble\iftrue\csname iftdir\endcsname\@ltj@@geometry@tatetrue\fi +\fi +\tl_if_in:NnT \@begindocumenthook { \tate } { \@ltj@@geometry@tatetrue } +\if@ltj@@geometry@tate + \if@ltj@@geometry@forceoff + \@ltj@@geometry@tatefalse + \else + \let\PackageWarningNoLine\@gobbletwo% 警告抑止 + \fi \fi -\typeout{\meaning\if@ltj@@geometry@tate} +} +\ExplSyntaxOff + +\AtEndOfPackageFile{geometry}{% +\let\PackageWarningNoLine=\orig@PackageWarningNoLine \if@ltj@@geometry@tate -\define@key{Gm}{hdivide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}}% -\define@key{Gm}{vdivide}{\Gm@parse@divide{#1}{rmargin}{height}{lmargin}}% + \let\PackageWarningNoLine=\orig@PackageWarningNoLine +%%% ここからパッチ開始 + +% TODO: +% * pTeX, LuaTeX ともに truedimen が正しく動作しない +% * pTeX resetpaper が正しく動作しない +% +% `h', `v' は「水平」「垂直」を意味するが: +% ユーザー側では「紙の物理的な水平方向」「物理的な垂直方向」を, +% しかしパッケージ内部処理では「字送り方向」「行送り方向」を表す. +% そのため,key-value interface 内で h, v の交換を行う必要がある. + +% twoside 指定時は,lmargin は小口側,rmargin はノド側の余白を指す. +% また,bindingoffset 偶数ページを右に,奇数ページを左にずらす. +\define@key{Gm}{hdivide}{\Gm@parse@divide{#1}{lmargin}{height}{rmargin}}% + +\define@key{Gm}{vscale}{\Gm@hbodytrue\edef\Gm@hscale{#1}}% +\define@key{Gm}{hscale}{\Gm@vbodytrue\edef\Gm@vscale{#1}}% +\define@key{Gm}{vdivide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}}% \define@key{Gm}{divide}{\Gm@parse@divide{#1}{tmargin}{width}{bmargin}% - \Gm@parse@divide{#1}{rmargin}{height}{lmargin}}% -\define@key{Gm}{hmargin}{\Gm@branch{#1}{tmargin}{bmargin}}% -\define@key{Gm}{vmargin}{\Gm@branch{#1}{rmargin}{lmargin}}% -\define@key{Gm}{margin}{\Gm@branch{#1}{tmargin}{rmargin}% - \Gm@branch{#1}{bmargin}{lmargin}}% + \Gm@parse@divide{#1}{lmargin}{height}{rmargin}}% +\define@key{Gm}{vmargin}{\Gm@branch{#1}{tmargin}{bmargin}}% +\define@key{Gm}{hmargin}{\Gm@branch{#1}{lmargin}{rmargin}}% +\define@key{Gm}{margin}{\Gm@branch{#1}{tmargin}{lmargin}% + \Gm@branch{#1}{bmargin}{rmargin}}% +\define@key{Gm}{headsep}{\Gm@defbylen{ltj@headsep}{#1}}% +\define@key{Gm}{footskip}{\Gm@defbylen{ltj@footskip}{#1}}% +\let\KV@Gm@foot\KV@Gm@footskip +\define@key{Gm}{vmarginratio}{\edef\Gm@hmarginratio{#1}}% +\define@key{Gm}{hmarginratio}{\edef\Gm@vmarginratio{#1}}% +\define@key{Gm}{nohead}[true]{\Gm@doifelse{nohead}{#1}% + {\Gm@setlength\headheight\z@\Gm@defbylen{ltj@headsep}\z@}{}}% +\define@key{Gm}{nofoot}[true]{\Gm@doifelse{nofoot}{#1}% + {\Gm@defbylen{ltj@footskip}\z@}{}}% +\define@key{Gm}{noheadfoot}[true]{\Gm@doifelse{noheadfoot}{#1}% + {\Gm@setlength\headheight\z@\Gm@defbylen{ltj@headsep}\z@ + \Gm@defbylen{ltj@footskip}\z@}{}}% +\define@key{Gm}{layoutwidth}{\Gm@layouttrue\Gm@setlength\Gm@layoutheight{#1}}% +\define@key{Gm}{layoutheight}{\Gm@layouttrue\Gm@setlength\Gm@layoutwidth{#1}}% +\define@key{Gm}{layoutsize}{\Gm@branch{#1}{layoutwidth}{layoutheight}}% +\define@key{Gm}{layout}{\Gm@layouttrue\@nameuse{Gm@#1}{Gm@layout}% + \Gm@setlength\@tempdima{\Gm@layoutheight}% + \Gm@setlength\Gm@layoutheight{\Gm@layoutwidth}% + \Gm@setlength\Gm@layoutwidth{\@tempdima}% +}% + +% \@mparswitch は傍注の出力位置を左右ページで変えるスイッチだが, +% geometry.sty はこれを左右ページのレイアウトを変えるか否かの判定にも使っている. +% 縦組クラスの場合は \@mparswitch は常に偽でないとおかしなことになるので +% \@mparswitch -> \Gm@ltj@layoutswitch と名称変更する. + +\let\Gm@ltj@layoutswitch\@mparswitch +\@mparswitchfalse +\define@key{Gm}{twoside}[true]{\Gm@doifelse{twoside}{#1}% + {\@twosidetrue\Gm@ltj@layoutswitchtrue}{\@twosidefalse\Gm@ltj@layoutswitchfalse}}% +\define@key{Gm}{asymmetric}[true]{\Gm@doifelse{asymmetric}{#1}% + {\@twosidetrue\Gm@ltj@layoutswitchfalse}{}}% + +% includemp 指定時は,\headsep (if reversemp || twocolumn) や, +% \footskip (if !reversemp || twocolumn) を傍注幅だけ増加させる. + +% h <-> v +\def\Gm@Dhratio{2:3}% = top:bottom default +\def\Gm@Dvratio{1:1}% = left:right default for oneside +\def\Gm@Dvratiotwo{3:2}% = inner:outer default for twoside. +\ifGm@swap@papersize + % geometry.sty ロード時に landscape オプションが指定されていた場合, + % それによって用紙サイズの縦横が入れ替わってしまっているので補正する. + \setlength\@tempdima{\paperwidth}% + \setlength\paperwidth{\paperheight}% + \setlength\paperheight{\@tempdima}% +\fi + +% save length +\def\Gm@save{% + \Gm@savelength{paperwidth}% + \Gm@savelength{paperheight}% + \Gm@savelength{textwidth}% + \Gm@savelength{textheight}% + \Gm@savelength{evensidemargin}% + \Gm@savelength{oddsidemargin}% + \Gm@savelength{topmargin}% + \Gm@savelength{headheight}% + %\Gm@savelength{headsep}% + \Gm@savelength{topskip}% + %\Gm@savelength{footskip}% + \Gm@savelength{baselineskip}% + \Gm@savelength{marginparwidth}% + \Gm@savelength{marginparsep}% + \Gm@savelength{columnsep}% + \Gm@savelength{hoffset}% + \Gm@savelength{voffset} + \Gm@savelength{Gm@layoutwidth}% + \Gm@savelength{Gm@layoutheight}% + \Gm@savelength{Gm@layouthoffset}% + \Gm@savelength{Gm@layoutvoffset}% + \Gm@saveboolean{@twocolumn}% + \Gm@saveboolean{@twoside}% + \Gm@saveboolean{Gm@ltj@layoutswitch}% + \Gm@saveboolean{@reversemargin}}% + +% frame +\ifluatex + \def\Gm@pageframe@cmd{\vb@xt@\z@} +\else + \def\Gm@pageframe@cmd{\vb@xt@\z@\bgroup\yoko\aftergroup\egroup} +\fi +\renewcommand*{\Gm@pageframes}{% + \Gm@pageframe@cmd{% + \ifGm@showcrop + \vb@xt@\z@{\vskip-1\Gm@truedimen in\vskip\Gm@layoutvoffset% + \hb@xt@\z@{\hskip-1\Gm@truedimen in\hskip\Gm@layouthoffset% + \vb@xt@\Gm@layoutwidth{% + \let\protect\relax + \hb@xt@\Gm@layoutheight{\Gm@cropmark(-1,1,-3,3)\hfil\Gm@cropmark(1,1,3,3)}% + \vfil + \hb@xt@\Gm@layoutheight{\Gm@cropmark(-1,-1,-3,-3)\hfil\Gm@cropmark(1,-1,3,-3)}}% + \hss}% + \vss}% + \fi% + \ifGm@showframe + \if@twoside + \ifodd\count\z@ + \let\@themargin\oddsidemargin + \else + \let\@themargin\evensidemargin + \fi + \fi + \moveright\@themargin% + \vb@xt@\z@{% + \vskip\topmargin\vb@xt@\z@{\vss\Gm@hrule}% + \vskip\headheight\vb@xt@\z@{\vss\Gm@hruled}% + \vskip\headsep\vb@xt@\z@{\vss\Gm@hrule}% + \if@reversemargin\vb@xt@\z@{% + \vss\vb@xt@\z@{\vss\Gm@hrule}% + \vskip\marginparwidth\vb@xt@\z@{\vss\Gm@hrule}% + \vskip\marginparsep + }\fi + \hb@xt@\textwidth{\llap{\Gm@vrule}\hfil\Gm@vrule}% + \vb@xt@\z@{\vss\Gm@hruled}% + \unless\if@reversemargin\vb@xt@\z@{% + \vskip\marginparsep\vb@xt@\z@{\vss\Gm@hrule}% + \vskip\marginparwidth\vb@xt@\z@{\vss\Gm@hruled}\vss% + }\fi% + \vskip\footskip\vb@xt@\z@{\vss\Gm@hruled}% + \vss}% + \fi% + }} \def\Gm@detall#1#2#3#4{% \@tempcnta\z@ \if#1h \let\Gm@mratio\Gm@hmarginratio - \edef\Gm@Dmratio{\if@twoside\Gm@Dhratiotwo\else\Gm@Dhratio\fi}% + \edef\Gm@Dmratio{\Gm@Dhratio}% \else \let\Gm@mratio\Gm@vmarginratio - \edef\Gm@Dmratio{\Gm@Dvratio}% + \edef\Gm@Dmratio{\if@twoside\Gm@Dvratiotwo\else\Gm@Dvratio\fi}% \fi \if#1h \ifx\Gm@tmargin\@undefined\else\advance\@tempcnta4\relax\fi @@ -48,9 +223,9 @@ \ifx\Gm@bmargin\@undefined\else\advance\@tempcnta1\relax\fi \Gm@cnth\@tempcnta \else - \ifx\Gm@rmargin\@undefined\else\advance\@tempcnta4\relax\fi + \ifx\Gm@lmargin\@undefined\else\advance\@tempcnta4\relax\fi \ifGm@vbody\advance\@tempcnta2\relax\fi - \ifx\Gm@lmargin\@undefined\else\advance\@tempcnta1\relax\fi + \ifx\Gm@rmargin\@undefined\else\advance\@tempcnta1\relax\fi \Gm@cntv\@tempcnta \fi \ifcase\@tempcnta @@ -101,8 +276,8 @@ \def\Gm@clean{% \ifnum\Gm@cnth<4\let\Gm@tmargin\@undefined\fi \ifodd\Gm@cnth\else\let\Gm@bmargin\@undefined\fi - \ifnum\Gm@cntv<4\let\Gm@rmargin\@undefined\fi - \ifodd\Gm@cntv\else\let\Gm@lmargin\@undefined\fi + \ifnum\Gm@cntv<4\let\Gm@lmargin\@undefined\fi + \ifodd\Gm@cntv\else\let\Gm@rmargin\@undefined\fi \ifGm@hbody\else \let\Gm@hscale\@undefined \let\Gm@width\@undefined @@ -166,15 +341,28 @@ \Gm@defbylen{height}{\Gm@vscale\Gm@layoutheight}% \fi \fi + \setlength\topskip\Gm@ltj@topskip \ifx\Gm@lines\@undefined\else - \setlength\maxdepth{1\Cht}% - \setlength\topskip{.5\maxdepth}% - \ifdim\topskip<\ht\tstrutbox - \setlength\@tempdima{\topskip}% - \setlength\topskip{\ht\tstrutbox}% - \Gm@warning{\noexpand\topskip was changed from \the\@tempdima\space - to \the\topskip}% + \@tempdima=\f@size\p@ \@tempdima=.5\@tempdima + \ifluatex + \advance\@tempdima\ltjgetparameter{talbaselineshift}% + \else + \advance\@tempdima\tbaselineshift \fi + \ifdim\maxdepth<\@tempdima + \PackageWarningNoLine{lltjp-geometry}% + {\noexpand\maxdepth was changed from \the\maxdepth\space + to \the\@tempdima} + \maxdepth\@tempdima + \fi + \setbox\z@=\hbox{\tate% next \ifdim must be executed in tate dir. + \ifdim\topskip<\ht\tstrutbox + \@tempdima\topskip + \global\topskip\ht\tstrutbox + \PackageWarningNoLine{lltjp-geometry}% + {\noexpand\topskip was changed from \the\@tempdima\space + to \the\topskip} + \fi}% \setlength\@tempdima{\baselineskip}% \multiply\@tempdima\Gm@lines \addtolength\@tempdima{\topskip}% @@ -185,33 +373,38 @@ \edef\Gm@height{\Gm@textheight}% \fi \fi}% + +\def\Gm@adjustmp{% + \ifGm@includemp + \@tempdimb\marginparwidth + \advance\@tempdimb\marginparsep + \Gm@wd@mp\@tempdimb + \if@twocolumn + \Gm@wd@mp2\@tempdimb + \fi + \fi}% \def\Gm@@process{% \Gm@expandlengths \Gm@adjustpaper - \addtolength\Gm@layoutwidth{-\Gm@bindingoffset}% + \addtolength\Gm@layoutheight{-\Gm@bindingoffset}% \Gm@adjustmp \Gm@adjustbody \Gm@detall{h}{width}{tmargin}{bmargin}% - \Gm@detall{v}{height}{rmargin}{lmargin}% + \Gm@detall{v}{height}{lmargin}{rmargin}% \setlength\textwidth{\Gm@width}% \setlength\textheight{\Gm@height}% + \setlength\headsep{\Gm@ltj@headsep}% + \setlength\footskip{\Gm@ltj@footskip}% \setlength\topmargin{\Gm@tmargin}% \setlength\oddsidemargin{\Gm@lmargin}% \addtolength\oddsidemargin{-1\Gm@truedimen in}% - \ifGm@includemp - \advance\textheight-\Gm@wd@mp - \advance\oddsidemargin\Gm@odd@mp - \fi - \if@mparswitch + \ifGm@ltj@layoutswitch \setlength\evensidemargin{\Gm@rmargin}% \addtolength\evensidemargin{-1\Gm@truedimen in}% - \ifGm@includemp - \advance\evensidemargin\Gm@even@mp - \fi \else \evensidemargin\oddsidemargin \fi - \advance\oddsidemargin\Gm@bindingoffset + \advance\evensidemargin\Gm@bindingoffset \addtolength\topmargin{-1\Gm@truedimen in}% \ifGm@includehead \addtolength\textwidth{-\headheight}% @@ -223,6 +416,17 @@ \ifGm@includefoot \addtolength\textwidth{-\footskip}% \fi + \ifGm@includemp + \advance\textwidth-\Gm@wd@mp + \if@twocolumn + \advance\headsep.5\Gm@wd@mp + \advance\footskip.5\Gm@wd@mp + \else\if@reversemargin + \advance\headsep\Gm@wd@mp + \else + \advance\footskip\Gm@wd@mp + \fi\fi + \fi \ifGm@heightrounded \setlength\@tempdima{\textheight}% \addtolength\@tempdima{-\topskip}% @@ -239,16 +443,75 @@ \addtolength\@tempdimb{\topskip}% \textheight\@tempdimb \fi - \advance\oddsidemargin\Gm@layoutvoffset% - \advance\evensidemargin\Gm@layoutvoffset% - \advance\topmargin\Gm@layouthoffset% + \advance\oddsidemargin\Gm@layouthoffset% + \advance\evensidemargin\Gm@layouthoffset% + \advance\topmargin\Gm@layoutvoffset% \addtolength\Gm@layoutheight{\Gm@bindingoffset}% }% end of \Gm@@process +% log +\def\Gm@logcontent#1{% + *geometry* verbose mode - [ #1 ] result:^^J% + \ifGm@pass * pass: disregarded the geometry package!^^J% + \else + * driver: \if\Gm@driver\else\Gm@driver\fi^^J% + * paper: \ifx\Gm@paper\@undefined\else\Gm@paper\fi^^J% + * layout: \ifGm@layout\else\fi^^J% + \ifGm@layout + * layout(width,height): (\the\Gm@layoutwidth,\the\Gm@layoutheight)^^J% + \fi + * layoutoffset:(h,v)=(\the\Gm@layouthoffset,\the\Gm@layoutvoffset)^^J% + \@ifundefined{Gm@lines}{}{* lines: \Gm@lines^^J}% + \@ifundefined{Gm@hmarginratio}{}{* hratio: \Gm@hmarginratio^^J}% + \@ifundefined{Gm@vmarginratio}{}{* vratio: \Gm@vmarginratio^^J}% + \ifdim\Gm@bindingoffset=\z@\else + * bindingoffset: \the\Gm@bindingoffset^^J\fi + * modes: % + \Gm@showbool{landscape}% + \Gm@showbool{includehead}% + \Gm@showbool{includefoot}% + \Gm@showbool{includemp}% + \if@twoside twoside\space\fi% + \ifGm@ltj@layoutswitch\else\if@twoside asymmetric\space\fi\fi% + \Gm@showbool{heightrounded}% + \ifx\Gm@truedimen\@empty\else truedimen\space\fi% + \Gm@showbool{showframe}% + \Gm@showbool{showcrop}% + ^^J% + * h-part:(L,W,R)=(\Gm@lmargin, \Gm@height, \Gm@rmargin)^^J% + * v-part:(T,H,B)=(\Gm@tmargin, \Gm@width, \Gm@bmargin)^^J% + \fi + \Gm@showdim{\paperwidth}% + \Gm@showdim{\paperheight}% + \Gm@showdim{\textwidth}% + \Gm@showdim{\textheight}% + \Gm@showdim{\oddsidemargin}% + \Gm@showdim{\evensidemargin}% + \Gm@showdim{\topmargin}% + \Gm@showdim{\headheight}% + \Gm@showdim{\headsep}% + \Gm@showdim{\topskip}% + \Gm@showdim{\footskip}% + \Gm@showdim{\marginparwidth}% + \Gm@showdim{\marginparsep}% + \Gm@showdim{\columnsep}% + * \string\skip\string\footins=\the\skip\footins^^J% + \Gm@showdim{\hoffset}% + \Gm@showdim{\voffset}% + \Gm@showdim{\mag}% + * \string\@twocolumn\if@twocolumn true\else false\fi^^J% + * \string\@twoside\if@twoside true\else false\fi^^J% + * \string\@mparswitch\if@mparswitch true\else false\fi^^J% + * \string\@reversemargin\if@reversemargin true\else false\fi^^J% + * (1in=72.27pt=25.4mm, 1cm=28.453pt)^^J}% + + \Gm@initall \Gm@processconfig \ProcessOptionsKV[c]{Gm}% \Gm@setdefaultpaper \ProcessOptionsKV[p]{Gm}% \Gm@process + +%%% 終了 \fi} \endinput