编译时Pandoc不显示YAML前置元数据中的日期

编程语言 2026-07-08

我正在使用Pandoc将我的Markdown(约4,000个单词)文件转换为PDF。我的问题是日期不会出现在PDF上。以下是我的系统信息:

pandoc 3.7.0.2
Features: -server +lua
Scripting engine: Lua 5.4

Operating System: Ubuntu 26.04 LTS                                    
          Kernel: Linux 7.0.0-22-generic

我的YAML前置元数据只有两个字段。并且我尝试了两种不同的日期格式:

---
date: June 14, 2026
linestretch: 1.5
---

和:

---
date: 2026-06-14
linestretch: 1.5
---

我甚至把linestretch参数去掉了,但仍然没有日期。我使用以下命令来编译:

pandoc j.md -o jtest.pdf

最后,我在命令行中设置日期,但没有成功:

pandoc j.md -s --variable date="June 14, 2026" -o jdate.pdf

但在一个小型的.md文件上,按预期工作。

解决方案

Run the following command to see which template Pandoc is using and verify it has the $date$ variable:

pandoc -D latex | grep date

You should see a line like: \date{$date$}

If it's missing, the date won't appear. If you see something like \date{} with nothing inside, your template has been customized and stripped the variable.

The most likely fix: use --metadata instead of --variable

Pandoc draws a distinction between metadata (parsed from YAML) and variables (for template substitution). The date field in your YAML front matter is metadata. If you're overriding it on the command line, you need to set it as metadata, not a variable:

pandoc j.md -s --metadata date="June 14, 2026" -o jdate.pdf

The --variable flag you used bypasses the metadata parser and may not be picked up correctly depending on how the template accesses it.

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章