I'd definitely go with Bianca Lobo's solution (the alternative one, really). But, just for fun, here's another way.
It's possible to strip $ symbols, but this is not the only problem: if you strip $ from \defined{$\Gamma$-function} you'll get into troubles. Moreover, simply stripping the $ would leave incorrect entries in the index in any case.
However one can use the @ feature of \index: with
\index{something@something else}
MakeIndex will use something for the sorting, while writing "something else" as the index entry.
Here's a complicated way to do what you want:
\documentclass{article}
\usepackage{xparse,l3regex}
\usepackage{imakeidx}
\makeindex
\ExplSyntaxOn
\NewDocumentCommand{\defined}{om}
{
\textbf{#2}
\IfNoValueTF{#1}
% No optional argument: do the complicated test
{ \heinz_index:n {#2} }
% Optional argument: use the simplest way
{ \label{#1}\index{#1@#2} }
}
\tl_new:N \l__heinz_index_tl
\cs_new_protected:Npn \heinz_index:n #1
{
% test if a $ is present in the argument
\tl_if_in:nnTF { #1 } { $ }
{ \__heinz_strip:n { #1 } } % a $ is scanned
{ \index{#1} } % no $, simple case
}
\cs_new_protected:Npn \__heinz_strip:n #1
{
% stringify the argument
\tl_set:Nx \l__heinz_index_tl { \tl_to_str:n { #1 } }
% remove $, backslash, spaces
\regex_replace_all:nnN { ( \$ | \\ | \s ) } { } \l__heinz_index_tl
% produce the \index command and the label
\__heinz_do_double_index:nV { #1 } \l__heinz_index_tl
}
\cs_new_protected:Npn \__heinz_do_double_index:nn #1 #2
{
\exp_args:NV \label \l__heinz_index_tl
\index{#2@#1}
}
\cs_generate_variant:Nn \__heinz_do_double_index:nn { nV }
\ExplSyntaxOff
\begin{document}
\defined{face}
\defined{$G$-invariant}
\defined{group}
\defined{$\Gamma$-function}
\defined[C-transform]{$\mathcal{C}$-transform}
\pageref{G-invariant}
\clearpage
\printindex
\end{document}
However, in some cases you'll have to express it in the form
\defined[<sorting key>]{<argument>}
as the stripping performed in the case of $\mathcal{C}$-transform will do no good. One might add to the list of tokens to be stripped off, but this is error prone and it doesn't seem really a sensible thing to do.
Note also that you have to use the "stripped" version in \pageref, so do \pageref{G-invariant} and not \pageref{$G$-invariant}. In any case a label such as $\Gamma$-function would be illegal.
\bfIt's obsolete: See: http://www.ctan.org/tex-archive/info/l2tabu or this answer: http://tex.stackexchange.com/questions/29448/despite-using-backslash-dollar-sign-error-persists/29449#29449 – Marco Daniel Feb 17 '13 at 13:14\documentclass{...}and ending with\end{document}. – Marco Daniel Feb 17 '13 at 13:18\labelcan't work. There is no reference point. – Marco Daniel Feb 17 '13 at 13:21\labelwrites not only a number, but also the page number and it's common to use a\labelfor referring to the page with\pageref– egreg Feb 17 '13 at 14:07\href. If you usenamerefit fails – Marco Daniel Feb 17 '13 at 14:17\defined{$\Gamma$-function}? I'd definitely go with the optional argument for sorting. – egreg Feb 17 '13 at 14:17