Пример #1
0
def createTitle():
    doc.preamble.append(pylatex.Command('title', 'Superphreak'))
    doc.preamble.append(pylatex.Command('author', 'Douglas Luman'))
    doc.preamble.append(pylatex.Command('date', '2016'))
    doc.append(pylatex.utils.NoEscape(r'\maketitle'))

    doc.generate_pdf('title', clean_tex=False)
Пример #2
0
def create_doc(title, with_tikz=False):
    logging.info("Creating PDF...")
    doc = pylatex.Document(geometry_options={'margin': '1.5cm'})
    doc.packages.append(pylatex.Package('hyperref'))
    doc.packages.append(pylatex.Package('amssymb'))
    doc.packages.append(pylatex.Package('amsmath'))
    doc.packages.append(pylatex.Package('float'))
    doc.packages.append(
        pylatex.Package('caption', {
            'labelformat': 'empty',
            'justification': 'centering'
        }))
    #doc.packages.append(pylatex.Package('todonotes'))

    # I don't think these are needed
    #doc.packages.append(pylatex.Package('needspace'))
    #doc.packages.append(pylatex.Package('pgfplots'))

    if with_tikz:
        doc.packages.append(pylatex.Package('tikz'))
        doc.preamble.append(
            pylatex.Command('usetikzlibrary', 'decorations.markings'))
        doc.preamble.append(pylatex.Command('usetikzlibrary', 'fit'))
        doc.preamble.append(pylatex.Command('usetikzlibrary', 'plotmarks'))

    doc.preamble.append(pylatex.Command('title', title))
    doc.preamble.append(pylatex.Command('date', ''))

    doc.append(pylatex.NoEscape(r"\maketitle"))
    doc.append(pylatex.NoEscape(r"\tableofcontents"))
    doc.append(pylatex.NoEscape(r"\newpage"))
    doc.append(
        pylatex.NoEscape(r"\captionsetup[subfigure]{labelformat=empty}"))

    return doc
Пример #3
0
 def _gen_title(self):
     """Add metadata to preamble and `\\\\maketitle` to body."""
     date = pl.NoEscape(r'\today')
     self.doc.preamble.append(pl.Command('title', self.args['title']))
     self.doc.preamble.append(pl.Command('author', self.args['author']))
     self.doc.preamble.append(pl.Command('date', date))
     self.doc.append(pl.NoEscape(r'\maketitle'))
Пример #4
0
 def _add_headers(self):
     """Add the `pagestyle` command and the headers/footers to the preamble."""
     self.doc.preamble.append(pl.Command('pagestyle', 'fancy'))
     self.doc.preamble.append(pl.Command('fancyhf', ' '))
     for pos, val in self.args['heads'].items():
         if val:
             self.doc.preamble.append(pl.Command(pos, val))
Пример #5
0
    def __init__(self, name, number, bank):
        self.name = name
        self.number = number
        self.bank = bank

        geometry_options = {
            "tmargin": "35mm",
            "lmargin": "25mm",
            "textwidth": "160mm",
            "textheight": "237mm",
        }

        self.doc = tex.Document(f"AccountReport_{self.name}",
                                documentclass="article",
                                document_options=['10pt', "a4paper"],
                                geometry_options=geometry_options,
                                lmodern=False)
        self.doc.preamble.append(
            tex.NoEscape(r"\renewcommand{\familydefault}{\sfdefault}"))
        self.doc.preamble.append(tex.Command('usepackage', 'helvet'))
        self.doc.preamble.append(
            tex.Command('usepackage', arguments='placeins', options="section"))

        self.addHeader()

        self.doc.preamble.append(tex.Command('title', "Financial Report"))
        # self.doc.preamble.append(Command('bank', 'Anonymous author'))
        self.doc.preamble.append(tex.Command('date', tex.NoEscape(r'\today')))
Пример #6
0
    def dumps(self):
        name_short = self.name_short
        if name_short is None:
            name_short = self.acronym

        command = pylatex.Command(
            command='newacro',
            arguments=[self.acronym, ],
            options=[name_short],
            extra_arguments=[pylatex.NoEscape(self.name_full), ]
        ).dumps()
        command += pylatex.Command(
            command='newcommand',
            arguments=[pylatex.NoEscape('\\' + self.acronym), pylatex.NoEscape(r'\ac{' + self.acronym + '}')],
        ).dumps()
        if self.plural:
            command += pylatex.Command(
                command='newcommand',
                arguments=[pylatex.NoEscape('\\' + self.acronym + 's'), pylatex.NoEscape(r'\acp{' + self.acronym + '}')],
            ).dumps()
        if self.short:
            command += pylatex.Command(
                command='newcommand',
                arguments=[pylatex.NoEscape('\\' + self.acronym + 'Short'), pylatex.NoEscape(r'\acs{' + self.acronym + '}')],
            ).dumps()
        return command
