Exemplo n.º 1
0
def append_liquor_list(doc, df, own_page):
    # TODO no interaction with dataframe?
    kinds = df[df.Category.isin(['Spirit', 'Vermouth',
                                 'Liqueur'])][['Kind', 'Type']]
    if own_page:
        print "Appending list as new page"
        doc.append(NewPage())
    listing = SamepageEnvironment()
    block = Center()
    if not own_page:
        block.append(HRuleFill())
        block.append(Command('\\'))
    block.append(VerticalSpace('16pt'))
    block.append(TitleText("Included Ingredients"))
    block.append(Command('\\'))
    listing.append(block)
    listing.append(VerticalSpace('12pt'))

    cols = add_paracols_environment(listing, 2, '8pt', sloppy=False)
    with cols.create(FlushRight()):
        for item in kinds.Kind:
            cols.append(LargeText(item))
            cols.append(Command('\\'))
    cols.append(Command('switchcolumn'))
    with cols.create(FlushLeft()):
        for item in kinds.Type:
            cols.append(LargeText(italic(item)))
            cols.append(Command('\\'))

    doc.append(listing)
Exemplo n.º 2
0
def test_position():

    repr(HorizontalSpace(size='20pt', star=False))

    repr(VerticalSpace(size="20pt", star=True))

    # Test alignment environments
    center = Center()
    center.append("append")
    repr(center)

    right = FlushRight()
    right.append("append")
    repr(right)

    left = FlushLeft()
    left.append("append")
    repr(left)

    minipage = MiniPage(width=r"\textwidth",
                        height="10pt",
                        pos='t',
                        align='r',
                        content_pos='t',
                        fontsize="Large")
    minipage.append("append")
    repr(minipage)

    textblock = TextBlock(width="200",
                          horizontal_pos="200",
                          vertical_pos="200",
                          indent=True)
    textblock.append("append")
    textblock.dumps()
    repr(textblock)
Exemplo n.º 3
0
def test_position():

    repr(HorizontalSpace(size='20pt', star=False))

    repr(VerticalSpace(size="20pt", star=True))

    # Test alignment environments
    center = Center()
    center.append("append")
    repr(center)

    right = FlushRight()
    right.append("append")
    repr(right)

    left = FlushLeft()
    left.append("append")
    repr(left)

    minipage = MiniPage(width=r"\textwidth", height="10pt", pos='t',
                        align='r', content_pos='t', fontsize="Large")
    minipage.append("append")
    repr(minipage)

    textblock = TextBlock(width="200", horizontal_pos="200",
                          vertical_pos="200", indent=True)
    textblock.append("append")
    textblock.dumps()
    repr(textblock)
Exemplo n.º 4
0
    def fromTable(self, s: Table):
        c = Center()
        # c.append(NoEscape(r"\newlength\q"))
        c.append(
            NoEscape(
                rf"\setlength\tablewidth{{\dimexpr (\textwidth -{2*s.col_num}\tabcolsep)}}"
            ))
        c.append(NoEscape(r"\arrayrulecolor{tablelinegray!75}"))
        c.append(NoEscape(r"\rowcolors{2}{tablerowgray}{white}"))

        ratios = s.cacu_col_ratio()
        # format = "|".join([rf"p{{{r}\textwidth}}<{{\centering}}" for r in ratios])
        format = "|".join(
            [rf"p{{{r}\tablewidth}}<{{\centering}}" for r in ratios])
        format = f"|{format}|"

        t = Tabular(format)
        t.add_hline()
        for i, row in enumerate(s.tables):
            if i == 0:
                t.append(NoEscape(r"\rowcolor{tabletopgray}"))

            row = [self.fromTokenLine(c) for c in row]
            if i == 0:
                row = [bold(c) for c in row]

            t.add_row(row)
            t.add_hline()

        c.append(t)
        return c
Exemplo n.º 5
0
def de_table(s: env.Table):
    col, row = s.shape

    c = Center()
    # c.append(NoEscape(r"\newlength\q"))
    c.append(
        NoEscape(
            r"\setlength\tablewidth{{\dimexpr (\textwidth -{}\tabcolsep)}}".
            format(2 * col)))
    c.append(NoEscape(r"\arrayrulecolor{tablelinegray!75}"))
    c.append(NoEscape(r"\rowcolors{2}{tablerowgray}{white}"))

    ratios = s.cacu_col_ratio()
    format = "|".join(
        [r"p{{{r}\tablewidth}}<{{\centering}}".format(r=r) for r in ratios])
    format = "|{format}|".format(format=format)

    t = Tabular(format)
    t.add_hline()
    for i, row in enumerate(s.iter_rows()):
        if i == 0:
            t.append(NoEscape(r"\rowcolor{tabletopgray}"))

        row = [de_line(c) for c in row]
        if i == 0:
            row = [bold(c) for c in row]

        t.add_row(row)
        t.add_hline()

    c.append(t)
    return c
