Set double spacing and line numbers when converting from Markdown to PDF with pandoc

给你一囗甜甜゛ 提交于 2019-12-02 17:38:28

In more recent version of Pandoc, you can use a YAML header and include a bunch of metadata in that, instead of using options on the command line. So, for instance, you can put this at the top of your .md file:

---
title: The Document Title
author:
    - Your Name
    - Co Author
date: \today{}
geometry: margin=2cm
header-includes:
    - \usepackage{setspace}
    - \doublespacing
    - \usepackage{lineno}
    - \linenumbers
---

Document Text

and pandoc will read those options and apply them automatically.

There is maybe an easy way: generate a file with the packages we need

 \usepackage{setspace}
 \doublespacing
 \usepackage[vmargin=1in,hmargin=1in]{geometry}
 \usepackage{lineno}
 \linenumbers

I named it options.sty. And use the -H FILE option that includes the content of the FILE at the end of the preamble. (as used in https://github.com/karthikram/smb_git)

 pandoc -H options.sty --bibliography mypaper.bib mypaper.md -o mypaper.pdf 

The advantage is that we don't need to edit the template. To add linenumbers, change margins, and set spacing it works.

You'll need to use a custom LaTeX template. First, use pandoc to create a copy of the default template:

pandoc -D latex > mytemplate.latex

Now edit this template. Somewhere in the preamble (between \documentclass{...} and \begin{document}), insert the lines

\usepackage{setspace}
\doublespacing

Then, to use your custom template:

pandoc --template mytemplate.latex mypaper.txt -o mypaper.tex
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!