def prepend_to_file(filename, lines, maxlines=1000, warn_message=None):
    """"prepend lines the tex-command filename """
    try:
        with open(filename, 'r') as f:
            lines_to_append = list(f)
    except IOError:
        lines_to_append = []
    with open(filename, 'w') as f:
        for line in lines:
            f.write(line + '\n')
        for i, line in enumerate(lines_to_append):
            f.write(line)
            if i > maxlines:
                print(warn_message)
                break
