簡體   English   中英

Pandoc:在自定義乳膠序言中使用變量

[英]Pandoc: use variables in custom latex preamble

我有文件 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

你可以看到我想做什么。 我試圖讓文本“this is in the header”顯示在頁眉中,但它沒有,它只顯示字符串“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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM