![xparse argspec을 사용하여 \동사 같은 동작을 어떻게 달성할 수 있나요?](https://rvso.com/image/281594/xparse%20argspec%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%5C%EB%8F%99%EC%82%AC%20%EA%B0%99%EC%9D%80%20%EB%8F%99%EC%9E%91%EC%9D%84%20%EC%96%B4%EB%96%BB%EA%B2%8C%20%EB%8B%AC%EC%84%B1%ED%95%A0%20%EC%88%98%20%EC%9E%88%EB%82%98%EC%9A%94%3F.png)
u{}
이전에 스캔한 토큰을 argspec 의 인수로 어떻게 사용할 수 있나요 xparse
?
\documentclass{article}
\usepackage{xparse}
\NewDocumentEnvironment {some-cool-env} {D<>{\stopscan} u{#1}} {%
Here is the text up until the stopping token: ``#2'' \newline
Here's the rest of the environment: \par
} {}
\begin{document}
\begin{some-cool-env}
I am a\stopscan teapot
\end{some-cool-env}
(some inner text)
\begin{some-cool-env}<|>
A custom built|teapot.
\end{some-cool-env}
\end{document}
그것은 줄 것이다
Here is the text up until the stopping token: "I am a"
Here's the rest of the environment:
teapot
(some inner text)
Here is the text up until the stopping token: "A custom built"
Here's the rest of the environment:
teapot.
내가 원하는 구문을 어떻게 얻을 수 있나요? ( xparse
'의 내부에 침입하지 않기를 바랍니다…)
위의 순진한 접근 방식은 다음과 같은 오류를 생성합니다.
ERROR: Illegal parameter number in definition of \__xparse_grab_arg:w. --- TeX said --- <to be read again> 1 l.9 \DumbVerb <|>test| --- HELP --- This is probably caused by a \newcommand, \renewcommand, \newenvironment, or \renewenvironment command in which a # is used incorrectly. A # character, except as part of the command name \#, can be used only to indicate an argument parameter, as in #2, which denotes the second argument. This error is also caused by nesting one of the above four commands inside another, or by putting a parameter like #2 in the last argument of a \newenvironment or \renewenvironment command.
@egreg의 답변 이후 질문 본문을 상당히 편집했지만 질문 제목은 동일하게 유지됩니다. @egreg가 답변한 질문은 xparse
. 그러한 경우 그의 대답은 효과가 있을 것이지만 불행히도 유사한 환경을 정의하는 데 즉시 일반화될 수는 없습니다. (그건 사실이 아닙니다. 여전히 보조 환경을 정의할 수 있지만 여전히 부정행위처럼 느껴집니다...)
답변1
이것은 아마도 너무 많이 늘어나는 것 같지만 작동하는 것 같으 xparse
므로 mu{#1}
두 단계로 수행할 수 있습니다.
\documentclass{article}
\usepackage{xparse}
\NewDocumentCommand\DumbVerb{D<>{|}}{\DumbVerbAux{#1}}
\NewDocumentCommand\DumbVerbAux{mu{#1}}{Here's #2}
\begin{document}
\DumbVerb test|
\DumbVerb<x>testx
\DumbVerb<\xyz>test\xyz
\end{document}
답변2
그만큼egreg의 답변아마도 현재로서는 최선의 접근 방식일 것입니다. 하지만 원하는 접근 방식이 실패하는 이유의 관점에서 이를 살펴보고 싶습니다. 여기에는 본질적으로 두 부분이 있습니다.
기술적인 수준에서 이전에 확보한 정보를 사용하도록 인수를 활성화하는 것은 (아마도) 가능하지만 완전히 일반적으로 수행하는 것은 매우 지루할 것입니다. 9개의 인수가 있는 함수를 상상해 보세요. 여기서는 이전에 확보한 8개의 가능한 인수를 허용해야 합니다. egreg의 답변에서와 같이 전용 보조 장치를 사용하면 이러한 복잡성을 피할 수 있지만애드 혹기초.
개념적 수준에서는 xparse
'LaTeX2e와 유사'하지만 '일관된' 문서 수준 인터페이스를 만들기 위한 것입니다. 여기서 요청의 문제점은 인터페이스가그렇지 않다일관성: 명령이 사용될 때마다 다른 마커를 검색해야 합니다. 이상적으로는 이러한 접근 방식이 문서에 나타나서는 안 되며, 확실히 규칙적으로 나타나서는 안 되므로 이를 지원할 필요성은 xparse
분명하지 않습니다.