Browse Source

Added \obeylines command to verse, verse* and chorus environments.

pull/54/head
Louis 10 years ago
parent
commit
315915221c
  1. 8
      songbook_core/data/latex/songs_minimal.sty
  2. 12
      songbook_core/errors.py
  3. 32
      songbook_core/plastex.py

8
songbook_core/data/latex/songs_minimal.sty

@ -0,0 +1,8 @@
% Minimal songs.sty package, to be loaded by the songbook_core library, by the
% PlasTeX packages. Some songs.sty commands are implemented in Python, in the
% songbook_core/plastex*.py packages, and some commands are implemented in this
% file.
\newenvironment{chorus}{\obeylines}{}
\newenvironment{verse}{\obeylines}{}
\newenvironment{verse*}{\obeylines}{}

12
songbook_core/errors.py

@ -85,3 +85,15 @@ class UnknownStep(SongbookError):
def __str__(self):
return """Compilation step "{step}" unknown.""".format(step=self.step)
class LatexImportError(SongbookError):
"""Could not import package."""
def __init__(self, package):
super(LatexImportError, self).__init__()
self.package = package
def __str__(self):
return """Error while importing LaTeX package "{}".""".format(
self.package
)

32
songbook_core/plastex.py

@ -11,6 +11,9 @@ import locale
import os
import sys
from songbook_core import __DATADIR__
from songbook_core import errors
def process_unbr_spaces(node):
r"""Replace '~' and '\ ' in node by nodes that
@ -49,16 +52,37 @@ class SongParser(object):
"""Analyseur syntaxique de fichiers .sg"""
@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."""
tex = TeX()
tex.disableLogging()
tex.ownerDocument.context.loadBaseMacros()
# Setting paths
sys.path.append(os.path.dirname(__file__))
tex.ownerDocument.context.loadPackage(tex, "plastex_patchedbabel")
tex.ownerDocument.context.loadPackage(tex, "plastex_chord")
tex.ownerDocument.context.loadPackage(tex, "plastex_songs")
old_texinputs = os.environ.get("TEXINPUTS", '')
os.environ["TEXINPUTS"] = "{}:{}".format(
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()
os.environ["TEXINPUTS"] = old_texinputs
return tex
@classmethod

Loading…
Cancel
Save