为什么`DeclarePairedDelimiter`如此复杂?

为什么`DeclarePairedDelimiter`如此复杂?

目前我使用以下内容来输入单例集:

\documentclass{article}

\newcommand*{\singleton}[2][]{\mathopen{#1\{}#2\mathclose{#1\}}}

\begin{document}
$\singleton x$, but $\singleton[\big]{(x, y)}$
\end{document}

我最近注意到它mathtools提供了DeclarePairedDelimiter完全相同的界面,但实现却有点奇怪。

\DeclarePairedDelimiter:
macro:#1#2#3->\@ifdefinable {#1}{\MT_delim_default_inner_wrappers:n {#1}\@namedef {MT_delim_\MH_cs_to_str:N #1_star:}##1{\@nameuse {MT_delim_\MH_cs_to_str:N #1_star_wrapper:nnn}{\left #2}{##1}{\right #3}}\@xp \@xp \@xp \newcommand \@xp \csname MT_delim_\MH_cs_to_str:N #1_nostar:\endcsname [2][\\@gobble]{\def \@tempa {\\@gobble}\def \@tempb {##1}\ifx \@tempa \@tempb \@nameuse {MT_delim_\MH_cs_to_str:N #1_nostarnonscaled_wrapper:nnn}{#2}{##2}{#3}\else \MT_etb_ifblank:nnn {##1}{\@nameuse {MT_delim_\MH_cs_to_str:N #1_nostarnonscaled_wrapper:nnn}{#2}{##2}{#3}}{\@nameuse {MT_delim_\MH_cs_to_str:N #1_nostarscaled_wrapper:nnn}{\@nameuse {\MH_cs_to_str:N ##1l}#2}{##2}{\@nameuse {\MH_cs_to_str:N ##1r}#3}}\fi }\DeclareRobustCommand {#1}{\@ifstar {\@nameuse {MT_delim_\MH_cs_to_str:N #1_star:}}{\@nameuse {MT_delim_\MH_cs_to_str:N #1_nostar:}}}}

(这是通过latexdef -p mathtools DeclarePairedDelimiter在 shell 中运行给出的。)

如果没有必要,我宁愿不导入我不了解其行为的包。有什么理由使用mathtools而不是我的自定义实现?后者是否会导致错误或意外输出?

相关内容