From 022cbb46f37d4d35cd121e8e8084685a38f6e85b Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Wed, 7 Aug 2024 00:01:24 +0400 Subject: [PATCH] Refactor `table` tag --- python/moire_converter.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/python/moire_converter.py b/python/moire_converter.py index aafcb8d..b2961e6 100644 --- a/python/moire_converter.py +++ b/python/moire_converter.py @@ -77,21 +77,22 @@ def tex_ref(self, arg) -> str: return f"\\ref{{{arg[0][0]}}}" def table(self, arg) -> str: + max_tds: int = 0 + for tr in arg[2:]: + if isinstance(tr, list): + tds = sum([1 for td in tr if isinstance(td, list)]) + max_tds = max(max_tds, tds) + s = dedent( """\ \\begin{table}[ht] \\begin{center} \\begin{tabular}{|""" + + "|".join(["l"] * max_tds) + + "|}\n" ) - max_tds = 0 - for tr in arg[2:]: - if isinstance(tr, list): - tds = sum([1 for td in tr if isinstance(td, list)]) - max_tds = max(max_tds, tds) - for k in range(max_tds): - s += "c|" - s += "}\n\\hline\n" - for tr in arg[2:]: + s += "\\hline\n" + for index, tr in enumerate(arg[2:]): if isinstance(tr, list): tds = [] for td in tr: @@ -100,7 +101,8 @@ def table(self, arg) -> str: for td in tds[:-1]: s += self.parse(td) + " & " s += self.parse(tds[-1]) - s += " \\\\\n\\hline\n" + s += " \\\\\n" + s += "\\hline\n" s += dedent( f"""\ \\end{{tabular}}