TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>}).

share|improve this question
up vote 6 down vote accepted

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.



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


            #2 \url{#1}

    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}.}.

share|improve this answer
+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
@DenisBitouzé: This might be true and there is almost surely a more elegant solution. Yet, I am not familiar with the etoolbox package at all. Hence, I can only provide the following alternative to avoid the \let construction: Define \newcommand{\myfootnote}[1]{\foottrue\footnote{#1}\footfalse} in the ifprinted statement, add an \else with \newcommand{\myfootnote}[1]{\footnote{#1}}, and replace every \footnote with \myfootnote in the body of the text. – crixstox Nov 29 '13 at 12:20
@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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.