Skip to content

Instantly share code, notes, and snippets.

@DenverCoder1
Created April 1, 2021 22:01
Show Gist options
  • Save DenverCoder1/b68bc4ce16b87a83e565628b3a3757f7 to your computer and use it in GitHub Desktop.
Save DenverCoder1/b68bc4ce16b87a83e565628b3a3757f7 to your computer and use it in GitHub Desktop.
// How to get Math Autocorrect on Google Docs
// Type shortcuts inspired by LaTeX anywhere in Google Docs
// Script by Jonah Lawrence (c) 2021
//
// Steps:
// 1. Open a Google Doc
// 2. Click the Tools tab, then Preferences
// 3. Switch to the Substitutions Tab
// 4. Paste this script in the Console
(async function () {
const response = await fetch("https://cdn.jsdelivr.net/gh/DenverCoder1/LaTeX-Gboard-Dictionary/dictionary.txt");
const text = await response.text();
const lines = text.split("\n").slice(1);
lines.forEach((line) => {
let [shortcut, symbol] = line.split("\t");
const replaceEl = document.querySelector("input[title='New substitution. Replace']");
const withEl = document.querySelector("input[title='With']");
replaceEl.value = shortcut;
withEl.value = symbol;
withEl.dispatchEvent(new Event('focus'));
withEl.parentElement.dispatchEvent(new KeyboardEvent('keyup'));
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment