Add a version number to the title of a LaTeX docum

2019-03-15 05:04发布

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

8条回答
迷人小祖宗
2楼-- · 2019-03-15 05:13

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
查看更多
Rolldiameter
3楼-- · 2019-03-15 05: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.

查看更多
甜甜的少女心
4楼-- · 2019-03-15 05:15

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.

查看更多
做个烂人
5楼-- · 2019-03-15 05:16

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.

查看更多
The star\"
6楼-- · 2019-03-15 05:20

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.

查看更多
Emotional °昔
7楼-- · 2019-03-15 05:23

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}}
查看更多
登录 后发表回答