diff --git a/src/formatitko/formatitko.tex b/src/formatitko/formatitko.tex index b03446f..1c60d80 100644 --- a/src/formatitko/formatitko.tex +++ b/src/formatitko/formatitko.tex @@ -134,3 +134,60 @@ \def\mod{\mathrel{\rm mod}} \settextsize{12} + + +\def\unparskip{\vskip-\parskip} + +\def\floatinsert#1{\par{ + \setbox0=\vbox{\boxmaxdepth=2pt\relax #1} + \dimen0=\dimexpr \ht0 + \dp0 + \baselineskip + \pagetotal - \pageshrink \relax + \ifdim\dimen0 > \pagegoal + \insert\topins{ + \penalty 100 + \splittopskip=0pt + \splitmaxdepth=\maxdimen + \floatingpenalty=0 + \box0 + \nobreak\bigskip\medskip + } + \else + \goodbreak\bigskip + \box0 + \goodbreak\bigskip + \unparskip + \fi +}} + +% Obecny plovouci objekt: \float{objekt}{popisek}{optional-id} +\def\float#1#2#3{\floatinsert{ +\medskip +\centerline{#1} +\medskip +\smallskip +{ + \setbox0=\hbox{#2} + \ifdim\wd0 < 0.8\hsize + \centerline{\box0} + \else + \centerline{\vtop{ + \hsize=0.8\hsize + \parindent=0pt + \leftskip=0pt plus 0.3\hsize + \rightskip=0pt plus 0.3\hsize + \parfillskip=0pt + \spaceskip=0.3333em + #2 + }} + \fi +}}} + +% Dva floaty vedle sebe: \float{objekt1}{popisek1}{id1}{objekt2}{popisek2}{id2} +\def\twofloats#1#2#3#4#5#6{\floatinsert{ +\medskip +\centerline{\vbox{\halign{\hss##\hss&\qquad\hss##\hss\cr +#1\cr +\noalign{\medskip\smallskip} +#2\cr +}}} +}} + diff --git a/src/formatitko/tex_generator.py b/src/formatitko/tex_generator.py index 20f6d4a..3bd56a9 100644 --- a/src/formatitko/tex_generator.py +++ b/src/formatitko/tex_generator.py @@ -155,20 +155,17 @@ class UCWTexGenerator(OutputGenerator): def generate_Figure(self, e: Figure): self.ensure_empty(2) - self.writeln(r"\vskip5pt") - self.writeln(r"\centerline{") + self.writeln(r"\float{") self.indent_more() self.generate(e.content) self.indent_less() - self.writeln(r"}") - self.writeln(r"\centerline{") + self.writeln(r"}{") self.indent_more() if 'number' in e.attributes: self.writeln(f"Obrázek {e.attributes['number']}:") self.generate(e.caption) self.indent_less() - self.writeln(r"}") - self.writeln(r"\vskip5pt{}") + self.writeln(r"}{}") self.ensure_empty(2) def generate_Emph(self, e: Emph):