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.

As part of a project to get LaTeX to output something useful, I found myself wanting to write a new hyperref driver for the desired format. The documentation explains what a driver needs to do, but it doesn't explain how to get hyperref to load the new driver instead of its given one. Looking through the code, I can't see an obvious hook but I may well be missing something. At the moment, I load the driver file using the \AtBeginDocument hook, but it worries me that this might not be very robust.

So, can I get hyperref to load a custom driver without modifying hyperref.sty? If not, are there any dangers from manually loading it myself at the start of the actual document?

share|improve this question

3 Answers 3

up vote 7 down vote accepted

I got notified about this thread and have now added option customdriver in hyperref 6.83f. From its README:

Option `customdriver'
---------------------
  The value of option `customdriver' is the name of an external
  driver file without extension `.def'. The file must have
  \ProvidesFile with a version date and number that match the
  date and number of `hyperref', otherwise a warning is given.

  Because the interface, what needs to be defined in the driver,
  is not well defined and quite messy, the option is mainly intended
  to ease developing, testing, debugging the driver part.
share|improve this answer
    
Thank you! That will make things much easier for me. –  Loop Space Sep 26 '12 at 14:20

You could use a hyperref.cfg with the line \def\Hy@driver{myhdriver}. This will load a myhdriver.def. But it will work only with LaTeX (means dvi output) and not with pdfLaTeX (pdf output). With pdfoutput hyperref will force the use of the hpdftex.def.

share|improve this answer
    
Sadly, I do want PDF output; unless there's a dvitotext program that no-one's been tell me about. (Yes, I know I could do latex -> dvi -> pdf -> text but that seems a little ridiculous, plus I was hoping for a robust solution that didn't rely on a specific engine.) –  Loop Space Aug 1 '11 at 12:30
    
Just a thought ... would it be possible to trick hyperref in to thinking it was being run by latex and not pdflatex? –  Loop Space Aug 1 '11 at 12:31
2  
Well you could perhaps set \pdfoutput=1 only at \begin{document}. But I would at first ask Heiko. Perhaps he is willing to implement an option specialdriver=..... –  Ulrike Fischer Aug 1 '11 at 12:41
    
@Andrew: Yes, email Heiko (ideally with a patch attached!). He is usually very responsive about such things. –  Lev Bishop Aug 1 '11 at 14:00
    
@Andrew: dvitotext is a FAQ :) tex.ac.uk/cgi-bin/texfaq2html?label=fmtconv+toascii Check out dvi2tty, crudetype, catdvi –  Lev Bishop Aug 1 '11 at 14:02

The patch below seems to do the trick. Declare the option customdriver to store its key in \HyOpt@CustomDriver. If that's nonempty then clobber \Hy@driver just before loading the driver file. EDIT: added context for the diff, as requested by Andrew Stacey.

*** hyperref-original.sty
--- hyperref-modified.sty
***************
*** 2861,2866 ****
--- 2861,2870 ----
      }%
    \fi
  }
+ \let\HyOpt@CustomDriver\ltx@empty
+ \define@key{Hyp}{customdriver}{%
+   \def\HyOpt@CustomDriver{#1}%
+ }
  \define@key{Hyp}{hyperfigures}[true]{%
    \Hy@boolkey[hyperfigures]{figures}{#1}%
  }
***************
*** 4206,4211 ****
--- 4210,4219 ----
        \fi
      \fi
    \fi
+   \ifx\HyOpt@CustomDriver\ltx@empty
+   \else
+     \let\Hy@driver\HyOpt@CustomDriver
+   \fi
    \Hy@Message{Driver\HyOpt@DriverType: \Hy@driver}%
    \chardef\Hy@VersionChecked=0 %
    \input{\Hy@driver.def}%

Used as

\documentclass{article}
\usepackage[customdriver={foo}]{hyperref}
\begin{document}
   \href{foo}{bar}
\end{document}
share|improve this answer
    
Very nice. Okay, so next question is what is Heiko's email address? –  Loop Space Aug 1 '11 at 18:19
    
@Andrew you can find the address on the comp.text.tex newsgroup. Or you can simply post it on c.t.t. directly. –  Bruno Le Floch Aug 2 '11 at 2:24
    
To make this answer most useful, you should make that a context or unified diff. I just blindly applied it against hyperref.sty from TL2010 and it was off by one line! –  Loop Space Aug 2 '11 at 10:42
    
I don't know what a context diff is, sorry :(. And indeed, my patch is against TL 2011. I've got to leave for a week, btw. –  Bruno Le Floch Aug 2 '11 at 11:22
    
Okey-dokey. I might update your post to a context diff (it's sort of what it says: it adds a little context around the changes so that if lines get a bit offset then it's still easy to see where the changes should be applied. If you're on a unix system, then you can produce them with diff -c instead of diff) –  Loop Space Aug 2 '11 at 11:34

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.