Skip to content

feat(editor): syntax highlighting for MATLAB (.m) and LaTeX (.tex) - #10371

Closed
innocarpe wants to merge 1 commit into
stablyai:mainfrom
innocarpe:feat/matlab-latex-syntax-highlighting
Closed

innocarpe wants to merge 1 commit into
stablyai:mainfrom
innocarpe:feat/matlab-latex-syntax-highlighting

Conversation

@innocarpe

@innocarpe innocarpe commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fixes [Feature]: Syntax highlighting for MATLAB (.m) and LaTeX (.tex) #10363: .m and .tex (plus common LaTeX family extensions) no longer open as flat plaintext.
  • MATLAB: TextMate-backed language using the MathWorks grammar (BSD-style license vendored beside the grammar), same registration path as Nim.
  • LaTeX: presentation-only Monarch tokenizer for comments (%), commands, \begin/\end environments, and math delimiters. Full VS Code LaTeX TextMate pulls many embedded language scopes; Monarch keeps the graph small while covering the reported need.
  • detectLanguage maps extensions so Monaco picks the new language ids.

Notes

  • .m is also used by Objective-C; Orca never mapped it before (plaintext). This change maps .m → MATLAB per the issue. We can add content-based sniffing later if Obj-C users need it.

Test plan

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/lib/monaco-languages/register-matlab.test.ts src/renderer/src/lib/monaco-languages/register-latex.test.ts src/renderer/src/lib/language-detect.test.ts (17 passed)
  • Open a .m file → keywords/comments/strings colored
  • Open a .tex file → % comments and \commands colored

ELI5

MATLAB (.m) and LaTeX (.tex) files opened as plain text with no coloring. They now get syntax highlighting so code and markup are easier to read in the editor.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The change adds MATLAB and LaTeX extension detection and syntax highlighting. It registers LaTeX with a Monarch tokenizer and MATLAB with a vendored TextMate grammar. Monaco setup invokes both registrations. Tests cover language detection, registration, tokenizer rules, and MATLAB grammar metadata.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Low · up to 8d818

Typing a MATLAB transpose can insert an extra quote and change the expression. Address this editor behavior before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description explains the change, motivation, linked issue, and automated test result. However, it omits several required template sections, including What Changed, Why, Visual Proof or an explicit… Update the description to include all required template sections. Add explicit user-facing and implementation details under What Changed, explain the approach under Why, provide visual proof or state N/A with a reason, complete AI Disclosur…
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: syntax highlighting for MATLAB and LaTeX files.
Linked Issues check Passed Issue #10363 requires syntax highlighting for MATLAB and LaTeX files, including comments, keywords, strings, and commands. The supplied PR evidence shows MATLAB registration with a vendored MathWorks …
Out of Scope Changes check Passed The supplied change summary shows only language registrations, supporting MATLAB grammar and license files, Monaco setup wiring, extension detection, and automated tests. The additional LaTeX-family e…
Full details: Linked Issues check

Explanation

Issue #10363 requires syntax highlighting for MATLAB and LaTeX files, including comments, keywords, strings, and commands. The supplied PR evidence shows MATLAB registration with a vendored MathWorks TextMate grammar, LaTeX registration with a Monarch tokenizer for comments, commands, environments, and math delimiters, and extension detection for .m, .tex, .ltx, .latex, and .sty. The added tests cover both registrations and language detection.

Full details: Out of Scope Changes check

Explanation

The supplied change summary shows only language registrations, supporting MATLAB grammar and license files, Monaco setup wiring, extension detection, and automated tests. The additional LaTeX-family extensions support the same syntax-highlighting objective. No unrelated change is demonstrated.

Full details: Description check

Explanation

The description explains the change, motivation, linked issue, and automated test result. However, it omits several required template sections, including What Changed, Why, Visual Proof or an explicit N/A, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. Manual validation items also remain unchecked.

Resolution

Update the description to include all required template sections. Add explicit user-facing and implementation details under What Changed, explain the approach under Why, provide visual proof or state N/A with a reason, complete AI Disclosure when applicable, address Review and Agent skill upstream boundary, complete Notes and Checklist, and report the manual testing results for MATLAB and LaTeX files.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 7 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/renderer/src/lib/language-detect.test.ts (1)

23-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the .latex mapping.

language-detect.ts adds .latex support, but this test block does not verify it. Add an assertion such as detectLanguage('paper/main.latex') → latex.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6d826717-9b84-4e15-be5d-62fcba6ab989

📥 Commits

Reviewing files that changed from the base of the PR and between 1bd36ce and a3beca8.

📒 Files selected for processing (9)
  • src/renderer/src/lib/language-detect.test.ts
  • src/renderer/src/lib/language-detect.ts
  • src/renderer/src/lib/monaco-languages/register-latex.test.ts
  • src/renderer/src/lib/monaco-languages/register-latex.ts
  • src/renderer/src/lib/monaco-languages/register-matlab.test.ts
  • src/renderer/src/lib/monaco-languages/register-matlab.ts
  • src/renderer/src/lib/monaco-languages/textmate-grammars/matlab-LICENSE.txt
  • src/renderer/src/lib/monaco-languages/textmate-grammars/matlab.tmLanguage.json
  • src/renderer/src/lib/monaco-setup.ts

