I've implemented the back-link procedure given in the answer here, which works fine when also extended further to include \subsection{} and \subsubsection{} back-links. All work fine in normal chapters and appendices except for \chapter headings used in Appendices which show as a link in the PDF but go nowhere when clicked. But, if I start the appendix without a `\chapter{}' the TOC and appendix's heading title is wrong.
So how do I get the \chapter{} elements in Appendices to work as they do in main body book chapters.
My MWE:
\documentclass{scrreprt}
\usepackage{hyperref}
\makeatletter
\let\hyperchapter\chapter
\def\chapter{\@ifstar\starchapter\mychapter}
\def\starchapter{\hyperchapter*}
\newcommand{\mychapter}[2][\@empty]% #1=optional (toc and top of page), #2=title
{\ifx#1\@empty \hyperchapter[#2]{\hyperlink{toc.chapter.\thechapter}{#2}}
\else \hyperchapter[#1]{\hyperlink{toc.chapter.\thechapter}{#2}}
\fi}
\let\hypersection\section
\def\section{\@ifstar\starsection\mysection}
\def\starsection{\hypersection*}
\newcommand{\mysection}[2][\@empty]% #1=optional (toc), #2=title
{\ifx#1\@empty \hypersection[#2]{\hyperlink{toc.section.\thesection}{#2}}
\else \hypersecton[#1]{\hyperlink{toc.section.\thesection}{#2}}
\fi}
\makeatother
\usepackage[titletoc,title]{appendix}
\begin{document}
\let\hypercontentsline=\contentsline
\renewcommand{\contentsline}[4]{\hypertarget{toc.#4}{}\hypercontentsline{#1}{#2}{#3}{#4}}
\tableofcontents
\chapter{This is a great headline}
\section{and another}
\chapter{This is a bad headline!}
\section{last section}
\begin{appendices}
\appendix
\chapter{First One}
Stuff
\section{A Heading}
Other Stuff
\chapter{Second One}
Some notes here.
\end{appendices}
\end{document}
[edit: clarity]
\chapterto\sectionbut that resulted in the appendix not being in the ToC. Still hoping someone might have an answer... – mwra Jun 20 '18 at 10:51