# How to test if I'm currently in a footnote or not

Is there a way to test if the current point is inside or outside a footnote?

The use case I have in mind is to provide two versions of a document, a "screen" one and a "printed" one and I'd like in the printed one automatically change the \href{<URL>}{<text>} into <text>\footnote{\url{<URL>}}, except in footnotes where this wouldn't make sense and \href{<URL>}{<text>} could be changed into <text> (\url{<URL>}).

-

Below an possible answer adapted to your usecase. For this solution I redefined \footnote and \href and used to if-statements. To really check if one is in a certain environment see this question.

\documentclass{article}

\usepackage{hyperref}

\newif\ifprinted
\printedtrue % for printet version
% \printedfalse % for screen version

\newif\iffoot
\footfalse

\ifprinted
\let\origfootnote\footnote
\renewcommand{\footnote}[1]{\foottrue\origfootnote{#1}\footfalse}
\renewcommand{\href}[2]{
\iffoot
#2 \url{#1}
\else
#2\footnote{#1}
\fi
}
\fi

\begin{document}
One of the best \TeX-communities can be found on \href{http://tex.stackexchange.com/}{\TeX.SE}.
There is a high probabilty that your \TeX-question is answered in a Q\&A-site\footnote{See for example \href{http://tex.stackexchange.com/}{\TeX.SE}.}.

\end{document}

-
+1. I was just posting the same answer... –  karlkoeller Nov 28 '13 at 10:05
Though it doesn't strictly answer the original question, I marked your answer as accepted because it answers my use case. Nevertheless, I read (I don't remember where) that redefining macros with \let as in \let\origfootnote\footnote is not the recommended way anymore and that patching commands with e.g. etoolbox patching tools is preferable (okay, that requires e-TeX): am I wrong? –  Denis Bitouzé Nov 29 '13 at 7:44
@crixstox Okay, I retrieve where I read redefining macros with \let is not recommended: in the documentation of the xpatch package, section 5 page 6 (though no explanation is given). In fact, it concerns only redefinition of macros that have an optional argument, hence your redefinition of \footnote with \let\origfootnote\footnote is perfectly advisable: sorry to have been suspicious ;) –  Denis Bitouzé Dec 16 '13 at 15:57