Browse Source

Remplacement des \\ par des chaines r"\" où necessaire

pull/20/head
Luthaf 11 years ago
parent
commit
447b0fae5b
  1. 19
      songbook/build.py
  2. 15
      songbook/index.py
  3. 4
      songbook/plastex.py
  4. 4
      songbook/songs.py

19
songbook/build.py

@ -16,6 +16,8 @@ from songbook.index import processSXD
from songbook.songs import Song, SongsList
from songbook import __SHAREDIR__
EOL = "\n"
def parseTemplate(template):
"""Return the list of parameters defined in the template."""
@ -65,13 +67,14 @@ def formatDeclaration(name, parameter):
if "default" in parameter:
value = parameter["default"]
return (
'\\def\\set@{name}#1{{\\def\\get{name}{{#1}}}}\n'.format(name=name)
r'\def\set@{name}#1{{\def\get{name}{{#1}}}}'.format(name=name)
+ EOL
+ formatDefinition(name, toValue(parameter, value))
)
def formatDefinition(name, value):
return '\\set@{name}{{{value}}}\n'.format(name=name, value=value)
return r'\set@{name}{{{value}}'.format(name=name, value=value) + EOL
def clean(basename):
@ -122,7 +125,7 @@ def makeTexFile(sb, output):
if "titleprefixwords" in sb:
prefixes = sb["titleprefixwords"]
for prefix in sb["titleprefixwords"]:
prefixes_tex += "\\titleprefixword{%s}\n" % prefix
prefixes_tex += r"\titleprefixword{%s}" % prefix +
sb["titleprefixwords"] = prefixes_tex
if "authwords" in sb:
# Populating default value
@ -134,9 +137,9 @@ def makeTexFile(sb, output):
for key in ["after", "sep", "ignore"]:
for word in authwords[key]:
if key == "after":
authwords_tex += "\\auth%sword{%s}\n" % ("by", word)
authwords_tex += r"\auth%sword{%s}" % ("by", word) + EOL
else:
authwords_tex += "\\auth%sword{%s}\n" % (key, word)
authwords_tex += r"\auth%sword{%s}" % (key, word) + EOL
sb["authwords"] = authwords_tex
if "after" in authwords:
authwords["after"] = [re.compile(r"^.*%s\b(.*)" % after)
@ -174,7 +177,7 @@ def makeTexFile(sb, output):
# output relevant fields
out = codecs.open(output, 'w', 'utf-8')
out.write('%% This file has been automatically generated, do not edit!\n')
out.write('\\makeatletter\n')
out.write(r'\makeatletter' + EOL)
# output automatic parameters
out.write(formatDeclaration("name", {"default": name}))
out.write(formatDeclaration("songslist", {"type": "stringlist"}))
@ -188,7 +191,7 @@ def makeTexFile(sb, output):
if len(songs) > 0:
out.write(formatDefinition('songslist', songslist.latex()))
out.write('\\makeatother\n')
out.write(r'\makeatother' + EOL)
# output template
commentPattern = re.compile(r"^\s*%")
@ -213,7 +216,7 @@ def makeTexFile(sb, output):
)
else:
imgdir = os.path.abspath(os.path.join(datadir, "img"))
line = line.replace("\\getDataImgDirectory", ' {%s/} ' % imgdir)
line = line.replace(r"\getDataImgDirectory", ' {%s/} ' % imgdir)
content[index] = line
out.write(u''.join(content))

15
songbook/index.py

@ -12,11 +12,12 @@ from unidecode import unidecode
import locale
import re
import sys
#import warnings
from songbook.authors import processauthors
from songbook.plastex import simpleparse
EOL = "\n"
# Pattern set to ignore latex command in title prefix
keywordPattern = re.compile(r"^%(\w+)\s?(.*)$")
firstLetterPattern = re.compile(r"^(?:\{?\\\w+\}?)*[^\w]*(\w)")
@ -137,21 +138,21 @@ class index:
def refToStr(self, ref):
if sys.version_info >= (2, 6):
return '\\hyperlink{{{0[link]}}}{{{0[num]}}}'.format(ref)
return r'\hyperlink{{{0[link]}}}{{{0[num]}}}'.format(ref)
else:
return '\\hyperlink{%(link)s}{%(num)s}' % ref
return r'\hyperlink{%(link)s}{%(num)s}' % ref
def entryToStr(self, key, entry):
if sys.version_info >= (2, 6):
return unicode('\\idxentry{{{0}}}{{{1}}}\n').format(key, '\\\\'.join(map(self.refToStr, entry)))
return unicode(r'\idxentry{{{0}}}{{{1}}}' + EOL).format(key, r'\\'.join(map(self.refToStr, entry)))
else:
return unicode('\\idxentry{%s}{%s}\n') % (key, '\\\\'.join(map(self.refToStr, entry)))
return unicode(r'\idxentry{%s}{%s}' + EOL) % (key, r'\\'.join(map(self.refToStr, entry)))
def idxBlockToStr(self, letter, entries):
string = '\\begin{idxblock}{' + letter + '}' + '\n'
string = r'\begin{idxblock}{' + letter + '}' + EOL
for key in sorted(entries.keys(), key=sortkey):
string += self.entryToStr(key, entries[key])
string += '\\end{idxblock}' + '\n'
string += r'\end{idxblock}' + EOL
return string
def entriesToStr(self):

4
songbook/plastex.py

@ -61,14 +61,14 @@ class SongParser:
def parsetex(filename):
"""Analyse syntaxique d'un fichier .sg
r"""Analyse syntaxique d'un fichier .sg
Renvoie un dictionnaire contenant les métadonnées lues dans le fichier. Les
clefs sont :
- languages: l'ensemble des langages utilisés (recherche des
\selectlanguages{}) ;
- titles: la liste des titres ;
- args: le dictionnaire des paramètres passés à \\beginsong.
- args: le dictionnaire des paramètres passés à \beginsong.
"""
# /* BEGIN plasTeX patch
# The following lines, and another line a few lines later, are used to

4
songbook/songs.py

@ -124,9 +124,9 @@ class SongsList:
def latex(self):
"""Renvoie le code LaTeX nécessaire pour intégrer la liste de chansons.
"""
result = ['\\input{{{0}}}'.format(song.path.replace("\\", "/").strip())
result = [r'\input{{{0}}}'.format(song.path.replace("\\", "/").strip())
for song in self.songs]
result.append('\\selectlanguage{%s}' % self._language)
result.append(r'\selectlanguage{%s}' % self._language)
return '\n'.join(result)
def languages(self):

Loading…
Cancel
Save