diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ec563956..105ed6434 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ ### Fixed * Fix parse error when using commands with arguments in parameter of \href or \url * Fix parse error when using parentheses in a group in a key value command argument +* Fix parse erron when using inline math in cases* environment in inline math +* ## [0.9.10-alpha.4] - 2024-12-21 diff --git a/src/nl/hannahsten/texifyidea/grammar/LatexLexer.flex b/src/nl/hannahsten/texifyidea/grammar/LatexLexer.flex index e9fc6686c..12a88e084 100644 --- a/src/nl/hannahsten/texifyidea/grammar/LatexLexer.flex +++ b/src/nl/hannahsten/texifyidea/grammar/LatexLexer.flex @@ -137,7 +137,7 @@ START_IFS=\\if | \\ifcat | \\ifx | \\ifcase | \\ifnum | \\ifodd | \\ifhmode | \\ ELSE=\\else END_IFS=\\fi -%states INLINE_MATH INLINE_MATH_LATEX DISPLAY_MATH TEXT_INSIDE_INLINE_MATH NESTED_INLINE_MATH PARTIAL_DEFINITION +%states INLINE_MATH INLINE_MATH_LATEX DISPLAY_MATH TEXT_INSIDE_INLINE_MATH NESTED_INLINE_MATH PARTIAL_DEFINITION ENVIRONMENT_INSIDE_INLINE_MATH %states NEW_ENVIRONMENT_DEFINITION_NAME NEW_ENVIRONMENT_DEFINITION NEW_ENVIRONMENT_SKIP_BRACE NEW_ENVIRONMENT_DEFINITION_END NEW_DOCUMENT_ENV_DEFINITION_NAME NEW_DOCUMENT_ENV_DEFINITION_ARGS_SPEC NEW_COMMAND_DEFINITION_PARAM1 NEW_COMMAND_DEFINITION_PARAM2 // latex3 has some special syntax @@ -475,6 +475,10 @@ END_IFS=\\fi // When already in inline math, when encountering a \text command we need to switch out of the math state // because if we encounter another $, then it will be an inline_math_start, not an inline_math_end \\text { yypushState(TEXT_INSIDE_INLINE_MATH); return COMMAND_TOKEN; } + // Similarly, environments like cases* from mathtools have text as their second column, which can have inline math + // We cannot use a single token for inline math start and end because the parser will try to parse the one that should be an 'end' as a 'start' + // Therefore, to make sure that we cannot have a START \begin{cases*} END ... START \end{cases*} END, we use a separate state + {BEGIN_TOKEN} { yypushState(ENVIRONMENT_INSIDE_INLINE_MATH); return BEGIN_TOKEN; } } // When in a \text in inline math, either start nested inline math or close the \text @@ -483,6 +487,11 @@ END_IFS=\\fi {CLOSE_BRACE} { yypopState(); return CLOSE_BRACE; } } + { + "$" { yypushState(NESTED_INLINE_MATH); return INLINE_MATH_START; } + {END_TOKEN} { yypopState(); return END_TOKEN; } +} + { {ROBUST_INLINE_MATH_END} { yypopState(); return INLINE_MATH_END; } } diff --git a/test/nl/hannahsten/texifyidea/psi/LatexParserTest.kt b/test/nl/hannahsten/texifyidea/psi/LatexParserTest.kt index b2ca8725f..5579f7e8c 100644 --- a/test/nl/hannahsten/texifyidea/psi/LatexParserTest.kt +++ b/test/nl/hannahsten/texifyidea/psi/LatexParserTest.kt @@ -52,6 +52,11 @@ class LatexParserTest : BasePlatformTestCase() { LatexFileType, """ $ math \text{ text $\xi$ text } math$ + + $\begin{cases*} + 1 & if $ p \equiv 1 \pmod 4$ \\ + -1 & if $ p \equiv 3 \pmod 4$ + \end{cases*}$ a """.trimIndent() ) myFixture.checkHighlighting()