
저는 이 기능을 우연히 발견했습니다(더 큰 질문의 일부이지만 두 가지 질문으로 나누었습니다).
\xpatchcmd
(from xpatch
) 또는 \patchcmd
(from ) 을 사용 etoolbox
하고 정의되지 않은 명령 시퀀스에 해당 명령을 (예를 들어 실수로) 적용하려면 물론 이 패치는 실패해야 합니다.
그러나 다음 코드는 실행되고 \someundefinedmacro
as를 생성합니다 \relax
. 여기서 \patchcmd
for 는 \someotherundefinedmacro
작동하지만 as를 반환하지 않습니다 \relax
(아직 정의되지 않음).
패치를 시도하기 전에 이 점을 확인해야 한다는 점을 인정해야 합니다. 또는 \GenericError
패치 매크로의 실패 분기에서 일부를 사용합니다.
여기에 짧은 MWE가 있습니다.
\documentclass{article}
\usepackage{xpatch}
% Patching an undefined macro... must fail as patching operation, of course (there's nothing to patch ;-))
\xpatchcmd{\someundefinedmacro}{Ministry of Silly Walks}{Mr. Gumby}{\typeout{Well, this is strange}}{\typeout{Nobody expects the Spanish Inquisition}}
%This does 'nothing'
\patchcmd{\someotherundefinedmacro}{Ministry of Silly Walks}{Mr. Gumby}{\typeout{Well, this is strange}}{\typeout{Nobody expects the Spanish Inquisition}}
%\show\someundefinedmacro -> relax
\begin{document}
\someundefinedmacro% Does nothing, since it's \relax'ed
% It will fail here (since `\someotherundefinedmacro` is really undefined
\someotherundefinedmacro%
\end{document}
답변1
예, 처리의 일부로 확인된 매크로는 다음과 같이 정의된 상태로 유지되었습니다 \relax
. 그래서 만약
\xpatchcmd{\foo}{<search>}{<replace>}{<true>}{<false>}
\foo
, \foo•
(글머리 기호는 공백에 대한 것임)이 시도되고 \\foo
, \\foo•
시작하지 않은 경우 휴식으로 정의된 상태로 유지됩니다.
이는 잘못된 내용이며 다음 버전에서 수정될 예정입니다 xpatch
.
그러나 매크로 는 정의되지 않은 매크로에 대한 패치가 시도되는 것처럼 \foo
정의된 상태로 유지됩니다 \relax
. 이를 방지하려면 너무 많은 패키지를 변경해야 합니다. 설명서에 경고가 추가됩니다.
그러나 매크로를 패치하려면 일반적으로 매크로가 존재하고 패치할 수 있는지 확인해야 합니다.