The preferred way is latexdiff
. You'll need to have Perl installed, as this is really a
script.
The usage is quite simple (see below), but check the documentation for more options.
latexdiff old.tex new.tex > diff.tex
On an unrelated note, I had a question some time ago about comparing PDF documents, but hopefully you won't need that.
You might also find this discussion helpful, which is partly related to what you're asking.
If you want to see how things can get tangled in a preamble have a look at the preamble of the Comprehensive LaTeX Symbol List. It might not be exactly spaghetti code but it can certainly be classified as code soup!
So you are right, you need to have a strategy and start working on it early in the development of your document. The tips below are from my own workflow and observations.
Early on, when I started with LaTeX, I realized that having used numerous macros and packages to change the looks of almost every single parameter originally set by the LaTeX book.cls
, I would have been better off developping my own class and this is my first tip.
1. Consider developing your own class or package to hold your changes.
It is as simple as hitting a save as
button to save the base class .dtx
file and its .ins
file. It will get you going with literate programming and honestly it should not take longer than an hour or two to find out how it all works. When you use doc
for the first time you might get disoriented, but eventually you get used to the conventions. Another advantage of this approach is that at the beginning of developing a new document, you will find out that on Mondays, Wednesdays and Thursdays, you will want your document to look one way and on the rest of the days of the week you will want it in another way. By writing your rationale down using literate programming, it helps you settle your ideas.
2. Have the packages and own related commands, near each other
For smaller changes, i.e., write short packages, either using the doc/docstrip system or if you are in a hurry just use the package filecontents
and write them on the fly while developing the document. This tends to remove a lot of code and comment lines in the preamble. I have all maths related macros normally in a package called moremaths
.
% MATHEMATICS
\usepackage{amsfonts}
\usepackage{amsmath}[2000/07/18] %% Displayed equations
\let\equation\gather %% See tabu and hyperref docs
\let\endequation\endgather
\usepackage{amssymb}[2002/01/22] %% and additional symbols
\usepackage{amsfonts}
\usepackage{xfrac}
\usepackage{stmaryrd}
\usepackage{mathtools}
\usepackage{eucal}
Similarly, for tables
%% Tables
%% TABLES
\RequirePackage{array}
\RequirePackage{booktabs}
\RequirePackage{longtable}
\RequirePackage{tabularx}
\RequirePackage{dcolumn}
\RequirePackage{multirow}
%% Set some local commands and colors
\RequirePackage{colortbl} % for colored table cells
\definecolor{green}{rgb}{0.1,0.1,0.1}
\newcommand{\done}{\cellcolor[gray]{0.9}done} %{0.9}for done tables
%
%
3. Divide the preamble into headings, such as typography
, graphics
, maths
, sectioning
etc.
If you do not develop your own class and use any of the major classes such as Koma
or memoir
, you will discover that in general these classes have their own configuration commands for every possible change; it helps if you divide all the relevant commands in sections. If the sections grow, i.e, if you have too many typography
save the code in a package and name it moretypography
or moremaths
etc. Again here, if the preamble grows question the need for your own class.
4. Have the problematic package settings in their own packages e.g., sethyperef
or setlistings
package etc.
Some packages are difficult to set and can give you problems if they are loaded before or after some packages (See Which packages should be loaded after hyperref instead of before?). Others need some complicated and long settings. Again here if you work on a long documents it may be worth changing these settings to small packages. If you identify sources of errors better save and restore commands rather than move them around. For example the verse
package gave me problems with the macro theHpoemline
and I normally only load it together with the following macros.
\let\oldH\theHpoemline
\let\theHpoemline\undefined
There are a lot of similar techniques in the Comprehensive LaTeX Symbol List, preamble, worth a read.
Best Answer
It depends a little if this files are only used by you are if you are planning to share them with other people, e.g. if you work with them on one document or the files are part of a LaTeX package.
But in general I would strongly recommend you to limit yourself to lowercase alphanumeric ASCII characters, i.e. a-z, 0-9 and
-
.The reasons for that are:
%
and#
. Others as&
can cause trouble as well and there is no real reason to use them, so avoid them. Even_
which is commonly used and will work inside\input
can cause trouble when the filename should be printed, so avoid it as well.I'm going through some effort in the
svn-multi
package to allow for arbitrary file names. This is done using verbatim mode which doesn't help for other input macros like\input
,\include
or\includegraphics
.