Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using XeLaTeX because of language problem.

The following code has no problem:

\documentclass{article}

%\usepackage{mdframed}

\newenvironment{mynote}{\footnote\bgroup}{\egroup}
\begin{document}
Hello\begin{mynote} world\end{mynote}.
\end{document}

However, the following code gives an error:

\documentclass{article}

\usepackage{mdframed}

\newenvironment{mynote}{\footnote\bgroup}{\egroup}
\begin{document}
Hello\begin{mynote} world\end{mynote}.
\end{document}

What is the reason for the error and how can I resolve it?

share|improve this question
    
\footnote, in LaTeX, can't be followed by \bgroup in order to build its argument. If it appears to work is just by chance and it will be typeset incorrectly anyway. –  egreg Jun 3 at 20:43
1  
The reason why this fails with mdframed is because the package adds code to \begin and \end. But trust me: your mynote environment doesn't work correctly. –  egreg Jun 3 at 20:48
add comment

1 Answer 1

up vote 5 down vote accepted

With environ you can define an environment which collects the body for later use.

\documentclass{article}
\usepackage{mdframed,environ}
\newsavebox\NBox
\NewEnviron{mynote}{\footnote{\BODY}}

\begin{document}
Hello\begin{mynote} world\end{mynote}.
\end{document}
share|improve this answer
    
Thank you. Your solution resolved the problem. However, I still wonder why the second code have not worked... –  seoneo Jun 3 at 20:59
add comment

Your Answer

 
discard

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.