《逻辑哲学论》风格的段落编号

《逻辑哲学论》风格的段落编号

我如何跟踪指示当前段落在逻辑层次结构中的位置的十进制数并将其打印在每个段落的页边距中?(以产生《逻辑哲学论》风格的编号)。

\def\on{}
\def\down{}
\def\up{}

\on
This is the first paragraph, paragraph number 1.

\on
This is paragraph number 2.

\down
This is paragraph number 2.1

\down 2
This is 2.101

\up
This is 2.11

\down
2.111

\up 3
3

\bye

如果\down带星号,则从零开始。 如果\up后面跟着一个整数,则应该将其作为参数,除非\up和整数之间有换行符。小数位数应该是无限的。

附言:在给出 (2) 个答案后,我为更改问题而道歉,但我意识到我没有意识到维特根斯坦编号的一个特点:最后的小数点永远不会是 0。因此,\down <n>比 更好\down*,正如上面所展示的那样。我认为 0 应该表示额外的不重要性。

在此处输入图片描述

答案1

我在评论中澄清的内容比你多.,而且(目前)你不需要\up\up\up2但是

在此处输入图片描述

% this would be so much easier in latex:-)

\newcount\zzdepth
\newcount\zza
\edef\zzbase{\the\allocationnumber}
\zzdepth\allocationnumber
\newcount\zzb
\newcount\zzc
\newcount\zzd

\def\thezz{{%
\ifnum\zzdepth>\zzbase\relax
\advance\zzdepth-1 %
\expandafter\thezz
\fi
}\the\count\zzdepth.%
}

\everypar{{\bf\thezz} }



\def\on{\advance\count\zzdepth 1\relax}
\def\eatstar*{}
\def\down{\futurelet\tmp\xxdown}
\def\xxdown{%
\ifx*\tmp
\advance\zzdepth 1 \count\zzdepth 0\relax
\expandafter\eatstar
\else
\advance\zzdepth 1 \count\zzdepth 1\relax
\fi}

\def\up{\advance\zzdepth -1 \advance\count\zzdepth 1\relax}

\on
This is the first paragraph, paragraph number 1.

\on
This is paragraph number 2.

\down
This is paragraph number 2.1

\down*
This is 2.10

\up
This is 2.2

\down
This is 2.2.1

\up\up
This is 3

\bye

答案2

纯粹的普通 TeX 代码,模拟维特根斯坦的输出。

\newcount\decide
\newcount\current
\newcount\temp
\newcount\level
\newcount\leveli
\newcount\levelii
\newcount\leveliii
\newcount\leveliv
\newcount\levelv
% add more if necessary

\parindent=0pt

\current=0

\def\on{%
  \par
  \global\advance\csname level\romannumeral\current\endcsname by 1
  \makezero
  \startpar
}
\def\up{\par\afterassignment\doup\decide=0}
\def\down{\par\afterassignment\dodown\decide=0}
\def\doup{%
  \ifnum\decide=0 % no number follows
    \global\advance\current by -1
  \else
    \global\advance\current by -\decide
  \fi
  \global\advance\csname level\romannumeral\current\endcsname by 1
  \makezero
  \startpar
}
\def\dodown{%
  \ifnum\decide=0 % no number follows
    \global\advance\current by 1
  \else
    \global\advance\current by \decide
  \fi
  \global\advance\csname level\romannumeral\current\endcsname by 1
  \makezero
  \startpar
}
\def\makezero{%
  \temp=\current
  \loop\ifnum\temp<5
    \advance\temp by 1
    \global\csname level\romannumeral\temp\endcsname=0  
  \repeat
}
\def\startpar{%
  \hangindent=4em
  \printcounters
}
\def\printcounters{%
  \leavevmode\hbox to 5em{%
    \temp=0 \decide=0
    \loop\ifnum\temp<5
      \advance\temp by 1
      \ifnum\csname level\romannumeral\temp\endcsname>0
        \decide=\temp
      \fi
    \repeat
    \the\level
    \ifnum\decide>0 .\fi
    \temp=0
    \loop\ifnum\temp<\decide
      \advance\temp by 1
      \the\csname level\romannumeral\temp\endcsname
    \repeat
    \hfil
  }\ignorespaces
}

\on
This is the first paragraph, paragraph number 1.

\on
This is paragraph number 2.

\down 2
This is paragraph 2.01

\on (2.02) \on (2.03) \on (2.04) \on (2.05) \on (2.06) \down (2.061)

\vfill\eject

\on This is 2.062 which goes on for some length in order to 
    make a line break; just add words until necessary

\on
This is paragraph number 2.063

\up 2
This is 2.1

\down
This is 2.11

\on
This is 2.12

\on
This is 2.13

\down
This is 2.131

\up
This is 2.14

\down
This is 2.141

\up
This is 2.15

\down
This is 2.151

\down
This is 2.1511

\on
This is 2.1512

\down
This is 2.15121

\up
This is 2.1513

\on
This is 2.1514

\on
This is 2.1515

\up 4
This is 3

\bye

第一页就像图中这样从第二页开始。

在此处输入图片描述

