|
@ -11,6 +11,9 @@ import locale |
|
|
import os |
|
|
import os |
|
|
import sys |
|
|
import sys |
|
|
|
|
|
|
|
|
|
|
|
from songbook_core import __DATADIR__ |
|
|
|
|
|
from songbook_core import errors |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_unbr_spaces(node): |
|
|
def process_unbr_spaces(node): |
|
|
r"""Replace '~' and '\ ' in node by nodes that |
|
|
r"""Replace '~' and '\ ' in node by nodes that |
|
@ -49,16 +52,37 @@ class SongParser(object): |
|
|
"""Analyseur syntaxique de fichiers .sg""" |
|
|
"""Analyseur syntaxique de fichiers .sg""" |
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def create_tex(): |
|
|
def load_package(tex, package): |
|
|
|
|
|
"""Wrapper to 'tex.ownerDocument.context.loadPackage' catching errors. |
|
|
|
|
|
""" |
|
|
|
|
|
if not tex.ownerDocument.context.loadPackage(tex, package): |
|
|
|
|
|
raise errors.LatexImportError(package) |
|
|
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
|
def create_tex(cls): |
|
|
"""Create a TeX object, ready to parse a tex file.""" |
|
|
"""Create a TeX object, ready to parse a tex file.""" |
|
|
tex = TeX() |
|
|
tex = TeX() |
|
|
tex.disableLogging() |
|
|
tex.disableLogging() |
|
|
tex.ownerDocument.context.loadBaseMacros() |
|
|
tex.ownerDocument.context.loadBaseMacros() |
|
|
|
|
|
|
|
|
|
|
|
# Setting paths |
|
|
sys.path.append(os.path.dirname(__file__)) |
|
|
sys.path.append(os.path.dirname(__file__)) |
|
|
tex.ownerDocument.context.loadPackage(tex, "plastex_patchedbabel") |
|
|
old_texinputs = os.environ.get("TEXINPUTS", '') |
|
|
tex.ownerDocument.context.loadPackage(tex, "plastex_chord") |
|
|
os.environ["TEXINPUTS"] = "{}:{}".format( |
|
|
tex.ownerDocument.context.loadPackage(tex, "plastex_songs") |
|
|
old_texinputs, |
|
|
|
|
|
os.path.join(__DATADIR__, "latex"), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
# Loading packages |
|
|
|
|
|
cls.load_package(tex, "plastex_patchedbabel") |
|
|
|
|
|
cls.load_package(tex, "plastex_chord") |
|
|
|
|
|
cls.load_package(tex, "plastex_songs") |
|
|
|
|
|
cls.load_package(tex, "songs_minimal.sty") |
|
|
|
|
|
|
|
|
|
|
|
# Unsetting paths |
|
|
sys.path.pop() |
|
|
sys.path.pop() |
|
|
|
|
|
os.environ["TEXINPUTS"] = old_texinputs |
|
|
|
|
|
|
|
|
return tex |
|
|
return tex |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
|