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):
"""Return the string that will render the song."""
return ur'\input{{{}}}'.format(files.relpath(
self.path,
os.path.dirname(context['filename'])
))
return ur'\input{{{}}}'.format(files.path2posix(
files.relpath(
self.path,
os.path.dirname(context['filename'])
)))
#pylint: disable=unused-argument
def parse(keyword, argument, contentlist, config):

2
patacrep/data/templates/layout.tex

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

2
patacrep/data/templates/songs.tex

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

15
patacrep/files.py

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

Loading…
Cancel
Save