Luca Sepe

How to convert sourcecode to XHTML, RTF, LaTeX and SVG

SVG RTF LaTeX Slides

Short answer use Highlight!

http://www.andre-simon.de/doku/highlight/en/highlight.php

What is Highlight?

Highlight converts sourcecode to HTML, XHTML, RTF, ODT, LaTeX, TeX, SVG, BBCode, Pango markup and terminal escape sequences with coloured syntax highlighting.

Quick introduction

Generate HTML:

highlight -i main.go -o main.go.html

Generate HTML with embedded CSS definitions and line numbers:

highlight -i main.go -o main.go.html --include-style --line-numbers

Generate HTML with inline CSS definitions:

highlight -i main.go -o main.go.html --inline-css

Generate SVG, customize fonts and theme:

highlight --out-format=svg --font-size 12 --font 'Fira Code' \
          --style=fine_blue -i main.go -o main.svg

Listing all themes available on your system:

ls /usr/share/highlight/themes

Here are some of my favorites:

theme sample
‐‐style=fine_blue
‐‐style=seashell
‐‐style=print
‐‐style=molokai
‐‐style=peaksea
‐‐style=freya
‐‐style=github
‐‐style=darkbone
‐‐style=acid

How to install Highlight

Dependencies

In order to compile highlight, you need to install:

  • Lua (5.x or LuaJIT as devel package)
  • Boost (at least the header files)
  • the optional GUI requires Qt5 and its development tools (qmake)

Installing Lua

On Debian:

sudo apt-get install lua5.3-dev

Installing Boost

On Debian:

sudo apt-get install libboost-all-dev

Installing Highlight

Clone the git repository

git clone https://gitlab.com/saalen/highlight.git

Build and install Highlight

cd highlight/
make cli
sudo make install
  • make cli compile static library and the CLI interface
  • make lib-static (optional, compile static library only)
  • make lib-shared (optional, compile shared library only)
  • make gui (optional, compile static library and the Qt GUI)