自动段落编号

自动段落编号
  • 这是一个2021 年后续行动问我的问题问题来自2015
  • 我想添加每个文本段落一个自动编号参见原始问题)。 在此处输入图片描述
  • 2015 年,用户@弗兰当时警告了我有关解决方案。

编辑:如果您 [原文如此!] 不想要任何命令启动段落,请使用 \everypar,风险自负...您会在评论中收到警告。

  • 对于用户来说也是如此@egreg

有太多地方使用了 \par,但数字不应该出现:不仅是章节标题,还有列表中的项目(包括单个段落中心环境)。人们可以考虑“条件编号”,在特殊的地方禁用它。这不是我愿意承担的任务。

在此处输入图片描述

2020 年引入的钩子管理主要面向软件包开发人员。不过,大多数可用的钩子对文档作者也很有用。

  • 问题:是否新的挂钩管理提供一种更简单的方法来对每个文本段落进行编号,而不会产生 2015 年提出的风险/问题埃格尔弗兰
  • 评论:如果是,那么一个单独的后续问题将是如何访问这些数字:以\label{}\ref{}模式引用它们。

MWE 显示的是不工作的版本,它显示了问题(问题、图表、标题等不需要的地方的数字)。MWE 只是我的修改版自 2015 年起- 请不要过多考虑代码和使用的包。

\documentclass{article}
\usepackage[excludeor]{everyhook}
\usepackage{graphicx}
\usepackage{blindtext}
\usepackage{parskip}
\newcounter{paragraphs}[section]

\newcommand{\myFillerAux}{ Test dummy text that has no meaning. }
\newcommand{\myFiller}{\myFillerAux\myFillerAux\myFillerAux\myFillerAux\myFillerAux\myFillerAux}

\begin{document}
\PushPostHook{par}{%
        \stepcounter{paragraphs}%
        \llap{\thesection.\theparagraphs\ \kern\parindent}%
}

\tableofcontents

\section{Test 1}
\myFiller

\begin{figure}
    \centering
    \includegraphics{example-image}
    \caption{Caption}
    \label{fig:my_label}
\end{figure}

\begin{equation}
    a^2 + b^2 = c^2
\end{equation}

\section{Test 2}
\myFiller

\begin{figure}
    \centering
    \includegraphics{example-image}
    \caption{Caption}
    \label{fig:my_label}
\end{figure}

\begin{equation}
    a^2 + b^2 = c^2
\end{equation}

\end{document}

在此处输入图片描述

相关内容