将所有“[”更改为 \llbracket

将所有“[”更改为 \llbracket

有没有办法将文档中的所有[和更改为和?而无需修改文本?]\llbracket\rrbracket

答案1

您可以“轻松”地在数学模式下将[和更改]\llbracket和:\rrbracket

\documentclass{article}

\usepackage{stmaryrd} % Where \llbracket and \rrbracket are defined

\begingroup
\catcode`[=\active \catcode`]=\active

% Define a meaning for active [ and ]
\gdef[{\llbracket} \gdef]{\rrbracket}

% Now take care of the \delcode of [ and ] for \left and \right
% First a temporary macro
\def\getdelim#1#2#3#4\relax{"#4}
% Use the temporary macro to get the right delcodes out of
% the meaning of \llbracket and \rrbracket
\global\delcode`[=\expandafter\getdelim\llbracket\relax
\global\delcode`]=\expandafter\getdelim\rrbracket\relax
\endgroup

% make [ and ] math active
\mathcode`\[="8000
\mathcode`\]="8000

\begin{document}
Here's a formula $a[b]=c[d]$; the brackets even change size with
\verb|\left| and \verb|\right|:
\[
\left[\frac{1}{2}\right]
\]
\end{document}

对于文本模式方括号,没有办法自动执行此操作,因为[]对于许多 LaTeX 命令来说具有句法含义。

在此处输入图片描述

相关内容