当 \detokenize 应用于 `-` 时,“fontenc” 的结果令人惊讶

当 \detokenize 应用于 `-` 时,“fontenc” 的结果令人惊讶

无论\detokenize是应用于字体包-还是--在其下,结果都是相同的。fontencT1

\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\begin{document}

\begin{tabular}{lcl}
Command    & applied to        & result                    \\\hline
Verb       & two minus signs   & \verb=--=                 \\
Detokenize & two minus signs   & \ttfamily\detokenize{--}  \\
Detokenize & one minus sing    & \ttfamily\detokenize{-}   \\
Detokenize & three minus signs & \ttfamily\detokenize{---} \\
\end{tabular}

\end{document}

在此处输入图片描述

这就像是\detokenize在将其魔法应用于其论点之前允许某种扩展发生。但我认为这恰恰是它不应该做的。

有人能解释一下这里发生了什么吗?为什么会有区别\verb

答案1

使用 xelatex 和 lualatex 时,无论是否使用,我都会得到相同的结果,\detokenize这与-默认情况下 catcode 12 的预期一致,因此\detokenize在这种情况下只返回与其参数相同的标记。连字不是通过 catcode 技巧完成的。

在此处输入图片描述

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\begin{document}

\begin{tabular}{lcl}
Command    & applied to        & result                    \\\hline
Verb       & two minus signs   & \verb=--=                 \\
Detokenize & two minus signs   & \ttfamily\detokenize{--}  \\
Detokenize & one minus sing    & \ttfamily\detokenize{-}   \\
Detokenize & three minus signs & \ttfamily\detokenize{---} \\
\end{tabular}


\begin{tabular}{lcl}
Command    & applied to        & result                    \\\hline
Verb       & two minus signs   & \verb=--=                 \\
Detokenize & two minus signs   & \detokenize{--}  \\
Detokenize & one minus sing    & \detokenize{-}   \\
Detokenize & three minus signs & \detokenize{---} \\
\end{tabular}



\begin{tabular}{lcl}
Command    & applied to        & result                    \\\hline
Verb       & two minus signs   & \verb=--=                 \\
Detokenize & two minus signs   & \ttfamily{--}  \\
Detokenize & one minus sing    & \ttfamily{-}   \\
Detokenize & three minus signs & \ttfamily{---} \\
\end{tabular}

\begin{tabular}{lcl}
Command    & applied to        & result                    \\\hline
Verb       & two minus signs   & \verb=--=                 \\
Detokenize & two minus signs   & {--}  \\
Detokenize & one minus sing    & {-}   \\
Detokenize & three minus signs & {---} \\
\end{tabular}

\end{document}

相关内容