I would like to define an \aboveorbelow command which can be used as follows:
\documentclass{article}
\begin{document}
\section{Animals}
\label{sec:animals}
\section{Another section}
The quick brown fox (from \ref{sec:animals} \aboveorbelow{sec:animals})
jumped over the lazy dog.
The quick brown fox (from \ref{sec:plants} \aboveorbelow{sec:plants})
jumped over the lazy dog.
\section{Plants}
\label{sec:plants}
\end{document}
and will produce "above" if the label with identifier equal to the argument appears earlier in the document than the invocation of \aboveorbelow, "below" if it appears later, and something else if it is missing.
How would I do that while properly recognizing intra-page references?
In the related question Referencing to "above" or "below"? two solutions require specific extra-labeling (e.g. with a \here or \location command); another one uses the varioref package, but will apparently fail for labels on the same page as the reference. I would rather use existing labels without having to create new ones, and preferably without having to patch the label command with etoolbox or anything like that.
