texjporg / jsclasses

Classes tailored for use with Japanese.
BSD 2-Clause "Simplified" License
60 stars 14 forks source link

[okumacro] \whichpage がエラー #78

Open aminophen opened 1 year ago

aminophen commented 1 year ago

LaTeX2e 2022-06-01 以降で okumacro パッケージの \whichpage が動かない。

https://okumuralab.org/tex/mod/forum/discuss.php?d=3545

h20y6m commented 1 year ago

ifthen パッケージの \ifthenelse のときだけ \pageref, \ref が特別に展開可能になるようです。 https://github.com/latex3/latex2e/blob/39012fde4b77523ab53d3c1d54f5788cf1a182e6/base/ltxref.dtx#L258-L265 https://github.com/latex3/latex2e/blob/39012fde4b77523ab53d3c1d54f5788cf1a182e6/base/ifthen.dtx#L267-L274

ifthen パッケージの真似をして

\@ifl@t@r\fmtversion{2022/06/01}
  {\def\okumacro@ref@exp{\let\pageref\@kernel@pageref@exp
                  \let\ref\@kernel@ref@exp}}
  {\def\okumacro@ref@exp{\def\@setref##1##2##3{%
         \ifx##1\relax\z@\else\expandafter##2##1\fi}}}

\def\whichpage#1{%
  \okumacro@ref@exp
  ...

のようにするとかでしょうか?

明らかに LaTeX カーネルの内部命令を使うことになりますし、\whichpage 自身は完全展開不可になりますが……

h20y6m commented 1 year ago

上のコード、\whichpage の中身をグループ化しないとまずいですね……(コピペされたみたいだけど大丈夫だろうか……)

zr-tex8r commented 1 year ago

単純に「展開可能版の\pageref」を別に用意して、 \whichpageの実装中の\pagerefをそれに置き換える方が素直じゃないですかね。

\def\okumacro@pageref#1{%
  \expandafter\expandafter\expandafter
      \okumacro@pageref@a\csname r@#1\endcsname{0}\@nil}
\def\okumacro@pageref@a#1#2#3\@nil{#2}

\def\whichpage#1{%
  \expandafter\ifx\csname r@#1\endcsname\relax
  \else
    \@tempcnta\okumacro@pageref{#1}\relax
    \advance\@tempcnta-\c@page
    \ifnum\@tempcnta=0
    \else
      \ifnum\@tempcnta=1 (次ページ)
      \else
        \ifnum\@tempcnta=-1 (前ページ)
        \else (\okumacro@pageref{#1}ページ)
        \fi
      \fi
    \fi
  \fi}

\okumacro@pagerefの動作は{0}がなければ\@kernel@pageref@expと同じ。{0}を入れた理由は「\r@REFが未定義のときに0に展開させる」ため。