20

The title section of my LaTeX documents usually look like

\title{Title}
\author{Me}
%\date{}      %// Today's date will appear when this is commented out.

\begin{document}
\maketitle

I'd really like to add another line in the title section for a version number:

\title{Title}
\author{Me}
\version{v1.2}
%\date{}      %// Today's date will appear when this is commented out.

\begin{document}
\maketitle

It doesn't necessarily have to be a command named version, but how can I get a version number to appear after the date (which is after the author)? I can manually set the version number.

So:

Title

Me

4/13/2010

v1.2

physicsmichael
  • 4,793
  • 11
  • 35
  • 54

9 Answers9

19

The easiest way to do exactly what I wanted to do was to simply use:

\title{Title}
\author{Me}
\date{\today\\v1.2}

\begin{document}
\maketitle
physicsmichael
  • 4,793
  • 11
  • 35
  • 54
  • 1
    Is it kosher to leave out the space after \\ like that? I have always done "\\ " whenever making a new line... – lindhe May 15 '17 at 11:39
14

My answer is probably too late for the original thread, but Latex has a very interesting package called vrsion (there is no 'e'), which is part of the standard distribution. Essentially, it numbers the .dvi file, i.e the number is increased every time Latex is run.

Personally, I use this as a simple work around for the lack of a human-friendly document version number from Git. Not ideal, but sometimes I have multiple copies of my documents and it helps avoid some confusion.

Max
  • 661
  • 1
  • 7
  • 12
  • 1
    Thanks Max. This is a great option. I'm really glad you posted your answer. Unfortunately it doesn't seem to actually change the file name produced (as I think your post suggests), but it answers my original question with a great tool! – physicsmichael Mar 08 '11 at 08:07
  • Actually, I used this package and did some more searching found this great resource: http://www.tug.org/pracjourn/2007-3/scharrer/scharrer.pdf It goes on to describe exactly how to get a footer on your LaTeX documents like `"Rev: 185_______Page 1_____2006-11-10 09:54"` when using Subversion to help with the revision control. Thanks again. – physicsmichael Mar 08 '11 at 08:17
  • Hi vgm64, thanks for the comment. The file name does not change. You use \version command to add the version number to your document (e.g. in the footer, header, etc). vrsion creates a file in your folder (.vrs) that maintains the version number through rebuilds of your document. Have a look at the vrsion manual; it explains things much better than I can. – Max Mar 08 '11 at 10:51
  • It seems that a tex file that uses the hyperref package together with vrsion does not compile. Do you have some workaround for this? – lmsasu Mar 29 '12 at 18:49
  • What are the advantages of using something an external program such as git vs using a version control Latex package such as the ones listed here http://texcatalogue.ctan.org/bytopic.html#classes ? – skan Nov 10 '16 at 17:20
  • vrsion doesn't seem to exist anymore / is no longer part of the standard distribution – Buochserhorn May 31 '17 at 16:54
6

For many version control systems, the checkin and checkout programs will expand certain strings in the documents into metadata the version control system has about the system, including the version number.

If you include these strings in the body of Tex definitions, then you can use them in your documents.

It's hard to say more without knowing which version control system you are using, but CTAN has the vc bundle, and rcs.sty is nice to use, for folks still using not only non-distributed, but not even concurrent VC...

Once you've got the strings (oh, I see you said manual entry is OK), you can then typeset this using

\title{Title\\\normalsize Version \versionnumber}

If you really want the author in between, then you can't use \title and \author together in the usual way - you should put your name on another line in the \title command.

Charles Stewart
  • 11,661
  • 4
  • 46
  • 85
4

If you have your document controlled inside a git repository, then this can be achieved using the gitinfo package. If correctly configured (which involves adding post-hooks to your git system), you can simply use \gitVtag to call the version number (as embodied in a git tag) or e.g. \gitAbbrevHash to get the abbreviated hash of the current commit of the repo.

E.P.
  • 342
  • 4
  • 13
3

Simple manual method:

  1. Create a file called (say) version.tex:

    \providecommand{\versionnumber}{3.0.1}

  2. Where you need to use it:

    \input{version}
    \title{Title\\\normalsize Version \versionnumber}

This will give you a single common place in your project or projects to update the version manually.

Brent.Longborough
  • 9,567
  • 10
  • 42
  • 62
2

If you need to display the version number only in the titlepage, you just need to modify it using

    \begin{titlepage}
    ...
    Version 1.x
    ...
    \end{titlepage}

after issuing the command \maketitle.

Otherwise, if you need to recall it in several times throughout the document, it's better to define a variable:

\def\Version#1{\def\version{#1}}

so that you define the version number with \Version{} and recall it with \version.

Alessandro Cuttin
  • 3,822
  • 1
  • 30
  • 36
1

Take a look at the packages rcsinfo and rcs. They include keys for extracting data from RCS tags within your document, so that will work if you are using CVS. I found this in The LaTeX Companion, pg 837. Something that works with your VCS of choice may have been written in the meantime.

Joel J. Adamson
  • 713
  • 4
  • 10
1

To provide a \version command like \author, you'd do:

\let\theversion=\relax
\providecommand{\version}[1]{\renewcommand{\theversion}{#1}}

If you're not using a titlepage environment, you can redefine \maketitle itself. Look in article.cls (or whatever class file you're using), copy-and-paste, and insert \theversion whereever and however you want. If you want to check for a version number before putting in the title, do something like:

\def\maketitle{%
% ... stuff copied from original class file...
\ifx\theversion\relax
% do nothing if there is no version defined
\else\bfseries\theversion% set the version
\fi

If you don't need it in the title per se you could add it as a footnote to the date (both of those properties related to the freshness of the resource so it makes some sense to put them together.

\title{My article}
\version{v1.2}
\date{\today\thanks{\theversion}}
Matthew Leingang
  • 2,579
  • 3
  • 20
  • 19
0

I use the package vhistory for a changelog table at the beginning of my documents.

\subject{Institute for nice formatted docs}
\title{My important document}
\subtitle{\vhCurrentVersion, \vhCurrentDate}
\author{Me}
\date{} % Activate to display a given date or no date (if empty)
\begin{document}
    \maketitle
    \clearpage
   \begin{versionhistory}
      \vhEntry{v0.1}{17.05.2019}{Me}{First release}
      \vhEntry{v0.2}{12.08.2019}{Someone}{Rewrite of chapter 2 ...}
      \vhEntry{v0.3}{04.03.2021}{Another editor}{Change after feedback of ...}
   \end{versionhistory}
   \tableofcontents

   [...]
\end{document}

With the following commands you get at any position the current version and the current date, which can be used in the title section.

PifPof
  • 1