11

I would like to include only a part of a .tex file into a different .tex file. The part I want to include is delimited by some comment tags, as it is used by catchfilebetweentags package.

I tried the solution of Will Robertson posted in \input only part of a file and it worked wonderfully ... except that the space that should appear in the output PDF file when the text jumps from one line to another in the source .tex file disappears.

The main file is the following:

\documentclass{article}%
\usepackage{catchfilebetweentags}

\begin{document}
\ExecuteMetaData[inputfile]{mytag}
\end{document} 

while the file where I want the text from (i.e., inputfile.tex) is the following:

\documentclass{article}%

\begin{document}
Some text.
%<*mytag>
Text to be included in the main file. This is the first line
and this is the second line. See the problem?
%</mytag>

\end{document} 

In my case, when I proccess the main file I get lineand instead of line and in the PDF file.

Where is the problem? Is it a catcode problem? I use MiKTeX 2.9 on a Windows 7 machine, if it helps.

1 Answer 1

9

For some reasons the author of catchfilebetweentags issues a command

\endlinechar=-1

that is obviously the cause of this behavior. I don't know if removing it has other side effects, but for your case it seems to work:

\usepackage{catchfilebetweentags}

\makeatletter
\def\CatchFBT@Fin@l#1[#2]{%
   \begingroup
      %\endlinechar\m@ne % <- this is the guilty party
      \makeatletter #2%
      \scantokens\expandafter{%
         \expandafter\CatchFBT@tok\expandafter{\the\CatchFBT@tok}}%
      \CatchFBT@IsAToken{#1}
         {\global#1\expandafter{\the\CatchFBT@tok}}
         {\xdef#1{\the\CatchFBT@tok}}%
      \ifx\CatchFBT@tok#1\else\global\CatchFBT@tok{}\fi
   \endgroup
}% \CatchFBT@Final
\makeatother

Instead of copying the whole definition from the package, you can use etoolbox:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\CatchFBT@Fin@l}{\endlinechar\m@ne}{}
  {}{\typeout{Unsuccessful patch!}}
\makeatother
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .