tout.py 1.2 KB

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