I want to include parts of a child document, specified by a range of line numbers, as LaTeX input, while producing useful SyncTeX information. It should also be possible to re-include lines already in the main document.
Example
Given input files
% -- main.tex
..: ...
20: Before input.\par
21: \inputlines{2}{4}{child.tex}
22: After input.\par
23: Repeat: \inputlines{22}{22}{main.tex}
..: ...
% -- child.tex
1: 1 First line.\par
2: 2 Second line.\par
3: 3 Third line.\par
4: 4 Fourth line.\par
5: 5 Fifth line.\par
I want the output to contain
...
Before input.
2 Second line.
3 Third line.
4 Fourth line.
After input.
Repeat: After input.
...
and invoking inverse search on "2 second line." should actually direct the editor to the correct line in child.tex
.
Existing partial solutions
Related question.
In
"\input only part of a file",
a solution is provided,
that does what I want except for SyncTeX support.
As far as I can tell, that is an unfortunate side effect
of processing a file with the \read
mechanism.
Crucially, this solution is robust in situations containing
multi-line constructs, such as multi-line \def
s
or the equation
environment.
Package "listings".
The command \lstinputlisting
of the listings
package
provides options firstline
and lastline
,
that perform the desired filtering,
while providing SyncTeX support.
It is however specialized for including files in verbatim and I was unable to verify
- How their filtering-by-line works, and
- if it can be transferred to LaTeX input without breaking either multi-line constructs or SyncTeX.
Package "catchbetweentags".
The catchfilebetweentags
package provides
a mechanism for including file contents marked
explicitly.
However, for my purposes requiring explicit
%<*tag> ... %</tag>
comments is undesirable,
and SyncTeX information is lost anyway.
Purpose
I am researching options for this,
in order to rewrite the apxproof
package
with SyncTeX support.
Currently this package creates an auxiliary file, that is later included,
thereby creating junk SyncTeX information,
that points to the auxiliary file.
Reading files partially, if possible without losing SyncTeX support, would allow building the functionality on a different basis.
MWE with apxproof, demonstrating the problem
\makeatletter\input{filecontents.sty}\makeatother
\begin{filecontents*}{\jobname.child.tex}
This proof has its contents stored in a child document.
SyncTeX will correctly point to this file
but
\begin{itemize}
\item It doesn't fix the loss of precision in \verb|thmrep|.
\item With many proofs, the large number of child documents
can become rather inconvenient.
\end{itemize}
\end{filecontents*}
\documentclass{article}
\usepackage{apxproof}
\usepackage{etoolbox}
\let\appendixprelim\relax % Prevent newpage before typesetting proofs.
\newtheoremrep{thm}{Theorem}
\preto\appendix{\noindent\hrulefill Appendix starts here}
\begin{document}
\section{Start}
\begin{thmrep}
This is a theorem, that will be repeated in the appendix.
SyncTeX sort of works here, for
It does however point only to the end of the environment,
not to individual paragraphs.
\end{thmrep}
\begin{appendixproof}
This is the proof, which will be put into the appendix via \verb|\VerbatimOut| mechanism.
\textsf{apxproof} defers it to the appendix,
by writing it out to \verb|\jobname.axp|
and then \verb|\input|ing it in the appendix.
Sadly, this mechanism causes SyncTeX to consider
the auxiliary file \verb|\jobname.axp| to be
the source of the contents.
\end{appendixproof}
\begin{appendixproof}
\input{\jobname.child.tex}
\end{appendixproof}
\end{document}
\begin{proof}\input{proof.123.inc}\end{proof}
as lesser evil.apxproof
package is quite useful, but its usability is hindered strongly by the loss of synctex support, so I was hoping to achieve the same behavior in some manner that preserves SyncTeX information.