GeneralNeed a command to generate "above"/"below" in references

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
sullivander
Posts: 3
Joined: Wed May 04, 2011 4:50 am

Need a command to generate "above"/"below" in references

Post by sullivander »

Greetings, first post here. I've searched forums (and the rest of the internet, it feels like) and can't find an answer to what seems like a simple question. I am trying to find a command that generates "above"/"below" as appropriate when referring to a label. As in, see the minimal working example "below".

I'm surprised that I cannot find such a command, as it seems like basic functionality. I'm trying to create one, and am going down the route of comparing \pageref{thelabel} and \thepage, but this obviously isn't guaranteed to work when the label and the reference are on the same page.

Any ideas? Either a pointer to an existing command, or a way to write a new one?

Many thanks,
Andrew

Minimal (sort of) Working Example:

Code: Select all

Code, edit and compile here:
\documentclass{article}
\usepackage{ifthen}
\newcommand{\locref}[1]{\ifthenelse{\pageref{#1}<\thepage}{above}{below}}
\begin{document}
% Here the command should resolve to "below" and does
Compared to this paragraph, the label is \locref{thelabel}.
\clearpage
% Here the command should resolve to "below" and does
Compared to this paragraph, the label is \locref{thelabel}.
This paragraph is above the label.
This paragraph contains the label.\label{thelabel}
This paragraph is below the label.
% Here the command should resolve to "above" but doesn't
Compared to this paragraph, the label is \locref{thelabel}.
\clearpage
% Here the command should resolve to "above" and does
Compared to this paragraph, the label is \locref{thelabel}.
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Need a command to generate "above"/"below" in references

Post by Stefan Kottwitz »

Hi Andrew,

welcome to the board! The varioref package provides similar features, for example references such as "on the previous page" or "above" if it falls onto the same page.

Code: Select all

... see \vpageref[above]{label} ...
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
it's not the very same as in your question, however it may be useful for you. You could improve it if you like.

Stefan
LaTeX.org admin
sullivander
Posts: 3
Joined: Wed May 04, 2011 4:50 am

Re: Need a command to generate "above"/"below" in references

Post by sullivander »

Hmm. Thanks for pointing out the varioref package, but it's not quite what I'm looking for: really just the simple words "above" or "below".
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Need a command to generate "above"/"below" in references

Post by Stefan Kottwitz »

Solving by referencing by labels is perhaps not the straigt solution. They are put in and used from the .aux file with page numbers. They are available after and also before their definition in text, in following compiling runs.

However, you could use a boolean variable, which is false and you set it to true at the required place in the text. Use an if command to check and to print out above resp. below if false resp. true.

Stefan
LaTeX.org admin
sullivander
Posts: 3
Joined: Wed May 04, 2011 4:50 am

Re: Need a command to generate "above"/"below" in references

Post by sullivander »

Thanks! That's actually a really clever way to handle it.
Yeats
Posts: 62
Joined: Fri Nov 07, 2008 12:29 pm

Need a command to generate "above"/"below" in references

Post by Yeats »

Stefan_K wrote:Solving by referencing by labels is perhaps not the straigt solution. They are put in and used from the .aux file with page numbers. They are available after and also before their definition in text, in following compiling runs.

However, you could use a boolean variable, which is false and you set it to true at the required place in the text. Use an if command to check and to print out above resp. below if false resp. true.

Stefan
I am sorry to necro this old thread but I thought better that than making a new one with same discussion. I am not so advanced Latex user. Any chance that someone could explain me how I could do that?

My mentor wants me to have footnotes saying: Cf. below P. XX or Cf. above P. XX depending where the reference is.
Post Reply