PDF中的Pandoc语法高亮不起作用 [英] Pandoc Syntax Highlighting in PDF not working

查看:125
本文介绍了PDF中的Pandoc语法高亮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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的命令是:

The command to compile my PDF I use is:

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语言.但是,该代码块中的所有内容都只会变成等宽字体,并且不会应用任何颜色.

According to the Pandoc documentation Pandoc documentation this should result in highlighted text for the Python language. However, everything in that code block only becomes monospace and no colors are applied.

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

What's more is, that there is an error when compiling:

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的内容.我什至安装了名为libghc-highlighting-kate-devhighlighting-kate软件包,因为我在某处读到,这就是pandoc所使用的,但无济于事,文本保持黑色.

My guess is, that there is something missing in the template to define Shaded. I even installed some package of highlighting-kate named libghc-highlighting-kate-dev, because I read somewhere, that this is what pandoc uses, but to no avail, the text stays black.

如何使语法突出显示起作用?

How do I get the syntax highlighting working?

EDIT#1

当我只是缩进代码以对代码使用标准markdown语法时,没有出现该错误.但是在那种情况下,我本身就不会有任何语法高亮显示.

That error did not appear, when I simply indented the code to use standard markdown syntax for code. But in that case I'll not have any syntax highlighting per se.

EDIT#2

标签"PDF","Python"和语法高亮"的确相关,因为这专门与创建PDF文件有关,并且与语法高亮有关.也可能是在创建的PDF文件中突出显示python代码仅存在问题,因此python标记也与此相关.在结束之前,请先阅读问题.

The tags "PDF", "Python" and "syntax-highlighting" are indeed related, since this is specifically about creating a PDF file and specifically about syntax highlighting. Also it could be that there is only a problem with highlighting python code in the created PDF files, so the python tag is also related. Please read the question before concluding too quickly.

推荐答案

尝试将--listings选项添加到您的pandoc编译命令中:

Try to add --listings option to your pandoc compile command:

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

这篇关于PDF中的Pandoc语法高亮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