Sunday, March 27, 2011

Redefining Commands with Parameters using \newenvironment

Pursuant to this question:

Redefining Commands in a New Environment

How does one redefine (or define using \def) a macro that uses parameters? I keep getting an illegal parameter definition in \foo error. Since I require custom delimiters, I can't use \newcommand or \renewcommand.

A general form of my code looks like this:

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

This must be possible. Right now I'm using plain-TeX definitions (as I mentioned in the question above) but I'd really like to be consistent with the LaTeX system.

From stackoverflow
  • You need to double the # characters for every nested definition. Internally, a \newcommand or a \newenvironment is calling \def.

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

    Besides that, this is the way to do what you're trying to do; there is no pure-LaTeX method to define a macro with delimited arguments.

0 comments:

Post a Comment