Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
60e96bff
Commit
60e96bff
authored
Jul 23, 2012
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify the LaTeX section (only three escapes are needed for alltt)
parent
930181c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
11 deletions
+6
-11
Tools/scripts/highlight.py
Tools/scripts/highlight.py
+6
-11
No files found.
Tools/scripts/highlight.py
View file @
60e96bff
...
...
@@ -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'''
\
e
nd{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))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment