Adapt text based on relative position of floats (e.g. figure or table) [duplicate]

I just thought of an interesting feature and was wondering if it is possible to do so in TeX or any of its derivatives. I'll explain it first.

Let's say we have the next simple LaTeX file. Imagine there is much more text.

\documentclass{article}
\usepackage{graphicx}

\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
In Figure \ref{fig:picture} you can see my picture.
It's very interesting!

\begin{figure}[b]
\includegraphics{my-picture}
\label{fig:picture}
\end{figure}

As you can see in the picture above, I like interesting pictures.
\end{document}


Just a regular document. But what if, due to there being much more text, that last sentence is displayed above the image in the resulting PS/PDF file? The "above" wouldn't fit anymore. It should be below.

Is there any way to adapt the source text so that "above" fits? I was thinking of some kind of special \ref which adapts the text automatically, based on the final position of the image, relative to the text. For example,

As you can see in the picture \ref[adapt]{fig:picture}{above}{below}, I like
interesting pictures.


If the final position of the referenced picture is above the \ref, it would say "above". If it is below the relevant text, it would say "below".

I already searched via Google but couldn't find anything about it. Does something like this exist? If not, is it easy to implement? I feel like it could be a nice package.

• varioref is what you're after here, as it provides this functionality out-of-the-box. – Werner Aug 29 '16 at 21:16
• That package looks perfect. I'm also just now noticing "related questions" which does also have this answer. I'm however pretty sure those related questions didn't turn up when I was asking the question. Thanks! – gieldops Aug 29 '16 at 21:19