tout.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #-------------------------------------------
  2. def addpath(x,ajout):
  3. if "includegraphics" in x:
  4. return x.replace("{",ajout)
  5. else:
  6. return x
  7. #
  8. templat= "../tpl.tex"
  9. #
  10. # Récupérer la liste des textes à introduire
  11. #
  12. with open("all_texts") as f:
  13. lf= f.readlines()
  14. #
  15. #on récupère le template
  16. with open(templat) as f:
  17. Ltmpl=f.readlines()
  18. #
  19. Lall=[]
  20. for l in Ltmpl:
  21. if "%@@debut" in l:
  22. break
  23. else:
  24. Lall.append(l)
  25. bound1= "pagestyle"
  26. bound2= "tableofcontents"
  27. for l in lf:
  28. lok="../"+l.replace("\n","")
  29. print(lok)
  30. with open(lok) as g:
  31. LL=g.readlines()
  32. #Z= getlines(LL,"debut","fin")
  33. start= False
  34. Z= []
  35. for x in LL:
  36. if "%@@debut" in x:
  37. start= True
  38. if "%@@fin" in x:
  39. break
  40. if start:
  41. Z.append(x)
  42. # graphiques
  43. ajout="{../"+l.split("/")[0]+"/"
  44. Lall+=[addpath(x,ajout) for x in Z if not "newcounter" in x]
  45. Lall.append("\\eject\n")
  46. with open("final.tex","w") as f:
  47. for x in Lall[:-1]:
  48. f.write(x)
  49. f.write("\\tableofcontents\n")
  50. f.write("\\end{document}\n")