Overloading show(io, expr::Expr)

Bit of a strange question here but would anyone know which show method controls how :(2*x) for example gets displayed as :(2x) in the repl. eg:

julia> :(2 * x)
:(2x)

There is a handful of show methods in show.jl that look suspect but I can’t seem to figure out who is responsible for this. I want to overload this to display as :(2 * x) instead to interface with Maxima in a package I’m developing.

Any help would be greatly appreciated!

Best,
Nathan

Just ask Julia, i.e. use introspection:

julia> ex = :(2x)
:(2x)

julia> show(STDOUT, ex)
:(2x)
julia> @which show(STDOUT, ex)
show(io::IO, ex::Union{Expr,GlobalRef,GotoNode,LabelNode,LineNumberNode,QuoteNode,Slot}) at show.jl:411

You will most likely then have to follow down the rabbit hole. You could try using Gallium (the debugger) for this, maybe inside Juno.

Thanks, found it in show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) finally.