Disable LaTeX Rendering - Keep Raw LaTeX

Disable LaTeX rendering but keep the raw LaTeX code visible (no MathJax, no KaTeX)

当前为 2025-02-14 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Disable LaTeX Rendering - Keep Raw LaTeX
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Disable LaTeX rendering but keep the raw LaTeX code visible (no MathJax, no KaTeX)
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to disable LaTeX rendering
    function disableLatexRendering() {
        // Find all elements containing LaTeX formulas, e.g., elements with class names like 'mathjax' or 'katex'
        const latexElements = document.querySelectorAll('script[src*="mathjax"], script[src*="katex"], span, div, p, img');

        latexElements.forEach(element => {
            // Check if the element contains LaTeX code (looks like \[ ... \] or \( ... \))
            if (element.innerHTML && (element.innerHTML.match(/\\\[(.*?)\\\]/) || element.innerHTML.match(/\\\((.*?)\\\)/))) {
                // Replace the LaTeX content with its raw version, preventing rendering
                element.innerHTML = element.innerText;
            }
        });

        // If MathJax or KaTeX is present, disable it
        if (window.MathJax) {
            window.MathJax.Hub.Config({
                showMathMenu: false, // Disable MathJax menu
                skipStartupTypeset: true, // Skip initial render
            });
        }

        // Prevent KaTeX from rendering
        if (window.katex) {
            window.katex.render = function() {};  // Override KaTeX rendering function
        }
    }

    // Run the function when the document is fully loaded
    window.addEventListener('load', function() {
        disableLatexRendering();
    });

    // Continuously check for new LaTeX content if the page is dynamic (AJAX)
    setInterval(disableLatexRendering, 1000);
})();