Compare commits

...

3 Commits

  1. 9
      src/formatitko/elements.py
  2. 6
      src/formatitko/output_generator.py
  3. 3
      src/formatitko/tex/formatitko.tex
  4. 14
      src/formatitko/tex/formatitkolib.tex
  5. 7
      src/formatitko/tex/table_of_contents.tex
  6. 20
      src/formatitko/tex_generator.py

9
src/formatitko/elements.py

@ -1,4 +1,4 @@
from panflute import Quoted, Emph, Link
from panflute import Quoted, Emph, Link, Div
from .command import Command, InlineCommand, BlockCommand, CodeCommand
@ -26,3 +26,10 @@ class FLink(Link):
class FileLink(Link):
pass
class FLineMarkup(Div):
def __init__(self, *args, **kwargs):
self.color = kwargs["color"]
del kwargs["color"]
super().__init__(*args, **kwargs)

6
src/formatitko/output_generator.py

@ -7,7 +7,7 @@ from panflute import stringify
from typing import Union, Callable
from .whitespace import NBSP
from .elements import FQuoted, Slanted, FLink, FileLink
from .elements import FQuoted, Slanted, FLink, FileLink, FLineMarkup
from .context import Group, InlineGroup, BlockGroup, Context
@ -88,6 +88,7 @@ class OutputGenerator:
DefinitionItem: self.generate_DefinitionItem,
DefinitionList: self.generate_DefinitionList,
Div: self.generate_Div,
FLineMarkup: self.generate_FLineMarkup,
Figure: self.generate_Figure,
Header: self.generate_Header,
HorizontalRule: self.generate_HorizontalRule,
@ -462,6 +463,9 @@ class OutputGenerator:
def generate_Div(self, e: Div):
self.generate_simple_tag(e)
def generate_FLineMarkup(self, e: FLineMarkup):
self.generate_Div(e)
def generate_Header(self, e: Header):
self.generate_simple_tag(e)

3
src/formatitko/tex/formatitko.tex

@ -21,6 +21,7 @@
\pdfglyphtounicode{radicalbig}{221A}
\pdfglyphtounicode{radicalBig}{221A}
\pdfglyphtounicode{hatwidest}{0302}
\input formatitkolib.tex
@ -130,7 +131,7 @@
\parindent=0pt
\leftskip=0pt plus 0.2\hsize
\rightskip=0pt plus 0.2\hsize
\parfillskip=0pt plus 0.2\hsize
\parfillskip=0pt
\spaceskip=0.3333em
\settextsize{10}
#1

14
src/formatitko/tex/formatitkolib.tex

@ -55,10 +55,20 @@
\def\unparskip{\vskip-\parskip}
\catcode`@=11
\def\vecoverrightarrow#1{\vbox{\m@th\ialign{##\crcr
\def\vecoverrightarrow#1{\mathpalette\vecoverrightarrowtmp{#1}}
\def\vecoverrightarrowtmp#1#2{\vbox{\m@th\ialign{##\crcr
\vecrightarrowfill\crcr\noalign{\kern-\p@\kern 0.09em\nointerlineskip}
$\hfil\displaystyle{#1\,}\hfil$\crcr}}}
$\hfil#1{#2\,}\hfil$\crcr}}}
\def\vecrightarrowfill{$\settextsize{5}\m@th\smash-\mkern-7mu%
\cleaders\hbox{$\mkern-2mu\smash-\mkern-2mu$}\hfill
\settextsize{5}\mkern-7mu\mathord\rightarrow$}
\catcode`@=12
\long\def\linemarkup#1#2{%
\par\noindent\hbox{%
\hbox{}\hskip -6pt {\colorlocal{#1}\vrule width 1pt \hskip 5pt}%
\hbox to \hsize{\vbox{#2}\hfil}%
%\hbox{}\hskip 5pt {\colorlocal{#1}\vrule width 1pt \hskip -6pt}%
}\par%
}

7
src/formatitko/tex/table_of_contents.tex

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

20
src/formatitko/tex_generator.py

@ -11,10 +11,14 @@ from .output_generator import OutputGenerator
from .images import ImageProcessor, ImageProcessorNamespaceSearcher
from .whitespace import NBSP
from .elements import FQuoted
from .elements import FQuoted, FLineMarkup
from .context import Group, InlineGroup, BlockGroup, Context
from .util import inlinify
def color_to_rgb(color):
import matplotlib.colors
return matplotlib.colors.to_rgb(color)
class UCWTexGenerator(OutputGenerator):
imageProcessor: ImageProcessor
_bold: int
@ -254,7 +258,7 @@ class UCWTexGenerator(OutputGenerator):
"AlignDefault": r"\quad#\quad\hfil"
}
self.writeln(r"\vskip1em")
self.writeln(r"\halign{\strut"+"&".join([aligns[col[0]] for col in e.colspec])+r"\cr")
self.writeln(r"\leavevmode\vbox{\halign{\strut"+"&".join([aligns[col[0]] for col in e.colspec])+r"\cr")
self.indent_more()
self.generate(e.head.content)
self.writeln(r"\noalign{\vskip 0.3em\hrule\vskip 0.3em}")
@ -262,7 +266,7 @@ class UCWTexGenerator(OutputGenerator):
self.writeln(r"\noalign{\vskip 0.3em\hrule\vskip 0.3em}")
self.generate(e.foot.content)
self.indent_less()
self.writeln("}")
self.writeln("}}")
self.writeln(r"\vskip1em")
def generate_TableRow(self, e: TableRow):
@ -297,6 +301,16 @@ class UCWTexGenerator(OutputGenerator):
def generate_Div(self, e: Div):
self.generate(e.content)
def generate_FLineMarkup(self, e: FLineMarkup):
self.ensure_empty(2)
r,g,b = color_to_rgb(e.color)
self.writeln(r"\linemarkup{\rgb{"+f"{r} {g} {b}"+"}}{")
self.indent_more()
self.generate(e.content)
self.indent_less()
self.writeln(r"}")
self.ensure_empty(2)
def generate_LineBlock(self, e: LineBlock):
self.writeln()
self.generate(e.content)

Loading…
Cancel
Save