Get the LaTeX string from a file by the *.ink filename.

def get_latex(ink_filename):
    """Get the LaTeX string from a file by the *.ink filename."""
    tex_file = os.path.splitext(ink_filename)[0] + ".tex"
    with open(tex_file) as f:
        tex_content = f.read().strip()
    pattern = re.compile(r"\\begin\{displaymath\}(.*?)\\end\{displaymath\}",
                         re.DOTALL)
    matches = pattern.findall(tex_content)

    if len(matches) == 0:
        pattern = re.compile(r"$$(.*?)$$",
                             re.DOTALL)
        matches = pattern.findall(tex_content)

    if len(matches) != 1:
        raise Exception("%s: Found not one match, but %i: %s" %
                        (ink_filename, len(matches), matches))
    formula_in_latex = matches[0].strip()
    formula_in_latex = remove_matching_braces(formula_in_latex)

    # repl = []
    # for letter in string.letters:
    #     repl.append(('\mbox{%s}' % letter, letter))
    # for search, replace in repl:
    #     formula_in_latex = formula_in_latex.replace(search, replace)
    return formula_in_latex