I would like to find out what options there are for applying syntax highlighting to Plain TeX, to turn Plain TeX documents into highlighted HTML.

The aim is to facilitate sharing tracked changes to the Plain TeX document. The document I wish to work with is fairly simple, but it does hand define several fonts, a bibliography environment, and make heavy use of \halign macros. Some automatic or semi-automatic handling of these would be an advantage. At a pinch I could do this with a sed script, but I would rather save myself some time.

Pygments does not seem to have support for Plain TeX. Emacs' AUCTeX has TeX-mode for Plain TeX, but although I seem to recall that it is possible to export HTML from AUCTeX, I cannot recall any details.

  • 2
    I'd try to look at ConTeXt's verbatim-like features (with syntax highlighting) together with xml export. (I am by no means a ConTeXt expert, but I wouldn't be surprised if such a solution worked (maybe almost) out-of-the-box.)
    – mbork
    Feb 26, 2012 at 15:04
  • You should be able to use the listings package to highlight plain TeX. Feb 26, 2012 at 17:07
  • @Peter: It's not obvious to me that listings will help me get HTML output. Feb 26, 2012 at 17:38
  • @mbork: Your thinking of t-vim (cf. Code highlighting in ConTeXt), I take it? That might work; I'll look into it. I guess I should upgrade my version of Context. Feb 26, 2012 at 17:42
  • 3
    I have an idea. If I'm not mistaken, Vim can highlight both plain TeX and LaTeX. Open your file with Vim, make sure the plain TeX syntax is selected, then use this magic trick: :TOhtml . The color scheme together with your file will be exported to a html file right in your Vim buffer. :) Feb 26, 2012 at 17:49

2 Answers 2


Converting my comment to an answer. :)

There is a plugin shipped with recent versions of Vim called 2html.vim. The idea is to export the current buffer - including the color scheme - to HTML. For example, I'll use Herbert's code from How to get started with plain TeX:

% gettingstarted.tex
\input pstricks



To use this plugin, put Vim in the normal mode and type:



A new file named yourcode.ext.html is generated. The output is as follows:


If I'm not mistaken, the choice of colors is related to the editor color scheme.

The generated HTML is full of inline styles. If you want a better output, I found the following entries to be added to your _vimrc file:

let html_use_css = 1 " Replaces the inline styles by CSS stylesheets. Values: 0 or 1
let html_number_lines = 0 " Shows line numbers. Values: 0 or 1
let html_no_pre = 1 " Don't wrap lines. Values: 0 or 1

Hope it helps. :)

  • I must have a really old version of 2html.vim - the HTML I get gives a completely different header. But the output is useful and most definitely helps, so accepted. I've written a small script to turn the font/color tag/attributes into span/class, which is far easier than writing a highlighter from scratch. I'll post the code if there is any interest. Feb 27, 2012 at 20:28
  • @Charles: TOHtml has an option to use CSS instead of raw font attributes. See :he TOHtml for details.
    – Aditya
    Dec 8, 2012 at 12:27
  • Actually Paulo aleady mentions it. Use let html_use_css =1.
    – Aditya
    Dec 8, 2012 at 12:29

You can do the same thing with emacs. Load the code into emacs and do M-x ps-print-buffer-with-faces. It will print a postscript image of the buffer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .