forked from jtauber/greek-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackends.py
111 lines (81 loc) · 3.21 KB
/
backends.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from utils import load_yaml
class LaTeX:
def __init__(self):
self.settings = load_yaml("LaTeX.yaml")
def lang_code(self, language):
return self.settings['languages'][language]
def preamble(self, typeface, language):
return """
\\documentclass[a4paper,12pt]{{scrartcl}}
\\usepackage{{setspace}}
\\usepackage{{fontspec}}
\\usepackage{{pfnote}}
\\usepackage{{polyglossia}}
\\setdefaultlanguage[variant=ancient]{{greek}}
\\setotherlanguage{{{language}}}
\\setromanfont{{{typeface}}}
\\linespread{{1.5}}
\\onehalfspacing
\\makeatletter
\\renewcommand\\@makefntext[1]{{\\leftskip=2em\\hskip-2em\\@makefnmark#1}}
\\makeatother
\\begin{{document}}
""".format(typeface=typeface, language=self.lang_code(language))
def book_chapter_verse(self, book, chapter, verse):
return """
\\textbf{{\Large {}.{}.{}}}~""".format(book, chapter, verse)
def chapter_verse(self, chapter, verse):
return """
\\textbf{{\Large {}.{}}}~""".format(chapter, verse)
def verse(self, verse):
return "\\textbf{{{}}}~".format(verse)
def word(self, text, headword=None, parse=None, gloss=None, language=None):
if headword is None and parse is None and gloss is None:
return text
else:
footnote = []
if headword:
footnote.append(headword)
if parse:
footnote.append("\\textendash\\ {}".format(parse))
if gloss:
footnote.append("\\textendash\\ \\text{}{{\\textit{{{}}}}}".format(self.lang_code(language), gloss))
return "{}\\footnote{{{}}}".format(text, " ".join(footnote))
def comment(self, text):
return "% {}".format(text)
def postamble(self):
return "\\end{document}"
class SILE:
def __init__(self):
self.settings = load_yaml("SILE.yaml")
def lang_code(self, language):
return self.settings['languages'][language]
def preamble(self, typeface, language):
return """\
\\begin[papersize=a4,class=book]{{document}}
\\font[family="{typeface}",size=12pt,language=el]
\\set[parameter=document.lineskip,value=6pt]
""".format(typeface=typeface)
def book_chapter_verse(self, book, chapter, verse):
return "\\font[size=16pt,weight=700]{{{}.{}.{}}} \\nobreak".format(
book, chapter, verse)
def chapter_verse(self, chapter, verse):
return "\\font[size=16pt,weight=700]{{{}.{}}} \\nobreak".format(chapter, verse)
def verse(self, verse):
return "\\font[weight=700]{{{}}} \\nobreak".format(verse)
def word(self, text, headword=None, parse=None, gloss=None, language=None):
if headword is None and parse is None and gloss is None:
return text
else:
footnote = []
if headword:
footnote.append(headword)
if parse:
footnote.append("– {}".format(parse))
if gloss:
footnote.append("– \\font[style=italic,language={}]{{{}}}".format(self.lang_code(language), gloss))
return "{}\\footnote{{{}}} %".format(text, " ".join(footnote))
def comment(self, text):
return "% {}".format(text)
def postamble(self):
return "\\end{document}"