Ability to include KATEX packages such as katex-physics

Hi everyone, I have just switched from org-roam to logseq in the past couple of days and I am very happy about it.
The one thing I miss is the ability to load latex packages in the preamble. I understand that logseq uses Katex, which is different from classic org-mode.

Recently, someone asked to include the package mhchem in this post and it was included (apparently) straightforwardly in this pull request.

As for myself, I would have liked to include the package katex-physics in all of my notes. But I guess everyone has his/her favorite package.

Is it easy possible to give the user the possibility to include his/her favorite package ? Or could someone include katex-physics by default for me ?

Thank you in advance

I made the mhchem package request and never even realized it was integrated.
So thanks :slight_smile:

1 Like

Well, for anyone who NEEDS katex-physics or any other package, I have a dirty workaround. I insist, it is very dirty, but at least it kind of works.

  1. First, find the logseq installation repository. On my linux machine, it is located at /opt/logseq-desktop
  2. Copy your package in folder resources/app/js. You should find katex.min.js and mhchem.min.js already there
  3. For the specific case of katex-physics, I need to register each macro to katex at the end of the file. I simply add
for (var key in macros_physics) {
    katex.__defineMacro(key, macros_physics[key]);
  1. You need to add this script at the end of the <header> section. My dirty workaround is to add this piece of code at the end of mhchem.min.js, since it is the last piece of javascript that is executed (to my knowledge) and that I don’t want to recompile logseq’s source code
function includeJs(jsFilePath) {
    var js = document.createElement("script");

    js.type = "text/javascript";
    js.src = jsFilePath;
    js.charset = "UTF-8"


  1. Relaunch logseq. If I have a formula using katex-physics on my first page, it does not render well at first. I just re-render it once.

I am sharing this for impatients (like me), but I am genuinely asking for better/simpler/cleaner ways to do the same thing :slight_smile: