最后修改的 LaTeX 命令
是否有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
pdfTeX 提供了原语
\pdffilemoddate
来查询文件的此信息。 (LuaTeX 使用自己的 Lua 函数来完成同样的事情。)由于 pdfTeX 在过去几年(至少)的所有 LaTeX 发行版中默认使用,所以使用新功能没有什么坏处,除非您正在处理非常旧的产品系统。下面是一个示例:(假设该文件自 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:(Assuming the file has been modified since year 2000.)
包 filemod 似乎完全满足您的需要。要获取文件的最后修改日期,您只需以通常的方式包含该包即可:
并打印当前文档的修改时间:
您还可以打印修改时间,并且有很多选项可以格式化输出。
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:
and the modification time of the current document is printed by:
you can also print the modification time, and there are many options to format the output.
不幸的是,TeX 不提供此类信息的命令;获取此类信息的唯一方法是
扩展 TeX 可能确实支持文件信息命令(也许是 luaTeX?),但它不是 TeX 本身的一部分。
Unfortunately, TeX does not provide commands for such information; the only way to get such information is
It is possible that extended TeXs do support file info commands (luaTeX perhaps?), but it's not part of TeX proper.
如果您使用自动构建系统,您可以要求它生成一个依赖于所有源文件的文件(可能名为
today.sty
)。在 make 中可能看起来像:
和
\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:
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.感谢 dmckee
thank dmckee
有 getfiledate LaTeX 包(它是我的一部分)默认情况下 LaTeX 分发)。它似乎被设计为自动输出一个段落,例如:
具有调整输出的能力。您绝对可以获得日期。但是,我不知道如何摆脱日期周围的换行符以及如何更改日期格式。老实说,我认为作者正是为了他们需要的单一目的而实现了它,并且对于一般用途来说相当麻烦。
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:
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.