CoCalc Public Filesfricas_md.py
Author: Bill Page
Views : 44
Description: Process FriCAS output using Markdown.
Compute Environment: Ubuntu 18.04 (Deprecated)
1def fricas_md(s):
2    import re
3    t = fricas._eval_line_using_file(s, restart_if_needed=False, reformat=False)
4    # cleanup plain text
5    t=re.compile(r'\r\r').sub('\r',t,count=0)
6    t=re.compile(r'\r').sub('\n',t,count=0)
7    t=re.compile(r'                                                                                                                 ').sub('',t,count=0)
8    t=re.compile(r'      ').sub('   ',t,count=0)
9    #t=re.compile(r'   Compiling').sub('Compiling',t)
10    # fix mathml overbar
11    t=re.compile(r'&#x000AF;').sub('&#x203E;',t,count=0)
12    # cleanup FriCAS LaTeX
13    t=re.compile(r'\\leqno$$.*$$\n').sub('',t)
14    t=re.compile(r'\\sb ').sub('_',t,count=0)
15    t=re.compile(r'\\sp ').sub('^',t,count=0)
16    t=re.compile(r'\\erf ').sub(r'\\mathrm{erf}',t,count=0)
17    t=re.compile(r'\\sech ').sub(r'\\mathrm{sech}',t,count=0)
18    t=re.compile(r'\\tanh ').sub(r'\\mathrm{tanh}',t,count=0)
19    # float result type to the right
20    t=re.compile(r' *Type: (.*)\n').sub(r'<p style="text-align:right">Type: \1</p>\n',t,count=0)
21    #print t
22    md(t, hide=False)