Ask Your Question

Revision history [back]

Using the latex_name parameter of var just changes the way the variable v is printed. You want to change the way specific vector objects are printed, if I understand correctly. Calling latex() on v calls the _latex_() method of v, followed by converting to a LatexExpr object.

sage: v = vector([1,2,3])
sage: v._latex_()
'\\left(1,\\,2,\\,3\\right)'

So you could define your own latex method for vectors that does the same thing, but puts \mid between entries instead of commas. Below, I copied the code from v._latex_() that I looked at using v._latex_?? in the Sage console and then modified the last line (adding LatexExpr) and the second to last line (replacing the comma with \mid).

def my_vector_latex(v):
    latex = sage.misc.latex.latex
    LatexExpr = sage.misc.latex.LatexExpr
    vector_delimiters = latex.vector_delimiters()
    s = '\\left' + vector_delimiters[0]
    s += '\mid\,'.join([latex(a) for a in v.list()]) # different than usual _latex_()
    return LatexExpr(s + '\\right' + vector_delimiters[1])

Then, you can do:

sage: latex(v)
\left(1,\,2,\,3\right)
sage: my_vector_latex(v)
\left(1\mid\,2\mid\,3\right)

Using the latex_name parameter of var just changes the way the variable v is printed. You want to change the way specific vector objects are printed, if I understand correctly. Calling latex() on v calls the _latex_() method of v, followed by converting to a LatexExpr object.

sage: v = vector([1,2,3])
sage: v._latex_()
'\\left(1,\\,2,\\,3\\right)'

So you could define your own latex method for vectors that does the same thing, but puts \mid between entries instead of commas. Below, I copied the code from v._latex_() that I looked at using v._latex_?? in the Sage console and then modified the last line (adding LatexExpr) and the second to last line (replacing the comma with \mid).

def my_vector_latex(v):
    latex = sage.misc.latex.latex
    LatexExpr = sage.misc.latex.LatexExpr
    vector_delimiters = latex.vector_delimiters()
    s = '\\left' + vector_delimiters[0]
    s += '\mid\,'.join([latex(a) '\\mid\\,'.join([latex(a) for a in v.list()]) # different than usual _latex_()
    return LatexExpr(s + '\\right' + vector_delimiters[1])

Then, you can do:

sage: latex(v)
\left(1,\,2,\,3\right)
sage: my_vector_latex(v)
\left(1\mid\,2\mid\,3\right)