9

Is there a package to produce syntax-colored blocks of source code in plain TeX ? A listings equivalent ? Or (maybe) some macro to produce a colored tex input for some given source code ? Is it possible to achieve something through LuaTeX ?

  • I suspect the easiest way might be to use Pygmentize and implement the macros it places in the parsed material to do the colouring: the parsing is tricky and is probably best done in something other than TeX! – Joseph Wright May 30 '16 at 17:02
  • minted perhaps? But I don't know actually – user31729 May 30 '16 at 17:03
  • @Joseph if there are few macros that would be good enough! – NoWhereMan May 30 '16 at 17:14
  • the highlight package ctan.org/pkg/highlight uses an external cpp program, supports many programming languages, custom "style sheets" and outputs both LaTeX and Plain TeX ! – NoWhereMan May 30 '16 at 18:43
  • There is Knuth's list.tex which creates a nicely formatted listing from any file, but no highlighting unfortunately. – Henri Menke May 30 '16 at 22:19
5

The syntax colored listings are solved by OPmac tricks 0124 (C syntax), 126 (html syntax) or 0152 (Python syntax). You can simply extend these macros for another language, if you need. Note that referred macros need not any special external processor. All is done in classical TeX.

  • that's pretty cool, although I feel that it might be pretty complicated (for a novice like me) to declare a new syntax def for another language (TBF most languages these days are C-like, though) – NoWhereMan Jun 13 '16 at 13:02
3

Knuth has developed the list.tex macros to produce code listings. To produce a listing of the file test.c with the content

#include <stdio.h>

int main()
{
  printf("Hello World!\n");
}

we input on the terminal

$ pdftex list.tex test.c <<< "\\bye"

and obtain the following output

enter image description here


Drawbacks:

  • No syntax highlighting
  • Overly long lines are not wrapped, but overflow the page
  • Tabs are converted to γ (for whatever reason)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.