|
|
@@ -1,7 +1,8 @@
|
|
|
-#!./venv/bin/python
|
|
|
+#!/home/moi/ProtoMemoires/venv/bin/python
|
|
|
import sys,pypandoc,os,re,subprocess,yaml
|
|
|
#
|
|
|
data_yml_mandatory_keys=['fichier', 'date', 'auteur', 'titre']
|
|
|
+data_yml_order=['date','type','auteur','statut','titre']
|
|
|
def star_sec(l):
|
|
|
# \section est transformée en \section* et on ne garde comme argument
|
|
|
# que ce qui est nécessaire.
|
|
|
@@ -34,16 +35,20 @@ def star_sec(l):
|
|
|
#-----------------------------------------------------------------------
|
|
|
with open("data.yml") as f:
|
|
|
lt=yaml.safe_load(f)
|
|
|
+
|
|
|
for x in data_yml_mandatory_keys: #vérifier la présence des clés obligatoires
|
|
|
if not x in lt.keys():
|
|
|
raise Exception(f"\n\n Il manque {x} dans data.yml\n\n")
|
|
|
-# si statut est défini, type dit l'être aussi:
|
|
|
+# si statut est défini, type doit l'être aussi:
|
|
|
if "statut" in lt.keys():
|
|
|
if "type" not in lt.keys():
|
|
|
raise Exception(f"\n\n statut est défini, mais pas type\n\n")
|
|
|
-else: # si statut n'est pas défini, on le définit à "" et type à "Conférence".
|
|
|
+ lt['statut']=", "+lt["statut"]
|
|
|
+else: # si statut n'est pas défini, on le définit à " " et type à "Conférence".
|
|
|
lt["statut"]=" "
|
|
|
lt["type"]="Conférence"
|
|
|
+# biblio ?
|
|
|
+has_bib= "biblio"in lt.keys()
|
|
|
#
|
|
|
# le fichier (docx, odt) qu'on va traiter:
|
|
|
#
|
|
|
@@ -51,9 +56,12 @@ fich=lt["fichier"].strip()
|
|
|
#
|
|
|
# fabriquer le titre à partir des données yml
|
|
|
#
|
|
|
-titre_elements="}{".join([lt[x].replace("\n","") for x in lt.keys()
|
|
|
- if x!="fichier"])
|
|
|
-le_titre="\\titre{"+titre_elements+"}"+"\n"
|
|
|
+titre_elements="}{".join([lt[x].replace("\n","") for x in data_yml_order])
|
|
|
+
|
|
|
+#le_titre="\\titre{"+titre_elements+"}"+"\n"
|
|
|
+le_titre= f"\\titre{{{titre_elements}}}\n"
|
|
|
+
|
|
|
+
|
|
|
#--------------------------------------------------------------------
|
|
|
template="../tpl.tex" # le template
|
|
|
#---------------------------------------------------------------------
|
|
|
@@ -73,9 +81,9 @@ if not os.path.isdir(images):
|
|
|
#
|
|
|
# conversion en latex
|
|
|
#
|
|
|
-extra_args= ["-s",f"--template={template}",f"--extract-media={images}"]
|
|
|
-#extra_args= ["-s",f"--template={template}",f"--extract-media={images}",
|
|
|
-# f"--lof=true"]
|
|
|
+#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()
|
|
|
|
|
|
@@ -102,26 +110,49 @@ with open(futurTex,"w") as f:
|
|
|
|
|
|
rp0,rp1= repPath
|
|
|
for l in L1:
|
|
|
-
|
|
|
+ if has_bib and "addbibresource{}" in l:
|
|
|
+ bibfile=lt['biblio']
|
|
|
+ l=l.replace("{","{"+bibfile)
|
|
|
+ if "textsuperscript{e}" in l:
|
|
|
+ print(l)
|
|
|
+ l=l.replace("textsuperscript{e}","ieme{}")
|
|
|
+ print(l)
|
|
|
+ #ccc=input()
|
|
|
while (q:=rechgrac.search(l)) != None:
|
|
|
l=l.replace(rp0,rp1)
|
|
|
# on supprime les "quote"
|
|
|
l=l.replace("\\begin{quote}","")
|
|
|
l=l.replace("\\end{quote}","")
|
|
|
+ # subsection-> subsection*
|
|
|
+ l=l.replace("subsection{","subsection*{")
|
|
|
|
|
|
+ if "@@fin" in l:
|
|
|
+ if has_bib:
|
|
|
+ f.write("\\begin{center}\\textbf{Bibliographie}\\end{center}\n")
|
|
|
+ f.write("\citeall[\\fullcite]\n")
|
|
|
+ f.write("\FloatBarrier\n")
|
|
|
f.write(l)
|
|
|
f.write("\n")
|
|
|
|
|
|
|
|
|
- if "debut" in l:
|
|
|
+ if "@@debut" in l:
|
|
|
+ f.write("\\fancyhead{}\n")
|
|
|
+ f.write("\\fancyhead[CE]{Mémoires: 2\ieme{} partie}\n")
|
|
|
+ aut= lt["auteur"]
|
|
|
+ f.write(f"\\fancyhead[CO]{{{lt['auteur']}, {lt['titre']}}}\n")
|
|
|
f.write(le_titre)
|
|
|
+
|
|
|
#
|
|
|
#---fin d'éciture du fichier tex
|
|
|
#
|
|
|
# lualatex, 2 fois:
|
|
|
#
|
|
|
-for i in {1,2}:
|
|
|
+
|
|
|
+subprocess.run(["/usr/bin/lualatex", futurTex])
|
|
|
+if has_bib:
|
|
|
+ subprocess.run(["/usr/bin/biber", futurTex.replace(".tex","")])
|
|
|
subprocess.run(["/usr/bin/lualatex", futurTex])
|
|
|
+subprocess.run(["/usr/bin/lualatex", futurTex])
|
|
|
#--- fin
|
|
|
|
|
|
|