Ask Your Question

color in latex...

asked 2020-06-03 08:26:15 +0200

Cyrille gravatar image

updated 2020-06-03 08:27:02 +0200

1) Is it possible to use text colors in show specifically with LatexExpr.

2) in mathematica, it is possible to insert a result in a text cell. Is it possible in SM markdown ?

3) same question in an HTML table ? SM tables are too basic

4) Need an exemple to localy change the background color of a result.

Thanks by advance

edit retag flag offensive close merge delete


"SM"=Sagemath, I suppose ? This abbreviation is a tad ambiguous (unless you really want to suggest that Sagemath==SM=sadomasochism ? This would be questioned by some...).

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2020-06-03 19:07:09 +0200 )edit

I have had also this idea but I was wondering that I was alone to have a bad spirit. I was using SM as MA for Mathematica. However it seems we need an acronym for Sagemath.

Cyrille gravatar imageCyrille ( 2020-06-04 07:13:00 +0200 )edit

For short we say Sage.

slelievre gravatar imageslelievre ( 2020-12-11 02:47:40 +0200 )edit

2 Answers

Sort by » oldest newest most voted

answered 2020-06-03 20:27:46 +0200

Juanjo gravatar image

updated 2020-06-03 20:51:36 +0200

1) Yes in a Jupyter notebook. See an example below.

2) You have already asked something similar in this other question. I think that the answers there also apply here.

3) Certainly you can put results inside HTML tables generated by code cells. Example:

Degrees = pi/180
angles = [0, 30, 45, 60, 90]
st = "style='text-align: center'"
tb = f"""
<table style='width:50%'>
  <tr style='color: white; background: black'>
    <th {st}>Angle</th>
    <th {st}>Sinus</th>
    <th {st}>Cosinus</th>
    <th {st}>Tangent</th>
for a in angles:
    tb += f"<tr><td {st}>${latex(a)}$</td>"
    tb += f"<td {st}>${latex(sin(a*Degrees))}$</td>"
    tb += f"<td {st}>${latex(cos(a*Degrees))}$</td>"
    tb += f"<td {st}>${latex(tan(a*Degrees))}$</td></tr>"
tb += "</table>"

To understand the code, google for Python f-string. I provide a screen capture of the result:

image description

4) Voici un exemple:

Degrees = pi/180
angle = 30
st = "style='background: black; color: white; padding: 0.5em'"
message = fr"The sinus and cosinus of ${latex(angle)}º$ are "
message += fr"<span {st}>${latex(sin(angle*Degrees))}$</span> and "
message += fr"<span {st}>${latex(cos(angle*Degrees))}$</span>"

And the corresponding screen capture:

image description

As you can see, I don't use LaTeXExpr, but latex. Likewise, formulae are coloured as a whole via CSS. If you need to change the color of only a part of an expression, then you should use the \color macro.

edit flag offensive delete link more

answered 2020-06-03 19:28:37 +0200

Emmanuel Charpentier gravatar image

1) Yes in the (Jupyter) notebook (Mathjax happens to understand \color...) . No in command-line (or emacs), unless you add the relevant \usepackage{xcolor} or analogous to the relevant latex preamble (see the docs).

2) Not as far as know. This is much better achieved in a SageTeX (or org-mode + sage-shell-mode in emacs) document (with the right modules in the preamble). Again, see the SageTeX documentation and example.

3) This might be doable by writing Sage code to spit out HTML results. ISTR that Sage has some relevant functions for that, but never used it. See the docs, again. An alternative is org-mode with HTML output.

4) is highly dependent of your output mode. There might be some Methjax happenstance, I dunno. See the relevant docs.

sage: r('library("fortunes")')
[1] "fortunes"  "tools"     "stats"     "graphics"  "grDevices" "utils"    
[7] "datasets"  "methods"   "base"
sage: r('fortune("RTFM")')

This is all documented in TFM. Those who WTFM don't want to have to WTFM again
on the mailing list. RTFM.
   -- Barry Rowlingson
      R-help (October 2003)
edit flag offensive delete link more


the syntax of the Latex \color statement (not quite obvious):

show(LatexExpr( r" {\color{Red} {tagada}}"))
ortollj gravatar imageortollj ( 2020-10-16 07:01:58 +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


Asked: 2020-06-03 08:26:15 +0200

Seen: 488 times

Last updated: Jun 03 '20