1
2 import re, sys
3 from common import default_movie, plain_exercise
4
5 -def plain_author(authors_and_institutions, auth2index,
6 inst2index, index2inst, auth2email):
7 text = '\n'
8 for author in auth2index:
9 email = auth2email[author]
10 email_text = '' if email is None else '(%s)' % email
11 text += ' '.join([author, str(auth2index[author]), email_text]) + '\n'
12 text += '\n'
13 for index in index2inst:
14 text += '[%d] %s\n' % (index, index2inst[index])
15 text += '\n'
16 return text
17
19
20
21 pattern = r'[Ss]ection(s?)\s+ref\{'
22 replacement = r'the section\g<1> ref{'
23 filestr = re.sub(pattern, replacement, filestr)
24 pattern = r'[Cc]hapter(s?)\s+ref\{'
25 replacement = r'the chapter\g<1> ref{'
26 filestr = re.sub(pattern, replacement, filestr)
27
28
29
30
31 cpattern = re.compile(r'^label\{.+?\}\s*$', flags=re.MULTILINE)
32 filestr = cpattern.sub('', filestr)
33
34 cpattern = re.compile(r'^(FIGURE:.+)label\{(.+?)\}', flags=re.MULTILINE)
35 filestr = cpattern.sub('\g<1>{\g<2>}', filestr)
36 filestr = re.sub(r'label\{.+?\}', '', filestr)
37
38
39 for label in section_label2title:
40 filestr = filestr.replace('ref{%s}' % label,
41 '"%s"' % section_label2title[label])
42
43 from common import ref2equations
44 filestr = ref2equations(filestr)
45
46 return filestr
47
49 """Transform dict with bibliography to a doconce ordered list."""
50 f = open(pyfile, 'r')
51 bibstr = f.read()
52 try:
53 bibdict = eval(bibstr)
54 except:
55 print 'Error in Python dictionary for bibliography in', pyfile
56 sys.exit(1)
57 text = '\n\n======= Bibliography =======\n\n'
58 for label in citations:
59
60 text += ' o ' + ' '.join(bibdict[label].splitlines()) + '\n'
61 text += '\n\n'
62 return text
63
65 for label in citations:
66 filestr = filestr.replace('cite{%s}' % label,
67 '[%d]' % citations[label])
68 if 'py' in bibfile:
69 bibtext = bibdict2doconcelist(bibfile['py'], citations)
70
71 cpattern = re.compile(r'^BIBFILE:.+$', flags=re.MULTILINE)
72 filestr = cpattern.sub(bibtext, filestr)
73
74
75 filestr = re.sub(r'idx\{.+?\}\n?', '', filestr)
76
77
78
79
80
81
82 return filestr
83
84 -def define(FILENAME_EXTENSION,
85 BLANKLINE,
86 INLINE_TAGS_SUBST,
87 CODE,
88 LIST,
89 ARGLIST,
90 TABLE,
91 EXERCISE,
92 FIGURE_EXT,
93 CROSS_REFS,
94 INDEX_BIB,
95 INTRO,
96 OUTRO):
97
98
99 FILENAME_EXTENSION['plain'] = '.txt'
100 BLANKLINE['plain'] = '\n'
101
102 INLINE_TAGS_SUBST['plain'] = {
103 'math': r'\g<begin>\g<subst>\g<end>',
104 'math2': r'\g<begin>\g<puretext>\g<end>',
105 'emphasize': None,
106 'bold': None,
107 'figure': None,
108 'movie': default_movie,
109 'verbatim': r'\g<begin>\g<subst>\g<end>',
110 'linkURL': r'\g<begin>\g<link> (\g<url>)\g<end>',
111 'linkURL2': r'\g<link> (\g<url>)',
112 'linkURL3': r'\g<link> (\g<url>)',
113 'linkURL2v': r'\g<link> (\g<url>)',
114 'linkURL3v': r'\g<link> (\g<url>)',
115 'plainURL': r'\g<url>',
116 'title': r'======= \g<subst> =======\n',
117 'author': plain_author,
118 'date': r'\nDate: \g<subst>\n',
119 'chapter': lambda m: r'\g<subst>\n%s' % ('%'*len(m.group('subst').decode('utf-8'))),
120 'section': lambda m: r'\g<subst>\n%s' % ('='*len(m.group('subst').decode('utf-8'))),
121 'subsection': lambda m: r'\g<subst>\n%s' % ('-'*len(m.group('subst').decode('utf-8'))),
122 'subsubsection': lambda m: r'\g<subst>\n%s' % ('~'*len(m.group('subst').decode('utf-8'))),
123 'paragraph': r'*\g<subst>* ',
124 'abstract': r'\n*\g<type>.* \g<text>\g<rest>',
125 }
126
127 from rst import rst_code
128 CODE['plain'] = rst_code
129 from common import DEFAULT_ARGLIST
130 ARGLIST['plain'] = DEFAULT_ARGLIST
131 LIST['plain'] = {
132 'itemize':
133 {'begin': '', 'item': '*', 'end': '\n'},
134
135 'enumerate':
136 {'begin': '', 'item': '%d.', 'end': '\n'},
137
138 'description':
139 {'begin': '', 'item': '%s', 'end': '\n'},
140
141 'separator': '\n',
142 }
143 CROSS_REFS['plain'] = plain_ref_and_label
144 from rst import rst_table
145 TABLE['plain'] = rst_table
146 EXERCISE['plain'] = plain_exercise
147
148 INDEX_BIB['plain'] = plain_index_bib
149
150
151