|
@@ -0,0 +1,105 @@
|
|
|
|
|
+#!./venv/bin/python
|
|
|
|
|
+import sys,pypandoc,os,re,subprocess
|
|
|
|
|
+#
|
|
|
|
|
+def star_sec(l):
|
|
|
|
|
+ it=iter(L)
|
|
|
|
|
+ ret=[]
|
|
|
|
|
+ passed= False
|
|
|
|
|
+ for x in it:
|
|
|
|
|
+ if "begin{document" in x:
|
|
|
|
|
+ passed= True
|
|
|
|
|
+ if passed and "section[" in x:
|
|
|
|
|
+ s=x
|
|
|
|
|
+ while "label" not in x:
|
|
|
|
|
+ x=next(it)
|
|
|
|
|
+ s=s+" "+x
|
|
|
|
|
+
|
|
|
|
|
+ if not "}" in s:
|
|
|
|
|
+ x=next(it)
|
|
|
|
|
+ s=s+x
|
|
|
|
|
+ k=s.find("]")
|
|
|
|
|
+ r=(s[:k]+"}").replace("[","*{")+" "
|
|
|
|
|
+ ret.append(r)
|
|
|
|
|
+ ret.append("\n")
|
|
|
|
|
+ else:
|
|
|
|
|
+ ret.append(x)
|
|
|
|
|
+ return ret
|
|
|
|
|
+#
|
|
|
|
|
+
|
|
|
|
|
+#-----------------------------------------------------------------------
|
|
|
|
|
+with open("data_titre") as f:
|
|
|
|
|
+ lt=f.readlines()
|
|
|
|
|
+if (llt:=len(lt))!=6:
|
|
|
|
|
+ m=f"\nle fichier data-titre a {llt} lignes (il en faut 6)"
|
|
|
|
|
+ raise Exception(m)
|
|
|
|
|
+fich=lt[0].strip()
|
|
|
|
|
+le_titre="\\titre{"+"}{".join([x.replace("\n","") for x in lt[1:]])+"}"+"\n"
|
|
|
|
|
+print(le_titre)
|
|
|
|
|
+#
|
|
|
|
|
+template="../tpl.tex"
|
|
|
|
|
+#
|
|
|
|
|
+exten=fich.split(".")[-1]
|
|
|
|
|
+
|
|
|
|
|
+if exten=="docx" or exten=="odt":
|
|
|
|
|
+ futurTex= fich.replace(exten,"tex")
|
|
|
|
|
+else:
|
|
|
|
|
+ s=f"\n{fich} : extension incorrecte"
|
|
|
|
|
+ raise Exception(s)
|
|
|
|
|
+
|
|
|
|
|
+#répertoire pour les images
|
|
|
|
|
+images= fich.split(".")[0]+"-media"
|
|
|
|
|
+print("Répertoire des images : ",images)
|
|
|
|
|
+if not os.path.isdir(images):
|
|
|
|
|
+ os.mkdir(images)
|
|
|
|
|
+
|
|
|
|
|
+# conversion en latex
|
|
|
|
|
+#extra_args= ["-s",f"--extract-media={images}"]
|
|
|
|
|
+extra_args= ["-s",f"--template={template}",f"--extract-media={images}"]
|
|
|
|
|
+#extra_args= ["-s",f"--template={template}",f"--extract-media={images}",
|
|
|
|
|
+# f"--lof=true"]
|
|
|
|
|
+L = pypandoc.convert_file(fich, 'tex',
|
|
|
|
|
+ extra_args=extra_args).splitlines()
|
|
|
|
|
+
|
|
|
|
|
+#-----------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+# section -> section*
|
|
|
|
|
+rechsec= r"section[{\[]"
|
|
|
|
|
+rechsecc=re.compile(rechsec)
|
|
|
|
|
+
|
|
|
|
|
+# pour modifier le latex en changeant le chemin vers les images.
|
|
|
|
|
+if exten=="docx":
|
|
|
|
|
+ rechgra=r"includegraphics\[.*\]{media.*}"
|
|
|
|
|
+ repPath=("media",f"{images}/word/media")
|
|
|
|
|
+elif exten=="odt":
|
|
|
|
|
+ rechgra=r"includegraphics\[.*\]{Pictures.*}"
|
|
|
|
|
+ repPath=("Pictures",f"{images}/Pictures")
|
|
|
|
|
+
|
|
|
|
|
+rechgrac=re.compile(rechgra)
|
|
|
|
|
+
|
|
|
|
|
+with open(futurTex,"w") as f:
|
|
|
|
|
+ L1=star_sec(L)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ rp0,rp1= repPath
|
|
|
|
|
+ for l in L1:
|
|
|
|
|
+
|
|
|
|
|
+ while (q:=rechgrac.search(l)) != None:
|
|
|
|
|
+ l=l.replace(rp0,rp1)
|
|
|
|
|
+ l=l.replace("\\begin{quote}","")
|
|
|
|
|
+ l=l.replace("\\end{quote}","")
|
|
|
|
|
+
|
|
|
|
|
+ f.write(l)
|
|
|
|
|
+ f.write("\n")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if "pagestyle" in l:
|
|
|
|
|
+ f.write(le_titre)
|
|
|
|
|
+
|
|
|
|
|
+#---fin d'éciture du fichier tex
|
|
|
|
|
+#
|
|
|
|
|
+# lualatex, 2 fois:
|
|
|
|
|
+for i in {1,2}:
|
|
|
|
|
+ subprocess.run(["/usr/bin/lualatex", futurTex])
|
|
|
|
|
+#--- fin
|
|
|
|
|
+
|
|
|
|
|
+
|