implement first version of dtx formatter
This commit is contained in:
parent
add194ce62
commit
94640f9eff
1 changed files with 62 additions and 5 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
from .constants import INS_FILE, DRV_FILE
|
||||||
|
from .enums import TeXFlavour, FormatterProperty, TeXType, FormatterMode
|
||||||
|
from .generic_text import GenericText
|
||||||
from .tex_formatter import TexFormatter
|
from .tex_formatter import TexFormatter
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -14,10 +17,64 @@ class DTXFormatter(TexFormatter):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def output_files(self) -> List[str]:
|
def output_files(self) -> List[str]:
|
||||||
return [] # TODO
|
files = [self.name + '.dtx']
|
||||||
|
if self.config.include_drv:
|
||||||
|
files.append(self.name + '.drv')
|
||||||
|
if self.config.include_ins:
|
||||||
|
files.append(self.name + '.ins')
|
||||||
|
return files
|
||||||
|
|
||||||
def open_output_stream(self, build_dir: Path) -> None:
|
def _get_internal_file(self) -> str:
|
||||||
pass
|
g = GenericText(INS_FILE)
|
||||||
|
switcher = {
|
||||||
|
TeXType.TeXPackage: '.sty',
|
||||||
|
TeXType.TeXClass: '.cls'
|
||||||
|
}
|
||||||
|
return g.format(
|
||||||
|
infile=self.name + '.dtx',
|
||||||
|
outfile=self.name + switcher[self.config.tex_out_type],
|
||||||
|
preamble='', # TODO
|
||||||
|
postamble='', # TODO
|
||||||
|
guards=', '.join(self.config.docstrip_guards)
|
||||||
|
)
|
||||||
|
|
||||||
def close_output_stream(self) -> None:
|
def _get_drv_file(self) -> str:
|
||||||
pass
|
g = GenericText(DRV_FILE)
|
||||||
|
return g.format(
|
||||||
|
documentclass='l3doc', # TODO
|
||||||
|
preamble='', # TODO
|
||||||
|
infile=self.name + '.dtx',
|
||||||
|
)
|
||||||
|
|
||||||
|
def format_pre_header(self) -> None:
|
||||||
|
self._shipout_line(r'% \iffalse meta-comment')
|
||||||
|
|
||||||
|
def format_post_header(self) -> None:
|
||||||
|
self._shipout_line('%</internal>')
|
||||||
|
self._shipout_line(
|
||||||
|
self._get_internal_file()
|
||||||
|
)
|
||||||
|
self._shipout_line('%')
|
||||||
|
self._shipout_line(
|
||||||
|
'%<{outtype}>{provides}'.format(
|
||||||
|
outtype=self.config.tex_out_type.value,
|
||||||
|
provides=self._get_provides_text()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self._shipout_line('%')
|
||||||
|
self._shipout_line('%<*driver>')
|
||||||
|
self._shipout_line(
|
||||||
|
self._get_drv_file()
|
||||||
|
)
|
||||||
|
self._shipout_line('%</driver>')
|
||||||
|
self._shipout_line(r'% \fi')
|
||||||
|
self._shipout_line('%')
|
||||||
|
|
||||||
|
def _post_process_line(self, line: str) -> str:
|
||||||
|
line = line.rstrip(' %\n')
|
||||||
|
if self.mode == FormatterMode.meta:
|
||||||
|
line = '% ' + line
|
||||||
|
if self.mode == FormatterMode.macrocode:
|
||||||
|
if self.config.tex_flavour == TeXFlavour.LaTeX2e:
|
||||||
|
line = line.rstrip(' %\n') + '%'
|
||||||
|
return line
|
||||||
|
|
Loading…
Reference in a new issue