mirror of https://github.com/patacrep/patacrep.git
Louis
12 years ago
6 changed files with 63 additions and 25 deletions
@ -1,16 +0,0 @@ |
|||||
#!/usr/bin/env python |
|
||||
# -*- coding: utf-8 -*- |
|
||||
|
|
||||
FILENAME = "naheulbeuk.tex" |
|
||||
|
|
||||
import plasTeX |
|
||||
from plasTeX.TeX import TeX |
|
||||
|
|
||||
doc = TeX(file = FILENAME).parse() |
|
||||
|
|
||||
language_list = set() |
|
||||
for node in doc.allChildNodes: |
|
||||
if node.nodeName == "selectlanguage": |
|
||||
language_list.add(node.argSource) |
|
||||
|
|
||||
print language_list |
|
@ -0,0 +1,31 @@ |
|||||
|
#!/usr/bin/env python |
||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
import plasTeX |
||||
|
from plasTeX.TeX import TeX |
||||
|
|
||||
|
def parsetex(filename): |
||||
|
"""Analyse syntaxique d'un fichier .sg |
||||
|
|
||||
|
Renvoie un dictionnaire contenant les métadonnées lues dans le fichier. Les |
||||
|
clefs sont : |
||||
|
- languages: l'ensemble des langages utilisés (recherche des |
||||
|
\selectlanguages{}). |
||||
|
""" |
||||
|
# Chargement du fichier .sg (.tex), et des modules nécessaires |
||||
|
tex = TeX(file = filename) |
||||
|
tex.disableLogging() |
||||
|
tex.ownerDocument.context.loadPackage(tex, "babel") |
||||
|
|
||||
|
# Analyse syntaxique |
||||
|
doc= tex.parse() |
||||
|
|
||||
|
# Extraction des données |
||||
|
data = { |
||||
|
"languages": set(), |
||||
|
} |
||||
|
for node in doc.allChildNodes: |
||||
|
if node.nodeName == "selectlanguage": |
||||
|
data["languages"].add(node.argSource) |
||||
|
|
||||
|
return data |
Loading…
Reference in new issue