Latex output of custom objets

question
#1

I define a object and want to generate the latex output using Latexify.jl. The object is defined as following

struct vecSym <: Number
name::String
function vecSym(x::String)
new(x)
end
end
function Base.show(io::IO, ::MIME"text/latex", vec::vecSym)
print(io, latexify(vec.name))
end

Then the output of the object is in latex style.

Then I define a method for this object as following

struct vecAdd
veca
function vecAdd(x)
new(x)
end
end
function Base.show(io::IO,::MIME"text/latex",y::vecAdd)
print(io, “+”,"(", y.veca, “)”)
end

Then the output is not in latex style anymore.


Does anybody know what happens? Why this vecAdd method can not show the output in the latex form as +((P_1,P_2))?

0 Likes

#2

You need to call show for each of your vecSym instances:

function Base.show(io::IO, mime::MIME"text/latex", y::vecAdd)
    print(io, "+(")
    show(io, mime, y.veca[1])
    print(io, ",")
    show(io, mime, y.veca[2])
    print(io, ")")
end

You can also define show for Tuple{vecSym,vecSym} and just call show(io, mime, y.veca) instead.

0 Likes

#3

Thank a lot.

0 Likes