def latexfile_preamble(list_of_packages=[]):
    string = "\documentclass{article}\n"
    string += "\\usepackage{amsmath}\n"
    string += "\\usepackage{amssymb}\n"
    string += "\\usepackage{graphicx}\n"
    
    for package in list_of_packages:
        string += latex_protect("\\usepackage{")+ package +"}\n"
    return string
def latexfile_append_question(question): #Given a Question return the latex string
    content = ""
    if question.structure['name']['isset']: # First the title
        content += latexfile_command(alias('name'), question.get_name())
    content += latex_protect(question.get_text()) + '\n'
    option = question.get_type()
    if question.has_answer():
        content += '\n'
        for answer in question.get_answer():
            content += latexfile_command('answer', answer.get_text(), str(answer.get_relativegrade()))
    content += '\n'
    for field in question.structure:
        if field not in ['@type', 'questiontext', 'answer', 'name']: # keep it for later/before
            if question.structure[field]['isset']: # if default we dont print it
                content += latexfile_command(alias(field), question.structure[field]['value'])
    return latexfile_environement('question', content, option)
def latexfile_end(env_name):
    return latex_protect('\end{' + env_name + '}') + '\n'
def latexfile_command(cmd_name, value, option = None):
    string = latex_protect("\\" + cmd_name )
    if option is not None:
        string += '[' + str(option) + ']'
    string += '{' + latex_protect(str(value)) + '}\n'
    return string
def latexfile_begin(env_name, option = None):
    string = latex_protect('\begin{' + env_name + '}')
    if option is not None:
        string += '[' + str(option) + ']'        
    return string + '\n'