2

Stephen Wolfram's 'A New Kind of Science' states in its colophon that it has 973 illustrations spread out over 1280 pages. Remarkably, he accomplishes this without ever using figure numbers. No figure has any number and each figure is referenced in the text using statements like '... the picture on the facing page ...' or '... the picture below ... ' or '... as illustrated to the left ...', etc.

Leaving aside the dubious science in this book, I find the positioning in the book to be a tour de force of book layout. My question is whether this can be accomplished using TeX?

I have never seen, or heard mention of, any LaTeX package that does anything like this, so I presume accomplishing something like this would require fine grained control of LaTeX's float positioning algorithm and implementing a custom solution, probably using LuaTeX or pythonTeX. Wolfram states that he used Mathematica to position the figures and to solve "innumerable small geometrical puzzles to do so".

  • 4
    I think either varioref or cleveref does something similar to this, if the figure is on the same or adjacent page. – You Jun 28 '14 at 19:19
  • Does Lua(La)TeX provide a "hook" (possibly in the form of a callback) into LaTeX's float placement algorithm? – Mico Jun 28 '14 at 19:34
  • @You - The varioref will indeed let you create such page references, but it still requires you to create floats with captions that are assigned labels. – Mico Jun 28 '14 at 20:14
  • @Mico: Not printing the label while still keeping the reference isn't really a technical problem. There will be lots of manual float placement hinting and making sure references aren't ambiguous, though. – You Jun 28 '14 at 20:25
  • 2
    @You varioref doesn't really have a restriction to it being on the same or adjacent page, it could easily say "top of page x" if the float is further away. – David Carlisle Jun 28 '14 at 23:52
2

This can handle up to 11 pictures per page.

\documentclass{article}
\usepackage{graphics,mwe}

\makeatletter
\newcounter{relative}
\newcount\R@temp
\newif\ifR@label
\newif\ifR@loop

