docs: def intelligently_find_filenames(line, TeX=False, ext=False,
                                   commas_okay=False):
      """Intelligently find filenames.
  
      Find the filename in the line.  We don't support all filenames!  Just eps
      and ps for now.
  
      :param: line (string): the line we want to get a filename out of
  
      :return: filename ([string, ...]): what is probably the name of the file(s)
      """
      files_included = ['ERROR']
  
      if commas_okay:
          valid_for_filename = '\\s*[A-Za-z0-9\\-\\=\\+/\\\\_\\.,%#]+'
      else:
          valid_for_filename = '\\s*[A-Za-z0-9\\-\\=\\+/\\\\_\\.%#]+'
  
      if ext:
          valid_for_filename += '\.e*ps[texfi2]*'
  
      if TeX:
          valid_for_filename += '[\.latex]*'
  
      file_inclusion = re.findall('=' + valid_for_filename + '[ ,]', line)
  
      if len(file_inclusion) > 0:
          # right now it looks like '=FILENAME,' or '=FILENAME '
          for file_included in file_inclusion:
              files_included.append(file_included[1:-1])
  
      file_inclusion = re.findall('(?:[ps]*file=|figure=)' +
                                  valid_for_filename + '[,\\]} ]*', line)
  
      if len(file_inclusion) > 0:
          # still has the =
          for file_included in file_inclusion:
              part_before_equals = file_included.split('=')[0]
              if len(part_before_equals) != file_included:
                  file_included = file_included[
                      len(part_before_equals) + 1:].strip()
              if file_included not in files_included:
                  files_included.append(file_included)
  
      file_inclusion = re.findall(
          '["\'{\\[]' + valid_for_filename + '[}\\],"\']',
          line)
  
      if len(file_inclusion) > 0:
          # right now it's got the {} or [] or "" or '' around it still
          for file_included in file_inclusion:
              file_included = file_included[1:-1]
              file_included = file_included.strip()
              if file_included not in files_included:
                  files_included.append(file_included)
  
      file_inclusion = re.findall('^' + valid_for_filename + '$', line)
  
      if len(file_inclusion) > 0:
          for file_included in file_inclusion:
              file_included = file_included.strip()
              if file_included not in files_included:
                  files_included.append(file_included)
  
      file_inclusion = re.findall('^' + valid_for_filename + '[,\\} $]', line)
  
      if len(file_inclusion) > 0:
          for file_included in file_inclusion:
              file_included = file_included.strip()
              if file_included not in files_included:
                  files_included.append(file_included)
  
      file_inclusion = re.findall('\\s*' + valid_for_filename + '\\s*$', line)
  
      if len(file_inclusion) > 0:
          for file_included in file_inclusion:
              file_included = file_included.strip()
              if file_included not in files_included:
                  files_included.append(file_included)
  
      if files_included != ['ERROR']:
          files_included = files_included[1:]  # cut off the dummy
  
      for file_included in files_included:
          if file_included == '':
              files_included.remove(file_included)
          if ' ' in file_included:
              for subfile in file_included.split(' '):
                  if subfile not in files_included:
                      files_included.append(subfile)
          if ',' in file_included:
              for subfile in file_included.split(' '):
                  if subfile not in files_included:
                      files_included.append(subfile)
  
      return files_included