代码语法显示

65 views
Skip to first unread message

Larry Cai

unread,
Feb 24, 2013, 9:04:08 PM2/24/13
to chaos....@gmail.com, kaiyu...@googlegroups.com, Bernard Xiong, li ming
建议大家加入 kaiyu...@googlegroups.com (我以前为电子书建的讨论组),当然也可以新建 mk...@googlegroups.com


问题:如何语法高亮显示代码
方案:@grissiom 提供的方式还是可以工作的不错的。
用pandoc的markdown扩展,(github能简单兼容)生成latex的 Verbatim宏, 定义latex中Shaded的显示模式

== markdown
~~~~~ {.bash}    
$ sudo apt-get install ruby1.9.1
$ sudo apt-get install pandoc
$ sudo apt-get install texlive-xetex
$ sudo apt-get install texlive-latex-recommended # 主要的Latex包
$ sudo apt-get install texlive-latex-extra # titlesec包,先不用知道
~~~~~~~~~~~~~~~  

有pandoc (ubuntu 12.04/ubuntu 12.10的缺省安装即可)转换成

== latex
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{$ }\KeywordTok{sudo} \NormalTok{apt-get }\KeywordTok{install} \NormalTok{ruby1.9.1}
\NormalTok{$ }\KeywordTok{sudo} \NormalTok{apt-get }\KeywordTok{install} \NormalTok{pandoc}
\NormalTok{$ }\KeywordTok{sudo} \NormalTok{apt-get }\KeywordTok{install} \NormalTok{texlive-xetex}
\NormalTok{$ }\KeywordTok{sudo} \NormalTok{apt-get }\KeywordTok{install} \NormalTok{texlive-latex-recommended }\CommentTok{# 主要的Latex包}
\NormalTok{$ }\KeywordTok{sudo} \NormalTok{apt-get }\KeywordTok{install} \NormalTok{texlive-latex-extra }\CommentTok{# titlesec包,先不用知道}
\end{Highlighting}
\end{Shaded}

== pdf
Inline image 1
这个latex看得复杂点,不如pygments来的流畅,但运转的不错。

大家觉得怎么样呢?

@grissiom : 有办法给代码块加个简单背影块吗?上次我没搞出来。
Inline image 2

rgs/larry 


image.png
image.png

Bernard Xiong

unread,
Feb 25, 2013, 12:40:18 AM2/25/13
to kaiyu...@googlegroups.com, chaos....@gmail.com, li ming
已经加入论坛, 
代码有个背景框确实显示得好些,这个看看Grissiom有什么办法吧,我对latex不在行呐

另外一个就是图形,如果能够更方便的在电子书中插入图形就更好了。


在 2013年2月25日星期一UTC+8上午10时04分08秒,Larry Cai写道:

Larry Cai

unread,
Feb 25, 2013, 2:27:06 AM2/25/13
to kaiyu...@googlegroups.com, chaos....@gmail.com, li ming
图形没问题呀,只是不能随意控制大小,一般调整好之后放在里面。

rgs/larry

2013/2/25 Bernard Xiong <bernar...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "中文开源技术书" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kaiyuanbook...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
True software development embraces consistent inconsistency.
blog: http://larrycaiyu.com

Grissiom

unread,
Feb 26, 2013, 2:16:26 AM2/26/13
to Larry Cai, kaiyu...@googlegroups.com, Bernard Xiong, li ming
2013/2/25 Larry Cai <larry...@gmail.com>
建议大家加入 kaiyu...@googlegroups.com (我以前为电子书建的讨论组),当然也可以新建 mk...@googlegroups.com


也加入列表了~
这些 LaTeX 的代码虽然繁复,但是如果不出问题的话是不用去管的,对咱们来说是透明的,所以应该是无所谓的……
 
@grissiom : 有办法给代码块加个简单背影块吗?上次我没搞出来。
Inline image 2

rgs/larry 



嗯,我试试~ 其实自己没有用过 Shaded 环境……

项目地址是哪个来着?……

--
Cheers,
Grissiom
image.png
image.png

bernard

unread,
Feb 26, 2013, 2:51:01 AM2/26/13
to Grissiom, Larry Cai, kaiyu...@googlegroups.com, li ming
Grissiom,
可以直接在RT-Thread manual-doc上操作,然后提供出结果即可
image.png
image.png

Larry Cai

unread,
Feb 28, 2013, 8:29:14 PM2/28/13
to Grissiom, kaiyu...@googlegroups.com, Bernard Xiong, li ming
我们还是可以用Grissiom 的方式(直接用Pandoc的缺省方案)

~~~~~~~~~~ {.ruby}
。。。
~~~~~~~~~~~~

支持的语言可以查看pandoc
$  pandoc -v 
pandoc 1.9.4.2
Compiled with citeproc-hs 0.3.4, texmath 0.6.0.6, highlighting-kate 0.5.1.
Syntax highlighting is supported for the following languages:
    Actionscript, Ada, Alert, Alert_indent, Apache, Asn1, Asp, Awk, Bash,
    Bibtex, Boo, C, Changelog, Clojure, Cmake, Coffeescript, Coldfusion,
    Commonlisp, Cpp, Cs, Css, D, Diff, Djangotemplate, Doxygen, Dtd, Eiffel,
    Email, Erlang, Fortran, Fsharp, Gnuassembler, Go, Haskell, Haxe, Html, Ini,
    Java, Javadoc, Javascript, Json, Jsp, Latex, Lex, LiterateHaskell, Lua,
    Makefile, Mandoc, Matlab, Maxima, Metafont, Mips, Modula2, Modula3,
    Monobasic, Nasm, Noweb, Objectivec, Objectivecpp, Ocaml, Octave, Pascal,
    Perl, Php, Pike, Postscript, Prolog, Python, R, Relaxngcompact, Rhtml, Ruby,

    Scala, Scheme, Sci, Sed, Sgml, Sql, SqlMysql, SqlPostgresql, Tcl, Texinfo,
    Verilog, Vhdl, Xml, Xorg, Xslt, Xul, Yacc, Yaml
Copyright (C) 2006-2012 John MacFarlane
This is free software; see the source for copying conditions.  There is no
warranty, not even for merchantability or fitness for a particular purpose.

它实际上产生用的是fancyvrb这个Latex的宏,Verbatim http://ftp.math.purdue.edu/mirrors/ctan.org/macros/latex/contrib/fancyvrb/fancyvrb.pdf 

\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\},frame=leftline}

我加了个参数后,就是
Inline image 1
这样就不错了,还可以加行号等等。

它缺省不支持背景色,需要更多Latex的知识,我不研究了。http://tex.stackexchange.com/questions/39276/background-color-for-fancyvrb 

建议大家买本: http://www.amazon.cn/dp/B004H8GJLA LaTeX2e完全学习手册

我会写个博客。

rgs/larry

2013/2/26 Grissiom <chaos....@gmail.com>

--
True software development embraces consistent inconsistency.
image.png
image.png
image.png
Reply all
Reply to author
Forward
0 new messages