Esempio n. 1
0
 def dumps(self):
     if self.fill:
         return "\\filldraw[{0}] {1} rectangle {2} {3};".format(
                 self.options,self.p1, self.p2, dumps_list(self))
     else:
         return "\\draw[{0}] {1} rectangle {2} {3};".format(
                 self.options,self.p1, self.p2, dumps_list(self))
Esempio n. 2
0
 def dumps(self, no_slash=True):
     if no_slash:
         return "node({1}) [{0}] {{ {2} }}".format(
                 self.options,self.name, dumps_list(self))
     else:
         return "\\node({1}) [{0}] {{ {2} }}".format(
                 self.options,self.name, dumps_list(self))
Esempio n. 3
0
    def dumps(self):
        if self.inline:
            string = '$' + dumps_list(self, token=' ') + '$'
        else:
            string = '$$' + dumps_list(self, token=' ') + '$$\n'

        super().dumps()
        return string
Esempio n. 4
0
    def dumps(self):
        if self.inline:
            string = '$' + dumps_list(self, token=' ') + '$'
        else:
            string = '$$' + dumps_list(self, token=' ') + '$$\n'

        super().dumps()
        return string
Esempio n. 5
0
def test_utils():
    # Utils
    escape_latex(s='')

    fix_filename(path='')

    dumps_list(l=[], escape=False, token='\n')

    bold(s='')

    italic(s='')

    verbatim(s='', delimiter='|')
Esempio n. 6
0
def test_utils():
    # Utils
    escape_latex(s='')

    fix_filename(path='')

    dumps_list(l=[], escape=False, token='\n')

    bold(s='')

    italic(s='')

    verbatim(s='', delimiter='|')
Esempio n. 7
0
def test_utils():
    # Utils
    escape_latex(s="")

    fix_filename(path="")

    dumps_list(l=[], escape=False, token="\n")

    bold(s="")

    italic(s="")

    verbatim(s="", delimiter="|")
Esempio n. 8
0
    def dumps(self) -> str:
        """Get a string representation of this cell.

        Returns:
            A string representation of itself.
        """
        return dumps_list(self, token=self.token)
Esempio n. 9
0
    def dumps_packages(self):
        """Represent the packages needed as a string in LaTeX syntax.

        :return:
        :rtype: list
        """

        return dumps_list(self.packages)
Esempio n. 10
0
    def dumps_packages(self):
        """Represents the packages needed as a string in LaTeX syntax.

            :return:
            :rtype: list
        """

        return dumps_list(self.packages)
Esempio n. 11
0
    def dumps_packages(self):
        """Represent the packages needed as a string in LaTeX syntax.

        Returns
        -------
        list
        """

        return dumps_list(self.packages)
Esempio n. 12
0
    def dumps(self, **kwargs):
        """Represents the container as a string in LaTeX syntax.

            :return:
            :rtype: list
        """

        self.propegate_packages()

        return dumps_list(self, **kwargs)
Esempio n. 13
0
    def dumps(self, **kwargs):
        """Represent the container as a string in LaTeX syntax.

        :return:
        :rtype: list
        """

        self._propagate_packages()

        return dumps_list(self, **kwargs)
Esempio n. 14
0
    def dumps_packages(self):
        r"""Represent the packages needed as a string in LaTeX syntax.

        Returns
        -------
        string:
            A LaTeX string representing the packages of the container
        """

        self._propagate_packages()

        # TODO: Use super call here
        return dumps_list(self.packages)
Esempio n. 15
0
    def dumps(self):
        """Represents the section as a string in LaTeX syntax."""

        if not self.numbering:
            num = '*'
        else:
            num = ''

        base = '\\' + self.__class__.__name__.lower() + num
        string = base + '{' + self.title + '}\n' + dumps_list(self)

        super().dumps()
        return string
Esempio n. 16
0
    def dumps(self):
        """Represents the section as a string in LaTeX syntax."""

        if not self.numbering:
            num = '*'
        else:
            num = ''

        base = '\\' + self.__class__.__name__.lower() + num
        string = base + '{' + self.title + '}\n' + dumps_list(self)

        super().dumps()
        return string
Esempio n. 17
0
    def dumps(self):
        """Represents the named container as a string in LaTeX syntax."""
        string = r'\begin{' + self.name + '}\n'

        if self.options is not None:
            string += '[' + self.options + ']'

        string += dumps_list(self)

        string += r'\end{' + self.name + '}\n'

        super(BaseLaTeXNamedContainer, self).dumps()

        return string
Esempio n. 18
0
    def dumps(self):
        """Represents the named container as a string in LaTeX syntax."""
        string = r'\begin{' + self.name + '}\n'

        if self.options is not None:
            string += '[' + self.options + ']'

        string += dumps_list(self)

        string += r'\end{' + self.name + '}\n'

        super().dumps()

        return string
Esempio n. 19
0
    def dumps(self):
        """Represents the document as a string in LaTeX syntax."""
        string = r'\begin{' + self.table_type + '}'

        if self.pos is not None:
            string += '[' + self.pos + ']'

        string += '{' + self.table_spec + '}\n'

        string += dumps_list(self)

        string += r'\end{' + self.table_type + '}'

        super().dumps()
        return string
Esempio n. 20
0
    def dumps(self):
        """Represents the document as a string in LaTeX syntax."""
        string = r'\begin{' + self.table_type + '}'

        if self.pos is not None:
            string += '[' + self.pos + ']'

        string += '{' + self.table_spec + '}\n'

        string += dumps_list(self)

        string += r'\end{' + self.table_type + '}'

        super().dumps()
        return string
Esempio n. 21
0
    def dumps(self):
        """Represents the document as a string in LaTeX syntax."""
        document = r'\begin{document}'

        document += dumps_list(self)

        document += r'\end{document}'

        super().dumps()

        head = r'\documentclass{' + self.documentclass + '}'

        head += self.dumps_packages()

        return head + document
Esempio n. 22
0
    def dumps(self):
        """Represents the document as a string in LaTeX syntax."""
        document = r'\begin{document}'

        document += dumps_list(self)

        document += r'\end{document}'

        super().dumps()

        head = r'\documentclass{' + self.documentclass + '}'

        head += self.dumps_packages()

        return head + document
Esempio n. 23
0
    def dumps_content(self, **kwargs):
        r"""Represent the container as a string in LaTeX syntax.

        Args
        ----
        \*\*kwargs:
            Arguments that can be passed to `~.dumps_list`


        Returns
        -------
        string:
            A LaTeX string representing the container
        """

        return dumps_list(self, escape=self.escape,
                          token=self.content_separator, **kwargs)
Esempio n. 24
0
def compile_latex(latex_str):
    old_cwd = os.getcwd()

    with tempfile.TemporaryDirectory() as tempdir:
        path = os.path.join(tempdir, 'output')

        logger.error(path)
        doc = Document(path,
                       data=[dumps_list([latex_str], escape=False)],
                       geometry_options='landscape')

        doc.packages.append(Package('xcolor', ['dvipsnames', 'table']))
        try:
            doc.generate_pdf(clean_tex=False, silent=False)
            doc.generate_tex()
        except subprocess.CalledProcessError as e:
            os.chdir(
                old_cwd)  # because pylatex change it but doesnt restore it
            raise e

        with open(path + '.pdf', 'rb') as fp:
            return fp.read()
