# How can I add version control info (to footers say?)

I'd like to keep track of revisions to a document and I use version control software for basically everything (SVN by the way, monotonically increasing revision numbers are their own reward).

I want to add SVN tags like $Id$ for example, SVN will then replace this (if the property is set) with the revision's ID. I'd be nice to show this somehow if only so I can keep track of things more easily. Ideally I'd like to have this info below the title, a list of the files that make up the document (a list of these IDs)

I am using subfiles to allow this to span multiple tex files if that helps.

I am hoping for an easy/canned way of doing this.

I'd like to then compile the document a certain way and have none of this info shown.

I did some searches for LaTeX pre-processor (so I could define a constant if I wanted this info for example) but I'd then have to search for displaying info on the front (which can be done, contents pages prove this) and stitch it all together.

I doubt I am the first to want to do this, so rather than reinvent the wheel, I ask you lot.

-

Did you try a asking a search engine? One of the first links mentions svn-multi, which can do exactly what you want to achieve.

\svnidlong
{$HeadURL$}
{$LastChangedDate$}
{$LastChangedRevision$}
{$LastChangedBy$}


after setting the svn:keywords to HeadURL LastChangedDate LastChangedRevision LastChangedBy.

With \usepackage{fancyhdr} you can then add the info (Repository URL, last revision and time of last commit) like so

\pagestyle{fancy}
\fancyfoot{}
\fancyfoot[OR]{\tiny \href{\svnkw{HeadURL}}{Revision \svnkw{LastChangedRevision}} --- last commit on \svnkw{LastChangedDate} --- page \thepage}
\fancyfoot[EL]{\tiny page \thepage\ --- \href{\svnkw{HeadURL}}{Revision \svnkw{LastChangedRevision}} --- last commit on \svnkw{LastChangedDate}}


Take a look at this article by Mark Eli Kalderon in a PracTeX Journal from 2007, which explains everything nicely.

-
You do not explain how to stop the info being shown, it's also very SVN specific, I was hoping for a mechanism where I could conditionally add content to pages you see, like a pre-processor. This is still a good answer - if rather specific –  Alec Teal Feb 5 at 17:17
I skimmed the link (I can use SVN I skipped the sections on using it) it doesn't talk about removing the info for the final version. If you see my comment on the other answer I mention the layout risk conditionally adding content has, does this suffer the same problem? –  Alec Teal Feb 5 at 17:21
Well you did specify SVN! In particular, you said you wanted to include SVN tags. –  cfr Feb 5 at 17:36
@AlecTeal -- All you need to do to adapt this answer is to wrap the \fancyfoot commands in a conditional. Something like \newif\ifsvn then \ifsvntrue\fancyfoot{<with SVN info>}\else\fancyfoot{<without SVN info>}\fi. The default is \svnfalse, but a simple \svntrue would print the information. –  jon Feb 5 at 17:55
Well, I thought the answer is needed to be very SVN specific since you mention "version control info" in the title of your question. As @jon showed, a conditional addition of comments (without changing the layout) is easily possible. Or do you want to conditionally show it depending on certain SVN tags? –  Habi Feb 7 at 8:13

This \Pagestamp[] macro I wrote for one of our internal styles. Without the optional argument, it uses the word DRAFT as the page stamp. However, you can use the optional argument to place (as I did) \today to give a date stamp to the document. If you had defined a version number in a \def, that could be included, as well.

\StopPageStamp will halt the stamp on subsequent pages.

In this case, the stamp is applied to the header and footer. That can be redone in the ps@... definitions.

EDITED to leave original page dimensions intact.

\documentclass{article}
\usepackage{lipsum}
\makeatletter
\def\PageStampFlag{F}
\def\thePageStamp{}
\newcommand{\ps@pagestamp}{
\renewcommand{\@evenfoot}{\hfil
\begin{tabular}{c}
\textrm{\thepage}\\
\textbf{\Large\thePageStamp}
\end{tabular}
\hfil}
\renewcommand{\@oddfoot}{\@evenfoot}
}

