import os, errno def print_file(dictionary, label, caption, anchor): label = label.replace(".py", "") file_loc = label + ".tex" path = open(file_loc, 'w') path.write("{\\linespread{0.8}\\selectfont\\centering") path.write("\\begin{longtable}[ht!]{ p{15.2cm} }") path.write("\\caption{" + caption + "}") path.write("\\label{tab:" + label + "}") path.write("\\vspace{3mm}") path.write("\\phantomsection\\belowpdfbookmark{") path.write(sorted(dictionary.items())[0][0].replace("_","\_")) path.write("}{verbs_" + str(anchor) + "}") path.write("\\endfirsthead") path.write("\\endhead") for i, (key, value) in enumerate(sorted(dictionary.items())): name = key.replace("_", "\_") template = value[0].replace(key.split()[0], \ "\\textbf{\\underline{" + key.split()[0] + "}}").replace("_", "\_") description = value[1] path.write("\\Tstrut") path.write("{\\footnotesize\n") path.write("\\textbf{\colorbox{table_gray}{\parbox{15.0cm}{\\texttt{") path.write(template) path.write("}}}}\\vspace{1.8mm}\\newline\n") path.write("" + description + "}\n") path.write("\\newline\n") path.write("\\Bstrut") if i != len(dictionary) - 1: path.write("\\phantomsection\\belowpdfbookmark{") path.write(sorted(dictionary.items())[i+1][0].replace("_", "\_")) path.write("}{verbs_" + str(anchor + i + 1) + "}") path.write("\\tabularnewline\n") path.write("\\end{longtable}}")