def find_latex_line(lines, latex):
 re_string = re.compile(latex.replace('\\', '\\\\'))
 for (i, line) in enumerate(lines):
  if re_string.match(line):
   return i
 else:
  return None

def find_latex_line ( lines , latex ) : re_string = re . compile ( latex . replace ( '\\' , '\\\\' ) ) for ( i , line ) in enumerate ( lines ) : if re_string . match ( line ) : return i else : return None
find the first line which matches a patters parameters lines : list list of strings latex : str search pattern returns line_num : int .