\newcommand{\ps@emptypagestamp}{
\renewcommand{\@evenfoot}{\hfil
\begin{tabular}{c}
~\\
\textbf{\Large\thePageStamp}
\end{tabular}
\hfil}
\renewcommand{\@oddfoot}{\@evenfoot}
}
\newcommand\PageStamp[1][DRAFT]{
\def\PageStampFlag{T}
\def\thePageStamp{#1}
\def\PlainStyle{pagestamp}
\def\EmptyStyle{emptypagestamp}
\pagestyle{\PlainStyle}
}

\newcommand\StopPageStamp[0]{
\def\PageStampFlag{F}
\def\PlainStyle{plain}
\def\EmptyStyle{empty}
\pagestyle{\PlainStyle}
}
\makeatother
\begin{document}
\PageStamp[\today]

\lipsum[1-6]
\StopPageStamp
The stamp should be gone.
\end{document}


-
I like this because it is general purpose (unlike the other answer) and is shows that the content may be removed. This is perfect. I mentioned in my question "(to footers say?)" as a reference to alignment, adding content to a page could change boundaries and rejig the layout (which is why I added the bit about "under the contents table") any thoughts on this? –  Alec Teal Feb 5 at 17:19
@AlecTeal It is true my original answer changed some page size settings. I have updated the answer to leave the original page sizes intact, so that turning on/off the stamp should not affect the remaining page dimensions from their defaults. –  Steven B. Segletes Feb 5 at 17:28

This is a variant of what I use. It is svn specific. It does not change the page layout. It is easy to switch off. It does not interfere with configured headers/footers. I've added a command to print a preliminary page containing the title, author etc. and a table of revision information for all files used in producing the document.

Here is a sample of the first two pages with the stamps enabled and the preliminary page included:

This makes use of several packages. prelim2e makes it easy to include the information at the bottom of pages (below the regular footer) and to switch between using this and not. I've also used a conditional from the package in a custom command which includes a table of revision information since you mentioned wanting to include information for all files, not just the main file.

Like Habi, I've used svn-multi to get the svn information included. I've used \tableofrevisions in the custom command to include information for all files. url is used to format the url.

titling is used so that \maketitle can be issued twice - once for the preliminary page and once for the regular first page.

I've used fake svn entries to show how these are handled. Obviously you would not really type these in yourself - you would let svn complete and update these as necessary.

Here's the code:

\documentclass{article}

% comment this line and uncomment the next to remove the stamp
\usepackage[draft]{prelim2e}
% \usepackage[final]{prelim2e}

% to pretty print the url
\usepackage{url}

% to reuse title, author etc. easily
\usepackage{titling}

% to handle the SVN info nicely
\usepackage[table,subgroups]{svn-multi}
% for example only - uncomment lines below to let svn populate fields
\svnidlong
{$HeadURL: http://www.myfiles.com/myfiles/mainfile.tex$}
{$LastChangedBy: somebody$}
{$LastChangedRevision: 6897559$}
{$LastChangedDate: 1012-04-01 012:20:43 +0100 (Wed, 01 Apr 1012)$}
%   \svnidlong
%       {$HeadURL:$}
%       {$LastChangedBy:$}
%       {$LastChangedRevision:$}
%       {$LastChangedDate:$}
% % if you prefer a more concise format
% % \svnid{$Id:$}
\svnRegisterAuthor{somebody}{Some Body}

\newsavebox{\prelimtxt}
\sbox{\prelimtxt}{%
\parbox{\textwidth}{%
\urlstyle{sf}%
\centering \small \textsf{Draft --- \today\ --- Revision \svnrev\ --- \svnyear--\svnmonth--\svnday\ \svnhour:\svnminute:\svnsecond}\\[1em]
}% end parbox
}% end sbox
\renewcommand{\PrelimText}{\usebox{\prelimtxt}}
\makeatletter
\newcommand*{\preliminfo}{%
\if@prelim@draft
\maketitle
\tableofrevisions
\cleardoublepage
\pagenumbering{arabic}
\fi
}
\makeatother

% for example only
\usepackage{filecontents,kantlipsum}

\begin{filecontents}{subfile.tex}
\svnidlong
{$HeadURL: http://www.myfiles.com/myfiles/subfile.tex$}
{$LastChangedBy: somebody$}
{$LastChangedRevision: 6897541$}
{$LastChangedDate: 1012-04-01 01:20:43 +0100 (Wed, 01 Apr 1012)$}
\kant[9]
\end{filecontents}

\title{Great paper}
\author{S.\ Body}

\begin{document}
\preliminfo
\maketitle

\kant[1-8]

\include{subfile}

\end{document}


To exclude the information, comment the line \usepackage[draft]{prelim2e} and uncomment \usepackage[final]{prelim2e}. Then the preliminary page will not be included and the first two pages will instead look like this:

Note that pagination, page breaks, headers and footers are unaffected. All that changes is the preliminary page is omitted and the information beneath the regular footer is not typeset.

@AlecTeal, you can accept any answer that you think is best, not only the highest rated one. Maybe I misunderstood you and this answer here suits you better, although I think they both achieve the same, since you either have to change the draft option (this answer) or conditionally turn off the SVN info in the footer (my answer). –  Habi Feb 7 at 8:16