[Version control using RCS, CVS or the like] Version control (also known as revision or source control) is a system that tracks changes to documents and source code. This makes it possible to revert to an earlier version or restore files that are accidentally overwritten or deleted. Typically, the system requires a location where the version control database (repository) is stored (usually password-protected). The authors working on the document pull the latest version of the source code from the database, which creates their own local version of the document files. They can then modify these local files, commit their changes, and push the changed files back to the database.
The version control system tracks these changes, who made the changes and when they were made. In the event that two or more authors have made conflicting changes to the same piece of text, the version control system will flag the conflict, and the authors need to decide whether to reject their change or overwrite the other author's change.
For example, if Mabel edits section 1 while Fred edits section 2, when they commit their changes there won't be a conflict. The version control system is able to merge their changes so that the source code on the database contains both the new section 1 and the new section 2. Fred and Mabel can then pull this file to update their own local copy. If they decide they don't like the changes, they can revert to an earlier version of the document. If they accidentally delete their local copy, they can pull a fresh copy from the database.
There are a number of different version control systems, some of which are open source, such as CVS, Subversion (SVN) and Git. Once you have decided which system to use, you need to install the software on your computer and find a location for the database.
In the case of a single author who's only interested in using the version control system as a means of backup, then a local directory can be used. For example, I keep my version control database on an external hard drive. The contents of the external hard drive are periodically backed up to a secondary external device, as an additional precaution. This means that if my primary hard drive fails (which it has done) I can pull all my source code from the database on the external hard drive and I only lose the most recent changes that haven't been committed to the repository. If my external hard drive fails (which it has done) I can restore the repository from the secondary external device and commit my local files. In this case I lose any of the revisions that haven't been backed up, but I still have the latest version of the document.
In the case of multiple authors, a server will be needed. The choice then comes down to a trade-off between document security and budget. There are free options available for public projects, but private projects usually require payment to a third party hosting service, or a secure server within your institution's firewall can be set up (assuming that all the authors are located within the institution). Some hosting services may be supported by advertisements. Bitbucket allows private hosting for up to 5 users under their free plan and GitHub provides private repositories under their paid plans .
Although Fred and Mabel can track all the document changes through the version control system, these changes aren't automatically added to the document and can't be viewed from the resulting PDF. This is often desired, but sometimes it's useful to include some of the revision information, particularly when a document is periodically updated and republished. In this latter case, there are some LaTeX packages that can do this, listed in the version-control topic.
For Git users, there's the gitinfo2 package  (which replaces the now deprecated gitinfo). For Subversion users, there are four packages available: svn , svninfo , svn-multi  and svn-prov . This last package (svn-prov) is designed for package authors. These packages are all available on both TeX Live and MiKTeX. There's also the vc package  that supports Git and Subversion, but this isn't on either TeX Live or MiKTeX and requires awk. For CVS users, there are packages such as rcs , rcsinfo  or rcs-multi , which are available both on TeX Live and MiKTeX.
For Windows users, there's a command line zip program available in GNU On Windows (GOW).
This book and the accompanying example documents and exercise solutions are in a Subversion repository. In order to insert version control information into one of these documents, I need to add a keyword anchor. This is just a bit of text in the form
The ⟨KeywordName⟩ indicates the information you want to insert and (for Subversion) may be one of :
- The last time the file was known to have been changed in the repository.
- The last known revision in which the file was changed in the repository.
- The last known user to change this file in the repository.
- The full URL to the latest version of the file in the repository.
- A compressed combination of the other keywords.
- Similar to
Idbut contains the full URL of the latest revision.
In addition to adding this text to the file under version control (called, for example, svninfo-sample.tex) you also need to tell Subversion to perform a keyword substitution whenever the file is committed. This is done using:
Now, after I next commit the file svninfo-sample.tex, the
$Id$ will be changed to the revision
information. For example:
$Id: svninfo-sample.tex 383 2014-12-12 19:23:03Z nlct
This will cause a problem when I build my document as
LaTeX will interpret those dollar
$ symbols as the maths
shift special character, so the information won't be typeset
correctly. However, recall from §2.1.1 Macro Definitions that you
\def to define a command with a particular syntax. For
Now I can have
$Id: svninfo-sample.tex 383 2014-12-12 19:23:03Z nlct
which is defined in a similar manner. Note that the trailing space is
part of the syntax. This command parses the
anchor and gathers the information for later use in the document. By
default this information is placed in the page footer.
For example, here's my original document called svninfo-sample.tex:
If I build this document using pdflatex, the resulting PDF file contains the footer
This is because there's currently no version control information in
the file, just the keyword anchor
$Id$. Next I need to add
this new file to my Subversion repository:
(See the Subversion user manual  for information on
setting up a repository.) Also, I need to indicate that this file
Id keyword anchor:
Now I can commit these changes to the repository:
This not only commits the new file svninfo-sample.tex to the repository, but also modifies the file so that it now looks like:
In addition to
\svnInfo, the svninfo package provides a way
to gather information from a different keyword, such as
Remember that you need to include these extra keywords in the
svn:keywords property to ensure they are also expanded. For example,
if you want to access the
rather than the
Id, then you need to set the keywords using
The Subversion information can be accessed using any of the following commands:
for the date in the form ⟨YYYY⟩-⟨MM⟩-⟨DD⟩ when the file was checked out or the current date if unknown;
for the year when the file was checked out or the current year if unknown;
for the month (in ⟨MM⟩ form) when the file was checked out or the current month if unknown;
for the day (in ⟨DD⟩ form) when the file was checked out or the current day if unknown;
for the date in the form of
\today when the file
was checked out or the current date if unknown.
A summary of the Subversion information can be obtained using
which uses the same format as the
Id keyword anchor. In
addition to the above commands, the svninfo package also
provides commands for multi-file documents. Every file of the
document must include either
Revision keyword. Two LaTeX runs are required.
displays the minimum revision number for all the files in the document, and
displays the maximum revision number for all the files in the
document. (If unknown, the defaults are
--maxrevision--.) The date from the
latest Subversion revision (in the same format as
If you want the URL to the file in the repository, you need the
and you can then use:
to access this information.
This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).