Checking TeX files for cite-errors
Today I had to TeX a longer file with numerous \cite[somestuff]{citekey}
sequences, of which some had hard-to-spot errors (some ‚]‘ were missing). The following Python script checks if each \cite
command has matching '[]'
and '{}'
sequences. I’ll probably extend this script to accept simple \cite{citekey}
sequences that have no optional parameter.
#!/usr/bin/python import re with open('filetocheck.tex') as f: content = f.readlines() index = 0 for a in content: index = index + 1 if "cite" in a: # check only lines that contain 'cite' matches = re.search(r'(.*)\[(.*)\]\{(.*)\}',a) # search for <sometext>[<sometext>]{<sometext>} if not matches: print (">>> Fail in row" , str(index), a) |