syntax highlighting of Julia code for pandoc conversion

621 views
Skip to first unread message

Douglas Bates

unread,
Jun 12, 2013, 5:22:32 PM6/12/13
to julia...@googlegroups.com
I'm on an Ubuntu system (13.04) where the version of pandoc,

$ pandoc --version
pandoc 1.10.1
Compiled with citeproc-hs 0.3.6, 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-2013 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.

does not support Julia yet.  I would try to specify the input file type as markdown_github except that markdown_github got left out of pandoc 1.10.1 

Has anyone achieved syntax highlighting with pandoc?  I tried specifying the language type as Matlab but that didn't do much except change the font color on numbers.

Lucas Wilcox

unread,
Jun 12, 2013, 6:07:05 PM6/12/13
to julia...@googlegroups.com
The latest version of pygments can highlight julia code and a pandoc
filter can be used to have pygments highlight source code. For example,
using the filter pygments.hs (from [1]) the following should work

cat file.md | pandoc -f markdown -t json \
| runhaskell ./pygments.hs \
| pandoc -S -f json -t html

where you need to specify the code in file.md to be of type julia, e.g,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.julia .numberLines}
function foo(bar)
bar
end
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[1] https://github.com/lcw/jocco/blob/master/docs/pygments.hs

Douglas Bates

unread,
Jun 13, 2013, 1:46:11 PM6/13/13
to julia...@googlegroups.com
Thanks for the suggestion - it is good to know that pygments now supports julia and jlcon (console output from a julia session) types.  Unfortunately I was using pandoc to create beamer slides and your pygments.hs plugin creates HTML output from each code section.  I fiddled around with things a bit but could not combine pygments, the json wrapper and the beamer output format successfully.

However, I just noticed that pandoc uses the highlighting-kate source-code highlighting Haskell library which supports Julia in recent versions.  I think what I need to do is to work out how to generate and install a new highlighting-kate package and then rebuild pandoc.  At least I hope so. 

Lucas Wilcox

unread,
Jun 14, 2013, 12:43:03 PM6/14/13
to julia...@googlegroups.com
On Thu, Jun 13, 2013 at 10:46:11AM -0700, Douglas Bates wrote:
> Thanks for the suggestion - it is good to know that pygments now supports
> julia and jlcon (console output from a julia session) types. Unfortunately
> I was using pandoc to create beamer slides and your pygments.hs plugin
> creates HTML output from each code section. I fiddled around with things a
> bit but could not combine pygments, the json wrapper and the beamer output
> format successfully.

Ah no problem. I gave it a shot too. I got it working in with LaTeX
output but when I have it create beamer slides it doesn't work (since
the frames include a Verbatim environment and are not marked as
fragile). I don't know how to tell pandoc to mark the frames with code
as fragile.

Douglas Bates

unread,
Jun 14, 2013, 2:46:20 PM6/14/13
to julia...@googlegroups.com
I installed cabal then used that to install the most recent versions of highlighting-kate and pandoc 
$ pandoc -v
pandoc 1.11.1
Compiled with citeproc-hs 0.3.8, texmath 0.6.1.5, highlighting-kate 0.5.3.9.
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, matlab, maxima, metafont, mips, modula2, modula3,
    monobasic, nasm, noweb, objectivec, objectivecpp, ocaml, octave, pascal,
    perl, php, pike, postscript, prolog, python, r, relaxngcompact, rhtml, 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/bates/.pandoc
Copyright (C) 2006-2013 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.

With those versions, Julia code blocks are highlighted.  The beamer source does have the frames marked as fragile.
Reply all
Reply to author
Forward
0 new messages