| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ad5ae04 commit c4ac789
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -145,23 +145,25 @@ def build_html_page(classified_text, title='python', | |||
| 145 | 145 | ||
| 146 | 146 | #### LaTeX Output ########################################## | |
| 147 | 147 | ||
| 148 | - default_latex_colors = { | ||
| 149 | - 'comment': 'red', | ||
| 150 | - 'string': 'green', | ||
| 151 | - 'docstring': 'green', | ||
| 152 | - 'keyword': 'orange', | ||
| 153 | - 'builtin': 'purple', | ||
| 154 | - 'definition': 'orange', | ||
| 155 | - 'defname': 'blue', | ||
| 156 | - 'operator': 'brown', | ||
| 148 | + default_latex_commands = { | ||
| 149 | + 'comment': '{\color{red}#1}', | ||
| 150 | + 'string': '{\color{ForestGreen}#1}', | ||
| 151 | + 'docstring': '{\emph{\color{ForestGreen}#1}}', | ||
| 152 | + 'keyword': '{\color{orange}#1}', | ||
| 153 | + 'builtin': '{\color{purple}#1}', | ||
| 154 | + 'definition': '{\color{orange}#1}', | ||
| 155 | + 'defname': '{\color{blue}#1}', | ||
| 156 | + 'operator': '{\color{brown}#1}', | ||
| 157 | 157 | } | |
| 158 | 158 | ||
| 159 | 159 | default_latex_document = r''' | |
| 160 | 160 | \documentclass{article} | |
| 161 | 161 | \usepackage{alltt} | |
| 162 | + \usepackage{upquote} | ||
| 162 | 163 | \usepackage{color} | |
| 163 | 164 | \usepackage[usenames,dvipsnames]{xcolor} | |
| 164 | 165 | \usepackage[cm]{fullpage} | |
| 166 | + %(macros)s | ||
| 165 | 167 | \begin{document} | |
| 166 | 168 | \center{\LARGE{%(title)s}} | |
| 167 | 169 | \begin{alltt} | |
@@ -181,17 +183,18 @@ def latex_escape(s): | |||
| 181 | 183 | return re.sub(r'[\\#$%^&_{}~]', lambda mo: xlat[mo.group()], s) | |
| 182 | 184 | ||
| 183 | 185 | def latex_highlight(classified_text, title = 'python', | |
| 184 | - colors = default_latex_colors, | ||
| 186 | + commands = default_latex_commands, | ||
| 185 | 187 | document = default_latex_document): | |
| 186 | 188 | 'Create a complete LaTeX document with colorized source code' | |
| 189 | + macros = '\n'.join(r'\newcommand{\py%s}[1]{%s}' % c for c in commands.items()) | ||
| 187 | 190 | result = [] | |
| 188 | 191 | for kind, text in classified_text: | |
| 189 | 192 | if kind: | |
| 190 | - result.append(r'{\color{%s}' % colors[kind]) | ||
| 193 | + result.append(r'\py%s{' % kind) | ||
| 191 | 194 | result.append(latex_escape(text)) | |
| 192 | 195 | if kind: | |
| 193 | 196 | result.append('}') | |
| 194 | - return default_latex_document % dict(title=title, body=''.join(result)) | ||
| 197 | + return default_latex_document % dict(title=title, macros=macros, body=''.join(result)) | ||
| 195 | 198 | ||
| 196 | 199 | ||
| 197 | 200 | if __name__ == '__main__': | |
| Back | FazBrowse Home | New Git URL |
0 commit comments