I'm using hyperref (and titletoc) package(s). I redefined \appendix that way

\newif\if@appendix\@appendixfalse
\renewcommand\appendix{\par
\setcounter{section}{0}%
\setcounter{subsection}{0}%
\gdef\thesection{\@Alph\c@section}%
\@appendixtrue
}


\@appendix if is needed to modify the heading title, as i asked before here:

\DeclareRobustCommand{\@seccntformat}[1]{%
\def\temp@@a{#1}%
\def\temp@@b{section}%
\ifx\temp@@a\temp@@b
\if@appendix
\else
\fi
\else
\fi
}


and

\renewcommand\section{\@startsection%
{section}{0}{0mm}%
{2\baselineskip}{0.5\baselineskip}%
{\centering\normalfont\normalsize\scshape
\if@appendix{%
Appendix~%
}\fi
}%


}

in practice if I'm writing

  subsection            ==> x.y subsection_name
section_not_appendix  ==> x. section_name
section_appendix      ==> Appendix x: appendix_name


for the moment I got what I wanted without using any other package which I would like possibly not to use.

My question is: Now I want to modify toc entry in the table of contents, in particular I would like to have such format

  Apppendix x: appendix_name


where x is also an hyperref linking to the appendix. I think that the easiest way to proceed (without adding any other packages) is to modify further the definition of \section in order to change the \addcontentesline command which should sit in it. Can anyone help me?

# EDIT

A minimal example is the following

\documentclass{article}
\usepackage{titletoc}
,urlcolor=blue
,anchorcolor=blue
,citecolor=blue
,filecolor=blue
,bookmarks=true
,unicode=true
,pdfcreator={XeLaTeX}
,pdfa=true
]{hyperref}

\makeatletter
\renewcommand\section{\@startsection%
{section}{0}{0mm}%
{2\baselineskip}{0.5\baselineskip}%
{\centering\normalfont\normalsize\scshape
\if@appendix{%
Appendix~%
}\fi
}%
}

\renewcommand\subsection{\@startsection%
{subsection}{1}{0mm}%
{1\baselineskip}{0.5\baselineskip}%
{\centering\normalfont\normalsize\itshape}%
}

\DeclareRobustCommand{\@seccntformat}[1]{%
\def\temp@@a{#1}%
\def\temp@@b{section}%
\ifx\temp@@a\temp@@b
\if@appendix
\else
\fi
\else
\fi
}

\makeatletter
\renewcommand\tableofcontents{%
\section*{\contentsname
\@mkboth{%
\contentsname}{\contentsname}}%
\@starttoc{toc}%
}

\newif\if@appendix\@appendixfalse
\renewcommand\appendix{\par
\setcounter{section}{0}%
\setcounter{subsection}{0}%
\gdef\thesection{\@Alph\c@section}%
\@appendixtrue
}

\makeatother

\titlecontents{section}%
[9mm]
{}
{\contentslabel[%
section.\thecontentslabel
}{%
\thecontentslabel.%
}]%
{7mm}}
{\hspace*{-7mm}}
{\hfill\contentspage}
{}

\titlecontents{subsection}%
[20mm]
{}
{\contentslabel[
subsection.\thecontentslabel%
}{%
\thecontentslabel%
}]%
{12mm}}%
{\hspace*{-12mm}}
{\hfill\contentspage}
{}

\begin{document}
\tableofcontents
\section{First}
\subsection{First-first}
\subsection{First-second}
\section{Second}
\section*{Unnumbered}
\subsection{Second-First}
\appendix
\section{This is the app}
\end{document}


The output of the table of contents the one I want to get except for the fact that I would like to have the appendix entry almost like the unnumbered entry: I would like it to be

 Appendix A: This is the app


with the A a hyperref to the appendix. How can i do?

• Can you provide at least some working document to work with. Is titletoc really necessary? – user31729 May 10 '16 at 11:55
• @ChristianHupfer Thanks for the attention. I edited the question adding an example. – MaPo May 10 '16 at 14:41

Maybe I found a solution, it's enough to define

\renewcommand\appendix{\par
\setcounter{section}{0}%
\setcounter{subsection}{0}%
\gdef\thesection{\@Alph\c@section}%
\@appendixtrue
\titlecontents{section}%
[2mm]
{}
{Appendix~%

• You are probably receiving some "duplicate destination" warnings. Add \renewcommand{\theHsection}{appendix.\thesection} to your \appendix command. – Werner May 10 '16 at 19:23