Keep Raw LaTeX Visible (No Rendering)

Keep LaTeX content as raw text without rendering it into formulas

目前为 2025-02-14 提交的版本。查看 最新版本

// ==UserScript==
// @name         Keep Raw LaTeX Visible (No Rendering)
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Keep LaTeX content as raw text without rendering it into formulas
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to make sure LaTeX code is kept as raw text
    function keepRawLatex() {
        // Target all LaTeX elements (common ones like <span>, <div>, <p> containing LaTeX expressions)
        const latexElements = document.querySelectorAll('span, div, p');

        latexElements.forEach(element => {
            // Check for LaTeX expressions using regex
            if (element.innerHTML && (element.innerHTML.match(/\\\[(.*?)\\\]/) || element.innerHTML.match(/\\\((.*?)\\\)/))) {
                // Replace rendered LaTeX content with raw LaTeX code, keeping it as plain text
                const rawLatex = element.innerHTML.replace(/\\\[(.*?)\\\]/g, '\\[ $1 \\]').replace(/\\\((.*?)\\\)/g, '\\( $1 \\)');
                element.innerHTML = rawLatex;
            }
        });
    }

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

    // If the page updates dynamically, re-check LaTeX every second
    setInterval(keepRawLatex, 1000);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址