Skip to content

Fix crash during LaTeX export with empty macros in preamble #3051

Open
Shubham-py404 wants to merge 4 commits intoMoganLab:mainfrom
Shubham-py404:fix-latex-empty-macro
Open

Fix crash during LaTeX export with empty macros in preamble #3051
Shubham-py404 wants to merge 4 commits intoMoganLab:mainfrom
Shubham-py404:fix-latex-empty-macro

Conversation

@Shubham-py404
Copy link
Copy Markdown

Fixes #1621

To be completely transparent, I was not able to reproduce the hard crash on my local Windows build—the engine seems to silently handle the empty symbol creation without failing. However, based on the stack trace provided in the original issue (which occurred on macOS), I tracked down the root cause.

The trace points to collect-user-defs-sub in tmtex.scm. When a document has an empty macro in the preamble like <assign||<macro|>>, (cadr t) evaluates to an empty string "". Passing this into string->symbol is unsafe and causes the fatal error on stricter environments like macOS.

I added a length check (> (string-length (cadr t)) 0) inside the cond block of collect-user-defs-sub. This ensures the parser validates that the macro actually has a name before attempting to convert it to a symbol. It safely ignores blank definitions and patches the potential crash across all platforms.

@Yuki-Nagori
Copy link
Copy Markdown
Contributor

@Shubham-py404 Please refer to https://github.com/MoganLab/mogan/blob/main/CONTRIBUTING.md to write the devel documentation and the TMU files for testable features in mogan/TeXmacs/tests/tmu. Thanks!

@da-liii da-liii self-requested a review March 30, 2026 09:17
@Shubham-py404
Copy link
Copy Markdown
Author

@Yuki-Nagori Thanks for the review! I have removed the unnecessary whitespace in tmtex.scm and added the developer documentation under devel/203_27.md.

Since this is my first time contributing to Mogan, could you point me to an example of a similar TMU test file for LaTeX exports? I want to make sure I format the automated test case correctly. Thank you!

@Shubham-py404
Copy link
Copy Markdown
Author

@Yuki-Nagori I actually spent some time looking through the other files in tests/tmu/ and reverse-engineered how the preamble macros are structured!

I just pushed 203_27.tmu, which contains the <assign||<macro|>> definition in the block to serve as the automated test case. Let me know if the formatting looks correct or if you need any other changes!

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.

LaTeX export fails silently if there exists an empty macro in the preamble

2 participants