3 # Copyright: Raphael 'kena' Poss <r.c.poss@uva.nl>
4 # this file is placed in the public domain.
6 # Convert a CSS stylesheet into one for Docutils' LaTeX output.
10 # pygmentize -S default -f html | pygments_css2sty.py >pygments-default.sty
14 # 2012-05-09: Günter Milde <milde@users.sf.net>:
15 # Bugfix: do not fail at lines without comment.
16 # Support for digits in role names.
17 # ``\providecommand`` instead of ``\newcommand``.
18 # Renamed from makesty.py to pygments_css2sty.py.
23 print '% Stylesheet for syntax highlight with Docutils'
24 print '% Generated by pygments_css2sty.py from a Pygments CSS style'
25 print '% (output of `pygmentize -S <style> -f html`).'
27 print r
'\RequirePackage{color}'
33 print "% " + l
.split('*')[1]
34 key
= l
.split(' ', 1)[0][1:]
39 col
= l
.split('#',1)[1][:6]
40 r
= float(int(col
[0:2], 16)) / 255.
41 g
= float(int(col
[2:4], 16)) / 255.
42 b
= float(int(col
[4:6], 16)) / 255.
43 s
= r
'\textcolor[rgb]{%.2f,%.2f,%.2f}{%s}' % (r
, g
, b
, s
)
45 if 'font-style: italic' in l
:
46 s
= r
'\textit{%s}' % s
47 if 'font-weight: bold' in l
:
48 s
= r
'\textbf{%s}' % s
51 col
= l
.split('#',1)[1][:6]
52 r
= float(int(col
[0:2], 16)) / 255.
53 g
= float(int(col
[2:4], 16)) / 255.
54 b
= float(int(col
[4:6], 16)) / 255.
55 cname
= 'DUcolor%d' % cnt
57 print r
'\definecolor{%s}{rgb}{%.2f,%.2f,%.2f}' % (cname
, r
, g
, b
)
58 s
= r
'\colorbox{%s}{%s}' % (cname
, s
)
60 if re
.match(r
'.*[0-9]', key
) is None:
61 print r
'\providecommand*\DUrole%s[1]{%s}' % (key
, s
)
63 print r
'\providecommand\csname DUrole%s\endcsname[1]{%s}' % (key
, s
)