在参照这个问题,我想问一下是否存在一个命令,当在文本正文中发出时会产生输出 X,但在任何类型的脚注中发出时会产生输出 Y。
例子:
This is a nice sentence says Mister \funnycommand.\footnote{This is a nice footnote says Mister \funnycommand.}
输出:
X 先生说这句话真好。*1
==============
*1 Y 先生说,这是一个很好的脚注。
答案1
假设您不使用改变脚注管理的软件包:
\documentclass{article}
%\documentclass{scrartcl} % works also with Koma-Script classes
\usepackage{etoolbox}
\newif\ifinfootnote
\makeatletter
\@ifundefined{scr@saved@footnotetext}
{\patchcmd{\@footnotetext}}
{\patchcmd{\scr@saved@footnotetext}}
{\reset@font}
{\reset@font\infootnotetrue}
{}{}
\patchcmd{\@mpfootnotetext}
{\reset@font}
{\reset@font\infootnotetrue}
{}{}
\makeatletter
\newcommand{\funnycommand}{\ifinfootnote Y\else X\fi}
\textheight=4cm % just for the example
\begin{document}
This is a nice sentence says
Mister \funnycommand.\footnote{This is a nice footnote
says Mister \funnycommand.} Again, \funnycommand
\fbox{\begin{minipage}{3cm}
\funnycommand\footnote{\funnycommand}
\end{minipage}}
\end{document}
笔记增加了与 Koma-Script 类的兼容性
答案2
黑客攻击---
\documentclass[10pt]{article}
\let\realfootnote=\footnote
\newif\ifinfootnote\infootnotefalse
\renewcommand{\footnote}[1]{{\infootnotetrue\realfootnote{#1}}} %double grouping!
\newcommand{\funnycommand}{\ifinfootnote Y\else X\fi}
\begin{document}
This is a nice sentence says
Mister \funnycommand.\footnote{This is a nice footnote
says Mister \funnycommand.} Again, \funnycommand
\end{document}
您必须修改它以考虑\footnote
您需要的可选参数。