@Werner recommended using one of preprocessors for merging the files. I tried a latexexpand perl script and this is what I found:
- It works fine for plain
\input macros. It requires them to located in their own lines, as the whole line with \input will be removed.
- It does not support more complex use cases. For example it will not expand bibtex bibliographies.
I've modified the script so that it does the (2). There is no guarantee it will work with anything other than my document, though:
#!/usr/bin/perl
# - latexpand D. Musliner University of Michigan
# Short program to expand out LaTeX \input and \include commands.
# Essentially a tiny part of 'go' hacked out.
# Removes comments as a side effect, does not deal with escaped %s.
#
# 15 Sept 1999 M. Lovell Hewlett-Packard, Co
# Improved comment removal code. Now handles escaped %'s.
#
#
$TEXINPUTS = $ENV{'TEXINPUTS'};
if (!$TEXINPUTS) { $TEXINPUTS = '.'; }
&scan_for_includes(shift);
#************************************************************
# - looks recursively for included & inputted files, expands.
# - note only primitive comment removal: cannot deal with escaped %s.
sub scan_for_includes
{
local(*FILE); if (!open(FILE,$_[0]))
{ warn "WARNING: could not open input file [$_[0]]\n"; return; }
while(<FILE>)
{
# comment removal
s/^%.*\n//;
s/([^\\])%.*\n/$1/;
if (/\\include[{\s]+([^\001}]*)[\s}]/)
{
$full_filename = $1;
if ($1 =~ m/\./)
{ $full_filename = &find_file($full_filename,$TEXINPUTS); }
else
{ $full_filename = &find_file("$full_filename.tex",$TEXINPUTS); }
warn " Found include for file [$full_filename]\n";
&scan_for_includes($full_filename);
}
elsif (/\\input[{\s]+([^\001}]*)[\s}]/)
{
$full_filename = $1;
if ($1 =~ m/\./)
{ $full_filename = &find_file($full_filename,$TEXINPUTS); }
else
{ $full_filename = &find_file("$full_filename.tex",$TEXINPUTS); }
warn " Found input for file [$full_filename]\n";
&scan_for_includes($full_filename);
}
elsif (/\\bibliographystyle/) {}
elsif (/\\bibliography/) {
$bibfname = $_[0];
$bibfname =~ s/.tex$//;
$bibfname = "${bibfname}.bbl";
&scan_for_includes($bibfname);
}
else { print; }
}
}
#************************************************************
# given filename and path, return full name of file, or die if none found.
sub find_file
{
foreach $dir (split(':',$_[1]))
{ if (-e "$dir/$_[0]") { return("$dir/$_[0]"); } }
die "ERROR: Could not find file [$_[0]] in path [$_[1]]\n";
}
For the sake of completeness this is my Makefile:
TEX = latex
INKSCAPE = inkscape
documentfile = manuscript_work
finalfile = manuscript
referencefile = bibliography
figures = \
figures/fig1.eps \
figures/fig2.eps \
figures_tex = $(addsuffix .eps_tex,$(basename $(figures)))
all: document
document: $(finalfile).pdf
$(finalfile).pdf: $(finalfile).ps
ps2pdf $(finalfile).ps
$(finalfile).ps: $(finalfile).dvi
dvips $(finalfile).dvi
$(finalfile).dvi: $(finalfile).tex
while ($(TEX) $(finalfile) ; \
grep -q "Rerun to get cross" $(finalfile).log ) do true ; \
done
$(finalfile).tex: $(documentfile).tex $(figures) $(figures_tex) $(documentfile).bbl
./latexexpand $(documentfile).tex > $(finalfile).tex #use modified latexexpand script
figures/%.eps: figures/%.svg
$(INKSCAPE) $< -z -C --export-eps=$@ --export-latex
$(documentfile).bbl: $(referencefile).bib
$(TEX) $(documentfile)
bibtex $(documentfile)
\input{fileX}by the content offileXautomatically. – Werner Aug 15 '11 at 05:01.texfile" which makes me think the he wants to strip all\input,\includereferences, hence the suggestion. – Werner Aug 15 '11 at 05:11\bibliographystyle{...}and\bibliography{...}macros. – Andrzej Aug 15 '11 at 05:17.texfile as usual; make a copy of it to (say).tex.bak; run one of the suggested parsers on.tex.bak; backup is up-to-date. With every compile, this process is repeated (via automation). – Werner Aug 15 '11 at 05:17\inputor\includefor your.eps_texfiles, the parsing suggestions in my previous comment should take whatever your changed in.eps_texand put it in your main.texfile, no? – Werner Aug 15 '11 at 05:25latexexpandscript)\inputmacros must be in separate lines, 2) it doesn't mergedocument.bblfile - I've already fixed the script to support that. – Andrzej Aug 15 '11 at 05:45