memmod.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. #
  7. # Données pour treatline.
  8. #
  9. # attention, l'ordre est important !
  10. tabler={"textsuperscript{e}":"ieme{}",
  11. "textsuperscript{ème}":"ieme{}",
  12. "textsuperscript{er}":"ier{}",
  13. "\\begin{quote}":"",
  14. "\\end{quote}":"",
  15. "subsection{":"subsection*{",
  16. "\\textquotesingle ":"'",
  17. "\\textquotesingle":"",
  18. "~":"",
  19. }
  20. def treatline(l):
  21. # Les substitutions éventuelles à faire sur une ligne
  22. for x,y in tabler.items():
  23. l=l.replace(x,y)
  24. return l
  25. def nocite_all(fich):
  26. # Créer un nocite{...} avec toutes les entrées du fichier fich
  27. # (un fichier .bib).
  28. with open(fich) as f:
  29. L=f.readlines()
  30. all=[]
  31. for x in L:
  32. if "@" in x:
  33. d=x.find("{")+1
  34. e=x.find(",")
  35. all.append(x[d:e])
  36. return f"\\nocite{{{','.join(all)}}}"