【问题标题】:How to solve error with YAML, Preamble (LaTex) and Pandoc conversion如何使用 YAML、Preamble (LaTex) 和 Pandoc 转换解决错误
【发布时间】:2020-12-31 20:49:17
【问题描述】:

几周前我开始使用 markdown 和 pandoc。我特别喜欢markdown编辑器writemonkey v.3!我在将 .md 转换为 .pdf 时遇到了一个小问题,这是由文档中的第一行引起的。文档中的第一行(见下文)是您如何在 writemonkey 中为文档命名。

name: seminarium 1

---
author: my name
date: 22 Augusti 2020
bibliography: testlibrary.bib
geometry: 
- top=2.5cm
- bottom=2.5cm
- left=2.5cm
- right=2.5cm
pagesize: a4
font: Times New Roman
fontsize: 12pt
header-includes:
   - \usepackage{setspace}
   - \setstretch{1.0}
   - \pagenumbering{gobble}

---

如果我删除第一行,pandoc 转换就像一个魅力。否则我会得到这个:

pandoc  sem1.md -o sem1.pdf --bibliography library.bib -V lang=sv                 
Error producing PDF.
! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.78 \usepackage

现在 - 我意识到我已经将 YAML 与 LaTex 代码结合在一起,我希望我的格式“不好”并且我可能会改进它,这样我就不必每次都删除第一行。也许告诉 Pandoc/LaTex 忽略第一行或制作一个单独的 .yaml 文件会有所帮助?

【问题讨论】:

  • 我猜你可以使用像sedawk 之类的命令行工具(无论Windows 等价物是什么)在将第一行传递给pandoc 之前剥离第一行...或者试试我的@ 987654321@ ;-)
  • 谢谢!你能指定如何剥离命令行中的第一行(顺便说一句,Windows 中的命令提示符或 powershell)?

标签: latex markdown pandoc


【解决方案1】:

好的!这就是我所做的。与 Writemonkey 配合使用效果很好。只需在记事本中复制粘贴并保存为 .ps1 文件并在 Powershell 中运行!

CD C:\Users\username\Desktop\ppp2020 # Filepath of .md, .yaml and .bib

Get-Content cap.md -Encoding UTF8 | Select-Object -Skip 2 | Set-Content cap_temp.md -Encoding UTF8 # Removes the first line (name:) from markdown document

pandoc  cap_temp.md default.yaml  -o cap.pdf --bibliography library.bib -V lang=sv # converts .md to .pdf 

Remove-Item 'C:\Users\username\Desktop\ppp2020\cap_temp.md' # This removes the tempfile

【讨论】:

    猜你喜欢
    • 2022-08-14
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-13
    相关资源
    最近更新 更多