quizcomp.converter.tex
1import os 2import typing 3 4import quizcomp.converter.template 5import quizcomp.model.constants 6import quizcomp.model.quiz 7import quizcomp.parser.document 8 9THIS_DIR: str = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) 10DEFAULT_TEMPLATE_DIR: str = os.path.join(THIS_DIR, '..', 'data', 'templates', 'edq-tex') 11 12JINJA_OPTIONS: typing.Dict[str, str] = { 13 'block_start_string': '<%', 14 'block_end_string': '%>', 15 'variable_start_string': '<<', 16 'variable_end_string': '>>', 17 'comment_start_string': '<#', 18 'comment_end_string': '#>', 19} 20 21class TexTemplateConverter(quizcomp.converter.template.TemplateConverter): 22 """ 23 A converter to convert a quiz to TeX using templates. 24 """ 25 26 def __init__(self, 27 template_dir: str = DEFAULT_TEMPLATE_DIR, 28 **kwargs: typing.Any) -> None: 29 super().__init__( 30 quizcomp.model.constants.Format.TEX, 31 template_dir, 32 jinja_options = JINJA_OPTIONS, 33 jinja_filters = { 34 'clean_label': _clean_label, 35 }, 36 **kwargs, 37 ) 38 39 def prepare(self, quiz: quizcomp.model.quiz.Quiz) -> None: 40 self._store_images(quiz) 41 42 def finalize(self, quiz: quizcomp.model.quiz.Quiz, text: str) -> str: 43 self._restore_image_sources(quiz) 44 45 return text 46 47def _clean_label(text: str) -> str: 48 """ Clean label text for TeX. """ 49 50 return quizcomp.parser.document.ParsedDocument.parse_text(text).to_tex()
THIS_DIR: str =
'/home/runner/work/quiz-composer/quiz-composer/quizcomp/converter'
DEFAULT_TEMPLATE_DIR: str =
'/home/runner/work/quiz-composer/quiz-composer/quizcomp/converter/../data/templates/edq-tex'
JINJA_OPTIONS: Dict[str, str] =
{'block_start_string': '<%', 'block_end_string': '%>', 'variable_start_string': '<<', 'variable_end_string': '>>', 'comment_start_string': '<#', 'comment_end_string': '#>'}
22class TexTemplateConverter(quizcomp.converter.template.TemplateConverter): 23 """ 24 A converter to convert a quiz to TeX using templates. 25 """ 26 27 def __init__(self, 28 template_dir: str = DEFAULT_TEMPLATE_DIR, 29 **kwargs: typing.Any) -> None: 30 super().__init__( 31 quizcomp.model.constants.Format.TEX, 32 template_dir, 33 jinja_options = JINJA_OPTIONS, 34 jinja_filters = { 35 'clean_label': _clean_label, 36 }, 37 **kwargs, 38 ) 39 40 def prepare(self, quiz: quizcomp.model.quiz.Quiz) -> None: 41 self._store_images(quiz) 42 43 def finalize(self, quiz: quizcomp.model.quiz.Quiz, text: str) -> str: 44 self._restore_image_sources(quiz) 45 46 return text
A converter to convert a quiz to TeX using templates.
TexTemplateConverter( template_dir: str = '/home/runner/work/quiz-composer/quiz-composer/quizcomp/converter/../data/templates/edq-tex', **kwargs: Any)