情况
我正在将一个文件的几个部分导入另一个文件(摘要摘录)。这是使用 touhami 在两个链接问题中描述的方法完成的。
问题
为什么当且仅当没有后续注释时,行后的空格才会消失%...
?如何解决?
显然,代码中不能使用换行符。但为了可读性,我更愿意使用换行符,而不需要%
到处添加。
平均能量损失(比较链接的帖子)
文件.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}
新文件.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}
答案1
我认为可以通过添加来解决这个问题
\usepackage{etoolbox}
\makeatletter
\patchcmd{\CatchFBT@Fin@l}{\endlinechar\m@ne}{}{}{}
\makeatother
平均能量损失
\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}