def _append2latexdoc(doc, content): if isinstance(content, list): for item in content: if item.get('title'): doc.append(_get_section(**item)) _append2latexdoc(doc, item['content']) else: _append2latexdoc(doc, item) else: section = _get_last_section(doc) if content.get('text'): if isinstance(content['text'], dict): section.append(open(content['text']['filename']).read()) else: temp = '' if isinstance(content['text'],list): for subtext in content['text']: temp += subtext elif isinstance(content['text'],str): temp = content['text'] else: raise Exception(f'Did not understand format of text string: \n {content["text"]}') section.append(temp) if content.get('latex_code'): if isinstance(content['latex_code'], dict): section.append(NoEscape(open(content['latex_code']['filename']).read())) else: section.append(NoEscape(content['latex_code'])) if content.get('table'): for table in content['table']: section.append(NoEscape('\\begin{table}[H]')) # note require float latex package for H command if table.get('filename'): df = pd.read_excel(table['filename'], **table['kwargs']) elif isinstance(table.get('dataframe'),pd.DataFrame): df = table.get('dataframe') section.append(NoEscape(df.to_latex(longtable=True,multicolumn_format='c'))) section.append(NoEscape('\\end{table}')) if content.get('image'): for image in content.get('image'): section.append(NoEscape('\\begin{figure}[H]')) # note require float latex package for H command Figure.add_image(section, image['filename']) section.append(NoEscape('\\end{figure}')) if content.get('subimage'): figure = Figure(position='H') for i, subimage in enumerate(content['subimage']): subfigure = SubFigure(width=NoEscape( r'{}\linewidth'.format(np.round(1. / subimage.get('nr_horizontal_subimages', 2), 2) - 0.01))) subfigure.add_image(subimage['filename']) if subimage.get('caption', False): subfigure.add_caption(subimage['caption']) if subimage.get('figure_caption', False) and i == 0: figure.add_caption(subimage['figure_caption']) figure.append(subfigure) if (i + 1) % subimage.get('nr_horizontal_subimages', 2) == 0 and i != 0 or subimage.get( 'nr_horizontal_subimages', 2) == 1: section.append(figure) figure = Figure(arguments=NoEscape('\ContinuedFloat'), position='H') section.append(figure) if content.get('packages'): [doc.packages.append(Package(package)) for package in content['packages']]
def makeImages(self, section, fileInfos): figure = Figure(position="h") for index, infos in enumerate(fileInfos): image = self.createImage(infos.filename, infos.caption) figure.append(image) if index % 2 == 1: section.append(figure) figure = Figure(position="h") if index == len(fileInfos) - 1: section.append(figure)