8

I need to show a list of items/keywords/duedates used throughout my document at the beginning of the document, and make them hyperlinks. To be able to use this information the beginning of the document, I'm (ab)using a ToC-like structure:

\documentclass{article}
\usepackage{hyperref}

\makeatletter
    \newcommand\listofduereviews{\textbf{Due Dates:}~\@starttoc{due}}
\makeatother

\newcommand{\duedate}[1]{%
    \hypertarget{link.#1}{#1}%
    \addtocontents{due}{\protect\hyperlink{link.#1}{(#1)}\quad}%
    }

\begin{document}
\listofduereviews
\bigskip

The first due date is \duedate{01-May-2012}, and the second due date is \duedate{02-May-2012}.
\end{document}

This does what I want:

enter image description here

But I feel I'm abusing ToCs for what they are not made for (or maybe I'm not, I just don't have enough LaTeX literacy to judge myself). What is a more elegant way to achieve this? Perhaps writing directly to a (non-listof) file?

9
  • I don't see what's unelegant about using \@starttoc; after all this LaTeX commands internally writes information to an external file (which seems to be what you are asking for in your final comment). Commented Jun 2, 2012 at 2:11
  • @GonzaloMedina, well, that's good news then! Basically, I'm looking for best practices. Commented Jun 2, 2012 at 4:00
  • You may care to take a look at the tocloft package (or memoir, which includes its functionality). This would allow you to set up a separate space for due dates, leaving the table of contents functionality intact and independent. I'm sorry, but at the moment I have neither the time nor the experience to make this into a good answer. Commented Jun 2, 2012 at 12:41
  • @Brent.Longborough what tocloft's \newlistof command does behind the scenes is to use \@starttoc in a similar manner to what Ali Mehrzi is already doing, so I don't really see the point of using tocloft here. And since Ali Mehrzi's code writes a file with extension .due, its code leaves .toc untouched, so the ToC functionality reamins intact and independent. Commented Jun 2, 2012 at 22:08
  • @GonzaloMedina: Yes, I admit it's a marginal change, but I thought OP might want to avoid \makeatletter and other pieces of LaTeX mysticism... :) Commented Jun 4, 2012 at 12:19

1 Answer 1

6

I don't see anything unelegant about using \@starttoc; after all this LaTeX command internally writes information to an external file (which seems to be what you are asking for in your final comment).

Of course, instead of using \@starttoc you could set the things yourself (using \@input, \newwrite, \openout...) but \@starttoc internally does exactly this job for you so I think your approach is perfectly valid.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .