gpt4 book ai didi

format - Pandoc:在自定义 latex 序言中使用变量

转载 作者:行者123 更新时间:2023-12-01 15:49:57 38 4
gpt4 key购买 nike

我有文件 test.md ,其中包含:

---
footertext: some text for the footer
headertext: this is in the header
---

here is the text body.

文件 format.tex 包含:
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L]{$headertext$}
\fancyfoot[L]{$footertext$}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\setlength{\headsep}{0.25in}

我运行命令:
pandoc -H format.tex test.md -o test.pdf

你可以看到我想做什么。我试图让文本“这是在标题中”显示在标题中,但它没有,它只显示字符串“headertext”(页脚同样的问题)。

我究竟做错了什么?

编辑:好的,我想我明白了。显然变量只在模板中可用,而不是在包含的开始或结束代码块中(就像我正在使用的那样),或者在 md 本身中。所以新的问题:为什么会这样?它不直观、不方便且文档记录不充分。

最佳答案

您可以轻松修改 pandoc 模板。访问默认模板

pandoc -D latex > new_template.latex

粘贴您的 format.tex 的内容在序言中。您应该使用 $if$如果您想将此模板用于多个文档,请在使用它之前检查变量是否存在:
\usepackage{fancyhdr}
\pagestyle{fancy}
$if(headertext)$\fancyhead[L]{$headertext$}$endif$
$if(footertext)$\fancyfoot[L]{$footertext$}$endif$
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\setlength{\headsep}{0.25in}

然后编译:
pandoc test.md -o test.pdf --template=new_template.latex

关于format - Pandoc:在自定义 latex 序言中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31764376/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com