4

I would like to be able to change the varioref strings. In particular, the on the facing page one.

It should not be a problem. The documentation clearly states various macros used, and I would think I would be able to change them using:

\renewcommand\reftextfaceafter{on the following page}
\renewcommand\reftextafter {on the next page}
\renewcommand\reftextfacebefore{on the previous page}
\renewcommand\reftextbefore {on the previous page}

This works fine, unless I use babel together with varioref.

MWE follows:

\documentclass{book}

\usepackage[english]{babel}  % works if this line is commented out

\usepackage{varioref}

\renewcommand\reftextfaceafter{on the following page}
\renewcommand\reftextafter {on the next page}
\renewcommand\reftextfacebefore{on the previous page}
\renewcommand\reftextbefore {on the previous page}

\begin{document}

empty page
\clearpage

\begin{figure}
\centering
\rule{5cm}{3cm}
\caption{Caption}
\label{fig}
\end{figure}

\clearpage

Figure \vref{fig}

\end{document}
  • Have you tried putting the \renewcommands after \begin{document}? – cfr Aug 2 '15 at 21:39
4

If you put the \renewcommands after \begin{document}, it works fine. If you put them in the preamble, they get overwritten when things are configured at the end of the preamble/beginning of the document.

However, I don't think putting them after \begin{document} is the correct solution, Looking at the manual for varioref, we find modified instructions for documents which use babel. These suggest the following code:

\documentclass[english]{book}
\usepackage{babel}  % works if this line is commented out
\usepackage{varioref}
\addto\extrasenglish{% page 5 of varioref's manual
  \renewcommand\reftextfaceafter{on the following page}%
  \renewcommand\reftextafter {on the next page}%
  \renewcommand\reftextfacebefore{on the previous page}%
  \renewcommand\reftextbefore {on the previous page}%
}
\begin{document}
empty page
\clearpage
\begin{figure}
\centering
\rule{5cm}{3cm}
\caption{Caption}
\label{fig}
\end{figure}
\clearpage
Figure \vref{fig}
\end{document}

renewed

Note that by passing english to the document class, rather than directly to babel, other packages which are language-aware will be able to pick up the setting.

  • A similar solution ;-) – user31729 Aug 2 '15 at 21:48
  • @ChristianHupfer Was... I don't actually think this is the right way to do it, though. See modified answer. Also, I noticed that you referred to my answer in your revised version. You should probably either link to version 1 of my answer or just remove it to avoid confusion ;). (Since I now say not to do this. Although I do say it works.) – cfr Aug 2 '15 at 21:56
  • @ChristianHupfer I don't know, to be honest. I don't know the package well enough to know whether it just suggests this method as one way or whether something else relies on it. So, I would probably say (right now) that it is more correct or better to do it this way - but only because the documentation says to do it this way and so I assume that is safer in the absence of evidence to the contrary. Generally, using packages' own commands to customise them works more reliably. Hence, it may do here, too.... But this is all highly defeasible. – cfr Aug 2 '15 at 22:01
  • 1
    “Fixed” words of phrases should always be redefined with \addto\extras<language> when babel is involved. – egreg Aug 2 '15 at 22:27
2

babel does some redefinitions right at \AtBeginDocument, so the \renewcommand of the \ref.... macros must be hooked even later on, i.e. use \AtBeginDocument{...} around the \renewcommand and the changes come into action, since this new \AtBeginDocument content addition is executed after previous ones. (Otherwise use the \addto - approach as suggested by cfr's solution -- this is mentioned in the manual of varioref package as well)

\documentclass{book}

\usepackage[english]{babel}  % works if this line is commented out

\usepackage{varioref}


\AtBeginDocument{%
\renewcommand\reftextfaceafter{on the following page}
\renewcommand\reftextafter{on the next page}
\renewcommand\reftextfacebefore{on the previous page}
\renewcommand\reftextbefore{on the previous page}
}
\begin{document}

empty page
\clearpage

\begin{figure}
\centering
\rule{5cm}{3cm}
\caption{Caption}
\label{fig}
\end{figure}

\clearpage

Figure \vref{fig}

\end{document}

enter image description here

  • 1
    better to use \addto\extraszzz really then it still works in bilingual documents. – David Carlisle Aug 2 '15 at 21:59
  • @DavidCarlisle: Yes, but as long there's no bilingual document... I'll however remember this for future purposes – user31729 Aug 2 '15 at 22:03
  • @ChristianHupfer marking the other reply as correct. Sorry, but the other reply was one minute earlier and is a little more complete. Thank you tho :P – Ricardo Cruz Aug 2 '15 at 22:39
  • @RicardoCruz: Nope, mine was first, but it's true, cfr answer is more general – user31729 Aug 2 '15 at 23:49
  • @ChristianHupfer ah, I think it said something like "answered 50 minutes ago" for one and "answered 52 minutes ago" for the other. Anyhow, sorry about the confusion. I have asked a few questions on this website, in the course of my thesis, and I really appreciate you guys helping out, so thank you ...! – Ricardo Cruz Aug 3 '15 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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