
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
) は、生成されたアクティブ コロンの展開を回避するために使用されます。