最后修改的 LaTeX 命令

发布于 2024-08-18 10:32:30 字数 85 浏览 2 评论 0原文

是否有一个 LaTeX 命令可以打印实际文档的“最后修改”日期?由于 LaTeX 项目由多个文件组成,因此该命令理想地打印实际文件的日期,而不是项目的日期。

Is there a LaTeX command that prints the "last modified" date of the actual document? Since LaTeX projects consist of more than one file this command ideally prints the date of the actual file, not that of the project.

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

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

发布评论

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

评论(6

爱的十字路口 2024-08-25 10:32:30

pdfTeX 提供了原语 \pdffilemoddate 来查询文件的此信息。 (LuaTeX 使用自己的 Lua 函数来完成同样的事情。)由于 pdfTeX 在过去几年(至少)的所有 LaTeX 发行版中默认使用,所以使用新功能没有什么坏处,除非您正在处理非常旧的产品系统。下面是一个示例:(

\documentclass{article}
\begin{document}
\def\parsedate #1:20#2#3#4#5#6#7#8\empty{20#2#3/#4#5/#6#7}
\def\moddate#1{\expandafter\parsedate\pdffilemoddate{#1}\empty}
this is the moddate: \moddate{\jobname.tex}
\end{document}

假设该文件自 2000 年以来已被修改。)

pdfTeX provides the primitive \pdffilemoddate to query this information for files. (LuaTeX uses its own Lua functions for the same thing.) Since pdfTeX is used by default in all LaTeX distributions in the last few years (at least), there's no harm in using the new functionality unless you're dealing with very old production systems. Here's an example:

\documentclass{article}
\begin{document}
\def\parsedate #1:20#2#3#4#5#6#7#8\empty{20#2#3/#4#5/#6#7}
\def\moddate#1{\expandafter\parsedate\pdffilemoddate{#1}\empty}
this is the moddate: \moddate{\jobname.tex}
\end{document}

(Assuming the file has been modified since year 2000.)

2024-08-25 10:32:30

filemod 似乎完全满足您的需要。要获取文件的最后修改日期,您只需以通常的方式包含该包即可:

\usepackage{filemod}

并打印当前文档的修改时间:

\filemodprintdate{\jobname}

您还可以打印修改时间,并且有很多选项可以格式化输出。

The package filemod seems to do exactly what you need. To get the last modified date of the file you just include the package in the usual way:

\usepackage{filemod}

and the modification time of the current document is printed by:

\filemodprintdate{\jobname}

you can also print the modification time, and there are many options to format the output.

少女的英雄梦 2024-08-25 10:32:30

不幸的是,TeX 不提供此类信息的命令;获取此类信息的唯一方法是

  1. 在运行 LaTeX 之前运行非 TeX 脚本来创建 TeX 文件,并以某种方式将该文件包含在主 LaTeX 文档中,或者
  2. 运行外部脚本来自 TeX(只有在启用了所谓的 write18 或 shellescape 功能时才有效;为此,您必须查阅 TeX 实现手册,并且不能有顽固的系统管理员)。

扩展 TeX 可能确实支持文件信息命令(也许是 luaTeX?),但它不是 TeX 本身的一部分。

Unfortunately, TeX does not provide commands for such information; the only way to get such information is

  1. by running a non-TeX script to create a TeX file before running LaTeX and including this file in your main LaTeX document somehow, or
  2. by running the external script from TeX (which only works if the so-called write18 or shellescape feature is enabled; you'd have to consult the manual of your TeX implementation for this, and not have a stubborn sysadmin).

It is possible that extended TeXs do support file info commands (luaTeX perhaps?), but it's not part of TeX proper.

混吃等死 2024-08-25 10:32:30

如果您使用自动构建系统,您可以要求它生成一个依赖于所有源文件的文件(可能名为 today.sty)。

在 make 中可能看起来像:

today.sty: $LATEX_SRCS
        echo "\date{" > $@
        date +D >> $@
        echo "}" >> $@

\usepackage{today.sty}

将使用文件更改后第一次构建的日期,并且在您删除today.sty或更改另一个源文件之前不会更新。

If you are using an automated build system, you could ask it to generate a file (perhaps named today.sty) which depends on all the source files.

In make that might look like:

today.sty: $LATEX_SRCS
        echo "\date{" > $@
        date +D >> $@
        echo "}" >> $@

and \usepackage{today.sty}.

The will use the date of the first build after a file changes, and won't update until either you delete today.sty or alter another source file.

救赎№ 2024-08-25 10:32:30

感谢 dmckee

LATEX_SRCS = test.tex

define moddate
date +%Y%m%d%H%M%S
endef

today.sty: $(LATEX_SRCS)
    @echo "\def\moddate{"$(shell $(moddate))"}"> $@

thank dmckee

LATEX_SRCS = test.tex

define moddate
date +%Y%m%d%H%M%S
endef

today.sty: $(LATEX_SRCS)
    @echo "\def\moddate{"$(shell $(moddate))"}"> $@
如歌彻婉言 2024-08-25 10:32:30

getfiledate LaTeX 包(它是我的一部分)默认情况下 LaTeX 分发)。它似乎被设计为自动输出一个段落,例如:

The date of last modification of file misc-test1.tex was 2009-10-11  21:45:50.

具有调整输出的能力。您绝对可以获得日期。但是,我不知道如何摆脱日期周围的换行符以及如何更改日期格式。老实说,我认为作者正是为了他们需要的单一目的而实现了它,并且对于一般用途来说相当麻烦。

There is the getfiledate LaTeX package (it was part of my LaTeX distribution by default). It seems to be designed to automatically output a paragraph like:

The date of last modification of file misc-test1.tex was 2009-10-11  21:45:50.

with a bit of ability to tweak the output. You can definitely get just the date. However, I couldn't figure out how to get rid of newlines around the date and how to change the date format. To be honest I think the authors implemented it exactly for the single purpose they needed it, and it is rather cumbersome for general use.

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