
内部から呼び出されるかどうかによって動作が異なるマクロを作成したいと思います\item
。
\def\mymacro{\if<INSIDE_ITEM> do this \else do that\fi}
これが使用できる例を次に示します。
This is how my macro performs outside an item: {\mymacro}
\item{1}. And this is how it performs inside an item: {\mymacro}
比較すると、数式モード内から呼び出されるかどうかに応じて動作が異なるマクロについても同様の状況が考えられます。次に例を示します。
\def\anothermacro{\ifmmode do this \else do that\fi}
問題は、アイテムの環境と通常の段落の環境の間に大きな違いがないように見えることです。何かアイデアはありますか?
追伸:私は本当に興味があります無地TeX (LaTeX ではなく)! また、追加のパッケージを必要としない簡単なソリューションも大歓迎です!
答え1
似たようなものカボハ提案されたコメントですが、ちょっとした安全チェックをします。の代わりに\item
新しい長さを使用するように を再定義し、前者がプラス になるように設定します。これは光学的には区別がつきませんが (わずか数ナノメートル)、テストが偽陽性につながる可能性は比較的低いと言えます。\itemindent
\parindent
\parindent
1sp
\ifdim\hangindent=\itemindent
\newdimen\itemindent
\itemindent\parindent
\advance\itemindent1sp
% the plain TeX definition is basically:
% \def\item{\par\hangindent\parindent\textindent}
\def\item{\par\hangindent\itemindent\textindent}
\def\mymacro{\ifdim\hangindent=\itemindent(INSIDE)\else(OUTSIDE)\fi}
Text text text text text text text text text \mymacro
\item{x} bla bla bla bla \mymacro
\item{x} bla bla bla bla \mymacro
Text text text text text text text text text \mymacro
\bye
答え2
コメントでのcabohahの提案に従って:
\newif\ifinitem
\initemfalse
\def\mymacro{\ifinitem hi!\else bye\fi}
\def\item{\par\initemtrue\hang\textindent}
\let\oldpar\par
\def\par{\initemfalse\oldpar}
This is how my macro performs outside an item: {\mymacro}
\item{1}. And this is how it performs inside an item: {\mymacro}
Now we are no longer inside the item: {\mymacro}
\bye