'Format a string for latex inclusion.'

def format_latex(self, strng):

    escape_re = re.compile('(%|_|\\$|#|&)', re.MULTILINE)
    cmd_name_re = re.compile(('^(%s.*?):' % ESC_MAGIC), re.MULTILINE)
    cmd_re = re.compile(('(?P<cmd>%s.+?\\b)(?!\\}\\}:)' % ESC_MAGIC), re.MULTILINE)
    par_re = re.compile('\\\\$', re.MULTILINE)
    newline_re = re.compile('\\\\n')
    strng = cmd_name_re.sub('\\n\\\\bigskip\\n\\\\texttt{\\\\textbf{    \\1}}:', strng)
    strng = cmd_re.sub('\\\\texttt{\\g<cmd>}', strng)
    strng = par_re.sub('\\\\\\\\', strng)
    strng = escape_re.sub('\\\\\\1', strng)
    strng = newline_re.sub('\\\\textbackslash{}n', strng)
    return strng
