The usual practice is that the index entries link to a page in the text where the word occurs. I am trying to index a list of files and am indexing each word in the file name. In the MWE below, clicking on the link in the index takes me to the appropriate section in the doc, and then I can click on that to open the file.

Since the body of this document has no real meaning in this case (I am only interested in the index), I would like a way to modify this two step process to be just one step. So, I would like the links in the index to be links to the file (as they are now in the main body of the document). I am assuming that this should only require a change to the \ProcessWord macro.


  • The datatool package was used here only since my real use case gets the file names via this package.
  • For the output links to open the actual files you need to use a PDF reader that supports that (such as Acrobat). The PDF viewer with TeXShop 2.43 does have support, but not the one with TeXWorks 2.3.



\usepackage{datatool}% database
\usepackage{imakeidx}% indexing
\usepackage{hyperref}% For cross references

% ---------- Process Each Word:
% https://tex.stackexchange.com/questions/12810/how-do-i-split-a-string
\def\ReadWords#1 #2\relax{%
      \ProcessWord[\@tempb]{#1}%  #1 = substr, #2 = rest of string
      \ifx\relax#2\relax% is #2 empty?
         \def\next{\endgroup\EndProcessWords}% your own end-macro if required
% ---------- 

    %\par\noindent\href{run:#1.pdf}{#1}% Moved Below


\DTLnewdbentry{DB}{FileName}{Now good enough}% 

\DTLnewdbentry{DB}{FileName}{Now good enough for you and me}% 



1 Answer 1


It turns out that the most obvious solution actually works -- not sure why this did not occur to me earlier:


Futher Improvements

enter image description here

You must log in to answer this question.

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