texstudio
texstudio copied to clipboard
(?highlighted-as:numbers) is not working
Environment
- TeXstudio: 4.0.0alpha2
- Qt: 5.15.2
- OS: Windows 10
- TeX distribution: not relevant
Problem already happened for TeXstudio version 3.0.4(Qt 5.12.3). same result for (?highlighted-as:picture), etc. works fine for (?highlighted-as:comment), etc.
Expected behavior
The script will run if it matches the trigger in math environment. Like the previous version 2.12.16.
Actual behavior
Nothing happened.
How to reproduce
add (?highlighted-as:numbers) before the trigger of a macro.
the issue comes from a change in logic. Math (and now also comments) are highlighted in a parallel thread, so that the main thread does not see it as it is not yet highlighted...
A possible workaround:
- create a list of mathematical environments you are interested in (I used a dictionary because I had a dictionary already)
- get the environment using
editor.document().getLastEnvName(line)
- check if your environment is in the list of mathematical environments
math_env = {
"align*": "eq",
"align": "eq",
"equation": "eq",
"coment": "cmnt",
"exemp": "exmp",
"math": "math"
}
// CHECK IF INSIDE MATH ENVIRONMENT
var line = cursor.lineNumber()
var env = editor.document().getLastEnvName(line)
if ( env in math_env){
// YOUR OLD SCRIPT GOES HERE
}
This is probably much slower, but get the job done.
I also tried to include (?not-highlighted-as:normal)
in order to avoid running this in such cases, but could not get it to work.
Any progress on this problem? It is not only (?highlighted-as: *)
itself that breaks. It also prevents the macro from triggering even after the prepended scope limit removed, until restarting TexStudio.
no progress