Skip to content

Instantly share code, notes, and snippets.

@juananpe
Last active Jul 28, 2021
Embed
What would you like to do?
Dynamic data in Overleaf
let ace = document.querySelector(".ace_editor");
// ace.env.editor.session.getLength(); // number of lines
let previousRow = 0
let r = ace.env.editor.find('\\get\{(.*?)\}\{(.*?)\}',{
backwards: false,
wrap: false,
caseSensitive: false,
wholeWord: false,
regExp: true
});
while (r?.end.row >= previousRow){
previousRow = r.end.row
const original = ace.env.editor.getSelectedText();
const values = original.match(/\{.*?\}/g)
const jsonvalue = await fetch(values[0].substring(1, values[0].length-1))
const cell = await jsonvalue.json()
const newValue = parseFloat(cell.entry.content.$t)
const range = ace.env.editor.selection.getRange();
ace.env.editor.session.replace(range, `\get${values[0]}{${newValue}}`);
r = ace.env.editor.find('\\get\{(.*?)\}\{(.*?)\}',{
backwards: false,
wrap: false,
caseSensitive: false,
wholeWord: false,
regExp: true
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment