Browse Source

Use absolute import for LaTeX songs

pull/165/head
Oliverpool 9 years ago
parent
commit
ff07c71d16
  1. 7
      patacrep/data/templates/layout.tex
  2. 8
      patacrep/data/templates/songs.tex
  3. 2
      patacrep/data/templates/songs/chordpro/latex/song
  4. 10
      patacrep/songs/latex/__init__.py
  5. 4
      patacrep/templates.py
  6. 8
      test/test_compilation/datadir.tex.control

7
patacrep/data/templates/layout.tex

@ -27,13 +27,8 @@
\makeatletter \makeatletter
\def\input@path{ % \def\input@path{ %
% include .sty folders
(* for dir in datadir *) (* for dir in datadir *)
{(( path2posix(dir) ))/latex/} % {(( dir | path2posix ))/latex/} %
(* endfor *)
% include datadir folders (for \import)
(* for dir in datadir *)
{(( path2posix(dir) ))/} %
(* endfor *) (* endfor *)
} }
\makeatother \makeatother

8
patacrep/data/templates/songs.tex

@ -81,15 +81,15 @@
(( super() )) (( super() ))
(* for lang in _langs|sort -*) (* for lang in _langs|sort -*)
\PassOptionsToPackage{(( lang2babel(lang) ))}{babel} \PassOptionsToPackage{(( lang | lang2babel ))}{babel}
(* endfor *) (* endfor *)
\usepackage[(( lang2babel(lang) ))]{babel} \usepackage[(( lang | lang2babel ))]{babel}
\lang{(( lang2babel(lang) ))} \lang{(( lang | lang2babel ))}
\usepackage{graphicx} \usepackage{graphicx}
\graphicspath{ % \graphicspath{ %
(* for dir in datadir *) (* for dir in datadir *)
{(( path2posix(dir) ))/} % {(( dir | path2posix ))/} %
(* endfor *) (* endfor *)
} }

2
patacrep/data/templates/songs/chordpro/latex/song

@ -1,5 +1,5 @@
(* if lang is defined -*) (* if lang is defined -*)
\selectlanguage{(( lang2babel(lang) ))} \selectlanguage{(( lang | lang2babel ))}
(* endif *) (* endif *)
(*- if metadata.columns is defined *) (*- if metadata.columns is defined *)

10
patacrep/songs/latex/__init__.py

@ -32,13 +32,9 @@ class Latex2LatexSong(Song):
def render(self): def render(self):
"""Return the code rendering the song.""" """Return the code rendering the song."""
# pylint: disable=signature-differs # pylint: disable=signature-differs
if not self.datadir: filename = os.path.basename(self.fullpath)
raise ValueError(self.datadir) path = os.path.abspath(os.path.dirname(self.fullpath))
path = files.path2posix(files.relpath( return r'\import{{{}/}}{{{}}}'.format(files.path2posix(path), filename)
self.fullpath,
self.datadir
))
return r'\import{{{}/}}{{{}}}'.format(os.path.dirname(path), os.path.basename(path))
def set_lang(self, language): def set_lang(self, language):
"""Set the language code""" """Set the language code"""

4
patacrep/templates.py

@ -84,8 +84,8 @@ class Renderer:
self.jinjaenv.filters['escape_tex'] = _escape_tex self.jinjaenv.filters['escape_tex'] = _escape_tex
self.jinjaenv.trim_blocks = True self.jinjaenv.trim_blocks = True
self.jinjaenv.lstrip_blocks = True self.jinjaenv.lstrip_blocks = True
self.jinjaenv.globals["path2posix"] = files.path2posix self.jinjaenv.filters["path2posix"] = files.path2posix
self.jinjaenv.globals["lang2babel"] = lang2babel self.jinjaenv.filters["lang2babel"] = lang2babel
self.template = self.jinjaenv.get_template(template) self.template = self.jinjaenv.get_template(template)

8
test/test_compilation/datadir.tex.control

@ -92,7 +92,7 @@ guitar,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% songs/./datadir.sg %% songs/./datadir.sg
\import{datadir_datadir/songs/}{datadir.sg} \import{@TEST_FOLDER@/datadir_datadir/songs/}{datadir.sg}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% songs/./datadir.sgc %% songs/./datadir.sgc
@ -119,7 +119,7 @@ Chordpro}[
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% songs/./datadir2.sg %% songs/./datadir2.sg
\import{datadir_datadir/songs/}{datadir2.sg} \import{@TEST_FOLDER@/datadir_datadir/songs/}{datadir2.sg}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% songs/./datadir2.sgc %% songs/./datadir2.sgc
@ -146,7 +146,7 @@ Chordpro}[
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% songs/./relative.sg %% songs/./relative.sg
\import{datadir_datadir/songs/}{relative.sg} \import{@TEST_FOLDER@/datadir_datadir/songs/}{relative.sg}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% songs/./relative.sgc %% songs/./relative.sgc
@ -173,7 +173,7 @@ Chordpro}[
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% songs/./subdir/subdir.sg %% songs/./subdir/subdir.sg
\import{datadir_datadir/songs/subdir/}{subdir.sg} \import{@TEST_FOLDER@/datadir_datadir/songs/subdir/}{subdir.sg}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% songs/./subdir/subdir.sgc %% songs/./subdir/subdir.sgc

Loading…
Cancel
Save