Add a version number to the title of a LaTeX document

前端 未结 8 1398
攒了一身酷
攒了一身酷 2021-02-04 07:17

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.

\         


        
相关标签:
8条回答
  • 2021-02-04 07:24

    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.

    0 讨论(0)
  • 2021-02-04 07:27

    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
    
    0 讨论(0)
  • 2021-02-04 07:28

    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.

    0 讨论(0)
  • 2021-02-04 07:29

    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.

    0 讨论(0)
  • 2021-02-04 07:31

    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.

    0 讨论(0)
  • 2021-02-04 07:38

    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}}
    
    0 讨论(0)
提交回复
热议问题