Пример #7
0
 def ImprLtxPresEjecMat(self, doc):
     #doc.append(u"\\subportadilla{Presupuestos Generales}{Presupuesto de ejecución material}" + '\n')
     chapter = pylatex_utils.Chapter(
         title=u'Presupuesto de ejecución material', numbering=False)
     chapter.append(pylatex.Command('cleardoublepage'))
     center = pylatex.Center()
     center.append(pylatex_utils.LargeCommand())
     center.append(pylatex.utils.bold(u'Presupuesto de Ejecución Material'))
     center.append(pylatex_utils.largeCommand())
     chapter.append(center)
     chapter.append(pylatex.VerticalSpace('2cm'))
     self.subcapitulos.ImprLtxResumen(chapter, "", False)
     chapter.append(
         pylatex.utils.bold(u'Presupuesto de Ejecución Material:'))
     chapter.append(pylatex.Command('dotfill'))
     chapter.append(pylatex.utils.bold(self.getLtxPriceString()))
     chapter.append(pylatex.VerticalSpace('0.5cm'))
     chapter.append(pylatex.NewLine())
     chapter.append(
         u'Asciende el presente presupuesto de ejecución material a la expresada cantidad de: '
     )
     chapter.append(
         pylatex_utils.textsc(
             basic_types.to_words(self.getRoundedPrice(), False) +
             ' euros.'))
     chapter.append(pylatex_utils.input('firmas'))
     doc.append(chapter)
Пример #8
0
def make_table_file(
    name: str,
    strings_per_bar: tuple,
    title_per_bar=None,
    available_columns_per_bar=None,
) -> None:
    if not available_columns_per_bar:
        available_columns_per_bar = tuple(37 for i in strings_per_bar)

    if title_per_bar is None:
        title_per_bar = tuple([
            "Fret positions for bar {0}".format(idx + 1)
            for idx in range(len(strings_per_bar))
        ])
    tables = tuple(
        make_string_table(strings, available_columns=available_columns)
        for strings, available_columns in zip(strings_per_bar,
                                              available_columns_per_bar))
    doc = pylatex.Document(document_options=["landscape", "a4paper"])
    doc.preamble.append(pylatex.Command("usepackage", arguments="lscape"))
    doc.preamble.append(pylatex.Command("usepackage", arguments="xcolor"))
    doc.preamble.append(
        pylatex.NoEscape(r"\usepackage[a4paper,bindingoffset=0.2in,%"))
    doc.preamble.append(
        pylatex.NoEscape(r"left=0.5cm,right=1cm,top=1.5cm,bottom=1cm,%"))
    doc.preamble.append(pylatex.NoEscape(r"footskip=.25in]{geometry}"))
    doc.preamble.append(pylatex.NoEscape(r"\pagenumbering{gobble}"))
    for title, table in zip(title_per_bar, tables):
        # doc.append(pylatex.utils.bold(pylatex.LargeText(title)))
        doc.append(pylatex.LargeText(pylatex.utils.bold(title)))
        doc.append(table)
    doc.generate_pdf(name)
    doc.generate_tex(name)
Пример #9
0
 def writePriceTableTwoIntoLatexDocument(self, doc):
     part = pylatex_utils.Part("Cuadro de precios no. 2")
     part.append(pylatex.Command('parttoc'))
     part.append(pylatex.Command('setcounter{chapter}{0}'))
     super(Obra, self).writePriceTableTwoIntoLatexDocument(part, 'root')
     part.append(pylatex.Command('input{firmas}'))
     doc.append(part)
Пример #10
0
def generate_latex(dataset1, dataset2, output):
    doc = pl.Document(page_numbers=True,
                      geometry_options={
                          "tmargin": "1cm",
                          "lmargin": "1cm"
                      })

    doc.packages.append(pl.Package('booktabs'))
    doc.preamble.append(
        pl.Command('title', 'VH/VL Packing for Gradient Boosted Regression'))
    doc.preamble.append(pl.Command('author', 'Veronica A. Boron'))
    doc.append(pl.NoEscape(r'\maketitle'))
    doc.append(
        'This document summarizes results for predicting VHVL packing angles using Gradient Boosted Regression via the \
        Scikit Learn framework.')
    doc.append(pl.NoEscape(r'\maketitle'))

    _add_data(doc, dataset1)
    doc.append(pl.NoEscape(r'\newpage'))

    _add_data(doc, dataset2)
    doc.append(pl.NoEscape(r'\newpage'))

    print('Generating PDF...')
    doc.generate_pdf(output, clean_tex=False)
Пример #11
0
    def sum_sample(self):
        """Summarize the analysis data and plots in a report
        """
        for i in range(len(self.infiles)):
            self.logger.info('\nCreating pdf for sample {} results.\n'.format(
                self.sample[i]))
            geometry_options = {
                'tmargin': '3cm',
                'bmargin': '3cm',
                'rmargin': '3cm',
                'lmargin': '3cm'
            }
            doc = px.Document(documentclass='article',
                              geometry_options=geometry_options)
            doc.preamble.append(
                px.Command('title',
                           'Sequencing results for sample ' + self.sample[i]))
            doc.preamble.append(px.Command('date', px.NoEscape(r'\today')))
            doc.append(px.NoEscape(r'\maketitle'))

            with doc.create(px.Section('Genome coverage')):
                #include table of results with statistics of coverage
                with doc.create(px.Subsection('Coverage results')):
                    with doc.create(px.Tabular(table_spec='l  l')) as table:
                        with open(self.stats_file, 'r') as stats:
                            table.add_hline()
                            stats_data = pd.read_csv(stats, sep='\t')
                            for num in range(len(stats_data.iloc[0])):
                                table.add_row([
                                    stats_data.columns[num],
                                    stats_data.iloc[0][num]
                                ])
                            table.add_hline()
                #include coverage plot
                with doc.create(px.Figure(position='htb!')) as plot:
                    plot.add_image(self.cov_plot[i],
                                   width=px.NoEscape(r'\linewidth'))
                    plot.add_caption(
                        'Genome coverage for sample ' + self.sample[i] +
                        '. Calculated using samtools depth with zero-coverage positions included.'
                    )
            #include mismatch plot comparing the sample to the reference
            with doc.create(px.Section('Comparison to reference genome')):
                with doc.create(px.Figure(position='htb!')) as plot:
                    plot.add_image(self.basefreq_plot + '_' + self.sample[i] +
                                   '.png',
                                   width=px.NoEscape(r'\linewidth'))
                    plot.add_caption(
                        'Mismatch fraction per position for sample ' +
                        self.sample[i] +
                        '. Calculated compared to reference {}.'.format(
                            self.config['folder_locations']['ref_fasta']))

            doc.generate_pdf(
                filepath=os.path.join(self.outputdir, self.sample_info[i] +
                                      '.Report'))
            self.logger.info(
                '\nDone creating pdf for sample {} results.\n'.format(
                    self.sample[i]))
Пример #12
0
 def ImprCompLtxPreParc(self, otra, doc):
     part = pylatex_utils.Part('Presupuestos parciales')
     part.append(pylatex.Command('parttoc'))
     part.append(pylatex.Command('setcounter{chapter}{0}'))
     part.append(pylatex_utils.ltx_begin("landscape") + '\n')
     super(Obra, self).ImprCompLtxPre(part, 'root', otra)
     part.append(pylatex_utils.ltx_end("landscape") + '\n')
     doc.append(part)
Пример #13
0
def append_a_lgs(doc, lsgen, eqns, vars, no_or_inf_solutions=False, homogen=False):
    doc.append(pylatex.Command('item'))
    doc.append(pylatex.Command('('))
    doc.append(pylatex.Command('displaystyle'))
    with doc.create(Array(options="t", arguments="rrrrrr")):
        ue, lsg = get_a_lgs(eqns, vars, no_or_inf_solutions, homogen)
        doc.append(ue)
        lsgen.append(lsg)
    doc.append(pylatex.Command(')'))
Пример #14
0
def append_a_lsg(doc, lsg):
    doc.append(pylatex.Command('item'))
    doc.append(pylatex.Command('('))
    doc.append(pylatex.Command('displaystyle'))
    doc.append(pylatex.NoEscape('\\mathbb{L} = \\{('))
    doc.append(", ".join(
        map(str, map(int, lsg))
    ))
    doc.append(pylatex.NoEscape(')\\}'))
    doc.append(pylatex.Command(')'))
Пример #15
0
def create_tikz_doc():
    logging.info("Creating PDF...")
    doc = pylatex.Document(documentclass='standalone',
                           document_options=['crop', 'tikz'])
    doc.packages.append(pylatex.Package('tikz'))
    doc.preamble.append(
        pylatex.Command('usetikzlibrary', 'decorations.markings'))
    doc.preamble.append(pylatex.Command('usetikzlibrary', 'fit'))
    doc.preamble.append(pylatex.Command('usetikzlibrary', 'plotmarks'))
    return doc
Пример #16
0
def append_a_det(doc, lsgen, m=0, n=0, misproportion_possible=False):
    doc.append(pylatex.Command('item'))
    doc.append(pylatex.Command('('))
    doc.append(pylatex.Command('displaystyle'))
    with doc.create(Array(options="t", arguments="rrrrrr")):
        if misproportion_possible:
            [m, n] = [random.randint(2, 3, 4) for _ in range(2)]
        A = rand_nice_numbers(m, n)
        doc.append(pylatex.NoEscape(make_matr_tex(A)))
        lsgen.append(np.linalg.det(A))
    doc.append(pylatex.Command(')'))
Пример #17
0
def append_a_matr(doc, lsgen, m=0, p=0, n=0, misproportion_possible=False):
    doc.append(pylatex.Command('item'))
    doc.append(pylatex.Command('('))
    doc.append(pylatex.Command('displaystyle'))
    with doc.create(Array(options="t", arguments="rrrrrr")):
        if misproportion_possible:
            [m, p, n] = [random.randint(2, 3) for _ in range(3)]
        ue, lsg = get_a_matr(m, p, n, misproportion_possible)
        doc.append(ue)
        lsgen.append(lsg)
    doc.append(pylatex.Command(')'))
Пример #18
0
    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
Пример #19
0
def append_a_lsg(doc, lsg):
    doc.append(pylatex.Command('item'))
    doc.append(pylatex.Command('('))
    doc.append(pylatex.Command('displaystyle'))
    if lsg.__class__ == np.float64:
        doc.append(str(int(round(lsg))))
    elif lsg.__class__ == np.ndarray:
        if (lsg == np.array([[0]])).all():
            doc.append("Keine Lösung")
        else:
            with doc.create(Array(options="t", arguments="rrrrrr")):
                doc.append(pylatex.NoEscape(make_matr_tex(lsg)))
    doc.append(pylatex.Command(')'))
Пример #20
0
def render_table_cell_latex(cell, c, top_space, btm_space, widths):
    cell = cell.walk(links_to_table_notes)
    cell_wrapper = lc.Span()
    content = utils.panflute2output(cell.content, format="latex")

    style = ""

    if cell.heading == 1:
        style = "\\sffamily "
    elif cell.heading == 2:
        style = "\\sffamily\\small "

    content = style + content

    cell_width = widths[c]

    if cell.col_span > 1:
        cell_width = sum(widths[c:c + cell.col_span])

    minipage = pl.MiniPage(
        width="{}\\columnwidth".format(cell_width),
        pos="t",
        align="left",
        content_pos="t",
    )
    minipage.append(pl.Command("setstretch", arguments="0.6"))

    if cell.vertical:
        minipage.append(lc.RotateBox(pl.NoEscape(content)))
    else:
        minipage.append(pl.NoEscape(content))

    cell_wrapper.append(pl.Command("noindent"))
    cell_wrapper.append(minipage)

    if c == 0:
        if top_space:
            cell_wrapper.append(pl.Command("T"))

        if btm_space:
            cell_wrapper.append(pl.Command("B"))

    if cell.col_span > 1:
        margins = "@{}" if cell.rm_horizontal_margins else ""
        multicolumn = pl.MultiColumn(cell.col_span,
                                     align=pl.NoEscape(f"{margins}l{margins}"),
                                     data=cell_wrapper)

        return multicolumn
    elif not cell.covered:
        return cell_wrapper
Пример #21
0
 def __init__(self, title):
     super().__init__(geometry_options={
         "tmargin": "1cm",
         "lmargin": "1cm",
         "rmargin": "1cm",
         "bmargin": "2cm"})
     self.preamble.append(tex.Package('graphicx'))
     self.preamble.append(tex.Command('title', title))
     self.preamble.append(tex.Command('author', 'Charles Wilmot'))
     self.preamble.append(tex.Command('date', tex.utils.NoEscape(r'\today')))
     self.append(tex.utils.NoEscape(r'\maketitle'))
     self.clearpage()
     self.append(tex.Command("tableofcontents"))
     self.clearpage()
