引用浮点数而不使用数字(可能使用 lua 或 python)

引用浮点数而不使用数字(可能使用 lua 或 python)

斯蒂芬·沃尔夫勒姆 (Stephen Wolfram) 的《一种新科学》在其版权页中指出,该书共有 973 幅插图,分布在 1280 页上。令人惊讶的是,他从未使用过图号就做到了这一点。没有一个图有编号,每幅图在正文中都使用“... 对页上的图片...”或“... 下面的图...”或“... 如左图所示...”等语句来引用。

抛开这本书的科学性不谈,我发现书中的定位是书籍布局的杰作。我的问题是这是否可以使用 TeX 来实现?

我从未见过或听说过任何 LaTeX 软件包可以做这样的事情,所以我推测要完成这样的事情需要对 LaTeX 的浮动定位算法进行精细控制并实现自定义解决方案,可能使用 LuaTeX 或 pythonTeX。Wolfram 表示他使用 Mathematica 来定位图形并解决“无数小几何难题”。

答案1

每页最多可以处理 11 张图片。

\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}

相关内容