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 ?
2 Answers
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) Jun 13, 2016 at 13:02
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
Drawbacks:
- No syntax highlighting
- Overly long lines are not wrapped, but overflow the page
- Tabs are converted to γ (for whatever reason)
minted
perhaps? But I don't know actuallylist.tex
which creates a nicely formatted listing from any file, but no highlighting unfortunately.