Skip to content

[Feature:Forum] Support display math in LaTeX#12161

Merged
bmcutler merged 6 commits intoSubmitty:mainfrom
samarthnaikk:main
Nov 14, 2025
Merged

[Feature:Forum] Support display math in LaTeX#12161
bmcutler merged 6 commits intoSubmitty:mainfrom
samarthnaikk:main

Conversation

@samarthnaikk
Copy link
Contributor

Why is this Change Important & Necessary?

Currently, Submitty's LaTeX rendering only supports in-line math mode (e.g., $E=mc^2$). This makes it difficult to display complex or multi-line equations in a clear and readable format. This change introduces support for "display math mode," which renders equations on their own line and centered, a standard feature in mathematical typesetting. This enhancement significantly improves the readability of course materials and student submissions that contain mathematical formulas.

Closes #11989
Related to #11931

What is the New Behavior?

Before:
Only in-line math using $...$ or \(...\) was rendered. Any expressions using $$...$$ or \[...\] were displayed as plain text.

After:
Users can now use $$...$$ and \[...\] to render mathematical expressions in display mode. The expressions will appear centered on a new line. Existing in-line math rendering is unaffected.

Example:

Before: $$a^2 + b^2 = c^2$$ would just show as plain text.

After: $$a^2 + b^2 = c^2$$ will render as:

$$ a^2 + b^2 = c^2 $$

What steps should a reviewer take to reproduce or test the bug or new feature?

  1. Navigate to an area in Submitty that renders Markdown, such as the instructions for a gradeable or a post in the discussion forum.
  2. Create or edit a post and enter a mathematical expression using display mode delimiters. For example: $$f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!} (x-a)^n$$
  3. Also test the other display mode delimiter: \[ \int_a^b f(x) \, dx = F(b) - F(a) \]
  4. Add an in-line expression to ensure existing functionality is not broken: This is an in-line equation: $E=mc^2$.
  5. Save and view the rendered output.
  6. Expected Result: The equations wrapped in $$ and \[ should be rendered on their own lines and centered. The equation wrapped in $ should appear in-line with the text.

Automated Testing & Documentation

  • Automated Testing: The existing front-end tests that check for KaTeX rendering should be updated to include test cases for display math mode. A new GitHub issue should be created if these tests are not included in this PR.
  • Documentation: The documentation on submitty.org regarding Markdown usage and supported LaTeX syntax should be updated to include information about the newly supported display math delimiters ($$...$$ and \[...\]). A new GitHub issue should be created to track this documentation update.

Other information

  • Breaking Change: No, this is not a breaking change. It is additive and preserves all existing functionality for in-line math rendering.
  • Migrations: This PR does not include database migrations as it is a front-end configuration change.
  • Security Concerns: There are no known security concerns with this change. It involves modifying the configuration of the KaTeX library, which is designed to safely render mathematical expressions without executing arbitrary scripts. The change does not introduce new libraries or dependencies. render mathematical expressions without executing arbitrary scripts. The change does not introduce new libraries or dependencies.

@codecov
Copy link

codecov bot commented Oct 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 21.71%. Comparing base (fef0849) to head (8d812f8).
⚠️ Report is 39 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main   #12161      +/-   ##
============================================
- Coverage     21.73%   21.71%   -0.03%     
- Complexity     9598     9612      +14     
============================================
  Files           268      268              
  Lines         36006    36073      +67     
  Branches        475      475              
============================================
+ Hits           7827     7832       +5     
- Misses        27708    27770      +62     
  Partials        471      471              
Flag Coverage Δ
autograder 21.39% <ø> (ø)
js 2.07% <ø> (ø)
migrator 100.00% <ø> (ø)
php 20.71% <ø> (-0.03%) ⬇️
python_submitty_utils 80.08% <ø> (ø)
submitty_daemon_jobs 90.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@skara9 skara9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good, fix these eslint errors and it should be good to merge.
("CI / JavaScript Lint" task below)

@samarthnaikk samarthnaikk changed the title Add Support for Display Math Mode in LaTeX [Feature:UI/UX] Add support for display math mode in LaTeX Oct 31, 2025
@samarthnaikk
Copy link
Contributor Author

I have made the required changes @skara9 . (The CI / JavaScript Lint errors are fixed)

@samarthnaikk samarthnaikk changed the title [Feature:UI/UX] Add support for display math mode in LaTeX [InstructorUI] Support display math in LaTeX Oct 31, 2025
@skara9 skara9 changed the title [InstructorUI] Support display math in LaTeX [Feature:Forum] Support display math in LaTeX Oct 31, 2025
Copy link
Contributor

@skara9 skara9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for the contribution.

@github-project-automation github-project-automation bot moved this from Seeking Reviewer to Awaiting Maintainer Review in Submitty Development Oct 31, 2025
@skara9 skara9 moved this from Awaiting Maintainer Review to Ready to Merge in Submitty Development Oct 31, 2025
Copy link
Contributor

@RyanStyron RyanStyron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After testing, can confirm that this PR resolves the attached issue. One note is that the markdown preview does differ from the published reply in that the published reply's render of text wrapped by $$ is not centered, whereas it is centered in the preview. This is not something that should necessarily hold the PR from being merged, but perhaps it should be considered.

@github-project-automation github-project-automation bot moved this from Ready to Merge to Awaiting Maintainer Review in Submitty Development Nov 5, 2025
@RyanStyron
Copy link
Contributor

After testing, can confirm that this PR resolves the attached issue. One note is that the markdown preview does differ from the published reply in that the published reply's render of text wrapped by $$ is not centered, whereas it is centered in the preview. This is not something that should necessarily hold the PR from being merged, but perhaps it should be considered.

Thoughts, @skara9?

@skara9
Copy link
Contributor

skara9 commented Nov 7, 2025

@RyanStyron It doesn't look like that's the case.
The math is consistently centered to the message text, not the container.
If we want to stretch the message to fill the container, that's also possible with a CSS change.

Copy link
Contributor

@skara9 skara9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samarthnaikk Take a look at the CSS and see if you can have the message fill the container width, so the display math is centered to the the box.
image
image

@github-project-automation github-project-automation bot moved this from Awaiting Maintainer Review to Work in Progress in Submitty Development Nov 7, 2025
@samarthnaikk
Copy link
Contributor Author

@skara9 I have updated the code with the required changes

@bmcutler bmcutler merged commit 58b54df into Submitty:main Nov 14, 2025
23 of 25 checks passed
@github-project-automation github-project-automation bot moved this from Work in Progress to Done in Submitty Development Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Add Support for Display Math Mode in LaTeX

4 participants