# Latex output of custom objets

**URL:** <https://discourse.julialang.org/t/latex-output-of-custom-objets/22875>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 7, 2019, 2:54pm UTC](https://discourse.julialang.org/t/latex-output-of-custom-objets/22875 "2019-04-07T14:54:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gangchern](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gangchern/32/13298_2.png) [@gangchern](https://discourse.julialang.org/u/gangchern)\
**Post date:** [April 7, 2019, 2:54pm UTC](https://discourse.julialang.org/t/latex-output-of-custom-objets/22875/1 "2019-04-07T14:54:34Z")

</div>

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.

 ![WeChatd645860395948ed1bebb1e20bb911578](https://global.discourse-cdn.com/julialang/original/3X/8/2/827eb85f2222a6e18017df1491634057a00855b3.png)

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.

 ![WeChat732af41b59831a42a1844a7c3d0e6744](https://global.discourse-cdn.com/julialang/original/3X/7/2/728d939662b55466258f73dd184f681466490373.png)  
Does anybody know what happens? Why this vecAdd method can not show the output in the latex form as +((P\_1,P\_2))?

---

<div class="post-metadata">

**Author:** ![maxmouchet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxmouchet/32/7834_2.png) [@maxmouchet](https://discourse.julialang.org/u/maxmouchet)\
**Post date:** [April 7, 2019, 4:39pm UTC](https://discourse.julialang.org/t/latex-output-of-custom-objets/22875/2 "2019-04-07T16:39:56Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

**Author:** ![gangchern](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gangchern/32/13298_2.png) [@gangchern](https://discourse.julialang.org/u/gangchern)\
**Post date:** [April 17, 2019, 8:22pm UTC](https://discourse.julialang.org/t/latex-output-of-custom-objets/22875/3 "2019-04-17T20:22:38Z")

</div>

Thank a lot.
