% An example showing Heiko Oberdiek how I use hyperref's \make@stripped@name
% Time-stamp: <2003-01-22 17:23:25 gildea>
\documentclass{article}
\usepackage[dvips]{hyperref}

% a simplified example
\def\mysubsection#1{\index{#1}%
  \par \vskip.5\baselineskip plus 1pt \penalty-400
  %% Position the PDF mark not so far in the left margin (hyperref 6.71v)
  %% (bug first reported 21 Oct 1999 against hyperref 6.66m).
  \leavevmode
  \hbox to 0pt{\hskip 2cm
    \myaddcontentsline{toc}{subsection}{#1}{#1}\hss}%
  \textbf{#1}\quad}

% override hyperref's override, passing all arguments to l@ function
\def\contentsline#1#2#3#4{\csname l@#1\endcsname{#2}{#3}{#4}}

\makeatletter

% \make@stripped@name is called here

\def\myaddcontentsline#1#2#3#4{%
  \make@stripped@name{#4}%      %put sanitized version into \newname

\addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}{\newname}}%
  \pdfbookmark[\csname toclevel@#2\endcsname]{#3}{\newname}%
}

% section and subsectiond links have to point to a different file
\renewcommand*\l@section[3]{\noindent   
  \textbf{\href{file:lesson#2.pdf}{#1}}%
  \par}

\renewcommand*\l@subsection[3]{{\parindent=0.5em
  \hyperref{file:lesson#2.pdf}{}{#3.2}{#1}%
  \par}}

\makeatother

\begin{document}

\tableofcontents

\section{Bug Report}
I'm writing a set of related documents where the table of contents
and
the index are a separate documents.  The index document wants to 
generate cross references to sections of the other documents by
name.
The names are known by the toc and index documents, but the section
numbers are not.

\mysubsection{addcontentsline}
I get around this problem by supplying my own version of
\verb|\addcontentsline|, which generates a PDF bookmark and writes
a toc
reference to it.  Both use the name of the section, not the section
number.  Because the section name has to be acceptable to
PostScript
and PDF, I use \verb|\make@stripped@name| to generate it.

\mysubsection{Characters{}, Special/Fragile}
Because I use \verb|\make@stripped@name| and pass its result as
the 4th argument to \verb|\contentsline|, it gets read by my
version of the \verb|\l@subsection| and passed to
\verb|\hyperref|, which chokes on a comma in argument 3.

\end{document}
