|
@ -41,10 +41,10 @@ class UCWTexGenerator(OutputGenerator): |
|
|
text = text.replace("", "") |
|
|
text = text.replace("", "") |
|
|
return text |
|
|
return text |
|
|
|
|
|
|
|
|
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": |
|
|
return |
|
|
return |
|
|
super()._generate(e) |
|
|
super().generate(e) |
|
|
|
|
|
|
|
|
def writepar(self, text: str): |
|
|
def writepar(self, text: str): |
|
|
self.ensure_empty(2) |
|
|
self.ensure_empty(2) |
|
@ -60,7 +60,7 @@ class UCWTexGenerator(OutputGenerator): |
|
|
|
|
|
|
|
|
def generate_Para(self, e: Para): |
|
|
def generate_Para(self, e: Para): |
|
|
self.ensure_empty(2) |
|
|
self.ensure_empty(2) |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self.ensure_empty(2) |
|
|
self.ensure_empty(2) |
|
|
|
|
|
|
|
|
def generate_HorizontalRule(self, e: HorizontalRule): |
|
|
def generate_HorizontalRule(self, e: HorizontalRule): |
|
@ -72,7 +72,7 @@ class UCWTexGenerator(OutputGenerator): |
|
|
self.writeln(r"\ucwmodule{verb}") |
|
|
self.writeln(r"\ucwmodule{verb}") |
|
|
self.writeln(r"\ucwmodule{link}") |
|
|
self.writeln(r"\ucwmodule{link}") |
|
|
self.writeln(r"\input formatitko.tex") |
|
|
self.writeln(r"\input formatitko.tex") |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self.writeln(r"\bye") |
|
|
self.writeln(r"\bye") |
|
|
|
|
|
|
|
|
def get_language_macro(self, lang: str): |
|
|
def get_language_macro(self, lang: str): |
|
@ -88,21 +88,21 @@ class UCWTexGenerator(OutputGenerator): |
|
|
def generate_InlineGroup(self, e: InlineGroup): |
|
|
def generate_InlineGroup(self, e: InlineGroup): |
|
|
self.write(r"{") |
|
|
self.write(r"{") |
|
|
self.write(self.get_language_macro(self.context.get_metadata("lang"))) |
|
|
self.write(self.get_language_macro(self.context.get_metadata("lang"))) |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self.write(r"}") |
|
|
self.write(r"}") |
|
|
|
|
|
|
|
|
def generate_BlockGroup(self, e: BlockGroup): |
|
|
def generate_BlockGroup(self, e: BlockGroup): |
|
|
self.writeln(r"\begingroup") |
|
|
self.writeln(r"\begingroup") |
|
|
self.indent_more() |
|
|
self.indent_more() |
|
|
self.writeln(self.get_language_macro(self.context.get_metadata("lang"))) |
|
|
self.writeln(self.get_language_macro(self.context.get_metadata("lang"))) |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self.indent_less() |
|
|
self.indent_less() |
|
|
self.writeln(r"\endgroup") |
|
|
self.writeln(r"\endgroup") |
|
|
|
|
|
|
|
|
def generate_Header(self, e: Header): |
|
|
def generate_Header(self, e: Header): |
|
|
self.ensure_empty(2) |
|
|
self.ensure_empty(2) |
|
|
self.write("\\"+"sub"*(e.level-1)+"section{") |
|
|
self.write("\\"+"sub"*(e.level-1)+"section{") |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self.write(r"}") |
|
|
self.write(r"}") |
|
|
self.ensure_empty(2) |
|
|
self.ensure_empty(2) |
|
|
|
|
|
|
|
@ -156,12 +156,12 @@ class UCWTexGenerator(OutputGenerator): |
|
|
self.writeln(r"\vskip5pt") |
|
|
self.writeln(r"\vskip5pt") |
|
|
self.writeln(r"\centerline{") |
|
|
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.writeln(r"\centerline{") |
|
|
self.indent_more() |
|
|
self.indent_more() |
|
|
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.writeln(r"\vskip5pt{}") |
|
@ -173,7 +173,7 @@ class UCWTexGenerator(OutputGenerator): |
|
|
else: |
|
|
else: |
|
|
self.write(r"{\I{}") |
|
|
self.write(r"{\I{}") |
|
|
self._italic+=1 |
|
|
self._italic+=1 |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self._italic-=1 |
|
|
self._italic-=1 |
|
|
self.write(r"}") |
|
|
self.write(r"}") |
|
|
|
|
|
|
|
@ -183,7 +183,7 @@ class UCWTexGenerator(OutputGenerator): |
|
|
else: |
|
|
else: |
|
|
self.write(r"{\bf{}") |
|
|
self.write(r"{\bf{}") |
|
|
self._bold+=1 |
|
|
self._bold+=1 |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self._bold-=1 |
|
|
self._bold-=1 |
|
|
self.write(r"}") |
|
|
self.write(r"}") |
|
|
|
|
|
|
|
@ -204,7 +204,7 @@ class UCWTexGenerator(OutputGenerator): |
|
|
|
|
|
|
|
|
def generate_Note(self, e: Note): |
|
|
def generate_Note(self, e: Note): |
|
|
self.write(r"\fn{") |
|
|
self.write(r"\fn{") |
|
|
self._generate(inlinify(e)) |
|
|
self.generate(inlinify(e)) |
|
|
self.write(r"}") |
|
|
self.write(r"}") |
|
|
|
|
|
|
|
|
def generate_Table(self, e: Table): |
|
|
def generate_Table(self, e: Table): |
|
@ -217,11 +217,11 @@ class UCWTexGenerator(OutputGenerator): |
|
|
self.writeln(r"\vskip1em") |
|
|
self.writeln(r"\vskip1em") |
|
|
self.writeln(r"\halign{\strut"+"&".join([aligns[col[0]] for col in e.colspec])+r"\cr") |
|
|
self.writeln(r"\halign{\strut"+"&".join([aligns[col[0]] for col in e.colspec])+r"\cr") |
|
|
self.indent_more() |
|
|
self.indent_more() |
|
|
self._generate(e.head.content) |
|
|
self.generate(e.head.content) |
|
|
self.writeln(r"\noalign{\hrule}") |
|
|
self.writeln(r"\noalign{\hrule}") |
|
|
self._generate(e.content[0].content) |
|
|
self.generate(e.content[0].content) |
|
|
self.writeln(r"\noalign{\hrule}") |
|
|
self.writeln(r"\noalign{\hrule}") |
|
|
self._generate(e.foot.content) |
|
|
self.generate(e.foot.content) |
|
|
self.indent_less() |
|
|
self.indent_less() |
|
|
self.writeln("}") |
|
|
self.writeln("}") |
|
|
self.writeln(r"\vskip1em") |
|
|
self.writeln(r"\vskip1em") |
|
@ -230,7 +230,7 @@ class UCWTexGenerator(OutputGenerator): |
|
|
for cell in e.content: |
|
|
for cell in e.content: |
|
|
if cell.colspan > 1: |
|
|
if cell.colspan > 1: |
|
|
self.write(r"\multispan"+str(cell.colspan)+"{} ") |
|
|
self.write(r"\multispan"+str(cell.colspan)+"{} ") |
|
|
self._generate(cell.content) |
|
|
self.generate(cell.content) |
|
|
if cell.next: |
|
|
if cell.next: |
|
|
self.write(" & ") |
|
|
self.write(" & ") |
|
|
self.write(r"\cr") |
|
|
self.write(r"\cr") |
|
@ -245,10 +245,10 @@ class UCWTexGenerator(OutputGenerator): |
|
|
self.writeraw(e.text) |
|
|
self.writeraw(e.text) |
|
|
|
|
|
|
|
|
def generate_Plain(self, e: Plain): |
|
|
def generate_Plain(self, e: Plain): |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
|
|
|
|
|
|
def generate_Span(self, e: Span): |
|
|
def generate_Span(self, e: Span): |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
|
|
|
|
|
|
def generate_CodeBlock(self, e: CodeBlock): |
|
|
def generate_CodeBlock(self, e: CodeBlock): |
|
|
self.writeln(r"\verbatim{") |
|
|
self.writeln(r"\verbatim{") |
|
@ -256,15 +256,15 @@ class UCWTexGenerator(OutputGenerator): |
|
|
self.writeln(r"}") |
|
|
self.writeln(r"}") |
|
|
|
|
|
|
|
|
def generate_Div(self, e: Div): |
|
|
def generate_Div(self, e: Div): |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
|
|
|
|
|
|
def generate_LineBlock(self, e: LineBlock): |
|
|
def generate_LineBlock(self, e: LineBlock): |
|
|
self.writeln() |
|
|
self.writeln() |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self.writeln() |
|
|
self.writeln() |
|
|
|
|
|
|
|
|
def generate_LineItem(self, e: LineItem): |
|
|
def generate_LineItem(self, e: LineItem): |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
if e.next: |
|
|
if e.next: |
|
|
self.write(r"\\") |
|
|
self.write(r"\\") |
|
|
self.endln() |
|
|
self.endln() |
|
@ -273,7 +273,7 @@ class UCWTexGenerator(OutputGenerator): |
|
|
self.ensure_empty(2) |
|
|
self.ensure_empty(2) |
|
|
self.writeln(r"\list{o}") |
|
|
self.writeln(r"\list{o}") |
|
|
self.indent_more() |
|
|
self.indent_more() |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self.indent_less() |
|
|
self.indent_less() |
|
|
self.write(r"\endlist") |
|
|
self.write(r"\endlist") |
|
|
self.ensure_empty(2) |
|
|
self.ensure_empty(2) |
|
@ -298,7 +298,7 @@ class UCWTexGenerator(OutputGenerator): |
|
|
style = delimiters[e.delimiter] |
|
|
style = delimiters[e.delimiter] |
|
|
self.writeln(r"\list{"+style+r"}") |
|
|
self.writeln(r"\list{"+style+r"}") |
|
|
self.indent_more() |
|
|
self.indent_more() |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self.indent_less() |
|
|
self.indent_less() |
|
|
self.writeln(r"\endlist") |
|
|
self.writeln(r"\endlist") |
|
|
self.ensure_empty(2) |
|
|
self.ensure_empty(2) |
|
@ -306,13 +306,13 @@ class UCWTexGenerator(OutputGenerator): |
|
|
def generate_ListItem(self, e: ListItem): |
|
|
def generate_ListItem(self, e: ListItem): |
|
|
self.endln() |
|
|
self.endln() |
|
|
self.write(r"\:") |
|
|
self.write(r"\:") |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self.endln() |
|
|
self.endln() |
|
|
|
|
|
|
|
|
def generate_BlockQuote(self, e: BlockQuote): |
|
|
def generate_BlockQuote(self, e: BlockQuote): |
|
|
self.writeln(r"\blockquote{") |
|
|
self.writeln(r"\blockquote{") |
|
|
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"}") |
|
|
|
|
|
|
|
@ -321,17 +321,17 @@ class UCWTexGenerator(OutputGenerator): |
|
|
self.write(r"\url{") |
|
|
self.write(r"\url{") |
|
|
else: |
|
|
else: |
|
|
self.write(r"\linkurl{"+e.url+r"}{") |
|
|
self.write(r"\linkurl{"+e.url+r"}{") |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self.write(r"}") # } |
|
|
self.write(r"}") # } |
|
|
|
|
|
|
|
|
def generate_Subscript(self, e: Subscript): |
|
|
def generate_Subscript(self, e: Subscript): |
|
|
self.write(r"\subscript{") |
|
|
self.write(r"\subscript{") |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self.write(r"}") |
|
|
self.write(r"}") |
|
|
|
|
|
|
|
|
def generate_Superscript(self, e: Superscript): |
|
|
def generate_Superscript(self, e: Superscript): |
|
|
self.write(r"\superscript{") |
|
|
self.write(r"\superscript{") |
|
|
self._generate(e.content) |
|
|
self.generate(e.content) |
|
|
self.write(r"}") |
|
|
self.write(r"}") |
|
|
|
|
|
|
|
|
def generate_simple_tag(self, e: Union[Element, None] = None, tag: str = "", attributes: Union[dict[str, str], None] = None, content: Union[ListContainer, Element, list[Union[Element, ListContainer]], str, None] = None, inline: Union[bool, None] = None): |
|
|
def generate_simple_tag(self, e: Union[Element, None] = None, tag: str = "", attributes: Union[dict[str, str], None] = None, content: Union[ListContainer, Element, list[Union[Element, ListContainer]], str, None] = None, inline: Union[bool, None] = None): |
|
|