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.
19 # 2013-03-27: Günter Milde:
20 # Implement bugfix from Juan Luis Cano Rodríguez for csnames.
25 print '% Stylesheet for syntax highlight with Docutils'
26 print '% Generated by pygments_css2sty.py from a Pygments CSS style'
27 print '% (output of `pygmentize -S <style> -f html`).'
29 print r
'\RequirePackage{color}'
35 print "% " + l
.split('*')[1]
36 key
= l
.split(' ', 1)[0][1:]
41 col
= l
.split('#',1)[1][:6]
42 r
= float(int(col
[0:2], 16)) / 255.
43 g
= float(int(col
[2:4], 16)) / 255.
44 b
= float(int(col
[4:6], 16)) / 255.
45 s
= r
'\textcolor[rgb]{%.2f,%.2f,%.2f}{%s}' % (r
, g
, b
, s
)
47 if 'font-style: italic' in l
:
48 s
= r
'\textit{%s}' % s
49 if 'font-weight: bold' in l
:
50 s
= r
'\textbf{%s}' % s
53 col
= l
.split('#',1)[1][:6]
54 r
= float(int(col
[0:2], 16)) / 255.
55 g
= float(int(col
[2:4], 16)) / 255.
56 b
= float(int(col
[4:6], 16)) / 255.
57 cname
= 'DUcolor%d' % cnt
59 print r
'\definecolor{%s}{rgb}{%.2f,%.2f,%.2f}' % (cname
, r
, g
, b
)
60 s
= r
'\colorbox{%s}{%s}' % (cname
, s
)
62 if re
.match(r
'.*[0-9]', key
) is None:
63 print(r
'\providecommand*\DUrole%s[1]{%s}' % (key
, s
))
65 print(r
'\expandafter\providecommand\csname DUrole%s\endcsname[1]{%s}'