繁体   English   中英

Pandoc语法高亮显示PDF无法正常工作

[英]Pandoc Syntax Highlighting in PDF not working

pandoc --version产量:

pandoc 1.12.2.1
Compiled with texmath 0.6.5.2, highlighting-kate 0.5.5.1.
Syntax highlighting is supported for the following languages:
    actionscript, ada, apache, asn1, asp, awk, bash, bibtex, boo, c, changelog, clojure, cmake, coffee, coldfusion, commonlisp, cpp, cs, css, curry, d, diff, djangotemplate, doxygen, doxygenlua, dtd, eiffel, email, erlang, fortran, fsharp, gnuassembler, go, haskell, haxe, html, ini, java, javadoc, javascript, json, jsp, julia, latex, lex, literatecurry, literatehaskell, lua, makefile, mandoc, markdown, matlab, maxima, metafont, mips, modelines, modula2, modula3, monobasic, nasm, noweb, objectivec, objectivecpp, ocaml, octave, pascal, perl, php, pike, postscript, prolog, python, r, relaxngcompact, rhtml, roff, ruby, rust, scala, scheme, sci, sed, sgml, sql, sqlmysql, sqlpostgresql, tcl, texinfo, verilog, vhdl, xml, xorg, xslt, xul, yacc, yaml
Default user data directory: /home/xiaolong/.pandoc
Copyright (C) 2006-2013 John MacFarlane
Web:  http://johnmacfarlane.net/pandoc
This is free software; see the source for copying conditions.  There is no
warranty, not even for merchantability or fitness for a particular purpose.

我正在尝试以下方法:

```python
Python 3.4.3 |Anaconda 2.3.0 (64-bit)| (default, Oct 19 2015, 21:52:17)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import random  # seed is determined here, if not set by the developer themself
>>> random.randint(0, 100)
50
>>> random.randint(0, 100)
62
>>> random.randint(0, 100)
53
>>> random.randint(0, 100)
17
>>> random.seed("I am a hashable object.")
>>> random.randint(0, 100)
41
>>> random.seed("I am a hashable object.")
>>> random.randint(0, 100)
41
>>> random.randint(0, 100)
88
>>> random.seed("I am a hashable object.")
>>> random.randint(0, 100)
41
>>> random.randint(0, 100)
88
````````````````````````````````````````````````````````````````````````````````

编译我使用的PDF的命令是:

pandoc --read=markdown --table-of-contents --toc-depth=2 --preserve-tabs --standalone --template=template.latex --latex-engine=xelatex Hausarbeit.md --highlight-style=pygments -o Hausarbeit.pdf

这是我在template.latex代码:

$if(highlighting-macros)$
$highlighting-macros$
$endif$
$if(verbatim-in-note)$
\usepackage{fancyvrb}
$endif$

根据Pandoc文档Pandoc文档,这应该导致Python语言的突出显示文本。 但是,该代码块中的所有内容仅变为等宽字体,并且不应用任何颜色。

更重要的是,编译时出错:

pandoc: Error producing PDF from TeX source.
! LaTeX Error: Environment Shaded undefined.

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

\GenericError  ...                                
                                                  \endgroup 
l.200 \begin{Shaded}

我的猜测是,模板中缺少定义Shaded 我甚至安装了一些软件包的highlighting-kate命名libghc-highlighting-kate-dev ,因为我读的地方,这是什么pandoc使用,但无济于事,文字保持黑色。

如何使语法高亮显示工作?

编辑#1

当我简单地缩进代码以使用代码的标准markdown语法时,没有出现该错误。 但在这种情况下,我本身不会有任何语法突出显示。

编辑#2

标签“PDF”,“Python”和“语法高亮”确实是相关的,因为这特别是关于创建PDF文件,特别是关于语法高亮。 也可能是在创建的PDF文件中突出显示python代码只有问题,因此python标签也是相关的。 请在结束太快之前阅读问题。

尝试在pandoc compile命令中添加--listings选项:

pandoc --read=markdown --table-of-contents --toc-depth=2 --preserve-tabs --standalone --template=template.latex --latex-engine=xelatex --listings Hausarbeit.md --highlight-style=pygments -o Hausarbeit.pdf

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM