
문맥:이 질문은 다음 질문에 대한 후속 질문입니다.매크로의 쉼표로 구분된 인수 목록에서 _(밑줄) 처리. 이 질문에서는 \codecitep
쉼표로 구분된 목록을 인수로 사용하고 링크를 생성하는 이러한 키를 인쇄하는 매크로를 만듭니다 hyperref
.
문제:내 MWE는 훌륭하게 작동하지만 실제 문서에서는 구현하지 못했습니다. 실제로 다음과 같은 오류가 발생합니다.
! LaTeX Error: \do undefined.
원인을 추적해 보니... 명령 \chapter
:
\codecitep
명령 위치~ 전에첫 번째 \chapter
컴파일은 잘 됐지만,~ 후에하지 않다.
해결책:(예, 해결책은 질문보다 먼저 나옵니다!)LaTeX 오류를 찾을 수 없습니다, \do
오류를 유발하는 명령 후에 정의를 재설정하면 컴파일 작업이 수행됩니다.
그러나 \def\do{}
각 \chapter
명령 뒤에 추가하는 것은 지저분한 방법이며 접미사로 KOMA \chapter
명령을 재정의/패치하는 것이 \def\do{}
지속 가능한 솔루션이라고 생각하지 않습니다.
질문:무엇이 \chapter
변경 \do
을 정의하고 이를 방지하는 방법이 내 \codecitep
매크로에 영향을 미치나요?
\documentclass{scrbook}
\usepackage{etoolbox}
\usepackage{hyperref}
\usepackage{lipsum}
\newcommand{\codecitep}[1]{% cf. https://tex.stackexchange.com/a/87423/64454
[%
\def\nextitem{\def\nextitem{, }}% Separator
\renewcommand*{\do}[1]{\nextitem{\hyperref[code:##1]{##1}}}% How to process each item
\docsvlist{#1}% Process list
]%
}
\begin{document}
\section{Body before chapter}
A sentence with one code-citation only \codecitep{key1}.
Another sentence with two code-citations and followed by dummy text \codecitep{key1, key2}.
\chapter{Chapter title}
%\def\do{}% <----- uncomment to make the error disappear
\section{Body after chapter}
A sentence with one code-citation only \codecitep{key1}.
Another sentence with two code-citations and followed by dummy text \codecitep{key1, key2}.
\lipsum[1-2]
\section{Appendix}
\lipsum[3]
\subsection{key1}
\label{code:key1}
\label{code:a_123}
\lipsum[4]
\subsection{key2}
\label{code:key2}
\label{code:bb_456}
\lipsum[5]
\end{document}
답변1
tocbasic.sty
에서 사용하는 패키지 는 scrbook
다음과 같습니다.
\let\do\relax
의 일부로 에 \doforeachtocfile
의해 실행됩니다 \chapter
. 이는 LaTeX에 따라 정의되지 않았기 \renewcommand\do{...}
때문에 할 수 없음을 의미합니다 .\do
실제로 \let\do\relax
두 개의 내부 매크로를 제거하면 문제가 사라집니다.
이 \renewcommand{\do}{...}
문제는 다른 상황에서도 나타났습니다. 내 생각에 가장 좋은 것은 자신만의 목록 프로세서를 사용하는 것입니다.
\documentclass{scrbook}
\usepackage{etoolbox}
\usepackage{hyperref}
\usepackage{lipsum}
\newcommand{\codecitep}[1]{% cf. https://tex.stackexchange.com/a/87423/64454
[%
\def\nextitem{\def\nextitem{, }}% Separator
\forcsvlist\codecitepitem{#1}% Process list
]%
}
\newcommand{\codecitepitem}[1]{%
\nextitem
\hyperref[code:#1]{\detokenize{#1}}%
}
\begin{document}
\section{Body before chapter}
A sentence with one code-citation only \codecitep{key1}.
Another sentence with two code-citations and followed by
dummy text \codecitep{key1, key2}.
\chapter{Chapter title}
\section{Body after chapter}
A sentence with one code-citation only \codecitep{key1}.
Another sentence with two code-citations and followed by
dummy text \codecitep{key1, key2}.
\lipsum[1-2]
\section{Appendix}
\lipsum[3]
\subsection{key1}
\label{code:key1}
\label{code:a_123}
\lipsum[4]
\subsection{key2}
\label{code:key2}
\label{code:bb_456}
\lipsum[5]
\end{document}
답변2
\do
많은 낮은 수준의 라텍스 구조에 사용됩니다 latex.ltx
.
\global\let\do\noexpand
~에\begin{document}
\let\do\@makeother
그리고
\let\do\do@noligs
와verbatim
\verb
\let\do\@makeother
~에filecontents
귀하의 사용 사례에서 무엇을 재설정하는지 정확히 추적하지는 않았지만 기본적으로 \do
분리된 목록이 실행되기 직전에 로컬 정의에만 사용해야 합니다.