forked from Shinonome/dots-hyprland
ai: latex: properly catch bracket-wrapped expressions
This commit is contained in:
@@ -125,9 +125,14 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
### LaTeX
|
### LaTeX
|
||||||
|
|
||||||
- Inline w/ dollar signs: $\\frac{1}{2} = \\frac{2}{4}$
|
|
||||||
- Inline w/ double dollar signs: $$\\int_0^\\infty e^{-x^2} dx = \\frac{\\sqrt{\\pi}}{2}$$
|
Inline w/ dollar signs: $\\frac{1}{2} = \\frac{2}{4}$
|
||||||
- Inline w/ backslash and square brackets \\[\\int_0^\\infty \\frac{1}{x^2} dx = \\infty\\]
|
|
||||||
|
Inline w/ double dollar signs: $$\\int_0^\\infty e^{-x^2} dx = \\frac{\\sqrt{\\pi}}{2}$$
|
||||||
|
|
||||||
|
Inline w/ backslash and square brackets \\[\\int_0^\\infty \\frac{1}{x^2} dx = \\infty\\]
|
||||||
|
|
||||||
|
Inline w/ backslash and round brackets \\(e^{i\\pi} + 1 = 0\\)
|
||||||
`,
|
`,
|
||||||
Ai.interfaceRole);
|
Ai.interfaceRole);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ ColumnLayout {
|
|||||||
Timer {
|
Timer {
|
||||||
id: renderTimer
|
id: renderTimer
|
||||||
interval: 1000
|
interval: 1000
|
||||||
repeat: true
|
repeat: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
renderLatex()
|
renderLatex()
|
||||||
for (const hash of renderedLatexHashes) {
|
for (const hash of renderedLatexHashes) {
|
||||||
@@ -45,17 +45,17 @@ ColumnLayout {
|
|||||||
function renderLatex() {
|
function renderLatex() {
|
||||||
// Regex for $...$, $$...$$, \[...\]
|
// Regex for $...$, $$...$$, \[...\]
|
||||||
// Note: This is a simple approach and may need refinement for edge cases
|
// Note: This is a simple approach and may need refinement for edge cases
|
||||||
let regex = /(\$\$([\s\S]+?)\$\$)|(\$([^\$]+?)\$)|(\\\[((?:.|\n)+?)\\\])/g;
|
let regex = /(\$\$([\s\S]+?)\$\$)|(\$([^\$]+?)\$)|(\\\[((?:.|\n)+?)\\\])|(\\\(([\s\S]+?)\\\))/g;
|
||||||
let match;
|
let match;
|
||||||
while ((match = regex.exec(segmentContent)) !== null) {
|
while ((match = regex.exec(segmentContent)) !== null) {
|
||||||
let expression = match[1] || match[2] || match[3];
|
let expression = match[1] || match[2] || match[3] || match[4] || match[5] || match[6] || match[7] || match[8];
|
||||||
if (expression) {
|
if (expression) {
|
||||||
// Qt.callLater(() => {
|
Qt.callLater(() => {
|
||||||
// });
|
|
||||||
const [renderHash, isNew] = LatexRenderer.requestRender(expression.trim());
|
const [renderHash, isNew] = LatexRenderer.requestRender(expression.trim());
|
||||||
if (!renderedLatexHashes.includes(renderHash)) {
|
if (!renderedLatexHashes.includes(renderHash)) {
|
||||||
renderedLatexHashes.push(renderHash);
|
renderedLatexHashes.push(renderHash);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user