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
\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

8
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 *)
}

2
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 *)

10
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"""

4
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)

8
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

Loading…
Cancel
Save