TransWikia.com

How can I display the page number of a cross-referenced object, but only if the object is on different page?

TeX - LaTeX Asked by SteeveDroz on March 4, 2021

I am creating a command called fullref{<label>} that takes a label and outputs the number of the labeled object and name and optionally the page number where to find the object if it’s on a page that differs from where the cross-referencing call-out occurs.

Examples:

Let a label label{chap_intro} and a text … as seen in chapter fullref{chap_intro}..

If they are on the same page, the text will output:

… as seen in chapter 1.1: "Introduction".

If they are on different pages, the text will output:

… as seen in chapter 1.1: "Introduction" on page 2.

Here is my command so far:

latex

newcommand{fullref}[1]{ref{#1}: "nameref{#1}" ifthenelse{
  equal{thepage}{pageref{#1}} % if the current page and the referenced page are the same
 }
 {} % then do nothing
 { on page pageref{#1}} % else append "on page …" if different
}

Even when on the same page, it displays "on page …".

What did I do wrong?

One Answer

The varioref package and its vref user macro accomplish what your fullref macro aims to do.

The package works with babel, and it offers ways to customize what is supposed to be typeset if the cross-referenced object happens to be on, near, or far away from the cross-referencing call-out. This customization works by redefining the macros reftextbefore, reftextfacebefore, reftextafter, reftextfaceafter, and reftextfaraway; see section 5 of the package's user guide for the full details.

Correct answer by Mico on March 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP