Skip to content

Conversation

@Meinzzzz
Copy link

Description :
Integrates a MathLive field to provide a richer math-editing experience, offering both a visual equation editor and a raw LaTeX code editor.
Key Features
Visual equation editing using MathLive, while preserving an area for directly editing raw LaTeX.
Technical Implementation:

  • MathLiveInputView: A new wrapper class for the MathLive web component that bridges it with CKEditor 5's view architecture.
  • RawLatexInputView: A specialized view for the raw LaTeX textarea.
  • MainFormView Refactor: 
    • Orchestrates the communication between the two inputs.
    • Manages the ResizeObserver lifecycle to prevent memory leaks.
    • Handles focus cycling and keyboard navigation.
  • Styles: Comprehensive CSS updates in mathform.css to support the new layout, including resize: both support and flexbox layouts for the dual inputs.

Testing:Unit Tests: Added comprehensive test suites for MathUI, covering:

  • Initialization and teardown.
  • Command execution and binding.
  • Synchronization logic between MathLive and Raw LaTeX inputs.
  • Keyboard shortcuts and focus management.

Dependencies:

  • Added mathlive package
image

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Nov 22, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Meinzzzz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly upgrades the math input functionality by integrating the MathLive library, offering users a more intuitive and powerful way to create and edit mathematical equations. The changes introduce a dual-interface approach, allowing users to switch between a visual equation editor and a direct LaTeX code editor, ensuring a flexible and robust math-editing experience within the application.

Highlights

  • MathLive Integration: Introduced MathLive for an enhanced visual math-editing experience, providing a richer and more interactive way to input equations.
  • Dual Input Modes: The system now offers both a visual equation editor and a raw LaTeX code editor, with bidirectional synchronization between the two for seamless editing.
  • New UI Components: Added MathLiveInputView and RawLatexInputView to manage the new input fields, replacing the previous single input approach.
  • MainFormView Refactor: The MainFormView has been significantly refactored to orchestrate communication between the new input views, manage focus cycling, and handle dynamic input resizing using a ResizeObserver.
  • Comprehensive Testing: New unit tests have been added and existing ones updated to cover initialization, command execution, and the complex synchronization logic between the MathLive and Raw LaTeX inputs.
  • Dependency Update: The mathlive package has been added as a new dependency to enable the visual math editor functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 is a significant enhancement, integrating MathLive to provide a much richer math editing experience. The implementation is comprehensive, covering the new component views, two-way data synchronization between the visual and raw LaTeX editors, resize handling, and updated tests. The code is well-structured, and the attention to details like cleaning up resources in the destroy method is commendable. I've identified a few areas for improvement, including a bug in the CSS, an enhancement to the resize synchronization logic, and a couple of refactoring opportunities to improve code clarity and robustness. Overall, this is a high-quality contribution.

Copy link
Contributor

@eliandoran eliandoran left a comment

Choose a reason for hiding this comment

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

I've tried testing it but it fails with:

Uncaught (in promise) TypeError: can't access property "bind", formView.mathLiveInputView is undefined
    _createFormView mathui.ts:92
    init mathui.ts:29
    promise callback*init/initPlugins/< chunk-CZONVLGZ.js:45733
    initPlugins chunk-CZONVLGZ.js:45726
    init chunk-CZONVLGZ.js:45614
    initPlugins chunk-CZONVLGZ.js:47131
    create ckeditor5.js:9558
    create ckeditor5.js:9553
    buildEditor CKEditorWithWatchdog.tsx:222
    CKEditorWithWatchdog CKEditorWithWatchdog.tsx:158

@eliandoran eliandoran marked this pull request as draft November 23, 2025 16:08
Comment on lines 245 to 267
this._resizeObserver = new ResizeObserver( entries => {
if ( !this._activeResizeTarget ) {
return;
}

for ( const entry of entries ) {
if ( entry.target === this._activeResizeTarget ) {
// Use style.width directly to avoid box-sizing issues causing infinite growth
const width = ( entry.target as HTMLElement ).style.width;

if ( !width ) continue;

const other = entry.target === this.mathLiveInputView.element
? this.rawLatexInputView.element
: this.mathLiveInputView.element;

if ( other && other.style.width !== width ) {
window.requestAnimationFrame( () => {
other.style.width = width;
} );
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole resize mechanism feels overengineered. Do we actually need it? I tried remove part of it and it worked just fine.

I would prefer not to have this logic, maybe see if we can work around it using CSS since the popup follows the biggest text area, I think it should be fine without it.

Copy link
Author

Choose a reason for hiding this comment

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

I think I found a good solution that works using only CSS and also feels nice to use. Instead of making both boxes resizable, only the LaTeX box remains resizable. The Mathlive component can then grow automatically depending on the input.

@eliandoran
Copy link
Contributor

Functionally speaking, it's pretty interesting since it makes it relatively easy for people not familiar with LaTeX to insert equations.
Before this can be merged there are two main aspects to be handled:

  1. The complexity of this PR is quite high, I believe not all of the modifications are necessary and the same can be achieved with a more minimal set of changes.
  2. We need to make sure that MathLive doesn't do any "calling home" and that it works completely offline and self-hosted within Trilium. There's also the downside of the library size, since from what I see from npm it's at least 5 MB big.

@Meinzzzz Meinzzzz marked this pull request as ready for review November 23, 2025 20:29
@eliandoran
Copy link
Contributor

@Meinzzzz , I see you've marked the PR as ready but no changes were pushed. Perhaps you forgot to push your changes?

@Meinzzzz
Copy link
Author

Sorry, i hit the revie button by accident.
To address the library size, it should be possible to download the minified production bundle directly from unpkg (~860 KB) instead of using the full npm package (~6 MB). Unpkg can provide all the necessary fonts and static CSS files needed for offline use.
For the offline/self-hosted requirement, if we download everything from unpkg (JS, CSS, fonts which is about ~20KB) and use them locally in Trilium. Then configure MathLive to use these local paths. At the moment i use a java script note to add a button with mathlive, so the approach with unpkg could work, but i am not sure how to handel mathlive updates with that.

@eliandoran
Copy link
Contributor

Sorry, i hit the revie button by accident. To address the library size, it should be possible to download the minified production bundle directly from unpkg (~860 KB) instead of using the full npm package (~6 MB). Unpkg can provide all the necessary fonts and static CSS files needed for offline use. For the offline/self-hosted requirement, if we download everything from unpkg (JS, CSS, fonts which is about ~20KB) and use them locally in Trilium. Then configure MathLive to use these local paths. At the moment i use a java script note to add a button with mathlive, so the approach with unpkg could work, but i am not sure how to handel mathlive updates with that.

Let's keep the size constraints for later after we run a nightly build on it to determine the impact of the changes.

@eliandoran eliandoran marked this pull request as draft November 24, 2025 11:14
@Meinzzzz Meinzzzz marked this pull request as ready for review November 26, 2025 22:10
@Meinzzzz Meinzzzz marked this pull request as draft November 28, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants