-
Notifications
You must be signed in to change notification settings - Fork 1
/
claude_latex.js
49 lines (45 loc) · 1.66 KB
/
claude_latex.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// ==UserScript==
// @name LaTeX Claude v2
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Render LaTeX formulas in Claude AI chatbot messages and responses using MathJax library
// @author Ovler
// @match https://claude.ai/chat/*-*
// @grant none
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
// Load MathJax library
var script = document.createElement("script");
script.type = "text/javascript";
script.setAttribute('src', "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS_HTML");
document.head.appendChild(script);
// Configure MathJax to render LaTeX formulas
window.MathJax = {
tex2jax: {
inlineMath: [ ['$','$'], ['\\(','\\)'] ],
processEscapes: true
},
CommonHTML: { scale: 100 }
};
// Wait for MathJax to load and render LaTeX formulas
var checkLoaded = setInterval(function() {
if (typeof MathJax !== "undefined" && MathJax.Hub.queue.queue.length === 0) {
clearInterval(checkLoaded);
MathJax.Hub.Queue(["Typeset", MathJax.Hub, document.body]);
}
}, 100);
// Listen for changes to the page content and re-render LaTeX formulas
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === "childList" || mutation.type === "subtree") {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, mutation.target]);
}
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
})();