替换文档中的所有点

替换文档中的所有点

我想通过调用宏来替换 LaTeX 文档中的所有点。仅在“.”上进行搜索和替换不会有帮助,因为这不会替换 LaTeX 生成的点,例如在章节编号、枚举中...

答案1

您可以指定.不同的 catcode,从而使其处于活动状态,然后定义.如下宏:

\catcode`\.=13 % make "." active
\def.{Lalala}

(改编自https://tex.stackexchange.com/a/40515/4012

请注意,这可能会给你带来麻烦。我对 catcode 和活动角色等不太了解,但重新定义.会带来麻烦。

这不适用于全部不过,你文本中的句号。我修复了小节和小节子以及编号列表。如果你需要替换另一个特定句号,请告诉我,我会看看我能做些什么。

\documentclass{article}

\usepackage{adforn}% just for the flower symbol, not necessary for the replacement of "."

\newcommand*{\period}{\adforn{60}} % replace \adforn{60} with whatever
                                   % you want to have instead of "."

\catcode`\.=13 % make "." active
\def.{\period}

\renewcommand{\thesubsection}{\thesection\period\arabic{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection\period\arabic{subsubsection}}

\usepackage{enumitem}

\usepackage{lipsum}% just for the Lorem ipsum text

\begin{document}
\tableofcontents
\section{section}
\subsection{subsection}
\subsubsection{subsubsection}

\begin{enumerate}[label=\arabic*\period]
    \item numbered list
    \item \texttt{\textbackslash ldots}: \ldots
\end{enumerate}

\lipsum[1]
\end{document}

答案2

这不可能简单地实现。使点处于活动状态不会影响 catcode 更改之前存储在宏中的点。它只适用于\lipsumdoncherry 的示例,因为包是在命令之后加载的\catcode- 并且 doncherry 很有可能在 Lipsum 中没有使用点(例如在数字中),而活动点会爆炸。

\begin{document}您应该仅在使用点的每个地方(例如数字中)更改点的 catcode并重置它。

要更改其他点,您必须仔细追踪所有发出点的命令并重新定义它们。

替换每个点的另一种方法是操作字体,但这也不简单,因为涉及很多字体。

相关内容