# Plaintext output in IJulia instead of html display

**URL:** <https://discourse.julialang.org/t/plaintext-output-in-ijulia-instead-of-html-display/20816>\
**Category:** New to Julia\
**Created:** [February 15, 2019, 10:08am UTC](https://discourse.julialang.org/t/plaintext-output-in-ijulia-instead-of-html-display/20816 "2019-02-15T10:08:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Thorne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian_thorne/32/6990_2.png) [@Brian\_Thorne](https://discourse.julialang.org/u/Brian_Thorne)\
**Post date:** [February 15, 2019, 10:08am UTC](https://discourse.julialang.org/t/plaintext-output-in-ijulia-instead-of-html-display/20816/1 "2019-02-15T10:08:41Z")

</div>

Hopefully a picture conveys my issue:

 ![Screenshot%20from%202019-02-15%2021-00-40](https://global.discourse-cdn.com/julialang/original/3X/0/1/01cb6dc9de11618abe3883020a308fc535f4eb72.png)

I’d like to understand why a Polynomial object - which can be rendered beautifully in an IJulia notebook - isn’t rendered nicely by default, and is there a simple recipe to tell IJulia/julia how I’d like my polynomials rendered?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [February 15, 2019, 1:26pm UTC](https://discourse.julialang.org/t/plaintext-output-in-ijulia-instead-of-html-display/20816/2 "2019-02-15T13:26:55Z")

</div>

`IJulia` captures the output in multiple formats and then the frontend decides which format is the “best one”. You can see this if you look at the `.ipynb` file:

```json
   "outputs": [
    {
     "data": {
      "text/html": [
       "1 &#43; 2&#8729;x &#43; 3&#8729;x^2 &#43; x^4"
      ],
      "text/latex": [
       "$1 + 2\\cdot x + 3\\cdot x^{2} + x^{4}$"
      ],
      "text/plain": [
       "Poly(1 + 2*x + 3*x^2 + x^4)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],

```

and, apparently `text/html` is ranked higher than `text/latex` in this case. It is possible to show superscripts in HTML so it seems like this is an oversight in `Polynomials`. I submitted a PR for that: [Display exponents nicely in "text/html" output. by fredrikekre · Pull Request #167 · JuliaMath/Polynomials.jl · GitHub](https://github.com/JuliaMath/Polynomials.jl/pull/167) which results in:  
 ![poly](https://global.discourse-cdn.com/julialang/original/3X/6/e/6e4ede64041a0c09f6a9c5a652b9405b6d7bde3e.png)

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [February 15, 2019, 10:36pm UTC](https://discourse.julialang.org/t/plaintext-output-in-ijulia-instead-of-html-display/20816/3 "2019-02-15T22:36:06Z")

</div>

Untested, but I guess you can do

```julia
append!(empty!(IJulia.ijulia_mime_types), [
    MIME("text/plain"),
    MIME("image/svg+xml"),
    [MIME("image/png"),MIME("image/jpeg")],
    [
        MIME("text/latex"),
        MIME("text/markdown"),
        MIME("text/html"),
    ],
])

```

The original setting is

> <https://github.com/JuliaLang/IJulia.jl/blob/604c9a76ee8f079e856305e13f9c73cdf730771f/src/display.jl#L19-L28>

But I’m not sure if this is for user-level configuration.

---

<div class="post-metadata">

**Author:** ![Brian\_Thorne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian_thorne/32/6990_2.png) [@Brian\_Thorne](https://discourse.julialang.org/u/Brian_Thorne)\
**Post date:** [February 16, 2019, 12:36am UTC](https://discourse.julialang.org/t/plaintext-output-in-ijulia-instead-of-html-display/20816/4 "2019-02-16T00:36:44Z")

</div>

Thanks for opening a PR to fix this straight away @fredrikekre. I didn’t realize that IJulia captures the output in multiple formats - that is quite cool.

@tkf your code was correct to change the default mime type, but as it is changing the default output for all outputs it doesn’t look like something a user should touch!

What the behavior looks like after the fix:

 ![Screenshot%20from%202019-02-16%2011-26-33](https://global.discourse-cdn.com/julialang/original/3X/a/b/aba69e87af97bb12a9b060a86375d51dba4271a9.png)

---

<div class="post-metadata">

**Author:** ![Brian\_Thorne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian_thorne/32/6990_2.png) [@Brian\_Thorne](https://discourse.julialang.org/u/Brian_Thorne)\
**Post date:** [February 16, 2019, 1:10am UTC](https://discourse.julialang.org/t/plaintext-output-in-ijulia-instead-of-html-display/20816/5 "2019-02-16T01:10:26Z")

</div>

If you were trying to override the IJulia output just for Polynomials would this be a reasonable approach?

```julia
using Polynomials

Polynomials.printpoly(io::IO, p::Poly{T}, ::MIME"text/html"; descending_powers=false, offset::Int=0) where {T} =
    Polynomials.printpoly(io, p, MIME"text/latex"(), descending_powers, offset)

```

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [February 16, 2019, 5:02am UTC](https://discourse.julialang.org/t/plaintext-output-in-ijulia-instead-of-html-display/20816/6 "2019-02-16T05:02:12Z")

</div>

It assumes that HTML renderer has MathJax and configured to recognize `$...$`. I guess it’s fine in IJulia, but if you want to add it to Polynomials.jl maybe you’d want to check `isdefined(Main, :IJulia) && Main.IJulia.inited`.

Or I guess a better way to do it is to set `IOContext` like `:mathjax => true` in IJulia, Documenter, etc. so that packages like Polynomials.jl can change its behavior in text/html `show`.
