diff --git a/latex/conversion.py b/latex/conversion.py index 9a49fdb..c379b80 100644 --- a/latex/conversion.py +++ b/latex/conversion.py @@ -1,27 +1,44 @@ import os def extraire_caml(nf_tex, nf_ml, nf_texo, tag) : + nf_tex = nf_tex.replace("file://", "") + nf_ml = nf_ml.replace("file://", "") + nf_texo = nf_texo.replace("file://", "") output_tex = open(nf_texo, "w") output_ml = open(nf_ml, "w") incode = False nomfonc = "" + complement = None + numfoncAnon = 0 mlref = os.path.basename(nf_ml) for l in open(nf_tex) : lstrip = l.strip() - if lstrip == r"\begin{"+tag+"}" : + if lstrip.startswith(r"\begin{"+tag+"}") : incode = True nomfonc = "" + complement = None + if "[" in lstrip : + complement = lstrip.split("[")[1].split("]")[0] continue if incode : - if nomfonc == "" and "let" in lstrip : - nomfonc = l[4:] - if nomfonc.startswith("rec ") : - nomfonc = nomfonc[4:] - nomfonc = nomfonc.split()[0] + if nomfonc == "" : + if lstrip == "" : + continue + if "let" in lstrip : + nomfonc = l[4:] + if nomfonc.startswith("rec ") : + nomfonc = nomfonc[4:] + nomfonc = nomfonc.split()[0] + else : + nomfonc = "anon" + str(numfoncAnon) + numfoncAnon += 1 output_ml.write("(*** " + nomfonc + " ***)\n") if lstrip == r"\end{"+tag+"}" : output_ml.write("(*** " + nomfonc + "_fin ***)\n\n") - output_tex.write(r"\lstinputcaml[linerange="+nomfonc+"-"+nomfonc+"_fin]{"+ mlref + "}\n") + if complement is not None : + output_tex.write(r"\inputcaml["+nomfonc+"]{"+ mlref + "}["+complement+"]\n") + else : + output_tex.write(r"\inputcaml["+nomfonc+"]{"+ mlref + "}\n") incode = False continue output_ml.write(l)