Greasy Fork 还支持 简体中文。

Keep Raw LaTeX Visible (No Rendering)

Keep LaTeX content as raw text without rendering it into formulas

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

  1. // ==UserScript==
  2. // @name Keep Raw LaTeX Visible (No Rendering)
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description Keep LaTeX content as raw text without rendering it into formulas
  6. // @author You
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Function to make sure LaTeX code is kept as raw text
  15. function keepRawLatex() {
  16. // Target all LaTeX elements (common ones like <span>, <div>, <p> containing LaTeX expressions)
  17. const latexElements = document.querySelectorAll('span, div, p');
  18.  
  19. latexElements.forEach(element => {
  20. // Check for LaTeX expressions using regex
  21. if (element.innerHTML && (element.innerHTML.match(/\\\[(.*?)\\\]/) || element.innerHTML.match(/\\\((.*?)\\\)/))) {
  22. // Replace rendered LaTeX content with raw LaTeX code, keeping it as plain text
  23. const rawLatex = element.innerHTML.replace(/\\\[(.*?)\\\]/g, '\\[ $1 \\]').replace(/\\\((.*?)\\\)/g, '\\( $1 \\)');
  24. element.innerHTML = rawLatex;
  25. }
  26. });
  27. }
  28.  
  29. // Run the function when the document is fully loaded
  30. window.addEventListener('load', function() {
  31. keepRawLatex();
  32. });
  33.  
  34. // If the page updates dynamically, re-check LaTeX every second
  35. setInterval(keepRawLatex, 1000);
  36. })();