Open aminophen opened 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
自身は完全展開不可になりますが……
上のコード、\whichpage
の中身をグループ化しないとまずいですね……(コピペされたみたいだけど大丈夫だろうか……)
単純に「展開可能版の\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
に展開させる」ため。
LaTeX2e 2022-06-01 以降で okumacro パッケージの \whichpage が動かない。
https://okumuralab.org/tex/mod/forum/discuss.php?d=3545