Compare commits

...

2 Commits

  1. 16
      src/formatitko/tex/formatitko.tex
  2. 38
      src/formatitko/tex_generator.py

16
src/formatitko/tex/formatitko.tex

@ -168,10 +168,10 @@
\fi \fi
}} }}
% Obecny plovouci objekt: \float{objekt}{popisek}{optional-id} % Obecny plovouci objekt: \float{objekt}{popisek}{mezera pred}{mezera po}
\def\float#1#2#3{\floatinsert{ \def\figure#1#2#3#4{
\medskip \medskip#3
\centerline{#1} \centerline{#1}#4
\medskip \medskip
\smallskip \smallskip
{ {
@ -189,7 +189,13 @@
#2 #2
}} }}
\fi \fi
}}} }}
\def\floatpage#1{
\pageinsert
\vbox to \vsize{#1}
\endinsert
}
% Dva floaty vedle sebe: \float{objekt1}{popisek1}{id1}{objekt2}{popisek2}{id2} % Dva floaty vedle sebe: \float{objekt1}{popisek1}{id1}{objekt2}{popisek2}{id2}
\def\twofloats#1#2#3#4#5#6{\floatinsert{ \def\twofloats#1#2#3#4#5#6{\floatinsert{

38
src/formatitko/tex_generator.py

@ -24,6 +24,8 @@ class UCWTexGenerator(OutputGenerator):
self.imageProcessor = imageProcessor self.imageProcessor = imageProcessor
self._bold = 0 self._bold = 0
self._italic = 0 self._italic = 0
self._floatpages = {}
super().__init__(output_file, *args, **kwargs) super().__init__(output_file, *args, **kwargs)
def escape_special_chars(self, text: str) -> str: def escape_special_chars(self, text: str) -> str:
@ -159,9 +161,8 @@ class UCWTexGenerator(OutputGenerator):
self.write(e.text) self.write(e.text)
self.write(r"`") self.write(r"`")
def generate_Figure(self, e: Figure): def generate_nonfloat_Figure(self, e: Figure):
self.ensure_empty(2) self.writeln(r"\figure{")
self.writeln(r"\float{")
self.indent_more() self.indent_more()
self.generate(e.content) self.generate(e.content)
self.indent_less() self.indent_less()
@ -177,8 +178,31 @@ class UCWTexGenerator(OutputGenerator):
self.indent_less() self.indent_less()
self.writeln("}") self.writeln("}")
self.indent_less() self.indent_less()
self.writeln(r"}{}") self.writeln(r"}{}{}")
self.ensure_empty(2)
def generate_Figure(self, e: Figure):
if "floatpage" in e.attributes:
fp = e.attributes["floatpage"]
flush = fp[-1]=="!"
if flush:
fp = fp[:-1]
self._floatpages.setdefault(fp, [])
self._floatpages[fp].append(e)
if flush:
self.writeln(r"\floatpage{")
self.writeln(r"\vfill")
for x in self._floatpages[fp]:
self.generate_nonfloat_Figure(x)
self.writeln(r"\vfill")
self.writeln(r"}")
del self._floatpages[fp]
else:
self.ensure_empty(2)
self.writeln(r"\floatinsert{")
self.generate_nonfloat_Figure(e)
self.writeln(r"}")
self.ensure_empty(2)
def generate_Emph(self, e: Emph): def generate_Emph(self, e: Emph):
if self._bold > 0: if self._bold > 0:
@ -236,9 +260,9 @@ class UCWTexGenerator(OutputGenerator):
self.writeln(r"\halign{\strut"+"&".join([aligns[col[0]] for col in e.colspec])+r"\cr") self.writeln(r"\halign{\strut"+"&".join([aligns[col[0]] for col in e.colspec])+r"\cr")
self.indent_more() self.indent_more()
self.generate(e.head.content) self.generate(e.head.content)
self.writeln(r"\noalign{\hrule}") self.writeln(r"\noalign{\vskip 0.3em\hrule\vskip 0.3em}")
self.generate(e.content[0].content) self.generate(e.content[0].content)
self.writeln(r"\noalign{\hrule}") self.writeln(r"\noalign{\vskip 0.3em\hrule\vskip 0.3em}")
self.generate(e.foot.content) self.generate(e.foot.content)
self.indent_less() self.indent_less()
self.writeln("}") self.writeln("}")

Loading…
Cancel
Save