Compare commits

...

3 Commits

  1. 29
      src/formatitko/tex/formatitko.tex
  2. 23
      src/formatitko/tex/table_of_contents.tex
  3. 18
      src/formatitko/tex/table_of_contents_pictures.tex
  4. 38
      src/formatitko/tex_generator.py

29
src/formatitko/formatitko.tex → src/formatitko/tex/formatitko.tex

@ -76,9 +76,18 @@
\fncount=1 \fncount=1
\def\fnmark{\superscript{\the\fncount}} \def\fnmark{\superscript{\the\fncount}}
\def\fn#1{\footnote\fnmark{#1}\advance\fncount by 1} \def\fn#1{\footnote\fnmark{#1}\advance\fncount by 1}
\def\section#1#2{\vfil\eject{\parskip1em\settextsize{20}\bf #1\kern 1em #2}} \def\section#1#2{
\def\subsection#1#2{{\parskip1em\settextsize{18}\bf #1\kern 1em #2}} \vfil\eject{\parskip1em\settextsize{20}\bf #1\kern 1em #2}
\def\subsubsection#1#2{{\parskip1em\settextsize{16}\bf #1\kern 1em #2}} \addtoc\tocsection{#1}{}{#2}
}
\def\subsection#1#2{
{\parskip1em\settextsize{18}\bf #1\kern 1em #2}
\addtoc\tocsubsection{#1}{}{#2}
}
\def\subsubsection#1#2{
{\parskip1em\settextsize{16}\bf #1\kern 1em #2}
\addtoc\tocsubsubsection{#1}{}{#2}
}
\def\subsubsubsection#1#2{{\parskip1em\settextsize{14}\bf #1\kern 1em #2}} \def\subsubsubsection#1#2{{\parskip1em\settextsize{14}\bf #1\kern 1em #2}}
\def\subsubsubsubsection#1#2{{\parskip1em\settextsize{12}\bf #1\kern 1em #2}} \def\subsubsubsubsection#1#2{{\parskip1em\settextsize{12}\bf #1\kern 1em #2}}
\def\subsubsubsubsubsection#1#2{{\parskip1em\settextsize{10}\bi #1\kern 1em #2}} \def\subsubsubsubsubsection#1#2{{\parskip1em\settextsize{10}\bi #1\kern 1em #2}}
@ -191,3 +200,17 @@
}}} }}}
}} }}
% Obsah a odkazy
\newwrite\tocfile
\immediate\openout\tocfile=toc-new.aux
% Voláme: \addtoc\tocmacro{number}{asterisks}{title}
\long\def\addtoc#1#2#3#4{
\edef\brum{
\write\tocfile{\string#1{\noexpand\the\noexpand\count0}{#2}{#3}{#4}}
}
\brum
}

23
src/formatitko/tex/table_of_contents.tex

@ -0,0 +1,23 @@
{
\def\pagelink#1{#1}
\def\toclink#1#2{%
#2
}
\def\stdskip{\vskip 3pt}
\def\tocsection#1#2#3#4{
\line{\settextsize{14}\bf\hbox to 2em{#2\hfil}#4~\hfil\pagelink{#1}}\stdskip
}
\def\tocsubsection#1#2#3#4{
\line{\bf\hskip 1.5cm \hbox to 3em{#2\hfil}#4~\hfil\pagelink{#1}}\stdskip
}
\def\tocsubsubsection#1#2#3#4{
\line{\bf\hskip 3cm \hbox to 4em{#2\hfil}#4~\hfil\pagelink{#1}}\stdskip
}
\def\tocpicture#1#2#3#4{}
\vskip 1cm
\input toc.aux
}

18
src/formatitko/tex/table_of_contents_pictures.tex

@ -0,0 +1,18 @@
{
\def\pagelink#1{#1}
\def\toclink#1#2{%
#2
}
\def\stdskip{\vskip 3pt}
\def\tocsection#1#2#3#4{}
\def\tocsubsection#1#2#3#4{}
\def\tocsubsubsection#1#2#3#4{}
\def\tocpicture#1#2#3#4{
\line{\hbox to 2em{#2\hfil}#4~\hfil\pagelink{#1}}\stdskip
}
\vskip 1cm
\input toc.aux
}

38
src/formatitko/tex_generator.py

@ -27,19 +27,25 @@ class UCWTexGenerator(OutputGenerator):
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:
text = text.replace("&", r"\&") if '\\' in text:
text = text.replace("%", r"\%") print("ESCAPE", text)
text = text.replace("$", r"\$") out = ""
text = text.replace("#", r"\#") for char in text:
text = text.replace("_", r"\_") out += {
text = text.replace("{", r"\{") '&': r"\&",
text = text.replace("}", r"\}") '%': r"\%",
text = text.replace("~", r"\textasciitilde{}") '$': r"\$",
text = text.replace("^", r"\textasciicircum{}") '#': r"\#",
text = text.replace("\\", r"\textbackslash{}") '_': r"\_",
text = text.replace(" ", "~") # We use unicode no-break spaces to force nbsp in output '{': r"\{",
text = text.replace("", "") '}': r"\}",
return text '~': r"\textasciitilde{}",
'^': r"\textasciicircum{}",
'\\': r"\textbackslash{}",
' ': r"~",
'': r"",
}.get(char, char)
return out
def generate(self, e: Union[Element, ListContainer]): def generate(self, e: Union[Element, ListContainer]):
if hasattr(e, "attributes") and "only" in e.attributes and e.attributes["only"] != "tex": if hasattr(e, "attributes") and "only" in e.attributes and e.attributes["only"] != "tex":
@ -164,6 +170,12 @@ class UCWTexGenerator(OutputGenerator):
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)
if 'number' in e.attributes:
self.writeln(r"\addtoc\tocpicture{"+str(e.attributes['number'])+"}{}{")
self.indent_more()
self.generate(e.caption.content)
self.indent_less()
self.writeln("}")
self.indent_less() self.indent_less()
self.writeln(r"}{}") self.writeln(r"}{}")
self.ensure_empty(2) self.ensure_empty(2)

Loading…
Cancel
Save