3

The recent acmart style (try here if that link is broken) doesn't seem to work properly with titletoc, producing an unwanted string of section names at the beginning of the table of contents:

enter image description here

I'm looking for output similar to that shown in the answer to this question, which I can get by replacing acmart by article:

enter image description here

I have looked at other table-of-contents solutions, but I particularly like the output of titletoc, so I would like to get that working if possible.

Here's the code:

\documentclass{acmart}

\usepackage{appendix}
\usepackage{titletoc}

\newcommand\DoToC{%
  \startcontents
  \printcontents{}{2}{\textbf{Contents}\vskip3pt\hrule\vskip5pt}
  \vskip3pt\hrule\vskip5pt
}

\begin{document}

\DoToC

\section{My First Section}
\section{My Second Section}

\begin{appendices}
\section{My First Appendix}
\DoToC
\subsection{My First Subsection}
\subsection{My Second Subsection}

\section{My Second Appendix}
\DoToC
\subsection{My First Subsection}
\subsection{My Second Subsection}
\end{appendices}

\end{document}
4
  • Where is that class fileacmart.cls ?
    – M S
    Mar 7 '17 at 10:26
  • See link at beginning of question.
    – Roly
    Mar 7 '17 at 10:27
  • Yes. Not Working and opening here.
    – M S
    Mar 7 '17 at 10:28
  • Weird. Opens for me fine. Added a link to the CTAN package.
    – Roly
    Mar 7 '17 at 10:36
2

The problem is, acmart loads hyperref. Normally hyperref redefines some titletoc internals to work. However, since you now load titletoc after hyperref, it does not have a chance to do so.

This means you need to redefine them yourself.

This works:

\documentclass{acmart}
\usepackage{appendix}
\usepackage{titletoc}
\makeatletter
  \def\ttl@Hy@steplink#1{%
    \Hy@MakeCurrentHrefAuto{#1*}%
    \edef\ttl@Hy@saveanchor{%
      \noexpand\Hy@raisedlink{%
        \noexpand\hyper@anchorstart{\@currentHref}%
        \noexpand\hyper@anchorend
        \def\noexpand\ttl@Hy@SavedCurrentHref{\@currentHref}%
        \noexpand\ttl@Hy@PatchSaveWrite
      }%
    }%
  }%
  \def\ttl@Hy@PatchSaveWrite{%
    \begingroup
      \toks@\expandafter{\ttl@savewrite}%
      \edef\x{\endgroup
        \def\noexpand\ttl@savewrite{%
          \let\noexpand\@currentHref
              \noexpand\ttl@Hy@SavedCurrentHref
          \the\toks@
        }%
      }%
    \x
  }%
  \def\ttl@Hy@refstepcounter#1{%
    \let\ttl@b\Hy@raisedlink
    \def\Hy@raisedlink##1{%
      \def\ttl@Hy@saveanchor{\Hy@raisedlink{##1}}%
    }%
    \refstepcounter{#1}%
    \let\Hy@raisedlink\ttl@b
  }%
\def\ttl@gobblecontents#1#2#3#4{\ignorespaces}%
\makeatother

\newcommand\DoToC{%
  \startcontents
  \printcontents{}{2}{\textbf{Contents}\vskip3pt\hrule\vskip5pt}
  \vskip3pt\hrule\vskip5pt
}

\begin{document}

\DoToC

\section{My First Section}
\section{My Second Section}

\begin{appendices}
\section{My First Appendix}
\DoToC
\subsection{My First Subsection}
\subsection{My Second Subsection}

\section{My Second Appendix}
\DoToC
\subsection{My First Subsection}
\subsection{My Second Subsection}
\end{appendices}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.