
나는 다음을 통해 요소에 액세스할 수 있는 목록을 생성하는 listofitems 패키지를 사용하고 있습니다.
\LIST[n]
하지만 매뉴얼에서 이중 확장이 필요하다고 읽었습니다.
특히 (이중 확장)이 \LIST[n]
비어 있는지 어떻게 확인합니까?
답변1
다음을 사용하여 항목을 두 번 확장할 수 있습니다 \expandafter\expandafter\expandafter
(두 번째 단계의 첫 번째 \expandafter
단계, 세 번째 단계는 인수를 {
한 번 확장하고, 첫 번째와 세 번째 단계는 제거하고, 두 번째 단계는 {
두 번째 이후에 인수를 확장합니다). 매크로의 인수를 확장해야 하는 경우 그 앞에 3을 추가해야 합니다 ( 여는 중괄호를 찾을 때까지 모든 것을 확장하므로 \expandafter
이는 필요하지 않으며 에도 필요하지 않습니다. 확장할 수 없는 두 개의 토큰을 찾을 때까지 모든 것을 확장합니다.\detokenize
\if
\documentclass{article}
\usepackage{listofitems}
\readlist\foo{12,abc,3,4,,}
\makeatletter
\providecommand\@secondofthree[3]{#2}
\newcommand\iflistitememptyTF[2]
{%
\if\relax\detokenize\expandafter\expandafter\expandafter{#1[#2]}\relax
\expandafter\@secondofthree
\fi
\@secondoftwo
}
\makeatother
\begin{document}
\iflistitememptyTF\foo{5}{empty}{not empty}
\end{document}