更改段落开始/结束命令

更改段落开始/结束命令

是否可以修改 TeX/LaTeX 命令,以便在段落之前/之后执行某些命令?例如,我们知道当 LaTeX 编译器看到 \par 命令或空白行时,它会结束当前段落并进入垂直模式(?)。

因此,我正在寻找一个可以修改的命令,以便我可以输入

%redefine some commands up here

\begin{document}
Paragraph 1

Paragraph 2
\end{document}

并使其产生与

\begin{document}
$\triangle$Paragraph 1

$\triangle$Paragraph 2
\end{document}

另一个相关问题也会产生类似的输出

\begin{document}
Paragraph 1$\square$

Paragraph 2$\square$
\end{document}

答案1

全局重新定义\par非常危险。但仅限于某个环境,可以添加一些元素而无需编写任何命令。例如:

(不保证真实文档的安全性)

平均能量损失

\documentclass{article}
\usepackage{xcolor}

\newenvironment{crazypar}{%at begin 
\smallskip
\def\par{%
\pdfprimitive\par\noindent\rule{\textwidth}{0.4mm}%
\pdfprimitive\par\makebox[-2em][c]{\color{red}$\triangle$}\hspace{1.5em}
}}%
{%at end
\newline\noindent\rule{\textwidth}{0.4mm}
}


\begin{document}

This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text.

This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. 

This is a dummy text. This is a dummy text.

\begin{crazypar}

This is a dummy text. 

This is a dummy text. This is a dummy text. This is a dummy text.

This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text.

This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text.  % no blank line here
\end{crazypar}

This is a dummy text. This is a dummy text. This is a dummy text. This is a dummy text.

\end{document}

相关内容