\label
을 포함하여 패치하고 싶은데 를 사용하면 또는 를 사용한 후에 패치해야 하는 #1
것 같습니다 . (코드는 없이도 작동해야 합니다 .) 그래서 이것이 제가 시도한 것인데 실패했습니다.hyperref
\begin{document}
\AtBeginDocument
hyperref
\documentclass{article}
\usepackage{hyperref}
\usepackage{xpatch}
% Attempt 1 - does nothing
% \pretocmd{\label}{#1}{}{err}
% Attempt 3 - fails (err)
% \AtBeginDocument{\pretocmd{\label}{#1}{}{err}}
% Attempt 4 - fails (err)
\AtBeginDocument{\pretocmd{\label}{##1}{}{err}}
\begin{document}
% Attempt 2 - works, inelegant
% \pretocmd{\label}{#1}{}{err}
Label name is \label{mylabel}.
\end{document}
답변1
나는 이 닭고기와 달걀 문제를 극복할 수 있는 실질적인 방법을 찾지 못했습니다 etoolbox
(또는 xpatch
매크로에 대한 포장일 뿐입니다). 명령이 다른 명령에 대한 인수에 있는 경우 에는 #1
대체 부분 \patchcmd
이나 유사한 부분 에 사용할 수 없습니다 (이 경우 ) .\pretocmd
\apptocmd
\AtBeginDocument
다음과 같은 방법이 있습니다 regexpatch
.
\documentclass{article}
\usepackage{regexpatch}
\usepackage{hyperref}
\AtBeginDocument{%
\makeatletter
% \A is the start of string anchor, \cP\# is l3regex for 'parameter token'
\regexpatchcmd{\label}{\A}{\cP\#1}{}{\err}%
\makeatother
}
\begin{document}
Label name is \label{mylabel}.
\end{document}
반면에 이 목적에는 showkeys
or 같은 패키지가 showlabels
훨씬 더 좋습니다.