From ff07c71d16f43289b996341c72d25abc35814b32 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sun, 8 Nov 2015 09:19:34 +0100 Subject: [PATCH] Use absolute import for LaTeX songs --- patacrep/data/templates/layout.tex | 7 +------ patacrep/data/templates/songs.tex | 8 ++++---- patacrep/data/templates/songs/chordpro/latex/song | 2 +- patacrep/songs/latex/__init__.py | 10 +++------- patacrep/templates.py | 4 ++-- test/test_compilation/datadir.tex.control | 8 ++++---- 6 files changed, 15 insertions(+), 24 deletions(-) diff --git a/patacrep/data/templates/layout.tex b/patacrep/data/templates/layout.tex index 135aba1b..28dba5e8 100644 --- a/patacrep/data/templates/layout.tex +++ b/patacrep/data/templates/layout.tex @@ -27,13 +27,8 @@ \makeatletter \def\input@path{ % - % include .sty folders (* for dir in datadir *) - {(( path2posix(dir) ))/latex/} % - (* endfor *) - % include datadir folders (for \import) - (* for dir in datadir *) - {(( path2posix(dir) ))/} % + {(( dir | path2posix ))/latex/} % (* endfor *) } \makeatother diff --git a/patacrep/data/templates/songs.tex b/patacrep/data/templates/songs.tex index e3562897..da48fdd7 100644 --- a/patacrep/data/templates/songs.tex +++ b/patacrep/data/templates/songs.tex @@ -81,15 +81,15 @@ (( super() )) (* for lang in _langs|sort -*) - \PassOptionsToPackage{(( lang2babel(lang) ))}{babel} + \PassOptionsToPackage{(( lang | lang2babel ))}{babel} (* endfor *) -\usepackage[(( lang2babel(lang) ))]{babel} -\lang{(( lang2babel(lang) ))} +\usepackage[(( lang | lang2babel ))]{babel} +\lang{(( lang | lang2babel ))} \usepackage{graphicx} \graphicspath{ % (* for dir in datadir *) - {(( path2posix(dir) ))/} % + {(( dir | path2posix ))/} % (* endfor *) } diff --git a/patacrep/data/templates/songs/chordpro/latex/song b/patacrep/data/templates/songs/chordpro/latex/song index e8016107..cb29cc29 100644 --- a/patacrep/data/templates/songs/chordpro/latex/song +++ b/patacrep/data/templates/songs/chordpro/latex/song @@ -1,5 +1,5 @@ (* if lang is defined -*) - \selectlanguage{(( lang2babel(lang) ))} + \selectlanguage{(( lang | lang2babel ))} (* endif *) (*- if metadata.columns is defined *) diff --git a/patacrep/songs/latex/__init__.py b/patacrep/songs/latex/__init__.py index 86c72400..d19cd10e 100644 --- a/patacrep/songs/latex/__init__.py +++ b/patacrep/songs/latex/__init__.py @@ -32,13 +32,9 @@ class Latex2LatexSong(Song): def render(self): """Return the code rendering the song.""" # pylint: disable=signature-differs - if not self.datadir: - raise ValueError(self.datadir) - path = files.path2posix(files.relpath( - self.fullpath, - self.datadir - )) - return r'\import{{{}/}}{{{}}}'.format(os.path.dirname(path), os.path.basename(path)) + filename = os.path.basename(self.fullpath) + path = os.path.abspath(os.path.dirname(self.fullpath)) + return r'\import{{{}/}}{{{}}}'.format(files.path2posix(path), filename) def set_lang(self, language): """Set the language code""" diff --git a/patacrep/templates.py b/patacrep/templates.py index 6a799295..612a99e4 100644 --- a/patacrep/templates.py +++ b/patacrep/templates.py @@ -84,8 +84,8 @@ class Renderer: self.jinjaenv.filters['escape_tex'] = _escape_tex self.jinjaenv.trim_blocks = True self.jinjaenv.lstrip_blocks = True - self.jinjaenv.globals["path2posix"] = files.path2posix - self.jinjaenv.globals["lang2babel"] = lang2babel + self.jinjaenv.filters["path2posix"] = files.path2posix + self.jinjaenv.filters["lang2babel"] = lang2babel self.template = self.jinjaenv.get_template(template) diff --git a/test/test_compilation/datadir.tex.control b/test/test_compilation/datadir.tex.control index a003cd42..14b11cb1 100644 --- a/test/test_compilation/datadir.tex.control +++ b/test/test_compilation/datadir.tex.control @@ -92,7 +92,7 @@ guitar, %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% songs/./datadir.sg -\import{datadir_datadir/songs/}{datadir.sg} +\import{@TEST_FOLDER@/datadir_datadir/songs/}{datadir.sg} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% songs/./datadir.sgc @@ -119,7 +119,7 @@ Chordpro}[ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% songs/./datadir2.sg -\import{datadir_datadir/songs/}{datadir2.sg} +\import{@TEST_FOLDER@/datadir_datadir/songs/}{datadir2.sg} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% songs/./datadir2.sgc @@ -146,7 +146,7 @@ Chordpro}[ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% songs/./relative.sg -\import{datadir_datadir/songs/}{relative.sg} +\import{@TEST_FOLDER@/datadir_datadir/songs/}{relative.sg} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% songs/./relative.sgc @@ -173,7 +173,7 @@ Chordpro}[ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% songs/./subdir/subdir.sg -\import{datadir_datadir/songs/subdir/}{subdir.sg} +\import{@TEST_FOLDER@/datadir_datadir/songs/subdir/}{subdir.sg} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% songs/./subdir/subdir.sgc