# Missing spaces when importing parts of other file

This question is a follow up and based on this question (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

## Why do the spaces behind lines go missing, if and only if there is no subsequent comment %... ? And how to fix that ?

Obviously one could not use line breaks in code. Though for readabilities sake I'd prefer to have such without the need to add %all over the place.

file.tex

\documentclass{amsart}
\usepackage{lipsum}

\newenvironment{mtexclude}{}{}
\begin{document}
First bla bla
%<*tag>
\section{Foo}
\subsection{Foo bar}
I need this % here is a space at end of line with comment afterwards
certain text \textbf{no more space!''},
plus another one: \textbf{without comments''}.
%
But space goes missing.
%note the space at the end of line 16 and 17 WITHOUT anything behind

\begin{mtexclude}% begin of part to skiped
\section{Baz}
\subsection{Baz bar}
no need for this
\end{mtexclude}%   end

\section{End}
\subsection{End bar}
and need this \dots

\begin{mtexclude}% begin of part to skiped
%no problems here
\section{Baz 2}
\subsection{Baz bar 2}
another part to be skiped
\end{mtexclude}%   end

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}


here are the results: file.tex newfile.tex

• unrelated but as you see in the images that you post, you should not use " in latex input, use   and '' – David Carlisle Feb 19 '17 at 16:45
• @DavidCarlisle I am sorry for such bad MWE. Usually I do use a custom command \quotes{text}, but by an oversight I have forgotten to do so here. – gr4nt3d Feb 19 '17 at 16:49
• no harm done, it doesn't affect the question in any way, I just thought it worth mentioning:-) – David Carlisle Feb 19 '17 at 16:55
• it seems to be a bug. – touhami Feb 21 '17 at 11:38
• you can try \usepackage{etoolbox} \makeatletter \patchcmd{\CatchFBT@Fin@l}{\endlinechar\m@ne}{}{}{} \makeatother – touhami Feb 21 '17 at 19:32

I think one can fix this by adding

\usepackage{etoolbox}
\makeatletter
\patchcmd{\CatchFBT@Fin@l}{\endlinechar\m@ne}{}{}{}
\makeatother


MWE

\documentclass{amsart}
\usepackage{lipsum}

\usepackage{catchfilebetweentags}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\CatchFBT@Fin@l}{\endlinechar\m@ne}{}{}{}
\makeatother

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

• once again there has been an error with \marginpar{} that I am unable to track down. If you happen to have time, I suppose you're expertise with this chain of questions would be invaluable. See tex.stackexchange.com/q/424247/74942 – gr4nt3d Mar 31 '18 at 22:43
• @gr4nt3d will try tomorow – touhami Mar 31 '18 at 22:48