2022-02-08 17:21:36 +01:00
|
|
|
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
|
2022-02-09 19:50:49 +01:00
|
|
|
from .enums import TeXFlavour, TeXType, FormatterProperty
|
2022-02-06 19:40:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
class SimpleTeXFormatter(TexFormatter):
|
2022-02-09 17:42:56 +01:00
|
|
|
@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
|
2022-02-08 17:21:36 +01:00
|
|
|
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]:
|
2022-02-09 17:42:56 +01:00
|
|
|
return [self.output_file]
|
2022-02-09 15:56:15 +01:00
|
|
|
|
|
|
|
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()
|
2022-02-09 19:50:49 +01:00
|
|
|
|
|
|
|
def format_post_header(self) -> None:
|
2022-02-09 21:11:46 +01:00
|
|
|
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]
|
|
|
|
)
|
2022-02-09 19:50:49 +01:00
|
|
|
)
|
2022-02-09 21:11:46 +01:00
|
|
|
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
|
|
|
|
)
|
2022-02-09 19:50:49 +01:00
|
|
|
)
|