Esempio n. 25
0
def test_mapper():
    assert dumps_list(['Test', 'text'], mapper=MediumText) == \
        '''\\begin{large}%
Esempio n. 26
0
 def add_row(self, cells, escape=False):
     """Add a row of cells to the table"""
     self.append(dumps_list(cells, escape=escape, token='&') + r'\\')
Esempio n. 27
0
 def dumps_packages(self):
     """Represents the packages needed as a string in LaTeX syntax."""
     self.propegate_packages()
     return dumps_list(self.packages)
Esempio n. 28
0
v = VectorName(name='')

M = np.matrix([[2, 3, 4],
               [0, 0, 1],
               [0, 0, 2]])
m = Matrix(matrix=M, name='', mtype='p', alignment=None)

# Package
p = Package(name='', base='usepackage', options=None)

# PGFPlots
tikz = TikZ(data=None) 

a = Axis(data=None, options=None) 

p = Plot(name=None, func=None, coordinates=None, options=None)

# Utils
escape_latex(s='')

fix_filename(filename='')

dumps_list(l=[], escape=False, token='\n')

bold(s='')

italic(s='')

verbatim(s='', delimiter='|')

Esempio n. 29
0
# Package
p = Package(name='', base='usepackage', options=None)

# PGFPlots
tikz = TikZ(data=None)

a = Axis(data=None, options=None)

p = Plot(name=None, func=None, coordinates=None, options=None)

# Utils
escape_latex(s='')

fix_filename(path='')

dumps_list(l=[], escape=False, token='\n')

bold(s='')

italic(s='')

verbatim(s='', delimiter='|')

# Lists
itemize = Itemize()
itemize.add_item(s="item")
itemize.append("append")

enum = Enumerate()
enum.add_item(s="item")
enum.append("append")
Esempio n. 30
0
 def add_row(self, cells, escape=False):
     """Add a row of cells to the table"""
     self.append(dumps_list(cells, escape=escape, token='&') + r'\\')
Esempio n. 31
0
 def dumps_packages(self):
     """Represents the packages needed as a string in LaTeX syntax."""
     self.propegate_packages()
     return dumps_list(self.packages)
Esempio n. 32
0
    def doit(self):

        is_multirow = self.num_metrics > 1 and self.spec.multirow

        def render_metric(value, best, second, decimals, format_string,
                          highlight_top, relative_to):
            if isinstance(value, numbers.Number):
                if relative_to is None or relative_to == 0 or not np.isfinite(
                        relative_to):
                    # absolute number
                    rendered = format_string.format(value, prec=decimals)
                else:
                    # percent
                    rendered = format_ratio_percent(value,
                                                    relative_to,
                                                    decimals=decimals)
                if highlight_top:
                    if value == best:
                        rendered = bold(rendered)
                    elif value == second:
                        rendered = italic(rendered)
                return rendered
            else:
                return value

        if self.spec.export_latex:
            row_height = None
        else:
            row_height = 0.65 if is_multirow and self.num_metrics >= 3 else 1

        column_spec = '|r' if self.spec.vertical_bars else 'r'
        t = Tabular('l' + column_spec * self.num_exps,
                    row_height=row_height,
                    pos=['t'])
        escape_header_fun = lambda text: text if self.spec.escape_latex_header else NoEscape(
            text)
        if self.spec.rotate_header:
            t.add_row([''] + [
                NoEscape(r"\rotatebox{90}{%s}" % escape_latex(
                    escape_header_fun(s.display_name(self.exps[s.name]))))
                for s in self.experiment_specs
            ])
        else:
            t.add_row([''] + [
                escape_header_fun(s.display_name(self.exps[s.name]))
                for s in self.experiment_specs
            ])
        t.add_hline()

        for seq in self.seq_names:
            fails = [
                self.is_failed(self.exps[s.name], seq)
                for s in self.experiment_specs
            ]
            failure_strings = [
                self.render_failure(self.exps[s.name], seq)
                for s in self.experiment_specs
            ]
            values = np.array([
                self.get_metrics(self.exps[s.name], seq, s.it)
                for s in self.experiment_specs
            ])

            top_values = list(range(self.num_metrics))
            for c, m in enumerate(self.metrics):
                try:
                    values[:, c] = np.around(values[:, c], m.decimals)
                except IndexError:
                    pass
                non_excluded_values = np.array(values[:, c])
                for i in m.exclude_columns_highlight:
                    non_excluded_values[i] = math.nan
                top_values[c] = best_two_non_repeating(
                    non_excluded_values, reverse=m.larger_is_better)

            if is_multirow:
                rows = [[
                    MultiRow(self.num_metrics, data=self.seq_displayname(seq))
                ]] + [list(['']) for _ in range(1, self.num_metrics)]
            else:
                rows = [[self.seq_displayname(seq)]]
            for c, (fail, failure_str,
                    value_col) in enumerate(zip(fails, failure_strings,
                                                values)):
                if failure_str is not None:
                    if self.spec.color_failed:
                        failure_str = TextColor(self.spec.color_failed,
                                                failure_str)
                    if is_multirow:
                        rows[0].append(
                            MultiRow(self.num_metrics, data=failure_str))
                        for r in range(1, self.num_metrics):
                            rows[r].append('')
                    else:
                        rows[0].append(failure_str)
                else:
                    tmp_data = [None] * self.num_metrics
                    for r, m in enumerate(self.metrics):
                        if m.failed_threshold and value_col[
                                r] > m.failed_threshold:
                            obj = "x"
                            if self.spec.color_failed:
                                obj = TextColor(self.spec.color_failed, obj)
                        else:
                            relative_to = None
                            if m.relative_to_column is not None and m.relative_to_column != c:
                                relative_to = values[m.relative_to_column, r]
                            obj = render_metric(value_col[r],
                                                top_values[r][0],
                                                top_values[r][1],
                                                m.effective_display_decimals(),
                                                m.format_string,
                                                m.highlight_top,
                                                relative_to=relative_to)
                            if fail and self.spec.color_failed:
                                obj = TextColor(self.spec.color_failed, obj)
                        tmp_data[r] = obj
                    if self.num_metrics == 1 or is_multirow:
                        for r, obj in enumerate(tmp_data):
                            rows[r].append(obj)
                    else:
                        entry = []
                        for v in tmp_data:
                            entry.append(v)
                            entry.append(NoEscape("~/~"))
                        entry.pop()
                        rows[0].append(dumps_list(entry))

            for row in rows:
                t.add_row(row)

            if is_multirow:
                t.add_hline()

        if self.spec.export_latex:
            os.makedirs(self.export_basepath, exist_ok=True)
            t.generate_tex(
                os.path.join(self.export_basepath, self.spec.export_latex))

        with self.create(Subsection(self.spec.name, numbering=False)) as p:

            if self.spec.metrics_legend:
                legend = Tabular('|c|', row_height=row_height, pos=['t'])
                legend.add_hline()
                legend.add_row(["Metrics"])
                legend.add_hline()
                for m in self.metrics:
                    legend.add_row([m.display_name])
                legend.add_hline()

                tab = Tabular("ll")
                tab.add_row([t, legend])
                content = tab
            else:
                content = t

            if True:
                content = FootnoteText(content)

            p.append(content)