footnote inside mbox

I know very similar questions have been asked, but I couldn't find a solution to my problem.

My original problem started using the glossaries package, using an acronym inside the framed environment, something like this:

\begin{framed}
bla bla \gls{Y2K} bla bla
\end{framed}


The expected behaviour was that next to Y2K should be a footnote, that footnote linking the acronyms, and the explaining text of the footnote at the bottom of the page.

Now I know the problem is not exactly with glossaries and framed, but with footnote and \mbox or \fbox.

Here's a minimal example that shows the problem:

\documentclass[11pt]{report}
\usepackage[pdftex,pagebackref]{hyperref}
\usepackage[acronym,toc,section=chapter,style=indexgroup,sanitize={name=false,description=false,symbol=true}]{glossaries}
\glsdisablehyper

\defglsdisplayfirst[main]{#1#4\protect\footnote{#2}}
\makeglossaries

\newglossaryentry{Y2K}{name=Y2K,description={Bla bla bla}}

\begin{document}
% Bla bla  \gls{Y2K} bla bla % Works fine
\fbox{Bla bla  \gls{Y2K} bla bla} % doesn't work as expected

\newpage
\printglossaries
\end{document}


I use pdflatex, makeglossaries, pdflatex to compile.

So, the thing is that I need to use a footnote inside \fbox, because framed uses \fbox and glossaries uses footnote.

I already tried using this but didn't do anything:

\usepackage[stable]{footmisc}
\usepackage{footnote}


One last thing, this piece of code:

\defglsdisplayfirst[main]{#1#4\protect\footnote{#2}}


I got it from here, maybe it could be tweaked to solve this problem.

EDIT 06-DEC-2013 After a long time I've found a problem with this solution. Instead of fbox I'm using the framed enviroment. When I use the first boxedgls inside framed there's no problem. If I use another framed enviroment after, it also generates the footnote (whether there is or not a gls inside).

MWE:

\documentclass[11pt]{report}
\usepackage{etoolbox}
\usepackage{framed}
\usepackage[pdftex,pagebackref]{hyperref}
\usepackage[acronym,toc,section=chapter,style=indexgroup,sanitize={name=false,description=false,symbol=true}]{glossaries}
\glsdisablehyper

\defglsdisplayfirst[main]{#1#4\protect\footnote{#2}}
\makeglossaries

\newglossaryentry{Y2K}{name=Y2K,description={Bla bla bla}}

\newcommand\glsdoafterbox{}

\let\orgfbox\fbox
\def\fbox#1{\orgfbox{#1}\glsdoafterbox\def\glsdoafterbox{}}

\newcommand{\boxedgls}[1]{%
\glstext{#1}%
\ifglsused{#1}{}%
{%
\footnotemark
\gappto\glsdoafterbox{\footnotetext{\glsentrydesc{#1}}\glsunset{#1}}%
}%
}

\begin{document}

\begin{framed}
Bla bla \boxedgls{Y2K} bla bla
\end{framed}

\newpage
\begin{framed}
Nothing here
\end{framed}

\newpage
\printglossaries
\end{document}

-
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you. –  Jubobs Mar 27 '13 at 13:12

You can't use \footnote inside a box. For example, the following won't produce the footnote text:

\fbox{Some text\footnote{with a footnote}}.


Instead you need to use a combination of \footnotemark and \footnotetext like this:

\fbox{Some text\footnotemark}\footnotetext{with a footnote}


Applying this to a glossary entry is complicated but can be done:

\documentclass[11pt]{report}
\usepackage[pdftex,pagebackref]{hyperref}
\usepackage[acronym,toc,section=chapter,style=indexgroup,sanitize={name=false,description=false,symbol=true}]{glossaries}
\glsdisablehyper

\defglsdisplayfirst[main]{#1#4\protect\footnote{#2}}
\makeglossaries

\newglossaryentry{Y2K}{name=Y2K,description={Bla bla bla}}

\begin{document}

\fbox{Bla bla  \glstext{Y2K}\ifglsused{Y2K}{}{\footnotemark} bla
bla}\ifglsused{Y2K}{}{\footnotetext{\glsentrydesc{Y2K}}\glsunset{Y2K}}

\newpage
\printglossaries
\end{document}


For a more automated solution you could do:

\documentclass[11pt]{report}
\usepackage{etoolbox}
\usepackage[pdftex,pagebackref]{hyperref}
\usepackage[acronym,toc,section=chapter,style=indexgroup,sanitize={name=false,description=false,symbol=true}]{glossaries}
\glsdisablehyper

\defglsdisplayfirst[main]{#1#4\protect\footnote{#2}}
\makeglossaries

\newglossaryentry{Y2K}{name=Y2K,description={Bla bla bla}}

\newcommand\glsdoafterbox{}

\let\orgfbox\fbox
\def\fbox#1{\orgfbox{#1}\glsdoafterbox\def\glsdoafterbox{}}

\newcommand{\boxedgls}[1]{%
\glstext{#1}%
\ifglsused{#1}{}%
{%
\footnotemark
\gappto\glsdoafterbox{\footnotetext{\glsentrydesc{#1}}\glsunset{#1}}%
}%
}

\begin{document}

\fbox{Bla bla \boxedgls{Y2K} bla bla}

\newpage
\printglossaries
\end{document}

-
That worked! I've tried it with framed and it also worked –  Nico Mar 27 '13 at 14:48
The "more automated solution" is exactly what I wanted (and works!), thank you very much –  Nico Mar 27 '13 at 15:01
After a long time I've found a problem with this solution. Instead of fbox I'm using the framed enviroment. When I use the first boxedgls inside framed there's no problem. If I use another framed enviroment after, it also generates the footnote (whether there is or not a gls inside). I've edited my question with an example. –  Nico Dec 6 '13 at 15:14