memmod.py 980 B

1234567891011121314151617181920212223242526272829303132333435
  1. import hashlib
  2. def dolabel(k,t):
  3. # faire une étiquette "unique" à partir de deux chaines de caratères k et t.
  4. s=(k+t).encode("UTF-8")
  5. return hashlib.sha1(s).hexdigest()
  6. # attention, l'ordre est important !
  7. tabler={"textsuperscript{e}":"ieme{}",
  8. "\\begin{quote}":"",
  9. "\\end{quote}":"",
  10. "subsection{":"subsection*{",
  11. "\\textquotesingle ":"'",
  12. "\\textquotesingle":"",
  13. "~":"",
  14. }
  15. def treatline(l):
  16. # Les substitutions éventuelles à faire sur une ligne
  17. for x,y in tabler.items():
  18. l=l.replace(x,y)
  19. return l
  20. def nocite_all(fich):
  21. # Créeer un nocite{...} avec toutes les entrées du fichier fich
  22. # (un fichier .bib).
  23. with open(fich) as f:
  24. L=f.readlines()
  25. ret="\nocite{"
  26. all=[]
  27. for x in L:
  28. if "@" in x:
  29. d=x.find("{")+1
  30. e=x.find(",")
  31. all.append(x[d:e])
  32. return f"\\nocite{{{','.join(all)}}}"