pytex/PyTeX/format/simple_tex_formatter.py

38 lines
1.1 KiB
Python
Raw Normal View History

from .formatting_config import FormattingConfig
2022-02-06 19:40:14 +01:00
from .tex_formatter import TexFormatter
2022-02-08 17:04:16 +01:00
from pathlib import Path
from typing import Optional, List, Tuple, Dict
from .enums import TeXFlavour, TeXType
2022-02-06 19:40:14 +01:00
class SimpleTeXFormatter(TexFormatter):
@property
def output_file(self) -> str:
switcher = {
TeXType.TeXClass: '.cls',
TeXType.TeXPackage: '.sty',
}
return self.name + switcher[self.config.tex_type]
2022-02-08 17:04:16 +01:00
def close_output_stream(self):
self._output_file.close()
2022-02-08 23:54:29 +01:00
@property
def future_config(self) -> List[Tuple[str, FormattingConfig]]:
return [] # TODO
2022-02-08 17:04:16 +01:00
2022-02-08 23:34:18 +01:00
@property
2022-02-08 17:04:16 +01:00
def dependencies(self) -> List[str]:
2022-02-08 17:40:08 +01:00
return [] # sty / cls file does not depend on anything
2022-02-08 17:04:16 +01:00
2022-02-08 18:26:25 +01:00
@property
2022-02-08 17:04:16 +01:00
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()