[英]pandoc doesn't text-wrap code blocks when converting to pdf
I'm using pandoc with xelatex engine to convert markdown to pdf. 我正在使用pandoc和xelatex引擎将markdown转换为pdf。 I'm running pandoc like this:
我正在运行像这样的pandoc:
pandoc -s 'backbone-fundamentals'.md -o 'backbone-fundamentals'.pdf \
--title-prefix 'Developing Backbone.js Applications' \
--normalize \
--smart \
--toc \
--latex-engine=`which xelatex`
If a code line is longer than the pdf document width it just gets cutoff. 如果代码行长于pdf文档宽度,它就会被截止。 Is there anyway to have pandoc text wrap long code lines?
反正有没有pandoc文本换长代码行?
If you have a recent installation of LaTeX that includes the fvextra package, then there is a simple solution, recently suggested by jannick0 . 如果您最近安装了包含fvextra软件包的LaTeX,那么jannick0最近提出了一个简单的解决方案。
Modify your YAML header options to include 修改您的YAML标题选项以包含
\usepackage{fvextra}
\begin{Highlighting}[breaklines,numbers=left]
and compile with xelatex. 并使用xelatex进行编译。
For instance, 例如,
---
header-includes:
- \usepackage{fvextra}
- \DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,commandchars=\\\{\}}
---
~~~~~{.java}
this is a very long long long long long long long long long long long long long line which is broken
~~~~~~
when compiled with 编译时
pandoc input.md --pdf-engine=xelatex -o output.pdf
If you had the .numberLines
option, ie, 如果你有
.numberLines
选项,即
---
header-includes:
- \usepackage{fvextra}
- \DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,commandchars=\\\{\}}
---
~~~~~{.java .numberLines}
this is a very long long long long long long long long long long long long long line which is broken
~~~~~~
then the same command would produce 那么同样的命令就会产生
Not having the text wrapped is (part of) the point of code blocks. 没有包装文本是代码块的(部分)。 As far as I know, the only way to wrap the code is manually.
据我所知,包装代码的唯一方法是手动。 For most languages, not exceeding a certain line length is considered good style anyway.
对于大多数语言来说,不超过一定的行长度无论如何都被认为是好的风格。
If your lines are length-limited but still too long for your LaTeX-generated pdf, consider reducing the font size for code blocks. 如果您的线条长度有限但对于LaTeX生成的pdf仍然太长,请考虑减小代码块的字体大小。 For this you need to change the LaTeX template used by pandoc.
为此,您需要更改pandoc使用的LaTeX模板。 A look at this answer to "How to set font size for all verbatims in Beamer presentation?"
看看这个答案 “如何设置Beamer演示中所有动词的字体大小?” should get you started.
应该让你开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.