Skip to content

Instantly share code, notes, and snippets.

@iqiancheng
Last active July 1, 2024 13:10
Show Gist options
  • Save iqiancheng/9945010cc85209185618c964bdd84fd1 to your computer and use it in GitHub Desktop.
Save iqiancheng/9945010cc85209185618c964bdd84fd1 to your computer and use it in GitHub Desktop.
LaTeX Cleanup UserScript for arXiv
// ==UserScript==
// @name arXiv LaTeX Zapper.user.js
// @namespace https://gist.github.com/iqiancheng
// @author qian.cheng
// @version 0.3
// @description Zap those pesky LaTeX elements that snuck into the HTML on arXiv
// @downloadURL https://gist.githubusercontent.com/iqiancheng/9945010cc85209185618c964bdd84fd1/raw/969a26e502d4487569a561013612eb6b019bfb1b/arxiv_latex_zapper.user.js
// @updateURL https://gist.githubusercontent.com/iqiancheng/9945010cc85209185618c964bdd84fd1/raw/969a26e502d4487569a561013612eb6b019bfb1b/arxiv_latex_zapper.user.js
// @match *://ar5iv.labs.arxiv.org/html/*
// @match *://arxiv.org/html/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function nukeLatexElements() {
// This regex is our LaTeX-spotting superpower
const latexPattern = /\\newfloatcommand|capbtabboxtable\s*\[\s*\]\s*\[|\\FBwidth/;
// Round up all the <p> and <span> suspects
const elements = document.querySelectorAll('p, span');
elements.forEach(element => {
// Is this element harboring LaTeX fugitives?
if (latexPattern.test(element.textContent)) {
// Caught red-handed! Time to disappear
element.remove();
console.log('Busted and removed:', element.textContent);
}
});
}
// Fire up our LaTeX cleanup crew when the page loads
window.addEventListener('load', nukeLatexElements);
// Set up a stakeout for any sneaky, late-arriving LaTeX
const observer = new MutationObserver(nukeLatexElements);
observer.observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment