Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using pdftex and the hyperref package. I have a number of automatically generated \hyperlink{<label>}{<text>}, which point to other automatically generated \hypertarget{<label>}{<text>}.

But since the two are generated independently, I don't know a priori whether a given label exists or not. The default behaviour when hyperlinking to an inexistent target is to put a "Go to page 1" link, which is completely useless for the user.

Is it possible to change that default behaviour to either

  • put no link when the link would be broken, or

  • point the link to itself?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

I added code for this to the ydoc package (beta version only), which is an alternative to ltxdoc/doc. There the macro descriptions are hyperlinked to the place where the macros are defined and vice versa.

To avoid dead links for internal macros which aren't described in the user manual part I remember each one by defining a macro like \defined@<name> when I set the \hypertarget{}. This definitions are also written to the .aux file so that they are available at the beginning of the document. The \hyperlink is then only set if \defined@<name> exist.

share|improve this answer
    
My goal was in fact to propose something to Joseph Wright for possible inclusion in l3doc, so ydoc is very relevant. I remember issues with the catcode of @ being other when reading the .aux file. How do you make sure that \def\defined@... actually defines \defined@... and not \defined delimited by @...? Are you using a \csname construction? –  Bruno Le Floch Feb 26 '11 at 0:24
    
@Bruno: Sorry, I can't follow you right now. Yes, the @ is other while reading the .aux file , which is what you want in this situation. I'm using \global\@namedef{href@desc@<macro>}{} and \global\@namedef{href@impl@<macro>}{} for the description and implementation. –  Martin Scharrer Feb 26 '11 at 0:36
    
@Martin: but then \@namedef should be tokenized as \@, followed by n, a, etc.? –  Bruno Le Floch Feb 26 '11 at 0:41
    
@Bruno: dammit, sorry, I had a long day :-) I meant the catcode of the @ in the .aux file is letter, not other. LaTeX itself uses macro with @ there, like \@writefile. See lines 1366-68 and 3900 of latex.ltx, there the .aux file is read and both times \makeatletter is used. –  Martin Scharrer Feb 26 '11 at 0:44
    
@Martin: I should have run some tests myself. So in the end, you do use a csname construction, but not because of the @, rather for the macro name. Thanks for the pointer to latex.ltx. –  Bruno Le Floch Feb 26 '11 at 0:56
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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