diff --git a/quizgen.py b/quizgen.py index 9a73fdb..6dfcde4 100755 --- a/quizgen.py +++ b/quizgen.py @@ -434,8 +434,10 @@ def add_dom_to_template(dom, html_file_name, quiz): # Add the header. By replacing this early, we allow the header to # contain IMG and LINK tags (or even CODE), though it would typically # be pure HTML + content = content.replace('[STYLES_SCRIPTS]', get_head()); content = content.replace('[SUBMIT_LABEL]', _('Submit')) content = content.replace('[HIDE_LABEL]', _('Hide')) + content = content.replace('[TEX]', get_tex()) content = content.replace('[HEADER]', get_header()) content = content.replace('[TITLE]', quiz['title']) content = content.replace('[BODY]', dom.toprettyxml()) @@ -549,6 +551,28 @@ def get_header(): else: header = header_file.read() return header + +# If the HTML contents file exist return the content of that +# file, otherwise return the STYLES_SCRIPTS. +custom_head = False +def get_head(): + global custom_head + try: + header_file = open('head.html') + except IOError: + header = STYLES_SCRIPTS + else: + header = header_file.read() + custom_head = True + return header + +# Returns standard TeX header with standard HTML and empty +# string otherwise. +def get_tex(): + if not custom_head: + return r"""$\newcommand{\ones}{\mathbf 1}$""" + else: + return '' # Should a footer file exist return the content of that file # otherwise return the standard footer @@ -654,24 +678,8 @@ def main(): - [TITLE] - - - - - - - - - + [STYLES_SCRIPTS] + + + + + +""" if __name__ == '__main__': main()