Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62aa994

Browse files
committed
* Added separate checks for matching braces.
* Added more LaTex cmds from the docs. * Blocked forward-slash warnings with delimiters-only option. * Put help message on shorter line to fit an 80 char screen.
1 parent b539d05 commit 62aa994

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

Tools/scripts/texcheck.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
python texcheck.py [-h] [-k keyword] foobar.tex
1515
1616
Options:
17-
-m Munge parenthesis and brackets. [0,n) would normally mismatch.
18-
-k keyword: Keyword is a valid LaTeX command. Do not include the backslash.
17+
-m Munge parenthesis and brackets. [0,n) would normally mismatch.
18+
-k keyword: Keyword is a valid LaTeX command. Do not include the backslash.
1919
-f: Forward-slash warnings suppressed.
2020
-d: Delimiter check only (useful for non-LaTeX files).
2121
-h: Help
@@ -52,6 +52,11 @@
5252
\refmodindex \seerfc \makeindex \makemodindex \renewcommand
5353
\indexname \appendix \protect \indexiv \mbox \textasciitilde
5454
\platform \seeurl \leftmargin \labelwidth \localmoduletable
55+
\LaTeX \copyright \memberline \backslash \pi \centerline
56+
\caption \vspace \textwidth \menuselection \textless
57+
\makevar \csimplemacro \menuselection \bfcode \sub \release
58+
\email \kwindex \refexmodindex \filenq \e \menuselection
59+
\exindex \linev \newsgroup \verbatim \setshortversion
5560
"""
5661

5762
def matchclose(c_lineno, c_symbol, openers, pairmap):
@@ -85,15 +90,17 @@ def checkit(source, opts, morecmds=[]):
8590
for cmd in morecmds:
8691
validcmds.add('\\' + cmd)
8792

88-
openers = [] # Stack of pending open delimiters
89-
9093
if '-m' in opts:
9194
pairmap = {']':'[(', ')':'(['} # Munged openers
9295
else:
9396
pairmap = {']':'[', ')':'('} # Normal opener for a given closer
9497
openpunct = sets.Set('([') # Set of valid openers
9598

9699
delimiters = re.compile(r'\\(begin|end){([_a-zA-Z]+)}|([()\[\]])')
100+
braces = re.compile(r'({)|(})')
101+
102+
openers = [] # Stack of pending open delimiters
103+
bracestack = [] # Stack of pending open braces
97104

98105
tablestart = re.compile(r'\\begin{(?:long)?table([iv]+)}')
99106
tableline = re.compile(r'\\line([iv]+){')
@@ -107,7 +114,7 @@ def checkit(source, opts, morecmds=[]):
107114
for lineno, line in izip(count(startline), islice(source, startline-1, None)):
108115
line = line.rstrip()
109116

110-
if '-f' not in opts and '/' in line:
117+
if '/' in line and '-f' not in opts and '-d' not in opts:
111118
# Warn whenever forward slashes encountered
112119
line = line.rstrip()
113120
print 'Warning, forward slash on line %d: %s' % (lineno, line)
@@ -123,7 +130,7 @@ def checkit(source, opts, morecmds=[]):
123130
if cmd not in validcmds:
124131
print r'Warning, unknown tex cmd on line %d: \%s' % (lineno, cmd)
125132

126-
# Check balancing of open/close markers (parens, brackets, etc)
133+
# Check balancing of open/close parenthesis and brackets
127134
for begend, name, punct in delimiters.findall(line):
128135
if '-v' in opts:
129136
print lineno, '|', begend, name, punct,
@@ -138,6 +145,18 @@ def checkit(source, opts, morecmds=[]):
138145
if '-v' in opts:
139146
print ' --> ', openers
140147

148+
# Balance opening and closing braces
149+
for open, close in braces.findall(line):
150+
if open == '{':
151+
bracestack.append(lineno)
152+
if close == '}':
153+
try:
154+
bracestack.pop()
155+
except IndexError:
156+
print r'Warning, unmatched } on line %s.' % (lineno,)
157+
if '-v' in opts:
158+
print ' --> ', bracestack
159+
141160
# Check table levels (make sure lineii only inside tableii)
142161
m = tablestart.search(line)
143162
if m:
@@ -152,6 +171,8 @@ def checkit(source, opts, morecmds=[]):
152171
lastline = lineno
153172
for lineno, symbol in openers:
154173
print "Unmatched open delimiter '%s' on line %d" % (symbol, lineno)
174+
for lineno in bracestack:
175+
print "Unmatched { on line %d" % (lineno,)
155176
print 'Done checking %d lines.' % (lastline,)
156177
return 0
157178

0 commit comments

Comments
 (0)