
구문 이 궁금합니다 expl3
(가장 최근 추가 사항을 사용하지 않고 2018년 이후의 추가 사항을 가정해 보겠습니다. [2018년에 대해서는 특별한 것이 없습니다. 임의의 날짜일 뿐입니다.너무 최근은 아닌데]) 어떤 것이 있는지 테스트하는 방법완전히 확장되면포함클래스 11 또는 12에 속하는 모든 캐릭터?
\documentclass[preview = true, varwidth = true]{standalone}
\usepackage{xparse}
\NewExpandableDocumentCommand{\mytest}{m m m}{
% CODE HERE
}
\newcommand{\myempty}{}
\newcommand{\mywhitespace}{ }
\newcommand{\myquad}{\qquad}
\newcommand{\myrelax}{\relax}
\newcommand{\mystring}{ x }
\begin{document}
\begin{tabular}{c}
\mytest{\myempty}{true}{false} \\ % false
\mytest{\mywhitespace}{true}{false} \\ % false
\mytest{\myquad}{true}{false} \\ % false
\mytest{\myrelax}{true}{false} \\ % false
\mytest{\mystring}{true}{false} \\ % true
\end{tabular}
\end{document}
을 사용하면 \tl_if_blank:nTF
작동하지 않습니다.
\documentclass[preview = true, varwidth = true]{standalone}
\usepackage{xparse}
\ExplSyntaxOn
\cs_generate_variant:Nn \tl_if_blank:nTF{eTF}
\NewExpandableDocumentCommand{\mytest}{m m m}{\tl_if_blank:eTF{#1}{#3}{#2}}
\ExplSyntaxOff
\newcommand{\myempty}{}
\newcommand{\mywhitespace}{ }
\newcommand{\myquad}{\qquad}
\newcommand{\myrelax}{\relax}
\newcommand{\mystring}{ x }
\begin{document}
\begin{tabular}{c}
\mytest{\myempty}{true}{false} \\ % false: OK
\mytest{\mywhitespace}{true}{false} \\ % false: OK
\mytest{\myquad}{true}{false} \\ % true: PROBLEM
\mytest{\myrelax}{true}{false} \\ % true: PROBLEM
\mytest{\mystring}{true}{false} \\ % true: OK
\end{tabular}
\end{document}
답변1
최상위 수준에서만 중괄호 그룹을 처리할 수 있다고 가정하면 다음과 {E}
같은 E
작업을 수행할 수 있습니다.
\ExplSyntaxOn
\prg_new_conditional:Npnn \vincent_if_blank:n #1 { p , T , F , TF }
{ \exp_args:Ne \__vincent_if_blank:n {#1} }
\cs_new:Npn \__vincent_if_blank:n #1
{
\tl_if_blank:nTF {#1}
{ \prg_return_true: }
{
\tl_map_function:nN {#1} \__vincent_if_blank_aux:n
\prg_return_true:
}
}
\cs_new:Npn \__vincent_if_blank_aux:n #1
{
\tl_if_single_token:nTF {#1}
{
\bool_lazy_or:nnT
{ \token_if_letter_p:N #1 }
{ \token_if_other_p:N #1 }
{ \tl_map_break:n { \use_i:nn \prg_return_false: } }
}
{ \tl_map_break:n { \use_i:nn \prg_return_false: } }
}
\NewExpandableDocumentCommand{\mytest}{m m m}{\vincent_if_blank:nTF{#1}{#3}{#2}}
\ExplSyntaxOff
교정기 처리에 대한 개선이 가능하지만 질문은 이 영역에 대한 기대치를 명확하게 정의하지 않습니다.
문제는 \qquad
확장과 같이 더욱 까다로워지고 \hskip 2em\relax
여기에는 catcode-11 및 12 토큰이 포함됩니다. 그러한 경우가 다음과 같이 처리될 수 있다고 가정하면
\usepackage{etoolbox}
\robustify\qquad
그런 다음 제안된 코드를 사용하여 원하는 출력을 얻을 수 있습니다.