将版本号添加到 LaTeX 文档的标题中

发布于 2024-08-28 18:04:18 字数 533 浏览 7 评论 0原文

我的 LaTeX 文档的标题部分通常看起来像

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

\begin{document}
\maketitle

我真的很想在标题部分中添加另一行以获取版本号:

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

\begin{document}
\maketitle

它不一定是名为 version 的命令,但是如何我可以让版本号出现在日期之后(在作者之后)吗?我可以手动设置版本号。

所以:

标题

4/13/2010

v1.2

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

原野 2024-09-04 18:04:22

我在文档的开头使用包 vhistory 作为更改日志表。

\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}

使用以下命令,您可以在任意位置获取当前版本和当前日期,这些信息可以在标题部分中使用。

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.

迷乱花海 2024-09-04 18:04:21

看一下 rcsinforcs 包。它们包括用于从文档中的 RCS 标签提取数据的密钥,因此如果您使用 CVS,这将起作用。我在The LaTeX Companion中找到了这个,第 837 页。与您选择的 VCS 兼容的东西可能是同时编写的。

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.

韬韬不绝 2024-09-04 18:04:21

要提供像 \author 这样的 \version 命令,您需要这样做:

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

如果您没有使用 titlepage 环境,您可以重新定义 < code>\maketitle 本身。查看 article.cls(或您正在使用的任何类文件),复制并粘贴,然后在您想要的任何位置以任何方式插入 \theversion。如果您想在放入标题之前检查版本号,请执行以下操作:

\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

如果标题本身不需要它,您可以将其作为脚注添加到日期(这两个属性都与新鲜度相关)因此将它们放在一起是有意义的。

\title{My article}
\version{v1.2}
\date{\today\thanks{\theversion}}

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}}
猫弦 2024-09-04 18:04:20

对于许多版本控制系统,签入和签出程序会将文档中的某些字符串扩展为版本控制系统拥有的有关系统的元数据,包括版本号。

如果你将这些字符串包含在 Tex 定义的正文中,那么你就可以在你的文档中使用它们。

如果不知道您使用的是哪个版本控制系统,很难说更多,但 CTAN 有 vc 包rcs.sty很好用,对于那些仍然使用非分布式甚至并发 VC 的人来说...

一旦你获得了字符串(哦,我看到你说手动输入就可以了),你就可以使用

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

If 来排版如果您确实希望作者位于两者之间,那么您就不能以通常的方式同时使用 \title 和 \author - 您应该将您的名字放在 \title 命令中的另一行。

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.

不必了 2024-09-04 18:04:20

如果您将文档控制在 git 存储库内,则可以使用 gitinfo 包 来实现。如果配置正确(包括向 git 系统添加 post-hook),您可以简单地使用 \gitVtag 来调用版本号(如 git 标签中所体现)或例如 \gitAbbrevHash< /code> 获取存储库当前提交的缩写哈希。

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.

人间☆小暴躁 2024-09-04 18:04:20

简单的手动方法:

  1. 创建一个名为(例如)version.tex的文件:

    \providecommand{\versionnumber}{3.0.1}

  2. 需要使用它的地方:

    \input{版本}
    \title{Title\\\normalsize Version \versionnumber}

这将为您在一个或多个项目中提供一个公共位置来手动更新版本。

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.

花间憩 2024-09-04 18:04:20

如果您需要仅在标题页中显示版本号,则只需

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

在发出命令 \maketitle 后使用它进行修改即可。

否则,如果您需要在整个文档中多次调用它,最好定义一个变量:

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

以便您使用 \Version{} 定义版本号并使用 \version 调用它

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.

春夜浅 2024-09-04 18:04:19

完成我想做的事情的最简单方法就是简单地使用:

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

\begin{document}
\maketitle

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
起风了 2024-09-04 18:04:19

我的回答对于原始线程来说可能太晚了,但是 Latex 有一个非常有趣的包,称为 vrsion(没有“e”),它是标准发行版的一部分。本质上,它对 .dvi 文件进行编号,即每次运行 Latex 时编号都会增加。

就我个人而言,我将此作为一个简单的解决方法,因为 Git 缺乏人性化的文档版本号。不太理想,但有时我有多个文档副本,这有助于避免一些混乱。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文