Disable LaTeX Rendering - Keep Raw LaTeX

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

目前為 2025-02-14 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();