From 4b213008cefbcd07ae2f254f224ae91525a69a0a Mon Sep 17 00:00:00 2001 From: Bruno Freitas Tissei <bft15@inf.ufpr.br> Date: Mon, 13 May 2019 19:01:28 -0300 Subject: [PATCH] Small fixes to latex generator Signed-off-by: Bruno Freitas Tissei <bft15@inf.ufpr.br> --- notebook/gen_latex.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/notebook/gen_latex.py b/notebook/gen_latex.py index 1bdd850..9d0bb08 100644 --- a/notebook/gen_latex.py +++ b/notebook/gen_latex.py @@ -48,23 +48,35 @@ class Tree: class LatexGenerator: def __init__(self, tree): + # TODO: Create output file, add header and finish code parsing and latex self.tree = tree self.hierarchy = ['chapter'] + [i*'sub' + 'section' for i in range(3)] - self.gen_latex(tree, 0) - - # Prints elements in arr in Latex format. - def gen_code_latex(self, content, depth): - print('\\' + self.hierarchy[depth] + '{' + content + '}') + self.gen_latex(tree) + + # Prints section title in Latex format. + # TODO: Instead of parsing format, get name of section through header of + # the algorithm/problem file. Capitalization should be used only for + # directories. + def gen_title_latex(self, content, depth): + text = ' '.join(list(map(lambda x : x.capitalize(), + content.split('.')[0].split('_')))) + print('\\' + self.hierarchy[depth] + '{' + text + '}') + + # Prints code in Latex format. + def gen_code_latex(self, path): + # TODO: Add code parsing funcion and code to latex generation + pass # Generates Latex for entire tree recursively - def gen_latex(self, sub, depth): + def gen_latex(self, sub, path = '', depth = 0): if type(sub) == list: for i in sub: - self.gen_code_latex(i, depth) + self.gen_title_latex(i, depth) + self.gen_code_latex(path + i) else: for i in sub: - self.gen_code_latex(i, depth) - self.gen_latex(sub[i], depth + 1) + self.gen_title_latex(i, depth) + self.gen_latex(sub[i], path + i + '/', depth + 1) def main(): -- GitLab