def createPDF(self): # Loop through each pacakage for ind in range(len(self.mBank["dateEnd"])): # Generate type of text to be used for report text = self.genText(ind) # Create section with self.mDoc.create( pyl.Section(self.mBank["dateBegin"][ind] + " - " + self.mBank["dateEnd"][ind])) as sec: # Add description of table sec.append(text["description"]) # Add long table of statistics to section self.addTable( sec, self.mBank["statistics"][ind], subxlabel={ "#": ["count"], "Hours": ["mean", "lower quartile", "median", "upper quartile"] }) self.addGraph(sec, self.mBank["graphs"][ind], title=text["plotTitle"]) # Append new page after table/graph self.mDoc.append(pyl.NewPage()) # Generate the pdf, and clean the latex files afterwards self.mDoc.generate_pdf(clean=True) return
def main(): if not os.path.exists("report"): os.mkdir("report") global tumor global max_distance global e_method for t in tumors: print(t) doc = pylatex.Document('report/results' + t) doc.append(pylatex.NewPage()) with doc.create(pylatex.Section(t)): for m in e_methods: for d in max_distances: tumor = t max_distance = d e_method = m with doc.create( pylatex.Subsection("Score = " + m.tag + ", Max dist. = " + str(d))): do_analysis(doc) doc.generate_pdf(clean_tex=False)
def add_page3(self): doc = self.m_doc doc.append("Influence of mesocrystal height") doc.append(pl.VerticalSpace("2cm")) doc.append("\n") with doc.create( pl.MiniPage(width=r"0.2\textwidth", height=r"0.25\textwidth", content_pos='t')): lines = data.split("\n") with doc.create(pl.Tabular('l l', row_height=0.8)) as table: myfont = [mono, tiny] for l in lines: parts = l.split(":") print(parts) if len(parts) == 2: table.add_row(parts[0], parts[1], mapper=myfont) elif len(parts) == 1: table.add_hline() table.add_row((l, " "), mapper=myfont) doc.append("\n") with doc.create( pl.MiniPage(width=r"0.8\textwidth", height=r"0.25\textwidth", content_pos='t')): doc.append( pl.Command('includegraphics', options='scale=0.8', arguments='meso.png')) doc.append("\n") doc.append(pl.NewPage())
def _init_doc(self, add_date=True): doc = pyl.Document(geometry_options=geometry_options) doc.packages.append(pyl.Package("float")) doc.packages.append(pyl.Package("hyperref")) doc.preamble.append(pyl.Command("title", self.title)) if add_date: doc.preamble.append(pyl.Command("date", pyl.NoEscape(r"\today"))) else: doc.preamble.append(pyl.Command("date", pyl.NoEscape(r""))) doc.append(pyl.NoEscape(r"\maketitle")) doc.append(pyl.NewPage()) doc.append(pyl.Command("tableofcontents")) doc.append(pyl.NewPage()) return doc
def make_subfigure(self, fig_funcs, layout=(5, 4), close=True): #todo figure out how to iterate properly n = np.product(layout) chunks = grouper(n, fig_funcs) w = str(1 / layout[1]) pbar = tqdm(total=len(fig_funcs)) for chunk in chunks: with self.doc.create(pyl.Figure(position='ht')) as tex_fig: for i, fig_func in enumerate(chunk): if fig_func is None: continue with self.doc.create( pyl.SubFigure( position='b', width=pyl.NoEscape(w + r'\linewidth'))) as subfig: fig = fig_func() file_path = self._save_fig( fig, bbox_inches='tight') # todo access these kwargs if close: plt.close(fig) subfig.add_image(file_path, width=pyl.NoEscape(r'\linewidth')) if i % layout[1] == layout[1] - 1: self.doc.append('\n') pbar.update(1) self.doc.append(pyl.NewPage())
def add_page2(self): doc = self.m_doc with doc.create(pl.Section('A section 2')): doc.append('Some regular text and some ') doc.append(italic('italic text. ')) with doc.create(pl.Figure(position='h!')) as kitten_pic: kitten_pic.add_image("meso.png", width=NoEscape(r'0.75\textwidth')) doc.append(pl.NewPage())
def _init_doc(self, name, add_date=True): doc = pyl.Document(name, geometry_options=geometry_options) doc.packages.append(pyl.Package('hyperref')) doc.preamble.append(pyl.Command('title', f'Supplementary Figures for {name}')) if add_date: doc.preamble.append(pyl.Command('date', pyl.NoEscape(r'\today'))) else: doc.preamble.append(pyl.Command('date', pyl.NoEscape(r''))) doc.append(pyl.NoEscape(r'\maketitle')) doc.append(pyl.NewPage()) return doc
def new_page(self): self.doc.append(pylatex.NewPage()) self.len_last_page = 0