\newcommand\new@relative[3]{% #1=label, #2=count, #3=page
  \expandafter\gdef\csname R@#1@count\endcsname{#2}%
  \expandafter\gdef\csname R@page#2\endcsname{#3}%
}%
\newcommand\Rlabel[1]{% #1 = label
  \@ifundefined{hypertarget}{}{\hypertarget{R@#1}{}}%
  \stepcounter{relative}%
  \@bsphack
  \begingroup
    \protected@write\@auxout{}{%
      \string\new@relative{#1}{\arabic{relative}}{\thepage}%
    }%
  \endgroup
  \@esphack
}%
\newcommand\Rref[1]{% #1 = label
   \@ifundefined{hyperlink}{\def\picture{picture}}{\def\picture{\hyperlink{R@#1}{picture}}}%
  \@ifundefined{R@#1@count}{\R@labelfalse}{\R@labeltrue}%
    \ifR@label%
    \edef\R@count{\csname R@#1@count\endcsname}%
    \edef\R@page{\csname R@page\R@count\endcsname}%
% find first picture on page
    \R@temp=\R@count
    \loop\advance\R@temp by -1
      \ifnum\R@temp>0
        \if\csname R@page\the\R@temp\endcsname\R@page \R@looptrue%
        \else\R@loopfalse\fi%
      \else\R@loopfalse\fi%
    \ifR@loop\repeat%
    \advance\R@temp by 1
    \edef\R@first{\the\R@temp}%
% find the last picture on page
    \loop\advance\R@temp by 1
      \@ifundefined{R@page\the\R@temp}{\R@loopfalse}{\R@looptrue}%
      \ifR@loop
        \if\csname R@page\the\R@temp\endcsname\R@page \relax%
        \else\R@loopfalse\fi%
      \fi%
    \ifR@loop\repeat%
    \advance\R@temp by -1
    \edef\R@last{\the\R@temp}%
% same page
    \if\R@page\thepage
      \R@temp=\c@relative%
      \advance\R@temp by -\R@count\relax%
      \ifnum\R@temp=0 {\picture{} above}%
      \else\ifnum\R@temp=-1 {\picture{} below}%
        \else\if\R@count\R@first{top \picture{} above}%
          \else\if\R@count\R@last{bottom \picture{} below}%
            \else\ifnum\R@temp>0 {\R@num{\the\R@temp} \picture{} above}%
              \else\advance\R@temp by 1
                \R@temp=-\R@temp%
                {\R@num{\the\R@temp} \picture{} below}%
      \fi\fi\fi\fi\fi%
% only one picture on page
    \else\if\R@first\R@last
        \R@temp=\c@page%
        \advance\R@temp by -\R@page\relax%
        \ifnum\R@temp=-1 {\picture{} on the next page}%
        \else\ifnum\R@temp=1 {\picture{} on the previous page}%
          \else {\picture{} on page \R@page}%
        \fi\fi%
 % multiple pictures on page
      \else\R@temp=\R@count
        \advance\R@temp by -\R@first\relax%
        \edef\R@number{\the\R@temp}% 0=top, 1=second...
        \R@temp=\c@page%
        \advance\R@temp by -\R@page\relax%
        \ifnum\R@temp=1
          \if\R@count\R@first{top \picture{} on the previous page}%
          \else\if\R@count\R@last{bottom \picture{} on the previous page}%
            \else{\R@num{\R@number} \picture{} on the previous page}%
          \fi\fi%
        \else\ifnum\R@temp=-1
          \if\R@count\R@first{top \picture{} on the next page}%
          \else\if\R@count\R@last{bottom \picture{} on the next page}%
            \else{\R@num{\R@number} \picture{} on the next page}%
          \fi\fi%
        \else%
          \if\R@count\R@first{top \picture{} on page \R@page}%
          \else\if\R@count\R@last{bottom \picture{} on page \R@page}%
            \else{\R@num{\R@number} \picture{} on page \R@page}%
    \fi\fi\fi\fi\fi\fi%
% label not defined
 \else{as yet unknown \picture}
 \fi}%
% some definitions
\def\R@num#1{\csname R@num#1\endcsname}%
\expandafter\edef\csname R@num1\endcsname{second}%
\expandafter\edef\csname R@num2\endcsname{third}%
\expandafter\edef\csname R@num3\endcsname{fourth}%
\expandafter\edef\csname R@num4\endcsname{fifth}%
\expandafter\edef\csname R@num5\endcsname{sixth}%
\expandafter\edef\csname R@num6\endcsname{seventh}%
\expandafter\edef\csname R@num7\endcsname{eighth}%
\expandafter\edef\csname R@num8\endcsname{ninth}%
\makeatother

\begin{document}

\begin{center}
\Rlabel{first}\includegraphics{example-image-a}
\end{center}

You may have noticed in the \Rref{first} and the \Rref{second}
that they are not quite the same as the \Rref{third}.

\begin{center}
\Rlabel{second}\includegraphics{example-image-b}
\end{center}

You may have noticed in the \Rref{first} and the \Rref{second}
that they are not quite the same as the \Rref{third}.

\begin{center}
\Rlabel{third}\includegraphics{example-image-c}
\end{center}

You may have noticed in the \Rref{first} and the \Rref{second}
that they are not quite the same as the \Rref{third}.

\Rref{test1}\\
\Rref{test2}\\
\Rref{test3}\\
\Rref{test4}\\
\Rref{test5}\\

\newpage
\Rref{test1}\\
\Rref{test2}\\
\Rref{test3}\\
\Rref{test4}\\
\Rref{test5}

\begin{center}
\Rlabel{test1}\Rlabel{test2}\Rlabel{test3}\Rlabel{test4}\Rlabel{test5}%
\includegraphics{example-image}
\end{center}

\Rref{test1}\\
\Rref{test2}\\
\Rref{test3}\\
\Rref{test4}\\
\Rref{test5}\\
\end{document}
| improve this answer | |

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.