Pandoc - 在生成的目录之前插入页面

时间:2014-08-31 11:28:19

标签: markdown epub pandoc tableofcontents

我一直在玩Pandoc。

无论如何在生成的目录之前插入页面?

例如:

  • 标题页
  • 插入自定义页面001
  • 插入自定义页面002
  • (生成)目录

非常感谢提前!

4 个答案:

答案 0 :(得分:6)

对于这个答案,我将假设您正在生成降价,尽管其他文件格式的过程也相同。

关键见解是Pandoc使用模板来确定最终展示位置。它有默认模板,如果你修改它们,你可以改变部分的顺序。

  1. 找到默认模板

    > 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
    
  2. 复制并修改默认模板

    > pandoc -D markdown > modified.markdown
    

    使用您喜欢的文字编辑器,您可以打开modified.markdown将$body$放在$toc$之前。

    $body$
    $if(toc)$
    $toc$
    $endif$
    
  3. 使用修改后的模板

    > pandoc --template modified.markdown <... rest of your command ...>
    

答案 1 :(得分:4)

我猜你想创建一个带有标题页或标题信息的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

答案 2 :(得分:3)

使用您可以在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

答案 3 :(得分:0)

这些解决方案都不适合我,建议使用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`.
    

就是这样。

相关问题