出于调试目的,我怎样才能自动在每个段落的开头添加 ¶ ?(我所说的段落不是指命令\paragraph
,而是指由空行分隔的两个文本块,如下面的 MWE 所示。)
虽然\everypar
对我来说没用(我用的是 TeX Live 2022),但\AddToHook{para/begin}{\P~}
在某种程度上还是有用的。它在每个段落前添加 ¶,包括不需要的部分标题等。
\documentclass{article}
\setlength{\parindent}{0em}
\begin{document}
\AddToHook{para/begin}{\P~}
\section*{This Sentence No Verb}
Far far away, behind the word mountains, far from the countries
\emph{Vokalia} and \emph{Consonantia}, there live the blind texts.
Separated they live in Bookmarksgrove right at the coast of the Semantics,
a large language ocean. The river Duden flows by their place and supplies
it with the necessary regelialia. It is a paradisemantic country, in which
roasted parts of sentences fly into your mouth.
Even the all-powerful Pointing has no control about the blind texts;
it is an almost unorthographic life. One day, however, a small line of
blind text by the name of \textsc{Lorem Ipsum} decided to leave for the far
World of Grammar. The Big Oxmox advised her not to do so, because there
were thousands of bad Commas, wild Question Marks and devious Semikoli, but
the Little Blind Text didn’t listen. She packed her seven versalia, put her
initial into the belt and made herself on the way.
When she reached the first hills of the Italic Mountains, she had a last
view back on the skyline of her hometown Bookmarksgrove, the headline of
Alphabet Village and the subline of her own road, the Line Lane.
\end{document}
我怎样才能限制\AddToHook
仅为纯文本段落?
答案1
目前没有万无一失的方法来确定“TeX 段落”是否是“真实段落”,但我们可以通过假设任何缩进的段落都是“真实”的来非常接近:
\documentclass{article}
\setlength{\parindent}{1sp} % Tiny sentinel value
% \usepackage{indentfirst} % Optional, to mark the first paragraph of a section
\AddToHook{para/begin}{%
\ifdim\wd\IndentBox=\parindent% Replace any indents with pilcrows
\setbox\IndentBox=\hbox{\P~}%
\fi%
}
\begin{document}
\section*{This Sentence No Verb}
Far far away, behind the word mountains, far from the countries
\emph{Vokalia} and \emph{Consonantia}, there live the blind texts.
Separated they live in Bookmarksgrove right at the coast of the Semantics,
a large language ocean. The river Duden flows by their place and supplies
it with the necessary regelialia. It is a paradisemantic country, in which
roasted parts of sentences fly into your mouth.
Even the all-powerful Pointing has no control about the blind texts;
it is an almost unorthographic life. One day, however, a small line of
blind text by the name of \textsc{Lorem Ipsum} decided to leave for the far
World of Grammar. The Big Oxmox advised her not to do so, because there
were thousands of bad Commas, wild Question Marks and devious Semikoli, but
the Little Blind Text didn’t listen. She packed her seven versalia, put her
initial into the belt and made herself on the way.
When she reached the first hills of the Italic Mountains, she had a last
view back on the skyline of her hometown Bookmarksgrove, the headline of
Alphabet Village and the subline of her own road, the Line Lane.
\begin{itemize}
\item This is the first paragraph of an item.
This is the second paragraph.
\item This is the second item.
\end{itemize}
And this is a paragraph after an itemize.
\end{document}
当然,即使这样也并非万无一失——例如,我不确定在某个itemize
环境中预期的行为是什么。
答案2
基于 Max 的回答(我已经接受),我想发布一个更详细的解决方案。
\documentclass[draft]{article}
%\documentclass[final]{article}
\usepackage{indentfirst}
\setlength{\parindent}{1em}
\usepackage{xcolor}
\definecolor{Crimson}{HTML}{C00000}
% create \ifdraft{DRAFT}{FINAL} command:
\makeatletter\def\ifdraft{%
\ifdim\overfullrule>\z@\expandafter\@firstoftwo%
\else\expandafter\@secondoftwo\fi}%
\makeatother
% replace parindent with ¶ sign:
\newcommand\mypilcrow{%
\ifdim\wd\IndentBox=\parindent\sbox{\IndentBox}{\color{Crimson}\P~}\fi%
}
\begin{document}
% in DRAFT mode, execute \mypilcrow at beginn of paragraph,
% in FINAL mode, do nothing:
\ifdraft{\AddToHook{para/begin}{\mypilcrow}}{}
% Temporarily disable in \itemize environment if so desired:
%\AddToHook{env/itemize/before}{\RemoveFromHook{para/begin}}
%\AddToHook{env/itemize/after}{\AddToHook{para/begin}{\mypilcrow}}
\section*{This Sentence No Verb}
Far far away, behind the word mountains, far from the countries \emph
{Vokalia} and \emph{Consonantia}, there live the blind texts. Separated they
live in Bookmarksgrove right at the coast of the Semantics, a large language
ocean. The river Duden flows by their place and supplies it with the necessary
regelialia. It is a paradisemantic country, in which roasted parts of
sentences fly into your mouth.
Even the all-powerful Pointing has no control about the blind texts;
it is an almost unorthographic life. One day, however, a small line of blind
text by the name of \textsc{Lorem Ipsum} decided to leave for the far World of
Grammar. The Big Oxmox advised her not to do so, because there were thousands
of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind
Text didn’t listen. She …
\begin{itemize}
\item packed her seven versalia,
\item put her initial into the belt and
\item made herself on the way.
She also added a new paragraph to the end of the last item.
\end{itemize}
When she reached the first hills of the Italic Mountains, she had a last view
back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet
Village and the subline of her own road, the Line Lane.
\end{document}
答案3
这只是一次脆弱且远未完成的尝试。
\@startsection
\section
,级别不高于(即不包括\chapter
和)的分段标题命令的共同起点\part
是在前面添加一个布尔赋值来表示“本段落非普通”。
因此,此尝试可能仅适用于没有任何分段标题样式包的原始标准类。
它不完整,因为除了分段标题之外还有各种情况,例如列表项。根据您的实际用例,是否值得完成一整套补丁?
\documentclass{article}
\setlength{\parindent}{0em}
\usepackage{xpatch}
\makeatletter
\newif\if@plaintextpara
\global\@plaintextparatrue
\xpretocmd\@startsection
{\@plaintextparafalse}
{}{\PatchFailed}
\AddToHook{para/begin}{%
\if@plaintextpara\P~\else\global\@plaintextparatrue\fi
}
\makeatother
\begin{document}
\section*{This Sentence No Verb}
Far far away, behind the word mountains, far from the countries
\emph{Vokalia} and \emph{Consonantia}, there live the blind texts.
Separated they live in Bookmarksgrove right at the coast of the Semantics,
a large language ocean. The river Duden flows by their place and supplies
it with the necessary regelialia. It is a paradisemantic country, in which
roasted parts of sentences fly into your mouth.
Even the all-powerful Pointing has no control about the blind texts;
it is an almost unorthographic life. One day, however, a small line of
blind text by the name of \textsc{Lorem Ipsum} decided to leave for the far
World of Grammar. The Big Oxmox advised her not to do so, because there
were thousands of bad Commas, wild Question Marks and devious Semikoli, but
the Little Blind Text didn’t listen. She packed her seven versalia, put her
initial into the belt and made herself on the way.
When she reached the first hills of the Italic Mountains, she had a last
view back on the skyline of her hometown Bookmarksgrove, the headline of
Alphabet Village and the subline of her own road, the Line Lane.
\begin{enumerate}
\item a
\item b
\end{enumerate}
\end{document}