1

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}
BadAtLaTeX
  • 1,139

1 Answers1

1

You need to redefine \marginpar to do nothing (in the same way of figure and table) so we need to do

\newenvironment{mtexclude}{%
    \setbox\mtbox\vbox\bgroup%
    \def\marginpar{}%
    \def\@float##1{\def\@captype{##1}}%
    \let\end@float\relax%
}{\egroup}

Note be careful that inside mtexclude counters style work try with a \section{foo} inside mtexclude and \section{bar} outside it.


MWE

\documentclass{amsart}
\usepackage{lipsum}

\usepackage{catchfilebetweentags}
\newtoks\temptoken
\newbox\mtbox
\makeatletter
\newenvironment{mtexclude}{%
    \setbox\mtbox\vbox\bgroup%
    \def\marginpar{}%
    \def\@float##1{\def\@captype{##1}}%
    \let\end@float\relax%
}{\egroup}
\makeatother

\begin{document}
\lipsum[1]
\CatchFileBetweenTags\temptoken{file}{tag}
\the\temptoken

\end{document}
touhami
  • 19,520
  • works splendidly! I am beginning to understand the scheme behind. Just reset everything to nothing inside the exclude environment. Though, I don't quite get the note (it might be addressed to readers unfamiliar with the first problem). The fact, that counters are still incremented is desirable; it was one important point of the first question in this row. – BadAtLaTeX Apr 01 '18 at 11:22
  • that's right, the two points – touhami Apr 01 '18 at 13:33