This is another follow up question based on this (using an altered MWE from this answer)
Situation
I am importing several parts of a file into another one (a summary-excerpt). This is done using the method described by touhami in the two linked questions.
Question
How to use \marginpar{} with this exclude approach?
When I try to compile a file loading another one which contains a \marginpar{} inside an excluded part it fails.
Compare MWE: newfile.tex fails due to the \begin{mtexclude} \marginpar{...} \end{mtexclude} in file.tex.
MWE (compare linked posts)
file.tex
\documentclass{amsart}
\newenvironment{mtexclude}{}{}
\begin{document}
First bla bla
%<*tag>
\section{Foo}
\begin{mtexclude}% begin of part to skiped
this works just fine
\end{mtexclude}% end
works fine aswell
\begin{mtexclude}% this exclude does not work
this works only in the main ``file.tex''
\marginpar{
this causes the error in compilation of newfile.tex
}
\end{mtexclude}
The end
%</tag>
Last bla bla
\end{document}
newfile.tex
\documentclass{amsart}
\usepackage{lipsum}
\usepackage{catchfilebetweentags}
\newtoks\temptoken
\newbox\mtbox
\makeatletter
\newenvironment{mtexclude}{%
\setbox\mtbox\vbox\bgroup%
\def\@float##1{\def\@captype{##1}}%
\let\end@float\relax%
}{\egroup}
\makeatother
\begin{document}
\lipsum[1]
\CatchFileBetweenTags\temptoken{file}{tag}
\the\temptoken
\end{document}