Would it be possible to enable syntax highlighting (colour) for code blocks on Mathematics SE?

For example, on Stack Overflow:

example syntax highlighting

My motivation for asking this question is that I was disappointed to see that the Python code in this post was in black & white.

  • $\begingroup$ You mean like the highlight one uses on pdf text documents ? $\endgroup$
    – user486983
    Commented Feb 14, 2020 at 14:22
  • $\begingroup$ @Isabella I mean for code blocks. $\endgroup$
    – Géry Ogam
    Commented Feb 14, 2020 at 14:32
  • 5
    $\begingroup$ I suppose that some users around here (including me) are not really familiar with the way syntax highlighting works on Stack Exchange sites. It might be good to give some pointers to basic info - I was able to find some links in the corresponding tag-info on Meta Stack Exchange. $\endgroup$ Commented Feb 14, 2020 at 15:01
  • 16
    $\begingroup$ If you're posting any substantial amount of code then your question is probably off-topic. $\endgroup$ Commented Feb 14, 2020 at 16:25
  • 2
    $\begingroup$ To help other confused readers: This image is an example of syntax highlighting d33wubrfki0l68.cloudfront.net/… $\endgroup$
    – s.harp
    Commented Feb 14, 2020 at 16:39
  • 7
    $\begingroup$ It would be helpful to have your thoughts on how syntax highlighting would contribute to the site. I suspect the posts at Math.SE will mainly involve pseudo-code rather than compiler parseable code specific to a programming language, but I'll try to quantify this impression. $\endgroup$
    – hardmath
    Commented Feb 14, 2020 at 18:48
  • 6
    $\begingroup$ There are some instances where non-pseudocode code fits in on MSE, though, for example in computer-algebra-systems, computational-mathematics, gap, magma-cas, etc. $\endgroup$
    – Alexander Gruber Mod
    Commented Feb 14, 2020 at 19:59
  • 3
    $\begingroup$ @hardmath I am just talking from my experience as a user. I was disappointed to see that the program in my post was in black and white here. $\endgroup$
    – Géry Ogam
    Commented Feb 14, 2020 at 23:30
  • $\begingroup$ @GéryOgam Do you agree with my edits? $\endgroup$ Commented Jul 13, 2023 at 11:19
  • 3
    $\begingroup$ @RodrigodeAzevedo Nevertheless, the mathematics involved in numerical analysis do not mandate writing code - beyond maybe pseudocode, and that's already a stretch. This site is about mathematics. There may be some code sometimes, but it's not the purpose of Math.SE. $\endgroup$ Commented Jul 13, 2023 at 12:06

2 Answers 2


Quoting former staff member @Oded:

We do not usually turn it on for sites that do not have a majority of posts with code in them (Lego, cooking, RPG are examples of such sites). Security tends to have more prose than code - hence, it isn't turned on.

The reason for this is that turning it on means including more JavaScript and slows everything down - performance matters to us.

Now, one could argue that MathJax is already ~1 MB or so (if I interpreted my browser tools correctly), which makes the 573 kB of Highlight.js less of a problem. (Yes, your browser caches those files; it's not 1.5 MB per page visit. Still, if you're on a slow 2G/3G connection ...)

  • 2
    $\begingroup$ There's a cooking site with a lot of code? $\endgroup$ Commented Jun 22, 2021 at 11:00
  • 1
    $\begingroup$ Is this request under consideration? Has it been rejected? $\endgroup$ Commented Jul 13, 2023 at 11:28

It may be true that code snippets appear in a minority of questions and responses, but when they do, they can be quite valuable (e.g., for simulations or in support of various theory). Syntax highlighting can make such snippets more accessible, even to those not intimately familiar with the languages. Math benefits from various forms of popular expression. One that enjoys arguably broader use than math notation is code.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .