6

I want to decorate some text and then reprint it undecorated. This is the code that I was using to do this.

\documentclass{article}
\usepackage{xcolor}
\makeatletter
\newcommand{\@aeformatcontent}[1]{\parbox[t]{5in}{\emph{#1}}}
\newcommand{\aeformatcontent}[1]{%%'
  $\star$\hspace*{0.5em}\@aeformatcontent{#1}\par
  \bgroup
    \def\aeget#1{#1}%%'
    $\phantom{\star}$\hspace*{0.5em}\@aeformatcontent{#1}%%'
  \egroup
} 

\newcommand{\aeget}[1]{\csname aephrase #1\endcsname}
\newcommand{\aedefine}[1]{\expandafter\def\csname aephrase #1\endcsname{{\color{red}#1}}}

\makeatother

\begin{document}

  \aedefine{this is a trial}
  \aeget{this is a trial}

  \aeformatcontent{\aeget{this is a trial}}

\end{document}

When I try to compile this, I get the error:

! Use of \aeget doesn't match its definition.
<argument> \aeget {
                   this is a trial}
l.24 ... \aeformatcontent{\aeget{this is a trial}}

? 

If I replace \def\aeget#1{#1} with

\renewcommand{\aeget}[1]{#1}

I get stuck in an infinite loop until LaTeX's capacity is exceeded.

I don't understand why neither of these approaches works. Neither do I understand why I'm getting different error messages.

8

Your internal redefinition of \aeget needs a doubled use of the parameter text:

\def\aeget##1{##1}

This resets \aeget to a no-op, but since it is redefined inside \aeformatcontent, you have to double the #s. Also see Defining LaTeX commands within other commands.

enter image description here

\documentclass{article}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\makeatletter
\newcommand{\@aeformatcontent}[1]{\parbox[t]{5in}{\emph{#1}}}
\newcommand{\aeformatcontent}[1]{%%'
  $\star$\hspace*{0.5em}\@aeformatcontent{#1}\par
  \bgroup
    \def\aeget##1{##1}%%'
    $\phantom{\star}$\hspace*{0.5em}\@aeformatcontent{#1}%%'
  \egroup
}

\newcommand{\aeget}[1]{\csname aephrase #1\endcsname}
\newcommand{\aedefine}[1]{\expandafter\def\csname aephrase #1\endcsname{{\color{red}#1}}}

\makeatother

\begin{document}

  \aedefine{this is a trial}
  \aeget{this is a trial}

  \aeformatcontent{\aeget{this is a trial}}

\end{document}
|improve this answer|||||
  • I should have known that. Humbled. – A.Ellett Sep 12 '13 at 4:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.