![목록 ASCII 공백 문자 구문 분석](https://rvso.com/image/305767/%EB%AA%A9%EB%A1%9D%20ASCII%20%EA%B3%B5%EB%B0%B1%20%EB%AC%B8%EC%9E%90%20%EA%B5%AC%EB%AC%B8%20%EB%B6%84%EC%84%9D.png)
나는 etoolbox의 목록 구문 분석 기능을 사용해 왔으며 공백으로 구분된 목록을 원하는 이상한 사용 사례가 있습니다.
\usepackage{etoolbox}
\DeclareListParser*{\symbolListParser}{<symbol for space character>}
\newcommand{\processSymbolList}[1]{
\symbolListParser{}{#1}
}
어디서부터 살펴봐야 할지 잘 모르겠습니다. 나는 목록에 관한 문서, 공간에 관한 문서, ASCII 문자에 관한 문서를 한동안 둘러보았지만 아무 소용이 없었습니다.
그래서 누군가가 나에게 어떻게 해야 하는지, 어디서 볼 수 있는지, 아니면 불가능하다고 말해 줄 수 있다면 정말 감사하겠습니다.
업데이트:나는 찾았다이것하지만 OP가 원했던 것과 같이 좀 더 깔끔한 것을 찾고 있었습니다.
업데이트 2:답변해주신 Tobi에게 감사드립니다. 나는 그것을 받아들였다. 아래는 목록 파서처럼 동작하는 보다 일반적인 버전의 spacelist입니다.
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{ \spacelist }{ mm }{
\seq_set_split:Nnn \l_tmpa_seq { ~ } { #2 }
\seq_map_inline:Nn \l_tmpa_seq {
#1{##1}
}
}
\ExplSyntaxOff
% to use you would write it like:
\spacelist{\fbox}{Boxes and Spaces in a List}
답변1
다음은 다음을 사용하는 접근 방식입니다.expl3
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{ \spacelist }{ m }{
\seq_set_split:Nnn \l_tmpa_seq { ~ } { #1 }
\seq_map_inline:Nn \l_tmpa_seq {
\fbox { ##1 }
}
}
\ExplSyntaxOff
\begin{document}
List: \spacelist{Boxes and Spaces in a List}
\end{document}
코드는 소위시퀀스이는 새로운 구문*에 있는 at 공백 #1
의 인수를 분할하여 생성되며 일반 공백은 무시됩니다. 스팽글은 이름이 지정된 로컬 임시 변수에 저장되어 있지 않으며 시퀀스 의 모든 항목을 반복할 수 있습니다. 현재 항목은 인수 code 로 제공됩니다 . 여기서는 매핑이 정의 내에 중첩되어 있기 때문 입니다 .\spacelist
~
\l_tempa_seq
\seq_map_inline
#1
##1
\fbox
필요에 따라 부품 을 교체할 수 있습니다 .
*새로운 구문현재 LaTeX3에 도입된 구문을 의미 expl3
하며 xparse
. 자세한 내용은 expl3
또는 설명서를 참조하세요 source3
.
답변2
패키지 listofitems
는 렌더링되거나 토큰화 해제된 형식으로 이를 제공할 수 있습니다.
\documentclass{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{listofitems}
\newcommand\spacelist[2][]{
\setsepchar{ }%
\readlist\mylist{#2}%
\showitems#1\mylist%
}
\begin{document}
List: \spacelist{Boxes and \textbf{Spaces} in a List}
Tokens: \spacelist[*]{Boxes and \textbf{Spaces} in a List}
\end{document}
답변3
목표에 맞는 패키지 없는 접근 방식을 TeX 매크로 두 줄로 작성할 수 있습니다.
\documentclass{article}
\catcode`z 3
\makeatletter
\newcommand\spacelist[1]{\spacelist@boxit #1 {z} }%
\long\def\spacelist@boxit #1 {\ifx z#1\relax\else
\fbox{#1}\expandafter\spacelist@boxit\fi}
\catcode`z 11
\makeatother
\begin{document}
List: \spacelist{Boxes and Spaces in a List}
\end{document}
유죄 인정: 구문 분석된 목록 \else
에 \fi
토큰이 포함되어 있으면 방법이 취약합니다.
여기에는 간단한 수단을 사용하는 더욱 강력한 방법이 있습니다. 하지만 인수에는 catcode 3 문자 Z가 포함되어서는 안 됩니다.
\documentclass{article}
\usepackage[T1]{fontenc}
\catcode`Z 3
\makeatletter
\newcommand\spacelist[1]{\spacelist@getone{}#1 Z }%
\long\def\spacelist@getone #1 {\spacelist@check #1.Z\spacelist@check{#1}}%
\long\def\spacelist@check #1Z#2\spacelist@check#3%
{\if\relax\detokenize{#1}\relax
\expandafter\@gobbletwo % abort parse
\else
%
% #3 contains the searched for item, but with an empty brace pair
% added, which serves to prevent brace removal in processing
% so I am showing here how to remove it with \expandafter/\@gobble
% initial braces are not lost.
%
\fbox{\detokenize\expandafter{\@gobble#3}}%
\fi
\spacelist@getone{}}%
\catcode`Z 11
\makeatother
\begin{document}
List: \spacelist{Boxes {and Spaces} in a {List with \if, \else, \end tokens}}
\end{document}