
是否有一種首選方法可以實現以下內容而不必離開 expl3 語法?
\documentclass{article}
\usepackage{expl3}
\usepackage[french]{babel}
\begin{document}
\ExplSyntaxOn
% suppose I am within a package here -- else the definition could just be made
% outside of the expl3 scope
\group_begin:
\char_set_catcode_active:N \:
% now expl3 syntax isn't possible any more
\gdef \c_colon_active_tl {:}
\endgroup
% just for showing things are working as expected:
a \c_colon_active_tl {} ~ vs~ a:
\ExplSyntaxOff
\end{document}
答案1
通常的先有雞還是先有蛋的問題,可以用以下\lowercase
技巧解決:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\group_begin:
\char_set_catcode_active:N \^^@
\char_set_lccode:nn { `^^@ } { `: }
\tl_to_lowercase:n { \group_end:
\tl_const:Nn \c_colon_active_tl { ^^@ }
}
\tl_show_analysis:N \c_colon_active_tl
輸出是
The token list \c_colon_active_tl contains the tokens:
> : (active character=undefined).
(對於 TeX Live 2017 之前的版本,您還需要\usepackage{l3tl-analysis}
才能\usepackage{xparse}
使其正常工作。)
2020 年更新
現在有一種更好的方法可以做到同樣的事情(順便說一句,上面的程式碼不能在最新的expl3
核心上運行)。
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\group_begin:
\char_set_active_eq:nN { `: } \scan_stop:
\tl_const:Nx \c_colon_active_tl { \char_generate:nn { `: } { 13 } }
\group_end:
\tl_analysis_show:N \c_colon_active_tl
由此可見
The token list \c_colon_active_tl contains the tokens:
> : (active character=undefined).
然而,在定義活動冒號的含義後,使用\c_colon_active_tl
將採用它,因為活動字元是巨集。\scan_stop:
(即)\relax
用於避免產生的活動結腸擴張。