【发布时间】:2020-06-28 04:18:58
【问题描述】:
我一直在玩 Pandoc。
有没有在生成的目录之前插入页面?
例如:
- 标题页
- 插入自定义页面 001
- 插入自定义页面 002
- (生成的)目录
非常感谢!
【问题讨论】:
-
为什么@mb21 的评论有赞?没有细节就没什么用了。
标签: markdown epub pandoc tableofcontents
我一直在玩 Pandoc。
有没有在生成的目录之前插入页面?
例如:
非常感谢!
【问题讨论】:
标签: markdown epub pandoc tableofcontents
我猜你想创建一个带有标题页或标题信息的 HTML 文件。解决方案是通过不止一个步骤来完成。
首先将标题页与任何其他页面一起编译为一个 html。
$ pandoc .\01_HEADER.markdown -o header.html
然后在正文之前包含该 header.html:
$ pandoc -s -S --toc -B .\header.html .\02_Document.markdown -o complete_doc.html
完成。
pandoc 帮助说明了使多部分文档成为可能的可能性,-B 和 -H 都可以工作,但我认为 -B 在我的情况下更正确。
-H FILENAME --include-in-header=FILENAME
-B FILENAME --include-before-body=FILENAME
-A FILENAME --include-after-body=FILENAME
在我的例子中,我使用样式表并得到一个完美的文档:
$ pandoc -s -S -c .\res\github-pandoc.css .\01_HEADER.markdown -o header.html
$ pandoc -s -S --toc --toc-depth=2 -c .\res\github-pandoc.css -B .\header.html .\02_Document.markdown -o complete_document.html
【讨论】:
-S 是什么意思?在 pandoc 文档中找不到它。
对于这个答案,我将假设您正在生成降价,尽管该过程对于其他文件格式也是相同的。
关键的见解是 Pandoc 使用模板来确定最终位置。它有默认模板,如果你修改它们,你可以改变部分的顺序。
找到默认模板
> pandoc -D markdown
$if(titleblock)$
$titleblock$
$endif$
$for(header-includes)$
$header-includes$
$endfor$
$for(include-before)$
$include-before$
$endfor$
$if(toc)$
$toc$
$endif$
$body$
$for(include-after)$
$include-after$
$endfor$
下一步您将不需要这个,但如果您对这些文件的位置感到好奇,可以询问无意义的文件类型(尽管我确信有更好的方法):
> pandoc -D nonsense
pandoc: Could not find data file /usr/local/.../templates/default.nonsense
复制并修改默认模板
> pandoc -D markdown > modified.markdown
使用您喜欢的文本编辑器,您可以打开 modified.markdown 将$body$ 放在$toc$ 之前。
$body$
$if(toc)$
$toc$
$endif$
使用修改后的模板
> pandoc --template modified.markdown <... rest of your command ...>
【讨论】:
使用你可以在pandoc --print-default-template=markdown的输出中观察到的include-before标签
---
title: My Way
toc: true
include-before: |
See these lines
Come __before__ the [toc](/dev/null)
---
# I've lived a life that's full
# I traveled each and every highway
# But more, much more than this
# I did it my way
【讨论】:
toc: true 添加到 YAML 部分,而不是添加 --toc 参数。对于多行(和多段)文本,使用include-before: |,并在后面添加一组相同缩进的行。
这些解决方案都不适合我,一个顶级评论建议使用 Pandoc 模板,但没有详细信息。所以这里有一个简单的修复方法。
从这里下载默认的 Pandoc 模板:https://github.com/jgm/pandoc-templates,例如我使用了default.tex,但将其重命名为template.tex。
修改模板以插入更多内容、创建新页面等,例如:
\input{title.tex}
\newpage
\input{acknowledgements.tex}
\newpage
$if(toc)$
$if(toc-title)$
\renewcommand*\contentsname{$toc-title$}
$endif$
\newpage
使用这个修改过的模板而不是默认模板,例如
pandoc --template=template.tex -o document.pdf document.tex`.
就是这样。
【讨论】: