from .formatting_config import FormattingConfig from .tex_formatter import TexFormatter from pathlib import Path from typing import Optional, List, Tuple, Dict from .enums import TeXFlavour, TeXType, FormatterProperty class SimpleTeXFormatter(TexFormatter): @property def output_file(self) -> str: switcher = { TeXType.TeXClass: '.cls', TeXType.TeXPackage: '.sty', } return self.name + switcher[self.config.tex_type] def close_output_stream(self): self._output_file.close() @property def future_config(self) -> List[Tuple[str, FormattingConfig]]: return [] # TODO @property def dependencies(self) -> List[str]: return [] # sty / cls file does not depend on anything @property def output_files(self) -> List[str]: return [self.output_file] def _post_process_line(self, line: str) -> str: if self.config.tex_flavour == TeXFlavour.LaTeX2e: raw = line.rstrip(' %\n') return '' if raw == '' else raw + '%' else: return line.rstrip() def format_post_header(self) -> None: if self.config.has_description: if self.config.tex_flavour == TeXFlavour.LaTeX2e: self._shipout_line( r'\Provides%s{%s}[%s - %s]' % ( self.config.tex_type.value.capitalize(), self.name, self.attribute_dict[FormatterProperty.date.value], self.attribute_dict[FormatterProperty.description.value] ) ) else: self._shipout_line( '\\ProvidesExpl%s { %s } { %s } { %s }\n { %s }' % ( self.config.tex_type.value.capitalize(), self.name, self.attribute_dict[FormatterProperty.date.value], self.config.version, self.config.description ) )