You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unpaired ] inside an inline equation makes escape_content escape the wrong bracket in added or deleted blocks #62
When a whole block is added or deleted, escape_content escapes the wrong ] if an inline equation inside a function's content argument contains an unpaired ], such as a half-open interval $(0, 1]$. The ] inside the equation is counted as the closing bracket of the function argument, so the argument's real closing bracket is escaped as \], and the output does not compile.
The same happens when the block is deleted (#diff-deleted[Text #emph[a $(0, 1]$ b\] end.]). A block that is only modified word by word is fine, and so is $[0, 1)$, where the count happens to balance.
Cause
escape_content in src/render.rs tracks bracket depth over the raw text to decide which ] are unbalanced. It doesn't skip inline equations, so the ] in $(0, 1]$ takes the depth from 1 to 0, and the ] that really closes #emph[ is then treated as unbalanced and escaped. Raw text and strings inside code arguments presumably have the same problem.
Possible fix
Skip inline equations when counting, reusing find_closing_dollar from #26, and do the same for raw text and quoted strings. Alternatively, take the bracket structure from typst_syntax::parse, so only brackets that are markup delimiters are counted.
Context
I found this diffing a thesis in which a new chapter has #cited[... a constant $q in (0, 1]$, ...].
Activity