4

Is there a recommended way to change the formatting of page numbers in references in LaTeX, i.e., what \pageref outputs? I looked at the kernel source, as well as cleveref.sty and varioref.sty and others. I guess I could hack something up, but it's unclear to me what, if any, methods are recommended for this.

Reason: For TUGboat, we run articles in draft mode with page numbers starting at 901. Frank (Mittelbach) suggested printing such page numbers as "?1", "?2", ..., in order to make it obvious that the page numbers are not real and should not be cited (which has happened).

It is easy for me to do this in the headers and footers, since ltugboat.cls (that is, tugboat.dtx) already redefines those; instead of simply typesetting \thepage, I can run a macro that checks if the value is >900 and do the right thing. No problem. Similarly for the table of contents, since ltugboat also already redefines \l@section.

Because this is for TUGboat, I cannot actually load cleveref or varioref or their myriad relations; it would be much too fragile. I need to make the change in my own macro, as non-invasive as possible.

Here is an example (output below). I didn't bother with an index, etc., though the same question applies to wherever LaTeX typesets the page number.

\documentclass[draft]{ltugboat}
\begin{document}
\tableofcontents
\section{Introduction}
\label{intro} Reference to page~\pageref{intro}.
\end{document}

If you run this, you won't see the "?1" in the header or toc unless you use the unreleased tugboat.dtx->ltugboat.cls from tugboat svn. But that's not important; my question is about the \pageref. I want the "901" to also be "?1". Thanks in advance ...

output of tugboat draft page references

0

1 Answer 1

3

\thepage is the representation of the page number that is used everywhere and it is the logical command to change: You can redefine it to get a, b, c, ... or i, ii, iii, ... as numbering and you can also redefine it to get your numbering. Even hyperref will handle that in the page labels as long as it expands to sensible text (so better don't add a framed box or color).

Pitfalls

  • The index will fail. The problem is not that the "number" can not be printed, but that makeindex can't sort it, it can only handle some standard numbering systems like roman and digits. If the index matters you would have to redefine \@wrindex to write something different to \thepage or use some other indexing program that allows to define custom page numbers. Below in the example I make use of a feature of the index package: it allows to associate different counters with the index command.

  • packages that try to compare page numbers for whatever reason will fail too (they would also for roman or alphabetic numbers so it is not special to your numbering) but normally that should be solvable if the need arises.

I'm using three ??? to show that I overwrite the ltugboat settings:

\documentclass[draft]{ltugboat}
\usepackage{index}
\newcommand\specialthepage{\inteval{\value{page}-900}}
\newindex[specialthepage]*{default}{idx}{ind}{Index}

\usepackage{hyperref}
\renewcommand\thepage{???\inteval{\value{page}-900}}

\begin{document}
\tableofcontents
\section{Introduction}
\label{intro} Reference to page~\pageref{intro}.
\index{Bär}, \index{Duck}
\printindex
\end{document}

enter image description here

enter image description here

6
  • Thanks Ulrike. I should have mentioned that my first attempt was indeed to redefine \thepage. But then I got failures for precisely the reason you describe - \thepage was no longer a number. Is there really no clean way to separate how the page number is typeset from the numeric value? A solution that fails with makeindex is not a complete solution for me ... Frank likes to have indexes in his dtx-based articles too. And, in general, it seems like appearance and value are two different things. I only want to change the appearance.
    – Karl Berry
    May 31 at 22:48
  • P.S. I can easily understand how things ended up the way they are. But in principle, if \thepage is about the appearance, then it seems to me it should not be used when writing the value. Since that surely can't be changed now, maybe some other new command to \typesetpagenumber is in order? Not that I actually expect any such thing ...
    – Karl Berry
    May 31 at 22:49
  • Imho you are confusing appearance and representation. It is not simply about a nicer look: documents do not number pages only with absolute page numbers, many documents use the same number with different representation to distinguish pages: Page iv is a different page than page 4 and page 사 and so you can't pass only the abstract value 4 around. Jun 1 at 7:34
  • LaTeX could naturally store also the absolute page numbers (after the next release that will be rather easy) and keep track of formulas like abspage 10 = arabic 6 and abspage 100= roman iv to convert the absolute number back to a representation but do you really think that would be better than passing the representation directly? How e.g. should then the index know which numbers can be compressed and how they must be formatted? Regarding your index: it should be rather easy to adapt the commands that write the index so that they use a \thepage variant without the question mark. Jun 1 at 7:34
  • I added an edit which shows how you could handle the index. Jun 1 at 8:06

You must log in to answer this question.

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