Suppose I'd like to patch a very complicated macro, say \autocite. For this, xpatch package is my friend. If the patch consists in applying a modal command which doesn't take arguments, such as \bfseries, \xpretocmd is also my friend:
\documentclass{article}
\usepackage{xpatch}
\usepackage[backend=biber]{biblatex}%
%
\addbibresource{biblatex-examples.bib}
%
% \autocite's patch
\xpretocmd{\autocite}%
{\bfseries}%
{\message{^^Jxpretocmd OK^^J^^J}}%
{\message{^^Jxpretocmd not OK^^J^^J}}
%
\begin{document}
\autocite{cicero}
\printbibliography
\end{document}
Now, suppose the patch consists in applying a macro which does take an argument, such as \textbf: I want \autocite... to become \textf{\autocite...}, whatever are the star/optional/mandatory arguments in .... For this, I can't use \textf{ and } as ⟨prepend⟩ and ⟨append⟩ in:
\xpretocmd{⟨command⟩}{⟨prepend⟩}{⟨success⟩}{⟨failure⟩}
\xapptocmd{⟨command⟩}{⟨append⟩}{⟨success⟩}{⟨failure⟩}
because of unbalanced braces. If { and } are replaced by \bgroup and \egroup:
\documentclass{article}
\usepackage{xpatch}
\usepackage[backend=biber]{biblatex}%
%
\addbibresource{biblatex-examples.bib}
%
% \autocite's patch
\xpretocmd{\autocite}%
{\textbf\bgroup}%
{\message{^^Jxpretocmd OK^^J^^J}}%
{\message{^^Jxpretocmd not OK^^J^^J}}
\xapptocmd{\autocite}
{\egroup}%
{\message{^^Jxapptocmd OK^^J^^J}}%
{\message{^^Jxapptocmd not OK^^J^^J}}
%
\begin{document}
\autocite{cicero}
\printbibliography
\end{document}
it doesn't work neither as \egroup is considered as the \autocite's argument.
Hence my question: how to patch with \xpretocmd and \xapptocmd a command by applying to it a macro with argument?
Edit. I placed a great deal of hope in the following trick, relying on \BODY command from environ package, but it fails as well...
\documentclass{article}
\usepackage{xpatch}
\usepackage{environ}
\usepackage[backend=biber]{biblatex}%
%
\addbibresource{biblatex-examples.bib}
%
\NewEnviron{boldify}{%
\textbf{\BODY}%
}
% \autocite's patch
\xpretocmd{\autocite}%
{\boldify}%
{\message{^^Jxpretocmd OK^^J^^J}}%
{\message{^^Jxpretocmd not OK^^J^^J}}
\xapptocmd{\autocite}
{\endboldify}%
{\message{^^Jxapptocmd OK^^J^^J}}%
{\message{^^Jxapptocmd not OK^^J^^J}}
%
\begin{document}
\autocite{cicero}
\printbibliography
\end{document}


\autociteis easily possible…\renewcommand\citesetup{\bfseries}does not suffice for your needs? – cgnieder Nov 06 '15 at 11:18\textbfis just an example. In the real life, the macro with argument is not so simple: namely, it is e.g.\switchocg{⟨refocgs⟩}{⟨complicated command such as \autocite with possibly several optional/mandatory arguments⟩}. – Denis Bitouzé Nov 06 '15 at 11:23\autociteends with a macro looking for its arguments. – egreg Nov 06 '15 at 11:23\autocitewith the same argument structure which passes its arguments to\autociteand wraps the whole thing in the macro you need – cgnieder Nov 06 '15 at 11:26\let\origautocite\autociteand\renewcommand{\autocite}[...]{...}because it requires to know what are the several optional/mandatory arguments of the command to be patched)? – Denis Bitouzé Nov 06 '15 at 11:27\pdfendlinkat the end. – Ulrike Fischer Nov 06 '15 at 14:03\AtEveryCitereminder but I guess that, just like\xpretocmd, it doesn't support arguments sich astextbf{(or\switchocg{⟨refocgs⟩}{) and\AtEveryCiteEndwouldn't support arguments such as}neither. Even though, there are several other commands (outsidebiblatex's area) I'd like to patch the same way. – Denis Bitouzé Nov 06 '15 at 15:05\At..Endwould work, as it is easy to define\startswitchocgand\stopswitchocgcommands which doesn't use an argument. – Ulrike Fischer Nov 06 '15 at 15:29biblatex's ones. Do you have some pointers about\start⟨macro⟩⟨stuff⟩\stop⟨macro⟩vs\⟨macro⟩{⟨stuff⟩}? – Denis Bitouzé Nov 06 '15 at 15:44