Browse Source

Gestion des chemins windows dans les fichiers LaTeX

pull/55/head
Luthaf 11 years ago
parent
commit
902c207381
  1. 9
      patacrep/content/song.py
  2. 2
      patacrep/data/templates/layout.tex
  3. 2
      patacrep/data/templates/songs.tex
  4. 15
      patacrep/files.py
  5. 8
      patacrep/templates.py

9
patacrep/content/song.py

@ -34,10 +34,11 @@ class SongRenderer(Content, Song):
def render(self, context): def render(self, context):
"""Return the string that will render the song.""" """Return the string that will render the song."""
return ur'\input{{{}}}'.format(files.relpath( return ur'\input{{{}}}'.format(files.path2posix(
self.path, files.relpath(
os.path.dirname(context['filename']) self.path,
)) os.path.dirname(context['filename'])
)))
#pylint: disable=unused-argument #pylint: disable=unused-argument
def parse(keyword, argument, contentlist, config): def parse(keyword, argument, contentlist, config):

2
patacrep/data/templates/layout.tex

@ -28,7 +28,7 @@
\makeatletter \makeatletter
\def\input@path{(* for dir in datadir *) \def\input@path{(* for dir in datadir *)
{((dir))/latex/} % {(( path2posix(dir) ))/latex/} %
(* endfor *) (* endfor *)
} }
\makeatother \makeatother

2
patacrep/data/templates/songs.tex

@ -86,7 +86,7 @@
\usepackage{graphicx} \usepackage{graphicx}
\graphicspath{(* for dir in datadir *) \graphicspath{(* for dir in datadir *)
{((dir))/img/} % {(( path2posix(dir) ))/img/} %
(* endfor *) (* endfor *)
} }

15
patacrep/files.py

@ -5,7 +5,8 @@
"""File system utilities.""" """File system utilities."""
import fnmatch import fnmatch
import os import os.path
import posixpath
def recursive_find(root_directory, pattern): def recursive_find(root_directory, pattern):
"""Recursively find files matching a pattern, from a root_directory. """Recursively find files matching a pattern, from a root_directory.
@ -26,3 +27,15 @@ def relpath(path, start=None):
return os.path.relpath(path, start) return os.path.relpath(path, start)
else: else:
return os.path.abspath(path) return os.path.abspath(path)
def path2posix(string):
""""Convert path from local format to posix format."""
if not string or string == "/":
return string
if os.path.splitdrive(string)[1] == "\\":
# Assuming DRIVE:\
return string[0:-1]
(head, tail) = os.path.split(string)
return posixpath.join(
path2posix(head),
tail)

8
patacrep/templates.py

@ -10,8 +10,7 @@ import os
import re import re
import json import json
from patacrep import encoding from patacrep import encoding, errors, files
from patacrep import errors
_LATEX_SUBS = ( _LATEX_SUBS = (
(re.compile(ur'\\'), ur'\\textbackslash'), (re.compile(ur'\\'), ur'\\textbackslash'),
@ -38,7 +37,8 @@ _VARIABLE_REGEXP = re.compile(ur"""
. # Match any single character . # Match any single character
)* # Repeat as often as possible )* # Repeat as often as possible
) # End of capturing group 1 ) # End of capturing group 1
\(\*\ *endvariables\ *\*\) # until (* endvariables *) is matched.""", \(\*\ *endvariables\ *\*\) # until (* endvariables *) is matched.
""",
re.VERBOSE|re.DOTALL) re.VERBOSE|re.DOTALL)
@ -96,6 +96,8 @@ class TexRenderer(object):
self.texenv.trim_blocks = True self.texenv.trim_blocks = True
self.texenv.lstrip_blocks = True self.texenv.lstrip_blocks = True
self.texenv.globals["path2posix"] = files.path2posix
try: try:
self.template = self.texenv.get_template(template) self.template = self.texenv.get_template(template)
except TemplateNotFound as exception: except TemplateNotFound as exception:

Loading…
Cancel
Save