1 """Latex output utility functions to help with producing valid Latex files.
2
3 Utility functions for handling processing and output of Latex.
4
5 """
6 """
7 ============================== License ========================================
8 Copyright (C) 2008, 2010-12 University of Edinburgh, Mark Granroth-Wilding
9
10 This file is part of The Jazz Parser.
11
12 The Jazz Parser is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 The Jazz Parser is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with The Jazz Parser. If not, see <http://www.gnu.org/licenses/>.
24
25 ============================ End license ======================================
26
27 """
28 __author__ = "Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>"
29
31 """
32 Applies necessary filters to Latex text before outputting. Mainly
33 involves escaping strings.
34
35 """
36 text = text.replace("#","\\#")
37 text = text.replace("%","\\%")
38 text = text.replace("_", "\\_")
39 return text
40
41 -def start_document(title=None, author=None, packages=[], options=[], toc=False):
42 output = ""
43 output += "\\documentclass[%s]{article}\n" % ",".join(options+['a4paper'])
44 for package in packages:
45 output += "\\usepackage{%s}\n" % package
46 output += "\\begin{document}\n"
47 if title is not None:
48 output += "\\title{%s}\n" % title
49 if author is not None:
50 output += "\\author{%s}\n" % author
51 else:
52 output += "\\author{}\n"
53 output += "\\maketitle\n"
54 if toc:
55 output += "\\tableofcontents\n"
56 return output
57