I use LaTeX to generate all of the documents for my courses and as a result I have a lot of small documents in a given directory, which can then be hard to navigate due to all of the files generated when the .tex files are compiled. I have tried moving the output using output-directory and making an individual directory for each document but neither of these options have been entirely satisfactory. So my question is what methods of file management have worked for you with respect to LaTeX file management? Thanks.
[Tex/LaTex] How to manage LaTeX files in a directory
best practicesrevision control
Related Solutions
You can probably hack it with something like this (I'm not sure if it would work). You may have to split the TeX file into the wrapper for the paper, and the body for the paper. In the wrapper for the paper, include the comment
package, and set
\usepackage{comment}
\includecomment{bodyOfText}
\includecomment{paraA}
\includecomment{paraB}
% One for each separate unit you want to split up.
\newenvironment\commented[1]{\end{bodyOfText}\begin{#1}}%
{\end{#1}\begin{bodyOfText}}
\begin{document}
\begin{bodyOfText}
\input{body}
\end{bodyOfText}
\end{document}
Inside body.tex
where you keep the body of your text, each part you want to extract should be demarcated by
\begin{commented}{paraA}
%text here
\end{commented}{paraA}
And in your thesis, you can do
\usepackage{comment}
\excludecomment{bodyOfText}
\excludecomment{paraA}
% again, one for each extraction.
\newcommand\extracttext[1]{\includecomment{#1}\begin{bodyOfText}%
\input{body}\end{bodyOfText}\excludecomment{#1}}
\begin{document}
%some other text
\extracttext{paraA}
%some other text
\extracttext{paraB}
\end{document}
I know coded the following Perl script which calls svn diff
in summary mode to get the changed files. It extracts these using svn cat
into two different directories and calls latexdiff
on each modified file. It modifies the TEXINPUTS
variable to load files first from the diff directory instead of the current one. This avoids the copying of all unchanged files.
Finally the main file is compile using latexmk
.
The usage is perl <scriptfile> <mainfile> <rev a> <rev b>
.
It is absolutely not fool-proof so far, but is more general as the shell script linked to in the comments. Please test it and provide some feedback.
#!/usr/bin/env perl
use strict;
use warnings;
my @FILES;
my $rpath = '.r';
my ($mainfile,$REVA,$REVB) = @ARGV;
my $dpath = ".diff-${REVA}-${REVB}";
open(my $pipe, '-|', "svn diff --summarize -r${REVA}:${REVB}") or die;
while (<$pipe>) {
next if not /^M.{7}(.*\.tex)$/;
push @FILES, $1;
}
close ($pipe);
exit (1) if not @FILES;
mkdir $rpath . $REVA;
mkdir $rpath . $REVB;
mkdir $dpath;
foreach my $file (@FILES) {
print $file, "\n";
$file =~ /^(.*)\//;
my $dir = $1 || "";
my $dira = $rpath . $REVA . '/' . $dir;
my $dirb = $rpath . $REVB . '/' . $dir;
my $ddir = $dpath . '/' . $dir;
mkdir $dira if not -e $dira;
mkdir $dirb if not -e $dirb;
mkdir $ddir if not -e $ddir;
system("svn cat -r${REVA} '$file' > '${rpath}${REVA}/$file'");
system("svn cat -r${REVB} '$file' > '${rpath}${REVB}/$file'");
system("latexdiff '${rpath}${REVA}/$file' '${rpath}${REVB}/$file' > '${dpath}/$file'");
}
if (not exists $ENV{"TEXINPUTS"} || $ENV{"TEXINPUTS"} eq '') {
$ENV{"TEXINPUTS"} = "$dpath:.:";
}
else {
$ENV{"TEXINPUTS"} = "$dpath:" . $ENV{"TEXINPUTS"};
}
system("latexmk -pdf $mainfile")
Best Answer
This won't answer your question exactly, but it has worked for me.
I'm using Cornerstone, a subversion (version control) client that lets you manage you files (if you don't know what version control is, look it up!).
You can tell cornerstone to ignore all files of a specific file type so I set mine to ignore
.aux
.log
.pdf
etc. This way my repository won't get cluttered up. The working version does tend to get totally cluttered, but is isn't a problem since I only open.tex
files from the main cornerstone window which doesn't display the ignored files.Version control is also godsent for anyone working on big projects etc. Cornerstone is for mac and isn't free but there are free subversion clients for both mac, linux and windows.