2009-01-30 104 views
1

根據這個問題參數:重新定義命令使用 newenvironment

Redefining Commands in a New Environment

一個人如何重新定義(或使用\def定義)使用參數宏?我不斷收到illegal parameter definition in \foo錯誤。由於我需要自定義分隔符,因此我無法使用\newcommand\renewcommand

A的我的代碼一般形式如下:

\newenvironment{foo}{% 
    ...spacing stuff and counter defs... 
    \def\fooitem#1. #2\endfooitem{% 
     ...stuff... 
    } 
    \def\endfooitem{endfoo} 
} 
{...after material (spacing)...} 

這必須是可能的。現在我正在使用plain-TeX定義(正如我在上面的問題中提到的那樣),但是我真的想要與LaTeX系統保持一致。

回答

1

您需要將每個嵌套定義的#個字符加倍。在內部,\ newcommand或\ newenvironment正在調用\ def。

\newenvironment{foo}{% 
    ... 
    \def\fooitem##1. ##2\endfooitem{% 
    ... 

除此之外,這是做你想做的事的方法;沒有純LaTeX方法來定義具有分隔參數的宏。