Exemplo n.º 6
0
    def fromImage(self, s: Image):
        # cur_dir = os.getcwd() #markdown的相对路径,一定是针对那个markdown的,
        # os.chdir(self.input_dir)
        link = s.link
        link = ImageTool.verify(link, self.image_dir, self.input_dir)
        # os.chdir(cur_dir)

        if config.give_rele_path:
            link = os.path.relpath(link, self.output_dir)

        link = link.replace("\\", "/")

        c = Center()
        c.append(
            NoEscape(rf"\vspace{{\baselineskip}}"
                     rf"\includegraphics[width=0.8\textwidth]{{{link}}}"
                     rf"\vspace{{\baselineskip}}"))
        return c
Exemplo n.º 7
0
def de_image(s: lines.Image):
    img_path = ImageTool.verify(s.link, config.cacheimg_dir)

    if img_path is None:
        c = Center()
        c.append(NoEscape('Link or path not found: {}'.format(s.link)))
        return c

    if config.give_rele_path:
        img_path = os.path.relpath(img_path, config.output_dir)
    img_path = norm_path(img_path)

    c = Center()
    if isinstance(s.parent, env.Quote):
        c.append(
            NoEscape(
                r"\includegraphics[width=0.8\textwidth]{{{img_path}}}".format(
                    img_path=img_path)))
    else:
        fig = Figure(position=config.fig_position)
        fig.add_image(img_path, placement='')
        if len(s.desc.strip()) > 0:
            fig.add_caption(s.desc)
        c.append(fig)
    return c
Exemplo n.º 8
0
    def to_tex(self):

        tab = self._create_tabular()
        tab.add_hline()
        for i in range(self.sheet.nrows):
            line = []
            merge_set = set()
            for j in range(self.sheet.ncols):
                res, mindex = self.in_merge_cell(i, j)

                if res == -1:
                    line.append(self.cell(i, j))
                else:
                    merge_set.add(mindex)
                    cres, cnum = self.ismulticol(mindex)
                    rres, rnum = self.ismultirow(mindex)
                    if res == 0:
                        if cres:
                            if rres:
                                line.append(
                                    MultiColumn(
                                        cnum,
                                        align=self._cacu_multicol_align(j),
                                        data=MultiRow(rnum,
                                                      data=self.cell(i, j))))
                            else:
                                line.append(
                                    MultiColumn(
                                        cnum,
                                        align=self._cacu_multicol_align(j),
                                        data=self.cell(i, j)))
                        else:
                            line.append(MultiRow(rnum, data=self.cell(i, j)))
                    elif res == 1:  # 不同行同列
                        if cres and rres:
                            line.append(
                                MultiColumn(cnum,
                                            align=self._cacu_multicol_align(j),
                                            data=""))
                        else:
                            line.append("")
                    elif res == 2:  # 不同列同行
                        pass

            tab.add_row(line)

            all_range = [[0, self.sheet.ncols - 1]]
            for mi in merge_set:
                merge_range = self.merge_col[mi]

                if merge_range[1] - merge_range[0] > 0 and merge_range[
                        1] - i > 0:
                    all_range = self._extract_range(all_range,
                                                    merge_range[2:4])

            if all_range[0][0] == 0 and all_range[0][1] == self.sheet.ncols - 1:
                tab.add_hline()
            else:
                for r in all_range:
                    tab.add_hline(r[0] + 1, r[1] + 1)

        table = TexTable(position=self.params["position"])
        table.append(tab)

        res = table
        if self.params["center"]:
            c = Center()
            c.append(
                NoEscape(
                    r"% \newlength\tablewidth % if haven't define the length 'tablewidth'"
                ))
            c.append(
                NoEscape(
                    rf"\setlength\tablewidth{{\dimexpr (\textwidth -{2*self.sheet.ncols}\tabcolsep)}}"
                ))
            c.append(table)
            res = c

        return self._format_tex(res.dumps())
Exemplo n.º 9
0
def local_data_assinatura(doc):
    doc.append(Command('raggedleft'))
    doc.append(Command('bigskip'))
    with doc.create(MiniPage(width=r'.5\textwidth')):
        center = Center()
        center.append(Command('hrulefill'))
        center.append(NewLine())
        center.append(Command('bigskip'))
        center.append(Command('bigskip'))
        center.append(NoEscape(r'Local e data \\'))
        center.append(Command('hrulefill'))
        center.append(NewLine())
        center.append(Command('bigskip'))
        center.append(NoEscape('Assinatura do(a) Coordenador(a) da Atividade'))
        doc.append(center)