# How can a command take #1 as an argument?

I was wondering how some commands manage to take #1 as an argument when used, not when declared.

For instance, biblatex's \DeclareFieldFormat can be used like this:

\DeclareFieldFormat {postnote} {#1}


I have taken a look at biblatex1.sty (lines 3480--3506, v2.3, revison 28161) but couldn't figure out how it can do that. Where is the trick?

This is what I want to achieve:

\foo {bar} {\textbf{#1}}


I want it to typeset bar in bold face; that is, to typeset whatever is given in the first argument in whatever format is given in the second one.

### From biblatex1.sty:

%---CUT---
\newrobustcmd*{\DeclareFieldFormat}{%
\@ifstar
{\blx@defformat\blx@defplainformat{ffd}*}
{\blx@defformat\blx@defplainformat{ffd}{}}}
%---CUT---

% {<macro>}{<class>}{<*>}

\def\blx@defformat#1#2#3{%
\@ifnextchar[%]
{\blx@defformat@i{#1}{#2}{#3}}
{\blx@defformat@i{#1}{#2}{#3}[*]}}

% {<macro>}{<class>}{<*>}[<entrytype>]{<name>}

\def\blx@defformat@i#1#2#3[#4]#5{%
\notblank{#3}
{\blx@resetformat{#2}{#5}}
{}%
\def\blx@defformat@a{#2}%
\def\blx@defformat@b{#4}%
\blx@xsanitizeafter{\def\blx@defformat@c}{#5}%
\afterassignment\blx@defformat@ii
#1}
%---CUT---

-
I've removed the biblatex tag: the issue is noting to do with biblatex. –  Joseph Wright Jan 25 '13 at 7:06

You need an auxiliary function, which is defined with one argument:

\documentclass{article}
\newcommand{\foo}[2]{%
\def\fooaux##1{#2}%
\fooaux{#1}%
}
\newcommand{\fooaux}[1]{}
\begin{document}
\foo{bar}{\textbf{#1,}} hhhh
\end{document}


The idea here is that \fooaux will end up defined as equivalent to

\renewcommand{\fooaux}[1]{%
\textbf{#1,}%
}


in the code above.

-