Browse Source

UCWTeX: Figure je float

jk-bakalarka
Jiří Kalvoda 9 months ago
parent
commit
945bb760e8
  1. 57
      src/formatitko/formatitko.tex
  2. 9
      src/formatitko/tex_generator.py

57
src/formatitko/formatitko.tex

@ -134,3 +134,60 @@
\def\mod{\mathrel{\rm mod}} \def\mod{\mathrel{\rm mod}}
\settextsize{12} \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&#4\cr
\noalign{\medskip\smallskip}
#2&#5\cr
}}}
}}

9
src/formatitko/tex_generator.py

@ -155,20 +155,17 @@ class UCWTexGenerator(OutputGenerator):
def generate_Figure(self, e: Figure): def generate_Figure(self, e: Figure):
self.ensure_empty(2) self.ensure_empty(2)
self.writeln(r"\vskip5pt") self.writeln(r"\float{")
self.writeln(r"\centerline{")
self.indent_more() self.indent_more()
self.generate(e.content) self.generate(e.content)
self.indent_less() self.indent_less()
self.writeln(r"}") self.writeln(r"}{")
self.writeln(r"\centerline{")
self.indent_more() self.indent_more()
if 'number' in e.attributes: if 'number' in e.attributes:
self.writeln(f"Obrázek {e.attributes['number']}:") self.writeln(f"Obrázek {e.attributes['number']}:")
self.generate(e.caption) self.generate(e.caption)
self.indent_less() self.indent_less()
self.writeln(r"}") self.writeln(r"}{}")
self.writeln(r"\vskip5pt{}")
self.ensure_empty(2) self.ensure_empty(2)
def generate_Emph(self, e: Emph): def generate_Emph(self, e: Emph):

Loading…
Cancel
Save