org-roam-ui
org-roam-ui copied to clipboard
[ENH] Adding possibility for latex macros
I write latex equations and I use some macros for that. When I was using org-roam-server it was using mathjax, and had a header which I could include latex macros.
I am wondering if there is a way to include latex macros in the rendering of org-roam-ui. I saw thanks to this post that KaTeX has a macros option which I think can do the trick.
The question is, can such a file can be supplied to org-roam-ui?
Yes I think that should not be too hard to add!
This has been added in the latest commit. The ref and eqref macros are implemented by default!
How should one attach a file with the macros? What should be the structure of this file?
Ah you would like to load a file of LaTeX macros. Could you show me a piece of this file?
At the moment you can set (org-roam-ui-latex-macros)
to an alist of latex macros as
(setq org-roam-ui-latex-macros
'(("\\something" . "\\textbf{#1}")))
So that when you write \something{word}
it will be interpreted as \textbf{word}
(i'm sure you know how latex macros work, not sure why im explaining that)
I think it should be possible to load a file of them, but that use-case seems pretty niche and I'm not sure how to tackle that effectively. (i.e. maybe you could try writing a function which reads that file and outputs such an alist, and share it here 😅 )
Actually, that's great! Is this released? I can't wait to check it out:)
Yes you should be able to use this now if you update to the latest version of org-roam-ui!
I just checked this and this does not seem to work... This is my configuration
(use-package! org-roam-ui
:after org-roam ;; or :after org
;; normally we'd recommend hooking orui after org-roam, but since org-roam does not have
;; a hookable mode anymore, you're advised to pick something yourself
;; if you don't care about startup time, use
;; :hook (after-init . org-roam-ui-mode)
:config
(setq org-roam-ui-sync-theme t
org-roam-ui-follow t
org-roam-ui-update-on-save t
org-roam-ui-open-on-start t)
(setq org-roam-ui-latex-macros
'(("\\kk" . "\\textbf{kk}")
("\\vv" . "\\textbf{vv}")
("\\xx" . "\\textbf{xx}")
)))
But still I see no rendering in org-roam-ui.

@roiholtzman I do not know if your issue still persists, but I set org-roam-ui-latex-macros
in the :init
section of my org-roam-ui
configuration. Maybe this works better for you:
(use-package! org-roam-ui
:after org-roam ;; or :after org
;; normally we'd recommend hooking orui after org-roam, but since org-roam does not have
;; a hookable mode anymore, you're advised to pick something yourself
;; if you don't care about startup time, use
;; :hook (after-init . org-roam-ui-mode)
:init
(setq org-roam-ui-latex-macros
'(("\\kk" . "\\textbf{kk}")
("\\vv" . "\\textbf{vv}")
("\\xx" . "\\textbf{xx}")))
:config
(setq org-roam-ui-sync-theme t
org-roam-ui-follow t
org-roam-ui-update-on-save t
org-roam-ui-open-on-start t))
We seem to hang out in the same niches of use cases ;) So I started to work on @ThomasFKJorna's suggestion of parsing custom macros from .tex
file(s) into an alist.
This should not be too much of a challenge for "fragile" macros defined via \def
and \newcommand
.
However, more complex macros defined with the xparse
package, e.g. via \NewDocumentCommand
, are trickier beasts. In particular, I have some macros where expansion depends on the presence of a second optional argument (can be checked via \IfValueTF{#2}
). I have opened a discussion on the KaTeX repo to ask if/how this can be handled; I can let you know once I hear back from the KaTeX devs.
@hwesterholt Thanks for the tip! Unfortunately, this does not work for me. The macros still do not render well.
Hi!
I don't know if this strategy can be exported to org-roam-ui (I hope so), but here is what I do when exporting org to html: simply use the dvipng backend for html. It creates images from the LaTeX formula, taking into account the LaTeX_HEADER of the file (which allows the use of preambule with a lot of macros), and places them in the html. Similar things can be done via dvisvg.
Maybe it can be a track for org-roam-ui-latex-dvipng
option ?
Best,
Ps. Thank you a lot @.ThomasFKJorna for this amazing package :)