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}
\hypertarget{link:two}{targettwo}
\newcommand{\aaa}{link:one}
\newcommand{\ccc}{\renewcommand{\aaa}{link:two} \aaa}
\hyperlink{\ccc}{something} %no link produced, only text: "link:two" and 6 errors
\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...
l.21 \hyperlink{\ccc}{aaa}
%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
l.21 \hyperlink{\ccc}{aaa}
%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.
<to be read again>
\par
l.21 \hyperlink{\ccc}{aaa}
%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.
\hyper@link@ ...\Hy@safe@activestrue \edef \x {#3}
\ifx \Hy@tempa \@empty \to...
l.21 \hyperlink{\ccc}{aaa}
%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.
<to be read again>
\par
l.21 \hyperlink{\ccc}{aaa}
%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.
\x ...r@link {link}{\let \reserved@d =*\def \par }
{\Hy@safe@activesfalse aaa}
l.21 \hyperlink{\ccc}{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.