def print_latex(self): """ Gerador de arquivos .tex e .pdf """ pdf = pylatex.Document("default") with pdf.create(pylatex.Section("Equações Diofantinas")) as section: section.append("Equação:") ultimo = self.numbers[-1] eq = [] cont = 1 for i in self.numbers: simbolo = "+" if i == ultimo: simbolo = "= 1" eq.append( pylatex.NoEscape(" {}x_{} {}".format(i, cont, simbolo))) cont = cont + 1 section.append(pylatex.Math(data=eq)) text = "n = {}".format(self.order) section.append(text) m = pylatex.Matrix(self.take_vec(), mtype='b') matrix = pylatex.Math(data=['b = ', m]) section.append(matrix) m = pylatex.Matrix(self.take_matrix(), mtype='b') matrix = pylatex.Math(data=['A = ', m]) section.append(matrix) section.append("Resposta = {}".format(self.cofactor_matrix())) section.append(pylatex.LineBreak()) section.append("Confirmando:") section.append(pylatex.LineBreak()) s = 0 for i in range(len(self.numbers)): r = self.numbers[i] * self.cofactor_matrix()[i] s = s + r resp = "\t {}\t{} \t* \t{} \t= \t{} \t({})\n".format( i, self.numbers[i], self.cofactor_matrix()[i], r, s) section.append(resp) if self.create_pdf: pdf.generate_pdf() pdf.generate_tex()
def addHeader(self): # Add document header header = tex.PageStyle("header", header_thickness=1, footer_thickness=1) # Create left header with header.create(tex.Head("L")): header.append(f"Account name: {self.name}") header.append(tex.LineBreak()) header.append(f"IBAN: {self.number}") # Create right header with header.create(tex.Head("R")): header.append(self.bank) # Create left footer with header.create(tex.Foot("L")): header.append("Econicer - Financial Report") # Create right footer with header.create(tex.Foot("R")): header.append("Page ") header.append(tex.Command("thepage")) self.doc.preamble.append(header) self.doc.change_document_style("header")
def addSection(self, title, text="", plotDict={}, plotPaths={}): with self.doc.create(tex.Section(title)): if text: self.doc.append(text) with self.doc.create(tex.Figure(position='h!')) as fig: for i, (plotName, cap) in enumerate(plotDict.items()): subplot = self.createFig(plotPaths[plotName], cap) fig.append(subplot) if (i + 1) % 2 == 0: self.doc.append(tex.LineBreak())
def _export_pdf(self, fname: str): geometry_options = {"margin": "1in"} doc = pylatex.Document(geometry_options=geometry_options) header = pylatex.PageStyle("header") with doc.create(pylatex.MiniPage(align="c")): doc.append( pylatex.HugeText(pylatex.utils.bold("Practice Sessions"))) doc.append(pylatex.LineBreak()) with header.create(pylatex.Foot("L")): header.append("@2019 Musicavis") with header.create(pylatex.Foot("R")): header.append(pylatex.simple_page_number()) doc.preamble.append(header) doc.change_document_style("header") for practice in self.practices: with doc.create( pylatex.Section( f"{practice.instrument.name.title()} ({practice.date:%a, %B %m %Y})" )): self._add_list_itemize_latex(doc, "Goals", practice.goals.all()) with doc.create(pylatex.Subsection("Exercises")): with doc.create(pylatex.Itemize()) as itemize: for x in practice.exercises.all(): itemize.add_item( f"{x.name} at {x.bpm_start}-{x.bpm_end}bpm for {x.minutes}m" ) self._add_list_itemize_latex(doc, "Improvements", practice.improvements.all()) self._add_list_itemize_latex(doc, "Positives", practice.positives.all()) with doc.create(pylatex.Subsection("Notes:")): if practice.notes: for note in practice.notes.split("\r\n"): doc.append(note) if note else doc.append( pylatex.NewLine()) doc.generate_pdf(fname.split(".pdf")[0], clean=True)