Skip to content

[QTI] Formulas using a LaTeX matrix, alignment or \boxed construct don't publish as MathML #6347

Open

Description

@rtibblesbot

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Target branch: unstable

Observed behavior

  • Publishing converts every legacy exercise to a QTI package (QTIExerciseGenerator). The conversion parses each formula's MathML into the pydantic MathML models.
  • Those models reject MathML that latex2mathml produces for common LaTeX: \begin{matrix}, \begin{pmatrix}, \begin{cases}, \begin{array}, \boxed, \substack.
  • The error reaches recurse_nodes uncaught, so the whole channel publish fails, not just the one item.
  • One cause: Mtable is not a presentation element, so Mrow refuses it. menclose has no model at all.
  • The same MathML in the MathML namespace passes validate_qti_item.
  • Same rule broken as [QTI] A QTI item containing an XML comment fails the channel publish #6229 and [QTI] A QTI item with a DOCTYPE entity reference fails the channel publish #6234 (native items): one item's error fails the publish instead of skipping that item. Their fixes don't reach the legacy conversion.
  • latex2mathml 3.78.1 writes the alignment & of aligned, align, alignat, gathered, eqnarray, rcases, dcases unescaped (<mi>&</mi>), so _convert's ET.fromstring raises ParseError. On unstable this aborts the publish too; with the [QTI] - The formulas are not shown in Kolibri #6327 fix the formula publishes as $$…$$ text instead, in legacy and QTI editor (<span data-latex>) items alike.

Errors and logs

pydantic_core._pydantic_core.ValidationError: 2 validation errors for Mrow
ValueError: No registered class found for tag: menclose
xml.etree.ElementTree.ParseError: not well-formed (invalid token)

User-facing consequences

  • A channel with one legacy question holding a matrix, a piecewise function or a boxed answer cannot be published at all.
  • With the [QTI] - The formulas are not shown in Kolibri #6327 fix, learners see the raw LaTeX source in place of a formula using an alignment environment.

Steps to reproduce

  1. On unstable (3857a5e), create an exercise with a single-choice question whose text is $$\begin{pmatrix}1\\2\end{pmatrix}$$.
  2. Publish the channel.
  3. The publish fails with the ValidationError above; $$\boxed{x}$$ fails with the ValueError; $$\begin{aligned}a&=b\\c&=d\end{aligned}$$ fails with the ParseError.

Acceptance Criteria

  • A legacy question containing each of \begin{matrix}, \begin{pmatrix}, \begin{cases}, \begin{array}{cc}, \boxed{x}, \substack{a\\b} publishes, and its QTI item passes validate_qti_item.
  • A formula using each of aligned, align, alignat, gathered, eqnarray, rcases, dcases with & publishes as MathML in the MathML namespace with its application/x-tex annotation, from legacy and QTI editor items, and the item passes validate_qti_item.
  • A formula the QTI item cannot carry costs at most that item, never the channel publish.

AI usage

Found by Claude Code while planning #6327: it probed latex2mathml output against the MathML models and the item XSD on unstable, and drafted this issue.

Activity

  1. added theissue type on Oct 27, 2026
  2. changed the title [-][QTI] A legacy exercise with a matrix or \boxed formula aborts the channel publish[/-] [+][QTI] Formulas using a LaTeX matrix, alignment or \boxed construct don't publish as MathML[/+] on Oct 27, 2026
  3. rtibblesbot commented on Oct 27, 2026

    @rtibblesbot
    ContributorAuthor

    Alignment environments fail the same way: aligned, align, alignat, gathered, eqnarray, rcases, dcases.

    • latex2mathml 3.78.1 writes the alignment & unescaped, so _convert's ET.fromstring raises ParseError:
      >>> convert(r"\begin{aligned}a&=b\end{aligned}")
      '<math …><mrow><mrow><mi>a</mi><mi>&</mi><mo>&#x0003D;</mo><mi>b</mi></mrow></mrow></math>'
      
    • On unstable the error aborts the publish, like the matrix cases.
    • With the [QTI] - The formulas are not shown in Kolibri #6327 fix, the formula publishes as $$…$$ text instead, in legacy and QTI editor (<span data-latex>) items alike; it logs Could not convert LaTeX to MathML.
    • matrix, pmatrix, cases, array, split with & parse fine.

    Reproduce: publish a question holding $$\begin{aligned}a&=b\\c&=d\end{aligned}$$.


    Written by rtibblesbot, an LLM-based coding agent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions