Exemplo n.º 1
0
Arquivo: table.py Projeto: CETHop/sage
    def _html_table_row(self, row, header=False):
        r"""
        Print the items of a list as one row of an HTML table. Used by
        the :meth:`_html_` method.

        INPUTS:

        - ``row`` - a list with the same number of entries as each row
          of the table.
        - ``header`` (default False) - if True, treat this as a header
          row, using ``<th>`` instead of ``<td>``.

        Strings get printed verbatim unless they seem to be LaTeX
        code, in which case they are enclosed in a ``script`` tag
        appropriate for MathJax. Sage objects are printed using their
        LaTeX representations.

        EXAMPLES::

            sage: T = table([['a', 'bb', 'ccccc'], [10, -12, 0], [1, 2, 3]])
            sage: T._html_table_row(['a', 2, '$x$'])
            <td>a</td>
            <td><script type="math/tex">2</script></td>
            <td><script type="math/tex">x</script></td>
        """
        from sage.plot.all import Graphics
        from latex import latex
        from html import math_parse
        import types

        if isinstance(row, types.GeneratorType):
            row = list(row)
        elif not isinstance(row, (list, tuple)):
            row = [row]

        column_tag = "<th>%s</th>" if header else "<td>%s</td>"

        if self._options['header_column']:
            first_column_tag = "<th class=\"ch\">%s</th>" if header else "<td class=\"ch\">%s</td>"
        else:
            first_column_tag = column_tag

        # First entry of row:
        entry = row[0]
        if isinstance(entry, Graphics):
            print first_column_tag % entry.show(linkmode = True)
        elif isinstance(entry, str):
            print first_column_tag % math_parse(entry)
        else:
            print first_column_tag % ('<script type="math/tex">%s</script>' % latex(entry))

        # Other entries:
        for column in xrange(1,len(row)):
            if isinstance(row[column], Graphics):
                print column_tag % row[column].show(linkmode = True)
            elif isinstance(row[column], str):
                print column_tag % math_parse(row[column])
            else:
                print column_tag % ('<script type="math/tex">%s</script>' % latex(row[column]))
Exemplo n.º 2
0
Arquivo: table.py Projeto: Babyll/sage
    def _html_table_row(self, file, row, header=False):
        r"""
        Write table row
        
        Helper method used by the :meth:`_html_` method.

        INPUT:

        - ``file`` -- file-like object. The table row data will be
          written to it.

        - ``row`` -- a list with the same number of entries as each row
          of the table.

        - ``header`` -- bool (default False). If True, treat this as a
          header row, using ``<th>`` instead of ``<td>``.

        OUTPUT:

        This method returns nothing. All output is written to ``file``.

        Strings are written verbatim unless they seem to be LaTeX
        code, in which case they are enclosed in a ``script`` tag
        appropriate for MathJax. Sage objects are printed using their
        LaTeX representations.

        EXAMPLES::

            sage: T = table([['a', 'bb', 'ccccc'], [10, -12, 0], [1, 2, 3]])
            sage: import StringIO
            sage: s = StringIO.StringIO()
            sage: T._html_table_row(s, ['a', 2, '$x$'])
            sage: print(s.getvalue())
            <td>a</td>
            <td><script type="math/tex">2</script></td>
            <td><script type="math/tex">x</script></td>
        """
        from sage.plot.all import Graphics
        from latex import latex
        from html import math_parse
        import types

        if isinstance(row, types.GeneratorType):
            row = list(row)
        elif not isinstance(row, (list, tuple)):
            row = [row]

        column_tag = "<th>%s</th>\n" if header else "<td>%s</td>\n"

        if self._options['header_column']:
            first_column_tag = '<th class="ch">%s</th>\n' if header else '<td class="ch">%s</td>\n'
        else:
            first_column_tag = column_tag

        # First entry of row:
        entry = row[0]
        if isinstance(entry, Graphics):
            file.write(first_column_tag % entry.show(linkmode = True))
        elif isinstance(entry, str):
            file.write(first_column_tag % math_parse(entry))
        else:
            file.write(first_column_tag % ('<script type="math/tex">%s</script>' % latex(entry)))

        # Other entries:
        for column in xrange(1,len(row)):
            if isinstance(row[column], Graphics):
                file.write(column_tag % row[column].show(linkmode = True))
            elif isinstance(row[column], str):
                file.write(column_tag % math_parse(row[column]))
            else:
                file.write(column_tag % ('<script type="math/tex">%s</script>' % latex(row[column])))
Exemplo n.º 3
0
    def _html_table_row(self, row, header=False):
        r"""
        Print the items of a list as one row of an HTML table. Used by
        the :meth:`_html_` method.

        INPUTS:

        - ``row`` - a list with the same number of entries as each row
          of the table.
        - ``header`` (default False) - if True, treat this as a header
          row, using ``<th>`` instead of ``<td>``.

        Strings get printed verbatim unless they seem to be LaTeX
        code, in which case they are enclosed in a ``script`` tag
        appropriate for MathJax. Sage objects are printed using their
        LaTeX representations.

        EXAMPLES::

            sage: T = table([['a', 'bb', 'ccccc'], [10, -12, 0], [1, 2, 3]])
            sage: T._html_table_row(['a', 2, '$x$'])
            <td>a</td>
            <td><script type="math/tex">2</script></td>
            <td><script type="math/tex">x</script></td>
        """
        from sage.plot.all import Graphics
        from latex import latex
        from html import math_parse
        import types

        if isinstance(row, types.GeneratorType):
            row = list(row)
        elif not isinstance(row, (list, tuple)):
            row = [row]

        column_tag = "<th>%s</th>" if header else "<td>%s</td>"

        if self._options['header_column']:
            first_column_tag = "<th class=\"ch\">%s</th>" if header else "<td class=\"ch\">%s</td>"
        else:
            first_column_tag = column_tag

        # First entry of row:
        entry = row[0]
        if isinstance(entry, Graphics):
            print first_column_tag % entry.show(linkmode=True)
        elif isinstance(entry, str):
            print first_column_tag % math_parse(entry)
        else:
            print first_column_tag % ('<script type="math/tex">%s</script>' %
                                      latex(entry))

        # Other entries:
        for column in xrange(1, len(row)):
            if isinstance(row[column], Graphics):
                print column_tag % row[column].show(linkmode=True)
            elif isinstance(row[column], str):
                print column_tag % math_parse(row[column])
            else:
                print column_tag % ('<script type="math/tex">%s</script>' %
                                    latex(row[column]))
Exemplo n.º 4
0
    def _html_table_row(self, file, row, header=False):
        r"""
        Write table row
        
        Helper method used by the :meth:`_html_` method.

        INPUT:

        - ``file`` -- file-like object. The table row data will be
          written to it.

        - ``row`` -- a list with the same number of entries as each row
          of the table.

        - ``header`` -- bool (default False). If True, treat this as a
          header row, using ``<th>`` instead of ``<td>``.

        OUTPUT:

        This method returns nothing. All output is written to ``file``.

        Strings are written verbatim unless they seem to be LaTeX
        code, in which case they are enclosed in a ``script`` tag
        appropriate for MathJax. Sage objects are printed using their
        LaTeX representations.

        EXAMPLES::

            sage: T = table([['a', 'bb', 'ccccc'], [10, -12, 0], [1, 2, 3]])
            sage: import StringIO
            sage: s = StringIO.StringIO()
            sage: T._html_table_row(s, ['a', 2, '$x$'])
            sage: print(s.getvalue())
            <td>a</td>
            <td><script type="math/tex">2</script></td>
            <td><script type="math/tex">x</script></td>
        """
        from sage.plot.all import Graphics
        from latex import latex
        from html import math_parse
        import types

        if isinstance(row, types.GeneratorType):
            row = list(row)
        elif not isinstance(row, (list, tuple)):
            row = [row]

        column_tag = "<th>%s</th>\n" if header else "<td>%s</td>\n"

        if self._options['header_column']:
            first_column_tag = '<th class="ch">%s</th>\n' if header else '<td class="ch">%s</td>\n'
        else:
            first_column_tag = column_tag

        # First entry of row:
        entry = row[0]
        if isinstance(entry, Graphics):
            file.write(first_column_tag % entry.show(linkmode=True))
        elif isinstance(entry, str):
            file.write(first_column_tag % math_parse(entry))
        else:
            file.write(first_column_tag %
                       ('<script type="math/tex">%s</script>' % latex(entry)))

        # Other entries:
        for column in xrange(1, len(row)):
            if isinstance(row[column], Graphics):
                file.write(column_tag % row[column].show(linkmode=True))
            elif isinstance(row[column], str):
                file.write(column_tag % math_parse(row[column]))
            else:
                file.write(column_tag %
                           ('<script type="math/tex">%s</script>' %
                            latex(row[column])))