[Tex/LaTex] Changing all “[” to \llbracket


Is there a way to change all [ and ]s in a document to \llbracket and \rrbracket? Without modifying the text?

Best Answer

You can “easily” change [ and ] to mean \llbracket and \rrbracket in math mode:



\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
% Use the temporary macro to get the right delcodes out of
% the meaning of \llbracket and \rrbracket

% make [ and ] math active

Here's a formula $a[b]=c[d]$; the brackets even change size with
\verb|\left| and \verb|\right|:

For text mode square brackets there is no way to do this automatically, because [ and ] has a syntactical meaning for many LaTeX commands.

enter image description here

Related Question