@@ -79,7 +79,7 @@ def main():
79
79
action = ArgParserWarnAction , dest = 'nowarns' , default = set (['underfull' ]),
80
80
help = 'Enable/disable warning from CLASS, which can be any package name, '
81
81
'LaTeX warning class (e.g., font), bad box type '
82
- '(underfull, overfull, loose, tight), or "all"' )
82
+ '(underfull, overfull, loose, tight), strict parsing (strict-parse), or "all"' )
83
83
arg_parser .add_argument (
84
84
'-O' , metavar = 'DIR' , dest = 'obj_dir' , default = 'latex.out' ,
85
85
help = 'Directory for intermediate files and control database '
@@ -230,14 +230,17 @@ def mkdir_p(path):
230
230
pass
231
231
else : raise
232
232
233
- def nested_parenthesis_end (string , opening , closing ):
233
+ def nested_parenthesis_end (string , opening , closing , lax_checking = False ):
234
234
"""Return index where closing character corresponds to opening character"""
235
235
stack = []
236
236
for i , c in enumerate (string ):
237
- if c == opening :
238
- stack .append (i )
239
- elif c == closing and stack :
240
- start = stack .pop ()
237
+ if c in opening :
238
+ stack .append (c )
239
+ elif c in closing and stack :
240
+ start_ch = stack .pop ()
241
+ if not lax_checking and opening .index (start_ch ) != closing .index (c ):
242
+ # Mismatch, e.g. expected ')', found '}'
243
+ return - 1
241
244
if not stack :
242
245
return i
243
246
return - 1
@@ -1288,7 +1291,11 @@ class LaTeXFilter:
1288
1291
elif ch == '{' :
1289
1292
# TeX uses this for various things we want to ignore, like
1290
1293
# file names and print_mark. Consume up to the '}'
1291
- epos = nested_parenthesis_end (self .__data [self .__pos - 1 :], '{' , '}' )
1294
+ lax_checking = False
1295
+ if "strict-parse" in self .__suppress :
1296
+ lax_checking = not self .__suppress ["strict-parse" ]
1297
+ epos = nested_parenthesis_end (self .__data [self .__pos - 1 :], '{[(' , '}])' ,
1298
+ lax_checking = lax_checking )
1292
1299
if epos == - 1 :
1293
1300
self .__message ('warning' , None ,
1294
1301
"unbalanced `{' in log; file names may be wrong" )
0 commit comments