4

If in a command \foo is one of my arguments, e.g. #1 how can I do a \def for \foobar, i.e., define a command with bar added to #1?

Specifically I try the following

\documentclass{scrbook}
\usepackage[refpage,noprefix]{nomencl}
\makeatletter
\newcommand*{\defsym}[3][]{\def#2{%
  \ifx\protect\@unexpandable@protect
    #3%
  \else
    \nomenclature{$#3$}{#1}\gdef#2{#3}#3%
  \fi} %
  %\def#2FwD{#3} % <-- this does not work
}
\makeatother
\usepackage{amsmath,amsfonts,amssymb}
\defsym{\Rn}{\mathbb{R}^n}

\makenomenclature
\begin{document}

$\Rn$ will be introduced later ...
%$\RnFwD$ will be introduced later ...

\clearpage

$\Rn$ is defined as ...

\printnomenclature
\end{document}

This uses List of symbols/abbreviations and macros to automatically put a symbol (here \Rn) in the Nomenclature (List of Symbols) on its first use. This works nicely for more, but now I got the rare ocasion that I want to make a first use of symbol that should not yet be recorded in the nomenclature. To this end I want to introduce a command \xFwd for every command \x declared by \defsym.

I tried this above, but when I uncomment that line I get the error Use of \Rn doesn't match its definition. which I think is due to the question that I posed first.

2 Answers2

6
\makeatletter

\def\addbar#1{%
  \expandafter\def\csname\expandafter\@gobble\string#1bar\endcsname}

\addbar\sin#1{hello #1}

\show\sinbar

\stop

defines \sinbar :

> \sinbar=macro:
#1->hello #1.
David Carlisle
  • 757,742
2
\documentclass{article}

\makeatletter
\def\foo#1#2{\@namedef{foo#1}{#2}}
\makeatother

\begin{document}
\foo{bar}{foobarbaz}

\foobar
\end{document}