Fix crash during LaTeX export with empty macros in preamble #3051
Fix crash during LaTeX export with empty macros in preamble #3051Shubham-py404 wants to merge 4 commits intoMoganLab:mainfrom
Conversation
|
@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! |
|
@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! |
|
@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! |
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.