This is kind of a double question but closely connected in my case. Inspired by https://tex.stackexchange.com/a/55769/14159 I tried to make an improved version which allows additional parameters for the defined symbols.
This is my current code:
\documentclass{article}
\usepackage{xparse}
\usepackage{nomencl}
\usepackage{xcolor}
% colorize to distinguish original and renewed command
\NewDocumentCommand{\defsym}{mmmmm} {%
\NewDocumentCommand{#1}{#2}{%
\RenewDocumentCommand{#1}{#2}{\textcolor{blue}{#4}}
\nomenclature{$#1$}{#5}
\textcolor{red}{#3}
}
}
\defsym\Uk{O{k}}{U_{#1}}{U_{##1}}{Some variable}
\makenomenclature
\begin{document}
\noindent$\Uk[j]$,$\Uk,$ $\Uk[p], \Uk[q]$ and $\Uk[r]$
\printnomenclature
\end{document}

Now to the two problems I have are
- The double definition
#3and#4is very ugly, is there some macro which increases the nesting level, i.e. which adds one # to each parameter? So that I could write\incnest{#3}instead of#4 - The
\RenewDocumentCommanddefinition is not global so all U's except the\Uk[q]are red. Is there some equivalent to\globalor\gdefin xparse. I found something similar for\renewcommandin \global\renewcommand equivalent of \global\def but it's a bit hacky.
Any tricks or workarounds to get it working are welcome.

texdoc expl3andtexdoc interface3. Redefining might be done, but it exposes you to the problem of doubling the#tokens. – egreg Oct 12 '12 at 13:25O{#3}to#3as it allows to define symbols with multiple optional arguments (the reason why I used xparse). It seems to be the perfect solution even if it looks a bit ugly :) thanks a lot. – buergi Oct 12 '12 at 13:37interface3.pdf. It's really hard to find the reference if one does not know its name especially since interface3 is not a very obvious name for it. – buergi Oct 12 '12 at 13:57