diff options
author | Raymond Hettinger <python@rcn.com> | 2012-07-23 05:24:24 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2012-07-23 05:24:24 (GMT) |
commit | d3f63d36611653a9d37d35a1e8e8888deb457408 (patch) | |
tree | e8772565b0bbe6f10750eafe1f6f67c36127fbb7 /Tools | |
parent | 392bfd30af8cf87801c724d5964f4b5b088b025d (diff) | |
download | cpython-d3f63d36611653a9d37d35a1e8e8888deb457408.zip cpython-d3f63d36611653a9d37d35a1e8e8888deb457408.tar.gz cpython-d3f63d36611653a9d37d35a1e8e8888deb457408.tar.bz2 |
Simplify the LaTeX section (only three escapes are needed for alltt)
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/scripts/highlight.py | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/Tools/scripts/highlight.py b/Tools/scripts/highlight.py index 005c0f4..aff5cae 100755 --- a/Tools/scripts/highlight.py +++ b/Tools/scripts/highlight.py @@ -57,7 +57,7 @@ def analyze_python(source): if kind: text, written = combine_range(lines, written, (srow, scol)) yield '', text - text, written = combine_range(lines, written, (erow, ecol)) + text, written = tok_str, (erow, ecol) yield kind, text line_upto_token, written = combine_range(lines, written, (erow, ecol)) yield '', line_upto_token @@ -172,15 +172,10 @@ default_latex_document = r''' \end{document} ''' -def latex_escape(s): - 'Replace LaTeX special characters with their escaped equivalents' - # http://en.wikibooks.org/wiki/LaTeX/Basics#Special_Characters - xlat = { - '#': r'\#', '$': r'\$', '%': r'\%', '^': r'\textasciicircum{}', - '&': r'\&', '_': r'\_', '{': r'\{', '}': r'\}', '~': r'\~{}', - '\\': r'\textbackslash{}', - } - return re.sub(r'[\\#$%^&_{}~]', lambda mo: xlat[mo.group()], s) +def alltt_escape(s): + 'Replace backslash and braces with their escaped equivalents' + xlat = {'{': r'\{', '}': r'\}', '\\': r'\textbackslash{}'} + return re.sub(r'[\\{}]', lambda mo: xlat[mo.group()], s) def latex_highlight(classified_text, title = 'python', commands = default_latex_commands, @@ -191,7 +186,7 @@ def latex_highlight(classified_text, title = 'python', for kind, text in classified_text: if kind: result.append(r'\py%s{' % kind) - result.append(latex_escape(text)) + result.append(alltt_escape(text)) if kind: result.append('}') return default_latex_document % dict(title=title, macros=macros, body=''.join(result)) |