Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/codemirror/extensions/latex-completions.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Support tab/control+space completions when editing tex documents.78This just uses the file @cocalc/assets/codemirror-extra/data/latex-completions.txt,9and I can't remember where that came from or how to update it.10*/1112import * as CodeMirror from "codemirror";13import { startswith } from "@cocalc/util/misc";14const data = require("@cocalc/assets/codemirror-extra/data/latex-completions.txt");1516const completions: string[] = data.split("\n");1718function tex_hint(editor) {19const cur = editor.getCursor();2021// Find the most recent backslash, since all our completions start with backslash.22const line = editor.getLine(cur.line);23const s = line.slice(0, cur.ch);24const i = s.lastIndexOf("\\");25const list: string[] = [];26if (i == -1) {27// nothing to complete28} else {29// maybe something -- search30// First, as a convenience if user completes `\begin{it[cursor here]}` do not31// end up with two close braces. This helps compensate with the32// "Auto close brackets: automatically close brackets" mode.33const delete_trailing_brace = line[cur.ch] == "}";34const t = s.slice(i);35for (const word of completions) {36if (startswith(word, t)) {37if (delete_trailing_brace && word[word.length - 1] == "}") {38list.push(word.slice(0, word.length - 1));39} else {40list.push(word);41}42}43}44}45return {46list,47from: CodeMirror.Pos(cur.line, i),48to: CodeMirror.Pos(cur.line, cur.ch),49};50}5152CodeMirror.registerHelper("hint", "stex", tex_hint);535455