From bb05a3c913ec15296eb3ebbb77452d0cc65e42e5 Mon Sep 17 00:00:00 2001 From: Jiri Kalvoda Date: Wed, 3 Apr 2024 10:51:48 +0200 Subject: [PATCH] Floatpage --- src/formatitko/tex/formatitko.tex | 16 ++++++++++----- src/formatitko/tex_generator.py | 34 ++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/formatitko/tex/formatitko.tex b/src/formatitko/tex/formatitko.tex index f6b6a6a..19ce5c8 100644 --- a/src/formatitko/tex/formatitko.tex +++ b/src/formatitko/tex/formatitko.tex @@ -168,10 +168,10 @@ \fi }} -% Obecny plovouci objekt: \float{objekt}{popisek}{optional-id} -\def\float#1#2#3{\floatinsert{ -\medskip -\centerline{#1} +% Obecny plovouci objekt: \float{objekt}{popisek}{mezera pred}{mezera po} +\def\figure#1#2#3#4{ +\medskip#3 +\centerline{#1}#4 \medskip \smallskip { @@ -189,7 +189,13 @@ #2 }} \fi -}}} +}} + +\def\floatpage#1{ +\pageinsert +\vbox to \vsize{#1} +\endinsert +} % Dva floaty vedle sebe: \float{objekt1}{popisek1}{id1}{objekt2}{popisek2}{id2} \def\twofloats#1#2#3#4#5#6{\floatinsert{ diff --git a/src/formatitko/tex_generator.py b/src/formatitko/tex_generator.py index 3e5d76a..344742f 100644 --- a/src/formatitko/tex_generator.py +++ b/src/formatitko/tex_generator.py @@ -24,6 +24,8 @@ class UCWTexGenerator(OutputGenerator): self.imageProcessor = imageProcessor self._bold = 0 self._italic = 0 + + self._floatpages = {} super().__init__(output_file, *args, **kwargs) def escape_special_chars(self, text: str) -> str: @@ -159,9 +161,8 @@ class UCWTexGenerator(OutputGenerator): self.write(e.text) self.write(r"`") - def generate_Figure(self, e: Figure): - self.ensure_empty(2) - self.writeln(r"\float{") + def generate_nonfloat_Figure(self, e: Figure): + self.writeln(r"\figure{") self.indent_more() self.generate(e.content) self.indent_less() @@ -177,8 +178,31 @@ class UCWTexGenerator(OutputGenerator): self.indent_less() self.writeln("}") self.indent_less() - self.writeln(r"}{}") - self.ensure_empty(2) + self.writeln(r"}{}{}") + + + 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): if self._bold > 0: