How do I detect whether I'm in a \footnote environment or not?
Asked
Active
Viewed 550 times
10
2 Answers
6
I just \def\infootnote to T or F. If you needed to branch on that basis, you could perform \if T\infootnote TRUE code\else FALSE code\fi.
\documentclass{article}
\let\svfootnote\footnote
\renewcommand\footnote[2][\thefootnote]{%
\stepcounter{footnote}%
\gdef\infootnote{T}%
\svfootnote[#1]{#2\gdef\infootnote{F}}%
}
\gdef\infootnote{F}
\textheight 1in
\begin{document}
Footnote status: \infootnote. Now entering a footnote%
\footnote{The status now: \infootnote. Done.}
Continuing with status: \infootnote. Again.
\footnote{The status now: \infootnote. Done.}
\end{document}

Steven B. Segletes
- 237,551
5
Define a conditional \iffootnote and redefine \footnote so that it makes \iffootnote come out true inside its parameter, but false outside. For example:
\documentclass{article}
\newif\iffootnote
\let\Footnote\footnote
\renewcommand\footnote[1]{\begingroup\footnotetrue\Footnote{#1}\endgroup}
\begin{document}
foo\footnote{a\iffootnote yes\else no\fi}
bar \iffootnote yes\else no\fi
\end{document}
n.r.
- 4,942
-
The
\footnotemacro defined by the LaTeX kernel also accepts an optional argument. – jub0bs Apr 15 '14 at 17:56 -
Biblatexdoes it, but it involves many lines of code patching various footnote commands (which vary depending on class and package loaded). You could, if you feel strong, borrow/steal that code. It's around lines 134-197 of biblatex2.sty. Or, if you loadbiblatexanyway you could piggy-back on its commands. – Paul Stanley Apr 15 '14 at 17:40\footnoteis just a macro, not an environment. – jub0bs Apr 15 '14 at 17:55