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}
Edit: Code available for both Subversion and Git here: https://github.com/suomela/gitwdiff
For diffing, I have successfully used the following approach. This is not Latex-aware, but it seems to work very well with Latex documents (and Bibtex files, too). I have used it both on Linux and Mac OS X.
It is word-based and hence does not care about line breaks. For example, you can have each paragraph as a very long line in your source code; even then, the diff output will be easy to read and concise. It uses a colour-coded output:
- white on red background: deleted
- bold black on yellow background: added.
It is designed for black-on-white terminals; customise the colour codes if needed.
If you have made very extensive changes, occasionally it is better to use the usual diff. Try it out and see what happens.
Usage:
Simply write svnwdiff
instead of svn diff
.
If you need a pager, pipe your output to less -R
instead of less
.
Examples:
- You can simply write
svnwdiff
and you will see all your local changes.
- You can use
svnwdiff -c6445 foo.tex
just like you can use svn diff -c6445 foo.tex
.
- Write
svnwdiff -c6445 foo.tex | less -R
if you need a pager.
Put the following shell scripts in your $PATH
:
svnwdiff:
#!/bin/sh
exec svn diff --diff-cmd="mywdiff" "$@"
mywdiff:
#!/bin/sh
# Ignore all flags
while getopts uL: flag; do true; done
shift $(($OPTIND - 1))
esc=`printf '\033['`
wdiff -n -w "${esc}41;97m" -x "${esc}m" -y "${esc}1;103m" -z "${esc}m" "$@" | fgrep -C2 "$esc"
Finally, you will also need the wdiff tool. If you are using Ubuntu or Debian, just install the "wdiff" package. On Mac OS X, "port install wdiff" should do the trick.
If you are having problems getting all this working, try the following:
- First make sure that something like "wdiff foo bar" works.
- Then make sure that "mywdiff foo bar" works.
- Only after that try to get "svnwdiff foo" working, too.
For merging, I have found out that the best solution is to not need to merge. I tend to use email, skype, etc. to coordinate who has got the write token on which parts of the document. If all coordination efforts fail, I use the above diff tool to figure out who has done what, and integrate manually.
Best Answer
I know coded the following Perl script which calls
svn diff
in summary mode to get the changed files. It extracts these usingsvn cat
into two different directories and callslatexdiff
on each modified file. It modifies theTEXINPUTS
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 usinglatexmk
.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.