
\footnote
(i)에서 요청한 것과 유사하게 매크로가 (a) 명령 외부에 있는지 (b) 명령 내부에 있는지 테스트하고 싶습니다.현재 각주에 있는지 테스트하는 방법, (ii)내가 \footnote
?, (iii)footnote boolean: 현재 각주에 있는지 확인하는 방법및 (iv)본문에 X가 출력되고 각주에 Y가 출력되는 동일한 명령.
일반적인 기술은 (1) 부울을 정의하고 기본값은 false입니다. (2) \footnote
진입 시 부울 값을 true로 설정하고 종료 시 false로 재설정하도록 재정의합니다. 이를 위해서는 원래 명령에 추가 및 추가가 필요합니다 \footnote
.
내 질문이 위의 (i)–(iii)에 대해 제공된 답변과 다른 점은 모두 a로 재정의한다는 것입니다 \let
. 그러나 종종 잊어버리더라도 이 \footnote
명령은 선택적 인수(각주 번호에 대한)를 사용합니다. (예를 들어 참조" \footnote
"~의LaTeX2e 비공식 참조 매뉴얼(2018년 10월).) 이 사실은 사용을 부적절하게 만듭니다 \let
. (예: "다음과 같이 해야 한다는 점을 기억하세요.절대선택적 인수로 정의된 \let\ORIxyz\xzy
경우 오래된 트릭을 사용하십시오 ."\xyz
xpatch
선적 서류 비치)
((iv)의 대답은 내가 이해하지 못하는 \footnotetext
대신 재정의합니다.)\footnote
따라서 \footnote
명령을 사용하여 재정의하고 싶습니다 \xpretocmd
.\xapptocmd
xpatch
를 사용하여 (각각 앞에 추가하고 추가하기 위해) . (보다엔리코의 유용한 설명.)
아래 MWE는 이 문제를 해결하려는 나의 시도입니다.
추가 명령을 주석 처리하면 \xapptocmd{\footnote}{\togglefalse{inFootnoteCommand}}{}{}
잘 작동합니다(부울 값을 false로 재설정하지 않아 \footnote
종료된 후에도 해당 명령이 있다고 생각하는 명백한 문제를 제외하고). 다음 출력을 참조하세요.
그러나 추가 명령을 주석 처리하지 않은 상태로 두면 (a) 부울을 재설정하지 못하고 (b) 출력이 본문 텍스트와 각주 텍스트 모두에서 분리되고 (c) 명령과 관련된 오류가 발생합니다 \footnote
. 그 자체:
누락된 \endcsname이 삽입되었습니다. \unskip I.38 \footnote [각주:\amIInAFootnote] 표시된 제어 시퀀스는 \csname과 \endcsname 사이에 나타나서는 안 됩니다.
내가 어디로 잘못 가고 있습니까?
MWE는 다음과 같습니다.
\documentclass{article}
\usepackage{xcolor}
\usepackage{xpatch}
\usepackage{etoolbox}
\newtoggle{inFootnoteCommand}
\togglefalse{inFootnoteCommand}
\newcommand{\amIInAFootnote}{%
\iftoggle{inFootnoteCommand}{%
\textcolor{blue}{You are in a footnote.}
}{%
\textcolor{red}{You are NOT in a footnote.}
}%
}
\parindent=0pt
\begin{document}
This line intentionally left blank %To move the text closer to the footnote
\vspace{400pt}
\xpretocmd{\footnote}{\toggletrue{inFootnoteCommand}}{SUCCESS\\}{FAIL\\}
\xapptocmd{\footnote}{\togglefalse{inFootnoteCommand}}{SUCCESS\\}{FAIL\\}
Before a footnote: \amIInAFootnote.
At the end of this sentence is a footnote:%
\footnote{Here’s the footnote: \amIInAFootnote}
Now, I'm back from the footnote: \amIInAFootnote
\end{document}
답변1
정의 를 살펴보면 \footnote
다음과 같은 내용을 알 수 있습니다.
> \footnote=macro:
->\@ifnextchar [\@xfootnote {\stepcounter \@mpfn \protected@xdef \@thefnmark {\
thempfn }\@footnotemark \@footnotetext }.
이는 fotnote 텍스트를 인수로 처리하려고 시도하지 않고 단순히 이를 에 위임한다는 의미입니다 \@footnotetext
. 패치를 하면 논쟁 이 되고 \footnote
상황 이 엉망이 됩니다. 이 문제를 해결하려면 다음 항목에 패치를 직접 적용하는 것으로 충분합니다 .\togglefalse
\@footnotetext
\@footnotetext
\documentclass{article}
\usepackage{xcolor}
\usepackage{xpatch}
\usepackage{etoolbox}
\newtoggle{inFootnoteCommand}
\togglefalse{inFootnoteCommand}
\newcommand{\amIInAFootnote}{%
\iftoggle{inFootnoteCommand}{%
\textcolor{blue}{You are in a footnote.}
}{%
\textcolor{red}{You are NOT in a footnote.}
}%
}
\parindent=0pt
\begin{document}
This line intentionally left blank %To move the text closer to the footnote
\vspace{400pt}
\makeatletter
\xpretocmd{\@footnotetext}{\toggletrue{inFootnoteCommand}}{SUCCESS\\}{FAIL\\}
\xapptocmd{\@footnotetext}{\togglefalse{inFootnoteCommand}}{SUCCESS\\}{FAIL\\}
\makeatother
Before a footnote: \amIInAFootnote.
At the end of this sentence is a footnote:%
\footnote{Here’s the footnote: \amIInAFootnote}
Now, I'm back from the footnote: \amIInAFootnote
\end{document}
결과:
답변2
추가하면
\show\footnote
패치 후에는 찾을 수 있습니다
> \footnote=\protected macro:
->\toggletrue {inFootnoteCommand}\@ifnextchar [\@xfootnote {\stepcounter \@mpfn
\protected@xdef \@thefnmark {\thempfn }\@footnotemark \@footnotetext }\togglefalse {inFootnoteCommand}.
즉, 각주 인수가 표시되기 전에 토글을 true 및 false로 설정하고 \@ifnextchar
항상 볼 수 있듯이 선택적 인수에 대한 미리보기를 깨뜨리는 것입니다.\togglefalse
마지막에 재설정할 필요가 없으며 그룹 내에서 토글을 설정하기만 하면 됩니다. 또는 footnotesize에 설정된 유일한 텍스트가 각주인 일반적인 경우에는 토글이 전혀 필요하지 않으며 간단히 글꼴 크기를 테스트할 수 있습니다.
\documentclass{article}
\usepackage{xcolor}
\usepackage{etoolbox}
\newtoggle{inFootnoteCommand}
\togglefalse{inFootnoteCommand}
\makeatletter
\let\saved@makefntext\@makefntext
\def\@makefntext#1{\saved@makefntext{\toggletrue{inFootnoteCommand}#1}}
\parindent=0pt
\begin{document}
This line intentionally left blank %To move the text closer to the footnote
\vspace{400pt}
\newcommand{\amIInAFootnote}{%
\iftoggle{inFootnoteCommand}{%
\textcolor{blue}{You are in a footnote.}%%%
}{%
\textcolor{red}{You are NOT in a footnote.}%%%
}%
}
Before a footnote: \amIInAFootnote.
At the end of this sentence is a footnote:%
\footnote{Here’s the footnote: \amIInAFootnote}
Now, I'm back from the footnote: \amIInAFootnote
\end{document}