1

Background

A custom Table of Contents entry was suggested to move page numbers from the right-hand side to the left-hand side.

Problem

The custom command loses ToC hyperlinks. I have tried to restore the hyperlinks as follows:

\goto{#3}[page(\currentlistentrylocation)]

This does not produce the correct page number link. Similar attempts include:

  • \goto{#3}[#3]
  • \gotopage{#3}
  • \goto{#3}[page(#3)]

It seems that these commands cannot reference a page number indirectly.

Code

Minimal example:

\setupinteraction[state=start,]
\setupcombinedlist[content][interaction=all,]

% Set the page number to the left of the section title.
\define[3]\SectionToCEntry{%
  \par \leftaligned\bgroup
    \hbox to 2em{\goto{#3}[page(\currentlistentrylocation)]}%
      \hskip 1em
      \vtop{\hsize\dimexpr\textwidth-3em\relax#2}
  \egroup \par%
}

\setuplist[section][
  alternative=command,
  command=\SectionToCEntry,
]

\starttext
  \placecontent
  \dorecurse{4}{
    \page
    \section[title={Section A}]
    \dorecurse{5}{\input knuth}
    \section[title={Section B}]
    \dorecurse{5}{\input ward}
  }
\stoptext

Question

I am wondering:

  • how would you retain the internal hyperlinks for such a custom ToC; or
  • is there a simpler approach to reconfiguring the ToC?

Related

Additional information:

Dave Jarvis
  • 11,809

1 Answers1

1

Use alternative=interactive as per Wolfgang's solution (from the mailing list):

% Set the page number to the left of the section title.
\define[3]\SectionToCEntry{%
  \leftaligned\bgroup
    \hbox to 2em{#3}%
      \hskip 1em
      \vtop{\hsize\dimexpr\textwidth-3em\relax#2}
  \egroup 
}

\setuplist[section][
  alternative=interactive,
  command=\SectionToCEntry,
]

Marco's solution is slightly more complicated:

\unprotect
\define[3]\SectionToCEntry{%
  \hbox \strc_lists_get_reference_attribute\v!all{%
    \par \leftaligned\bgroup
      \hbox to 2em{#3}%
        \hskip 1em
        \vtop{\hsize\dimexpr\textwidth-3em\relax#2}
    \egroup \par%
  }
}
\protect

The \unprotect is required to accommodate for \v!all.

Dave Jarvis
  • 11,809