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:
$$\begin{array}{l|llllll}
f & {\alpha_{0 0}} & {\alpha_{0 1}} & {\alpha_{0 2}} & {\alpha_{1 0}} & {\alpha_{1 1}} & {\alpha_{1 2}} \\ \hline
\sin & \sin\left({\alpha_{0 0}}\right) & \sin\left({\alpha_{0 1}}\right) & \sin\left({\alpha_{0 2}}\right) & \sin\left({\alpha_{1 0}}\right) & \sin\left({\alpha_{1 1}}\right) & \sin\left({\alpha_{1 2}}\right) \\
\cos & \cos\left({\alpha_{0 0}}\right) & \cos\left({\alpha_{0 1}}\right) & \cos\left({\alpha_{0 2}}\right) & \cos\left({\alpha_{1 0}}\right) & \cos\left({\alpha_{1 1}}\right) & \cos\left({\alpha_{1 2}}\right) \\
\tan & \tan\left({\alpha_{0 0}}\right) & \tan\left({\alpha_{0 1}}\right) & \tan\left({\alpha_{0 2}}\right) & \tan\left({\alpha_{1 0}}\right) & \tan\left({\alpha_{1 1}}\right) & \tan\left({\alpha_{1 2}}\right) \\
\end{array}$$
Edit. Corrected the header_column
option.