Skip to content

MarkdownRenderer: support Latex - #48

Merged
gapry merged 2 commits into
mainfrom
Latex
Mar 31, 2026
Merged

gapry merged 2 commits into
mainfrom
Latex

Conversation

@gapry

@gapry gapry commented Mar 31, 2026

Copy link
Copy Markdown
Owner

No description provided.

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR successfully adds LaTeX/math rendering support to the MarkdownRenderer component. The implementation correctly integrates KaTeX with the React Markdown pipeline using remark-math and rehype-katex plugins.

Changes:

  • Added required dependencies (katex, remark-math, rehype-katex)
  • Configured ReactMarkdown with math processing plugins
  • Added appropriate CSS styling for rendered math expressions

The implementation is sound and ready to merge after addressing the minor file formatting issue.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

margin: 1.5em 0;
overflow-x: auto;
overflow-y: hidden;
} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add a newline at the end of the file. Missing final newlines can cause issues with version control systems and certain build tools that expect POSIX-compliant text files.

Suggested change
}
.katex-display {
margin: 1.5em 0;
overflow-x: auto;
overflow-y: hidden;
}

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request integrates mathematical expression rendering into the MarkdownRenderer component using remark-math, rehype-katex, and katex. Feedback includes correcting a non-existent version number for the katex dependency, removing a vertical overflow restriction in the CSS to prevent clipping of tall expressions, and configuring the KaTeX plugin to handle syntax errors gracefully without crashing the component.

Comment thread package.json
"preview": "vite preview"
},
"dependencies": {
"katex": "^0.16.44",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The version 0.16.44 for katex does not appear to exist on npm. The current latest version in the 0.16.x branch is 0.16.11. This typo will likely cause installation or build failures.

Suggested change
"katex": "^0.16.44",
"katex": "^0.16.11",

Comment on lines +37 to +41
.katex-display {
margin: 1.5em 0;
overflow-x: auto;
overflow-y: hidden;
} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Setting overflow-y: hidden on .katex-display can cause clipping of tall mathematical expressions, such as large matrices, fractions, or summations with limits. It is recommended to only use overflow-x: auto to handle horizontal scrolling for long equations without risking vertical clipping.

.katex-display {
  margin: 1.5em 0;
  overflow-x: auto;
}

<ReactMarkdown
remarkPlugins={[remarkGfm]}
remarkPlugins={[remarkGfm, remarkMath]}
rehypePlugins={[rehypeKatex]}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

By default, rehype-katex will throw an error if it encounters invalid LaTeX syntax, which can crash the entire rendering of the component. It is safer to set throwOnError: false so that KaTeX renders the problematic string as-is (usually in red) instead of throwing an exception.

Suggested change
rehypePlugins={[rehypeKatex]}
rehypePlugins={[[rehypeKatex, { throwOnError: false }]]}

@gapry
gapry merged commit 69b9727 into main Mar 31, 2026
1 check passed
@gapry
gapry deleted the Latex branch March 31, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant