Public
Edited
Jan 18, 2024
Insert cell
Insert cell
function extractElementsWithProofs(texContent) {
const elementPattern = /\\begin\{(theorem|proposition|corollary|lemma|definition)\}(.*?)\\end\{\1\}/gs;
const labelPattern = /\\label\{(.*?)\}/;
const refPattern = /\\ref\{(.*?)\}/g;

let extractedElements = [];
let match;

while ((match = elementPattern.exec(texContent)) !== null) {
const [fullMatch, elementType, elementText] = match;
const labelMatch = elementText.match(labelPattern);
const label = labelMatch ? labelMatch[1] : null;

let references = [];
let refMatch;
while ((refMatch = refPattern.exec(elementText)) !== null) {
references.push(refMatch[1]);
}

extractedElements.push({
type: elementType,
label: label,
text: elementText,
references: references
});
}

return extractedElements;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more