How to add syntax coloring for new languages?

What I’m trying to do

I would like Mathematica code blocks to format nicely like they do for other languages with syntax coloring.

Consider in the following two code blocks:

def fun():
    x = 1
f[x0_] := Module[{x = x0},
  While[x > 0, x = Log[x]]; x

The python code looks good, but the wolfram code looks like verbatim:

What I’ve tried

Mathematica (aka wolfram language) is less popular but is still supported in many editors like Sublime e.g. WolframLanguage - Packages - Package Control)

I managed to find a project that formats wolfram code with css/html here: GitHub - halirutan/Mathematica-Source-Highlighting: Highlighting of Mathematica code for Mathematica.stackexchange

I’ve tried to hook it up, but I don’t know how to do this properly, any guidance here would be much appreciated!

1 Like

@eb1ack I was just wanting to ask this question! Are there any plugin developers here that might be able to help? #get-help

It looks like @deathau’s plugin CM Editor Syntax Highlighting has Mathematica as a parser language. Give it a try?

1 Like

@valentine.195 Thanks! That solves it for edit mode, but what about preview mode too?

Edit mode:

Preview mode:

1 Like

I think syntax coloring in preview is provided by PrismJS. I don’t see Mathmatica in their list of supported languages:

I don’t think there’s anything the Obsidian devs can do about that. I think you’d have to open an issue with the PrismJS team:


Prism just recently added support for mathematica: Next features to add for wolfram language · Discussion #2926 · PrismJS/prism · GitHub

But wolfram code blocks still don’t work in obsidian!

1 Like

@craig Can you ping obsidian devs to rebuild the app with the latest prism?

Hi @eb1ack , sorry, I’m just a fellow user. I don’t have any pull with the Obsidian devs.

1 Like

Maybe you can ping Licat or Silver in the Discord server (Community - Obsidian)

1 Like

Thanks for the tip, I’ll try to contact them there!

This is a perfect example here of how things work in software development so that many can benefit:

  • Know which (so called “upstream”) third-party code is used. I wish Obsidian would have an official list somewhere.

  • Nail down a bug or feature request to one of these “building blocks”.

  • Make a bug report, feature request or even a pull request there and see that it gets fixed or implemented.

  • Ask the “downstream” software using that code/library to include the new version of the “upstream” package.

Working like this has the greatest benefits for all:

  • Both upstream and downstream developers can focus on their part of the code.
  • Other users and projects will benefit, because upstream packages and libraries tend to get used by many.

Writing custom workarounds and patches at the “end of the chain”

  • is counterproductive
  • will break eventually when upstream code is updated
  • unnecessarily binds resources and time that could better be used on the actual downstream project

Just my 2¢.


I have this problem too.

PrismJS claims that you can use ‘wolfram’, ‘mathematica’, ‘wl’ or ‘nb’ to reference Mathematica code, but in Obsidian no syntax highlighting occurs.

1 Like

Yes indeed, but the Obsidian devs need to update the Obsidian app (and use the updated prism library).

1 Like

Wolfram Mathematica code is still not highlighted in obsidian v0.12.10 :frowning:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.