Skip to content

Commit

Permalink
fix handling math check in math alias envs
Browse files Browse the repository at this point in the history
  • Loading branch information
sunderme committed Feb 9, 2024
1 parent 20ca117 commit 7922859
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/syntaxcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,18 @@ bool SyntaxCheck::checkCommand(const QString &cmd, const StackEnvironment &envs)
bool textOrMathEnvUsed=false;
for (int i = envs.size()-1; i > -1; --i) {
Environment env = envs.at(i);
if(textOrMathEnvUsed &&(env.name=="math" || env.name=="text" )){
continue; // only the lowest text/math is valid as they can be used alternately
if(textOrMathEnvUsed){
if(env.name=="math" || env.name=="text" ) continue; // only the lowest text/math is valid as they can be used alternately
// look also for alias envs!
QStringList altEnvs = ltxCommands->environmentAliases.values(env.name);
bool skip=false;
foreach (const QString &altEnv, altEnvs) {
if (altEnv=="math" || altEnv=="text" ){
skip=true;
break;
}
}
if(skip) continue; // only the lowest text/math is valid as they can be used alternately
}
if (ltxCommands->possibleCommands.contains(env.name) && ltxCommands->possibleCommands.value(env.name).contains(cmd))
return true;
Expand Down
5 changes: 4 additions & 1 deletion src/tests/syntaxcheck_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,10 @@ void SyntaxCheckTest::checkAllowedMath_data(){
<<"$\\textit{$ {\\alpha}$}$"<<false;
QTest::newRow("nested math in text in math and extra braces (underscore)")
<<"$\\textit{$ {a_b}$}$"<<false;

QTest::newRow("handle math aliases correctly")
<<"\\usepackage{amsmath}\n\\begin{align}\n\\alpha\n\\end{align}"<<false;
QTest::newRow("handle math aliases correctly, force error")
<<"\\usepackage{amsmath}\n\\begin{align}\n\\text{\\alpha}\n\\end{align}"<<true;
}

void SyntaxCheckTest::checkAllowedMath(){
Expand Down

0 comments on commit 7922859

Please sign in to comment.