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: self._shipout_line(self._get_provides_text())