Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

Present a LaTeX table in ask.sagemath.org's markdown

asked 2 years ago

Emmanuel Charpentier gravatar image

updated 1 year ago

FrédéricC gravatar image

This is more an HTML question than a Sage question, and specific to this site.

My problem is to present a table in (an anwer to) a question asked here. Sage's table objects' LaTeX representation use \tabular environment which, somehow, are not accepted by (the current version of) Markdown used here ; @slelievre suggestion to double backslashes do not work either.

@slelievre suggested here to use html representation instead, which only partially works : this representation lacks line breaks between table rows.

Adding <br> to each </tr> is not enough : lines are indeed separated, but each line is formatted separately, and header lines are lost.

This might be a bug in ask.sagemath.org supporting software...

Hints ?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 2 years ago

Juanjo gravatar image

updated 2 years ago

It seems that tabular is not an environment supported by MathJax, as can be seen here. So, a possible solution is to convert the tabular environment to array. Assuming that all the cells are in math mode, this can be done by the function to_array defined as follows:

def to_array(tabular):
    return tabular.replace("tabular","array").replace("$","").replace(r"\\",r"\\\\")

Note that backslashes in the newline commands should be doubled so that Markdown can process them correctly. Let us test it using the table in the question asked here:

variables = flatten([[var(f"alpha_{i}_{j}", latex_name=fr"\alpha_{{{i} {j}}}") 
                    for j in [0..2]] for i in [0,1]])
table_object = table([[f(v) for v in variables] for f in [sin, cos, tan]],
               header_row=variables, header_column=[function("f"), sin, cos, tan])
tabular_env = latex(table_object)
print(to_array(tabular_env))

Now, one can copy the output and paste it in the text box to post or answer a question:

fα00α01α02α10α11α12sinsin(α00)sin(α01)sin(α02)sin(α10)sin(α11)sin(α12)coscos(α00)cos(α01)cos(α02)cos(α10)cos(α11)cos(α12)tantan(α00)tan(α01)tan(α02)tan(α10)tan(α11)tan(α12)

Edit. Corrected the header_column option.

Preview: (hide)
link

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: 2 years ago

Seen: 261 times

Last updated: Oct 30 '22