-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preamble option for KaTex #2784
Comments
I implemented a basic version (on local copy of Logseq) which just allows the user to set the (defn render!
[state]
(let [[id s display?] (:rum/args state)]
(let [macros (clj->js (get (state/get-config) :katex-macros {}))]
(try
(js/katex.render s (gdom/getElement id)
#js {:displayMode display?
:throwOnError false
:strict false
:macros macros})
(catch js/Error e
(js/console.error e)))))) but this requires the usage to be like (in their :katex-macros {
"\\if" "\\ \\text{if}\\ "
} but that is somewhat unpleasant. The option that is closer to the issue linked is to have some special file (ex: |
I'm curious as to why this was closed? It doesn't appear to have been added or an alternative created, unless I'm missing something. |
Yeah I am also pretty interested in this feature, and I wonder if there is a more elegant solution. |
+1 for such feature. It would be much nice to write e.g. \rng(f ∘ g) instead of \operatorname{rng}(f \circ g). |
You can add Katex macros directly in your function whenAvailable(name, callback) {
var interval = 10; // ms
window.setTimeout(function() {
if (window[name]) {
callback(window[name]);
} else {
whenAvailable(name, callback);
}
}, interval);
}
whenAvailable("katex", function(t) {
// Put your macros below, key will be replaced by the corresponding macro
katex.__defineMacro(key, macro);
}); |
Thanks @kalaspa ! That works. Just posting some examples of how to use it whenAvailable("katex", function(t) {
// Put your macros below, key will be replaced by the corresponding macro
katex.__defineMacro("\\E", "\\mathbb{E}");
katex.__defineMacro("\\pdv", "\\dfrac{\\partial #1}{\\partial #2}");
katex.__defineMacro("\\dv", "\\dfrac{d #1}{d #2}");
}); |
Thanks! This is much cleaner that hacking directly into katex.min.js. |
Hi @honzaprevratil I still use the same code and the macro works for me. When I open the logseq sometimes there is a popup asking if I allow logseq to run |
I would be nice if we can define extra commands for KaTex, then we do not need to type the complicated expression each time. It is indeed possible in KaTex, for example this issue. There is also a similar plugin for Obsidian.
The text was updated successfully, but these errors were encountered: