## Sunday, December 17, 2006

### HyperRef Options for Proper BackReferencing with Figures Numbered Within Sections and Partial Roman Page Numbering

That's a really long title, I know.

I have a long document that has roman page numbering for its first four pages (i.e., its title page, table of contents, and list of figures). After that, the rest of the document has arabic page numbering starting at page 1 (so the first four pages of the document are i-iv, and the fifth page is page 1).

I have the option (via package amsmath)
`\numberwithin{figure}{section}`
turned on. This lets my figures be numbered by section (e.g., Figure 2.1).

I have backreferencing turned on (via hyperref) in my bibliography.

It turns out that hyperref won't get all of the links correct unless you massage it quite a bit. For example, page i and page 1 can get the same label (page.1) and so back references to page 1 end up getting sent to page i, which is clearly not correct. A similar thing can happen with Figure 2.1 and figure B.1; they both get labeled as figure.1 and so links to them get confused. There are lots of other pitfalls you run into as you turn on and off options to try to fix things.

Anyway, I had to dig through the hyperref and backref sources to figure out which options to set. These were the ones that I ended up needing. Things work as expected now.
`\usepackage[pdfpagelabels,pagebackref,            hypertexnames=true,plainpages=false,            naturalnames]{hyperref}`
NOTE: If you are producing a DVI rather than a PDF, if you want the links to work, you should probably use:
`\usepackage[dvipdfm,            pdfpagelabels,pagebackref,            hypertexnames=true,plainpages=false,            naturalnames]{hyperref}`
That's the same line, but the "dvipdfm" option was added in front.

You should also use pdflatex to build your document. You can pass pdflatex an -output-format dvi option to get it to produce a DVI. (note: you can also symlink pdflatex to latex to get it to produce a DVI) (ALSO: you can add -src-specials to the pdflatex line if you're into source specials)

Phew. That took a long time to figure out. I need a beer.