Пример #22
0
def _confusion_matrices(data):

    for layer in data:
        matrix = np.zeros((2,3))
        for i_true in [1, 2, 3]:
            subdata = data[layer][np.where(data[layer]['Output_number_true'] == i_true)]
            for i_nn in [1, 2, 3]:
                nclas = np.count_nonzero(subdata['Output_number_estimated'] == i_nn)
                if i_nn == 1:
                    matrix[0, i_true - 1] = float(nclas) / subdata.shape[0]
                else:
                    matrix[1, i_true - 1] += float(nclas) / subdata.shape[0]

        table = latex.Tabular('r r c c c')
        table.add_row('', '', '', latex.utils.bold('True'), '')
        table.add_row(
            '',
            '',
            latex.utils.bold('1'),
            latex.utils.bold('2'),
            latex.utils.bold('3')
        )
        table.add_hline()
        table.append(latex.Command('addlinespace', options='3mm'))
        for i in range(2):
            if i == 0:
                cell0 = latex.MultiRow(
                    # 3,
                    2,
                    data=latex.Command(
                        'rotatebox',
                        ['90', latex.utils.bold('Network')],
                        'origin=c'
                    )
                )
                n = '1'
            else:
                cell0 = ''
                n = '2/3'
            row = [cell0, latex.utils.bold(n)]
            for j in range(3):
                row.append('{:.2f}'.format(matrix[i, j]))
            table.add_row(row)
            if i == 0:
                table.append(latex.Command('addlinespace', options='4mm'))
        path = 'confusion_{}.tex'.format(layer)
        with open(path, 'w') as wfile:
            wfile.write(table.dumps())
            print '  -> wrote ' + path
Пример #23
0
 def ImprLtxResumen(self, doc, sect, recurre=True):
     if (self.hasQuantities()):
         if (sect != 'root'):
             doc.add_item(self.getTitle())
             doc.append(pylatex.Command('dotfill'))
             doc.append(self.getLtxPriceString())
         else:
             doc.append(pylatex_utils.LargeCommand())
             doc.append(pylatex.utils.bold('Total'))
             doc.append(pylatex.Command('dotfill'))
             doc.append(pylatex.utils.bold(self.getLtxPriceString()))
             doc.append(pylatex_utils.NormalSizeCommand())
         if (recurre):
             self.subcapitulos.ImprLtxResumen(
                 doc, pylatex_utils.getLatexSection(sect), recurre)
Пример #24
0
    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
Пример #25
0
 def add_hline(document):
     if self.has_label:
         cmd = r"\cline{" + "2-{0}".format(self.amount_elements +
                                           1) + "}"
         document.append(pylatex.NoEscape(cmd))
     else:
         document.append(pylatex.Command("hline"))
Пример #26
0
    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())
Пример #27
0
 def add2document(self, doc) -> None:
     with doc.create(pylatex.Section(self.name)):
         for table in self.tables:
             table.add2document(doc)
             doc.append(pylatex.NoEscape(""))
             doc.append(pylatex.Command("newline"))
             doc.append(pylatex.NoEscape(""))
             doc.append(
                 pylatex.Command(
                     "vspace",
                     arguments="{0}mm".format(
                         self.VERTICAL_SPACE_BETWEEN_TABLE),
                 ))
             doc.append(pylatex.NoEscape(""))
             doc.append(pylatex.Command("newline"))
             doc.append(pylatex.NoEscape(""))
Пример #28
0
    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")
Пример #29
0
    def addYearlyReports(self, plotPaths):

        for i, (year, paths) in enumerate(plotPaths.items()):
            self.addYearSection(year, paths)

            if (i + 1) % 2 == 0:
                self.doc.append(tex.Command("newpage"))
Пример #30
0
 def ImprLtxPre(self, doc, sect):
     '''Imprime presupuestos parciales.'''
     if (self.hasQuantities()):
         if (sect != 'root'):
             doc.append(pylatex.Section(self.getTitle()))
         self.quantities.ImprLtxPre(doc, self.getTitle())
         self.subcapitulos.ImprLtxPre(doc,
                                      pylatex_utils.getLatexSection(sect))
         if self.subcapitulos:
             doc.append(pylatex.Command('noindent'))
             doc.append(pylatex_utils.largeCommand())
             doc.append(
                 pylatex.utils.bold('Total: ' + self.getTitle() + ' '))
             doc.append(pylatex.Command('dotfill'))
             doc.append(pylatex.utils.bold(self.getLtxPriceString()))
             doc.append(pylatex.NewLine())
             doc.append(pylatex_utils.NormalSizeCommand())