答案3

LaTeX3 解决方案。我对你的语法做了一些小改动。

  • 我添加了用于打开和关闭段落编号的开关。当它打开时,新段落会自动获得一个新编号。(如果不希望这样,只需在序言中添加几行代码即可轻松更改。)

  • 我提供了要上升或下降的层级数作为\upor的可选参数\down(在括号内),而不是检查那里是否有数字。这更符合 LaTeX 语法,只要没有段落以左括号开头,就应该更安全。

  • 数字被转换为 36 进制数进行打印,这意味着从10到 的数字35被打印为a到 的字母z

  • 如果数字超过 35 或超出限制,则会发出警告\up

\documentclass{article}

\usepackage{expl3}
\usepackage{xparse}

\ExplSyntaxOn

% This sequence contains the current paragraph number
\seq_new:N \g_tract_parnumber_seq

% Printing the paragraph number
\cs_new:Nn \tract_parnumber_print:
  {
    \exp_args:Ne \tract_parnumber_print_aux:n
      { \seq_map_function:NN \g_tract_parnumber_seq \tract_parnumber_print_auxi:n }
  }
\cs_new:Nn \tract_parnumber_print_aux:n
  {
    \tl_head:n { #1 }
    \int_compare:nNnT { \tl_count:n { #1 } } > 1
      { . \tl_tail:n { #1 } }
  }
\cs_new:Nn \tract_parnumber_print_auxi:n
  { { \tract_number_print:n { #1 } } }
% This function formats a single element of the paragraph number (one digit).
\cs_new:Nn \tract_number_print:n
  { \int_to_base:nn { #1 } { 36 } }

% Functions for manipulating the paragraph number
\cs_new_protected:Nn \tract_parnumber_reset:
  {
    \seq_gclear:N \g_tract_parnumber_seq
    \seq_gput_right:Nn \g_tract_parnumber_seq { 0 }
  }
\cs_new_protected:Nn \tract_parnumber_advance:
  {
    \group_begin:
      \seq_gpop_right:NN \g_tract_parnumber_seq \l_tmpa_int
      \seq_gput_right:Nx \g_tract_parnumber_seq
        { \int_eval:n { \l_tmpa_int + 1 } }
      \int_compare:nNnT { \l_tmpa_int } > { 34 }
        {
          \msg_warning:nnx { tractatus } { number-too-high }
            { \int_eval:n { \l_tmpa_int + 1 } }
        }
    \group_end:
  }
% The up and down functions assume that the paragraph number is advanced afterwards.
\cs_new_protected:Nn \tract_parnumber_down:n
  {
    \prg_replicate:nn { #1 }
      { \seq_gput_right:Nx \g_tract_parnumber_seq { 0 } }
  }
\cs_new_protected:Nn \tract_parnumber_up:n
  {
    \group_begin:
      \prg_replicate:nn { #1 }
        { \seq_gpop_right:NN \g_tract_parnumber_seq \l_tmpa_int }
      \seq_if_empty:NT \g_tract_parnumber_seq
        {
          \msg_warning:nn { tractatus } { top-level-removed }
          \seq_gput_right:Nn \g_tract_parnumber_seq { -1296 }
        }
    \group_end:
  }

% Turning numbering on and off
\cs_new_protected:Nn \tract_parnumbers_on:
  {
    \group_begin:
      \reversemarginpar
      \setlength\marginparwidth{8ex}
      \everypar{
        \tract_parnumber_advance:
        \marginpar{\tract_parnumber_print:}
      }
  }
\cs_new_protected:Nn \tract_parnumbers_off:
  { \group_end: }

% Messages
\msg_new:nnn { tractatus } { number-too-high }
  {
    The~current~paragraph~(sub-)number~exceeds~35,~which~is~the~highest~number~
    that~can~be~printed~as~a~single~digit.~This~number~is~#1.
  }
\msg_new:nnn { tractatus } { top-level-removed }
  {
    You~just~removed~the~top~paragraph~numbering~level.~
    I~will~set~the~counter~to~-zz~=~-1295~as~a~marker.
  }

% Document level commands.
\NewDocumentCommand\resetparnumber { } {
  \tract_parnumber_reset:
}
\NewDocumentCommand\parnumberson { } {
  \tract_parnumbers_on:
  \cs_set_eq:NN \parnumberson \prg_do_nothing:
  \cs_set_eq:NN \parnumbersoff \tract_parnumbers_off:
}
\NewDocumentCommand\parnumbersoff { } { }
\NewDocumentCommand\down { O{1} } {
  \tract_parnumber_down:n { #1 }
}
\NewDocumentCommand\up { O{1} } {
  \tract_parnumber_up:n { #1 }
}

\AtBeginDocument{\resetparnumber}

\ExplSyntaxOff

\begin{document}

Hello World!

\parnumberson

This is the first paragraph, paragraph number 1.

This is paragraph number 2.

\down
This is paragraph number 2.1

\down[2]
This is 2.101

\up
This is 2.11

\down
2.111

\up[3]
3

\parnumbersoff

\end{document}

MWE 输出

相关内容