ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 20 Feb 2020 12:49:44 +0100Why doesn't show() render latex properly?https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/The following code:
import numpy as np
P = np.matrix('0 0 20 20; 0 20 20 0')
show(P)
Gives me the output
[[𝟶𝟶𝟸𝟶𝟸𝟶]
[𝟶𝟸𝟶𝟸𝟶𝟶]]
In old sage, I guess around 6.0 or something, the show() command would render a proper latex matrix. I.e like you would see in a mathematics textbook.
Is there any way I can get this functionality back?
Thanks.
Edit: I'm using Sage 9.0 v 0.6.0 on Windows.Wed, 19 Feb 2020 13:25:25 +0100https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/Answer by rburing for <p>The following code:</p>
<pre><code>import numpy as np
P = np.matrix('0 0 20 20; 0 20 20 0')
show(P)
</code></pre>
<p>Gives me the output</p>
<pre><code>[[𝟶𝟶𝟸𝟶𝟸𝟶]
[𝟶𝟸𝟶𝟸𝟶𝟶]]
</code></pre>
<p>In old sage, I guess around 6.0 or something, the show() command would render a proper latex matrix. I.e like you would see in a mathematics textbook.</p>
<p>Is there any way I can get this functionality back?</p>
<p>Thanks.</p>
<p>Edit: I'm using Sage 9.0 v 0.6.0 on Windows.</p>
https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?answer=49982#post-id-49982I don't know how it used to work, but the way I understand it is that NumPy's matrix type is not a SageMath data type, so it doesn't support SageMath's latex rendering (in particular, it doesn't have a `_latex_()` method).
So just convert to a SageMath data type first:
sage: show(matrix(P))
$$\left(\begin{array}{rrrr}
0 & 0 & 20 & 20 \\\\
0 & 20 & 20 & 0
\end{array}\right)$$Wed, 19 Feb 2020 13:56:08 +0100https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?answer=49982#post-id-49982Comment by eod for <p>I don't know how it used to work, but the way I understand it is that NumPy's matrix type is not a SageMath data type, so it doesn't support SageMath's latex rendering (in particular, it doesn't have a <code>_latex_()</code> method).</p>
<p>So just convert to a SageMath data type first:</p>
<pre><code>sage: show(matrix(P))
</code></pre>
<p>$$\left(\begin{array}{rrrr}
0 & 0 & 20 & 20 \\
0 & 20 & 20 & 0
\end{array}\right)$$</p>
https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49988#post-id-49988Hmm, the matrix command gives me an error in jupyter for both sage 8.0 an 9.0 -- but it works in the console. Any idea why?Wed, 19 Feb 2020 15:39:08 +0100https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49988#post-id-49988Comment by rburing for <p>I don't know how it used to work, but the way I understand it is that NumPy's matrix type is not a SageMath data type, so it doesn't support SageMath's latex rendering (in particular, it doesn't have a <code>_latex_()</code> method).</p>
<p>So just convert to a SageMath data type first:</p>
<pre><code>sage: show(matrix(P))
</code></pre>
<p>$$\left(\begin{array}{rrrr}
0 & 0 & 20 & 20 \\
0 & 20 & 20 & 0
\end{array}\right)$$</p>
https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49989#post-id-49989What is the error?Wed, 19 Feb 2020 15:40:55 +0100https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49989#post-id-49989Comment by eod for <p>I don't know how it used to work, but the way I understand it is that NumPy's matrix type is not a SageMath data type, so it doesn't support SageMath's latex rendering (in particular, it doesn't have a <code>_latex_()</code> method).</p>
<p>So just convert to a SageMath data type first:</p>
<pre><code>sage: show(matrix(P))
</code></pre>
<p>$$\left(\begin{array}{rrrr}
0 & 0 & 20 & 20 \\
0 & 20 & 20 & 0
\end{array}\right)$$</p>
https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49990#post-id-49990When I try to use the matrix command I get:
TypeError: 'numpy.ndarray' object is not callableWed, 19 Feb 2020 15:45:03 +0100https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49990#post-id-49990Comment by rburing for <p>I don't know how it used to work, but the way I understand it is that NumPy's matrix type is not a SageMath data type, so it doesn't support SageMath's latex rendering (in particular, it doesn't have a <code>_latex_()</code> method).</p>
<p>So just convert to a SageMath data type first:</p>
<pre><code>sage: show(matrix(P))
</code></pre>
<p>$$\left(\begin{array}{rrrr}
0 & 0 & 20 & 20 \\
0 & 20 & 20 & 0
\end{array}\right)$$</p>
https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49991#post-id-49991What code do you use as input, exactly?Wed, 19 Feb 2020 15:46:55 +0100https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49991#post-id-49991Comment by eod for <p>I don't know how it used to work, but the way I understand it is that NumPy's matrix type is not a SageMath data type, so it doesn't support SageMath's latex rendering (in particular, it doesn't have a <code>_latex_()</code> method).</p>
<p>So just convert to a SageMath data type first:</p>
<pre><code>sage: show(matrix(P))
</code></pre>
<p>$$\left(\begin{array}{rrrr}
0 & 0 & 20 & 20 \\
0 & 20 & 20 & 0
\end{array}\right)$$</p>
https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49992#post-id-49992For example "matrix([[1,2],[3,4]])" as copied from the sagemath docs.Wed, 19 Feb 2020 16:21:30 +0100https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49992#post-id-49992Comment by rburing for <p>I don't know how it used to work, but the way I understand it is that NumPy's matrix type is not a SageMath data type, so it doesn't support SageMath's latex rendering (in particular, it doesn't have a <code>_latex_()</code> method).</p>
<p>So just convert to a SageMath data type first:</p>
<pre><code>sage: show(matrix(P))
</code></pre>
<p>$$\left(\begin{array}{rrrr}
0 & 0 & 20 & 20 \\
0 & 20 & 20 & 0
\end{array}\right)$$</p>
https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49993#post-id-49993Surely if you run only that, there should be no error. What code do you run before that?Wed, 19 Feb 2020 16:33:27 +0100https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49993#post-id-49993Comment by rburing for <p>I don't know how it used to work, but the way I understand it is that NumPy's matrix type is not a SageMath data type, so it doesn't support SageMath's latex rendering (in particular, it doesn't have a <code>_latex_()</code> method).</p>
<p>So just convert to a SageMath data type first:</p>
<pre><code>sage: show(matrix(P))
</code></pre>
<p>$$\left(\begin{array}{rrrr}
0 & 0 & 20 & 20 \\
0 & 20 & 20 & 0
\end{array}\right)$$</p>
https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49994#post-id-49994Are you using a variable called `matrix`? That would overwrite the built-in SageMath function called `matrix`, which you want to use here, so you should use a different name.Wed, 19 Feb 2020 18:31:26 +0100https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=49994#post-id-49994Comment by eod for <p>I don't know how it used to work, but the way I understand it is that NumPy's matrix type is not a SageMath data type, so it doesn't support SageMath's latex rendering (in particular, it doesn't have a <code>_latex_()</code> method).</p>
<p>So just convert to a SageMath data type first:</p>
<pre><code>sage: show(matrix(P))
</code></pre>
<p>$$\left(\begin{array}{rrrr}
0 & 0 & 20 & 20 \\
0 & 20 & 20 & 0
\end{array}\right)$$</p>
https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=50000#post-id-50000I'm not overwriting the variable or anything like that.Thu, 20 Feb 2020 12:46:41 +0100https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=50000#post-id-50000Comment by eod for <p>I don't know how it used to work, but the way I understand it is that NumPy's matrix type is not a SageMath data type, so it doesn't support SageMath's latex rendering (in particular, it doesn't have a <code>_latex_()</code> method).</p>
<p>So just convert to a SageMath data type first:</p>
<pre><code>sage: show(matrix(P))
</code></pre>
<p>$$\left(\begin{array}{rrrr}
0 & 0 & 20 & 20 \\
0 & 20 & 20 & 0
\end{array}\right)$$</p>
https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=50001#post-id-50001Tried it again the next day and now I can't reproduce the error. No idea what caused it.Thu, 20 Feb 2020 12:49:44 +0100https://ask.sagemath.org/question/49980/why-doesnt-show-render-latex-properly/?comment=50001#post-id-50001