Closed Kal-Elx closed 8 months ago
I realized that this problem is also visible when using the RegExp class in dart which I assume is causing this problem.
String findEquations(String data) {
final latexRegex = RegExp(latexPattern);
return data.replaceAllMapped(latexRegex, (match) {
return 'EQUATION';
});
}
Feel free to close this issue if that is the case.
That is the case. The \A
tag is not in JavaScript RegExp syntax, which is what Dart uses.
The corresponding Dart RegExp would be:
var latexRE = RegExp(r"\\\(.+?\\\)|(?<=\s|^)\$[^$]+?\$");
The ^
matches the start of the input string.
If you pass multiLine: true
to the RegExp constructor, it instead matches the start of a line. For this RegExp, it'll work either way since \s
matches line-terminators, so only at the start of the text is the start of a line not after a whitespace character.
(Should the RegExp match $$....$$
as well as $....$
? If so, try: RegExp(r"\\\(.+?\\\)|(?<=\s|^)(\${1,2})[^$]+?\1")
.)
Hello,
While trying to add an inline syntax for Latex I encountered a bug in this otherwise great package, I hope you can help me out.
To detect a Latex equation I'm using the regex
\\\(.+?\\\)|(?<=([\s])|(\A))\$[^$]+?\$
. This regular expression will match any string that starts with \( and ends with \), or any string that starts and ends with a dollar sign $, but only if the first dollar sign is either at the start of the string (\A) or follows a whitespace character (\s). I have verified that this regex is correct using regex101.com.The package fails to detect equations that starts with $ if they are at the beginning of a string or if they are preceded by two line breaks.
I wrote a minimal example:
Let me know if you have any ideas on how to fix this or if there are any workarounds I can do on my side. Thanks!