Ask Your Question
1

Displaying result problem

asked 2020-08-28 17:20:43 +0200

Cyrille gravatar image

updated 2020-08-28 20:36:59 +0200

slelievre gravatar image

The results of the following code is perfectly displayed in QSagemath server but not in v 9.1 under windows 10

%display latex
A=[0.8,0.44],[0.05,0.1],[0.1,0.36]
b=(24000,2000,6000)
c=(108.21,72.522) 
P=InteractiveLPProblemStandardForm(A,b,c,["x_1","x_2"],slack_variables=["e_3","e_4","e_5"])
P = P.standard_form()
P.run_simplex_method()
P = P.standard_form()
P.run_simplex_method()
edit retag flag offensive close merge delete

Comments

Please be more specific:

  • what is "QSagemath server"?
  • what is the perfect display you see there and don't see elsewhere?
  • under Windows10, are you using Sage with the Jupyter notebook?
slelievre gravatar imageslelievre ( 2020-08-28 20:36:29 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-08-31 16:26:55 +0200

Florentin Jaffredo gravatar image

It happens to me sometimes using Sagemath 9.1 in windows with jupyter-lab. I think Mathjax struggles when \color is not properly encapsulated within braces. here is a quick and dirty fix to remove all colors:

A=[0.8,0.44],[0.05,0.1],[0.1,0.36]
b=(24000,2000,6000)
c=(108.21,72.522) 
P=InteractiveLPProblemStandardForm(A,b,c,["x_1","x_2"],slack_variables=["e_3","e_4","e_5"])
P = P.standard_form()
S = str(P.run_simplex_method())

then to display the result:

from IPython.display import Markdown, display
import re
S2 = re.sub(r"\\color{.*?}", "", S)
display(Markdown(S2))

It's possible to keep the colors, but I'm not knowledgeable enough in regex to do it with a one-liner, so it's even uglier:

from IPython.display import Markdown, display
import re

start = 0
S2 = ""
spans = [m.span() for m in re.finditer(r"\\color{.*?}", S)]
for s in spans:
    end = min(S[s[1]:].find('&'), S[s[1]:].find(r'\\'))
    S2 += S[start:s[0]]+"{"+S[s[0]:s[1]]+"{"+S[s[1]:s[1]+end]+"}}"
    start = s[1]+end
S2 = S2+S[start:]
display(Markdown(S2))

Results: Before:

image description

After:

image description

edit flag offensive delete link more

Comments

Of course a real fix would be welcomed, but I have no idea where to start.

Florentin Jaffredo gravatar imageFlorentin Jaffredo ( 2020-08-31 16:39:06 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-08-28 17:20:43 +0200

Seen: 334 times

Last updated: Aug 31 '20