# Nested macros and hyperlink problem

I am new to LaTeX and write a document with the use of the hyperref package. Here is this simple scenario which I do not understand. I have to use a macro like \ccc in \hyperlink but it causes 6 errors and I can not fix the problem:

\documentclass[a4paper,12pt,oneside]{book}
\usepackage{hyperref}
\begin{document}

\end{document}


log:
.
.
.
! Use of \hyper@link@ doesn't match its definition.
\@ifnextchar ... \reserved@d =#1\def \reserved@a {
#2}\def \reserved@b {#3}\f...
%6 errors
If you say, e.g., \def\a1{...}', then you must always
put 1' after \a', since control sequence names are
made up of letters only. The macro here has not been
followed by the required stuff, so I'm ignoring it.

! Argument of \@firstoftwo has an extra }.
<inserted text>
\par
%6 errors
I've run across a }' that doesn't seem to match anything.
For example, \def\a#1{...}' and \a}' would produce
this error. If you simply proceed now, the \par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your }' was spurious, just type 2' and it will go away.

Runaway argument?
! Paragraph ended before \@firstoftwo was complete.
\par
%6 errors
I suspect you've forgotten a }', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.

! Extra }, or forgotten \endgroup.
\ifx \Hy@tempa \@empty \to...
%6 errors
I've deleted a group-closing symbol because it seems to be
spurious, as in $x}$'. But perhaps the } is legitimate and
you forgot something else, as in \hbox{$x}'. In such cases the way to recover is to insert both the forgotten and the deleted material, e.g., by typing I$}'.

Runaway argument?
{\let \reserved@d =*\def
! Paragraph ended before \hyper@link was complete.
\par
%6 errors
I suspect you've forgotten a }', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.

! Too many }'s.
{\Hy@safe@activesfalse aaa}
%6 errors
You've closed more groups than you opened.
Such booboos are generally harmless, so keep going.
.
.
.


I am Using TeXnicCenter with MikTeX 2.9.

-
Welcome to TeX.SX! What's the purpose of this nesting? There may be better ways to do this. –  egreg Apr 11 '12 at 7:46

The correct syntax is \hyperlink{<name>}{<text>} where <name> must be a valid, expandable label name. It can not contain any non-expandable commands. This excludes any form of assignment, e.g. \renewcommand. The name must instead expand directly to some text only.

So your:

\newcommand{\aaa}{link:one}


is wrong and will never work. You need to write it some way like this:

\newcommand{\aaa}{link:one}
\ccc

This means: Do any redefinition of \aaa before \hyperlink and make sure that \aaa expands to only the name.
@MarcoDaniel: The now gone "example" was the original text posted in the question. I only accidentally pasted it at the end of my answer. ;-) Note that a simple expandable macro works, because it is expanded internally. Either using \csname .. \endcsname or by writing it into an auxiliary file. Both do not support unexpandable stuff. –  Martin Scharrer Apr 13 '12 at 13:10
@MarcoDaniel: If you think so. Using \$ccc doesn't make much sense IMO. –  Martin Scharrer Apr 13 '12 at 13:35