Not signed in (Sign In)

Not signed in

Want to take part in these discussions? Sign in if you have an account, or apply for one below

  • Sign in using OpenID

Discussion Tag Cloud

Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.

Welcome to nForum
If you want to take part in these discussions either sign in now (if you have an account), apply for one now (if you don't).
    • CommentRowNumber1.
    • CommentAuthorandreas
    • CommentTimeJun 15th 2014

    I want to generate tables in SAGE, and paste these into an nLab page. However, SAGE can generate three types of tables, namely plain text, LaTeX, or HTML, but all of these come out completely garbled when I simply paste them into an nLab page and save.

    SAGE reference page: http://www.sagemath.org/doc/reference/misc/sage/misc/table.html

    How could I solve this problem?

    • CommentRowNumber2.
    • CommentAuthorzskoda
    • CommentTimeJun 15th 2014
    • (edited Jun 15th 2014)

    I am not an expert, but in any case, both the source and the visual should be left available, for others to be able to change them by changing source and recompile at a later stage.

    • CommentRowNumber3.
    • CommentAuthorAndrew Stacey
    • CommentTimeJun 15th 2014

    You could write a new export routine to output Markdown+itex.

    • CommentRowNumber4.
    • CommentAuthorandreas
    • CommentTimeJun 15th 2014

    Andrew, this is the kind of thing I don’t know how to do. Any pointers to where I could learn?

    • CommentRowNumber5.
    • CommentAuthorRodMcGuire
    • CommentTimeJun 15th 2014

    It would be best to give an example of what you are trying to include (LaTeX and HTML outputs).

    Maybe a simple script or text editor macro can convert either the HTML or LaTeX into something the nLab likes.

    If you want the general solution of a special iTex exporter from Sage, all of the Sage table code (latex, html) is in sage / src / sage / misc / table.py - though to figure out how to augment that you may need to contact the guy who wrote it, John Palmieri.

    • CommentRowNumber6.
    • CommentAuthorAndrew Stacey
    • CommentTimeJun 15th 2014

    I did something like this for matrices (I wanted to modify the way sage outputted matrices for LaTeX). What I did was to find the export function in the Sage code and modify it to my needs. I suspect that it wouldn’t be hard to do the same thing for tables. Basically, it concatenates a variety of arrays so you simply need to modify the joining strings.

    You’d need to make it do Markdown table syntax, but if it’s maths in the entries then you’ll need to add the dollars before and after each cell. Nevertheless, it’s a simple enough join. I’d experiment a little in the Sandbox to get the format right, then take a look at the Sage code (which Rod has linked to) to find the function to modify.

    Oh, and I’d start by simply writing it as a function rather than a class method. As an example, here’s my matrix output code:

    def print_matrix(m):
        latex = sage.misc.latex.latex
        LatexExpr = sage.misc.latex.LatexExpr
        nr = m.nrows()
        nc = m.ncols()
        if nr == 0 or nc == 0:
            return ""
    
        S = m.list()
        rows = []
    
        for r in range(0,nr):
            s = ""
            for c in range(0,nc):
                if c == nc-1:
                    sep=""
                else:
                    sep=" & "
                entry = latex(S[r*nc+c])
                s = s + entry + sep
            rows.append(s)
    
        tmp = []
        for row in rows:
            tmp.append(str(row))
        s = " \\\\\n".join(tmp)
    
        return LatexExpr("\\begin{bmatrix}\n" + s + "\n\\end{bmatrix}")
    
    def print_matrix_columns(m):
        latex = sage.misc.latex.latex
        LatexExpr = sage.misc.latex.LatexExpr
        nr = m.nrows()
        nc = m.ncols()
        if nr == 0 or nc == 0:
            return ""
    
        S = m.list()
        rows = []
    
        for c in range(0,nc):
            s = ""
            for r in range(0,nr):
                if r == nr-1:
                    sep=""
                else:
                    sep=" \\\\ "
                entry = latex(S[r*nc+c])
                s = s + entry + sep
            rows.append(s)
    
        tmp = []
        for row in rows:
            tmp.append(str(row))
        s = "\n\\end{bmatrix},\n\\begin{bmatrix}\n".join(tmp)
    
        return LatexExpr("\\left\\{\\begin{bmatrix}\n" + s + "\n\\end{bmatrix}\\right\\}")
    
    def print_vector(v):
        latex = sage.misc.latex.latex
        LatexExpr = sage.misc.latex.LatexExpr
        nr = len(v)
        if nr == 0:
            return ""
    
        S = v.list()
        s = ""
    
        for r in range(0,nr):
            if r == nr-1:
                sep=""
            else:
                sep=" \\\\ "
            entry = latex(S[r])
            s = s + entry + sep
    
        return LatexExpr("\\begin{bmatrix}\n" + s + "\n\\end{bmatrix}")
    

    I’ve written almost no python code before, this is all figured out by looking at the existing code and changing little bits.

    • CommentRowNumber7.
    • CommentAuthorandreas
    • CommentTimeJun 15th 2014

    Thanks Andrew, will try to figure it out!!