@nwparker nwparker added the enhancement New feature or request label Jul 27, 2026
Wire .m files to a TextMate-backed matlab language (MathWorks grammar) and
.tex/.ltx/.sty/.cls to a Monarch latex tokenizer for comments, commands,
environments, and math. Update detectLanguage so the Monaco viewer picks
these up instead of plaintext.
@innocarpe
innocarpe force-pushed the feat/matlab-latex-syntax-highlighting branch from a3beca8 to 8d81891 Compare October 29, 2026 05:19
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Low impact] The changes affect syntax coloring for a limited set of editor file types.

The PR appears safe to merge, with two non-blocking highlighting issues worth fixing.

Findings

  1. P2 MATLAB tokens remain uncolored ▶
  2. P2 Literal dollars change later colors ▶

Summary

Adds MATLAB highlighting through a vendored TextMate grammar and LaTeX highlighting through Monarch.

  • MATLAB files get MATLAB-aware syntax coloring.
  • LaTeX files show comments, commands, and math with syntax colors.
  • MATLAB and LaTeX file endings select their matching editor languages.

Acknowledgment: innocarpe explicitly deferred content-based Objective-C detection for .m files. The PR intentionally maps .m to MATLAB. The code also deliberately preserves .cls for Apex.

Tests and visual checks were not run; this checkout has no installed dependencies.

Reviews (1) · Last reviewed commit: "feat(editor): syntax highlighting for MA..." · Reviewed by Greptile

Comment on lines +50 to +51
configuration: matlabLanguageConfiguration,
loadGrammar: loadMatlabTextMateGrammar

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 MATLAB tokens remain uncolored

The registration passes TextMate names directly to Monaco. The grammar marks function as storage.type.function.matlab and numbers as constant.numeric.matlab, which the default editor themes do not color. These remain plain despite the new highlighting support.

Map these names to Monaco’s keyword and number tokens, as the other TextMate registrations do, and test the resulting colors.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +49 to +59
// \begin{env} / \end{env}
[
/\\(begin|end)\s*\{[a-zA-Z*]+\}/,
{
cases: {
'@default': 'keyword'
}
}
],
// Commands: \command, \command*, \\, and special single-char commands
[/\\(?:[a-zA-Z]+|[^a-zA-Z\s])/, 'keyword'],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Literal dollars change later colors

The rules read text inside \verb and verbatim as LaTeX syntax. For example, \verb|$HOME| starts inlineMathDollar, and a verbatim block containing $HOME does the same. Neither closing construct leaves that state, so ordinary text afterward stays colored as math until another dollar sign appears.

Add literal-text rules before the general command and environment rules. Test that text after each closing construct returns to normal colors.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bd50012c-1b0c-4039-878e-60448b8cb8d2
Commits

Reviewing files that changed from the base of the PR and between a3beca8 and 8d81891.

Files selected for processing: 7
  • src/renderer/src/lib/monaco-languages/register-latex.test.ts
  • src/renderer/src/lib/monaco-languages/register-latex.ts
  • src/renderer/src/lib/monaco-languages/register-matlab.test.ts
  • src/renderer/src/lib/monaco-languages/register-matlab.ts
  • src/renderer/src/lib/monaco-setup.ts
  • src/shared/editor-language/editor-language-detect.test.ts
  • src/shared/editor-language/editor-language-detect.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: "'", close: "'" },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Do not auto-close the MATLAB transpose operator.

When a user types A' at the end of a line, this pair can insert another ' and leave A''. In MATLAB, ' is an operator, so the inserted character changes the expression. Remove the single-quote auto-closing pair; keep string highlighting in the grammar. (code.visualstudio.com)

@nwparker

Copy link
Copy Markdown
Contributor

Thank you @innocarpe for this! We've shipped both languages as official plugins instead of building them into Orca, so they can be updated on their own: MATLAB Syntax and LaTeX Syntax. Your work is credited: you're a co-author of the MATLAB plugin commit.

To install: Settings → Plugins → turn on plugins → search for it and install. It needs Orca 1.4.246 or newer (older versions show "Needs Orca 1.4.246"), because that's the first release where an enabled plugin syntax takes precedence over Orca's own mapping for these files.

Closing this PR as superseded. If it falls short for you, please reopen and tell us what is missing.

@nwparker nwparker closed this Oct 30, 2026
senadaruc pushed a commit to senadaruc/orca-plugins that referenced this pull request Oct 31, 2026
Highlights .m files with MathWorks' MATLAB TextMate grammar (BSD-2-Clause).
Needs Orca 1.4.246, the first release where an enabled plugin syntax beats
Orca's Objective-C mapping for .m.

Covers the MATLAB half of stablyai/orca#10363 and replaces stablyai/orca#10371.

Co-authored-by: Wooseong Kim <innocarpe@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Syntax highlighting for MATLAB (.m) and LaTeX (.tex)

3 participants