Skip to content

LaTeX reader: \DeclareMathOperator, optional arguments with a default, empty macro bodies - #23

Open
simonebortolin wants to merge 1 commit into
claude/latex-operator-namesfrom
claude/latex-macro-expansion
Open

simonebortolin wants to merge 1 commit into
claude/latex-operator-namesfrom
claude/latex-macro-expansion

Conversation

@simonebortolin

@simonebortolin simonebortolin commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Second of a stack: main ← #22 ← this ← write-back (NotWrittenBack).

Expands the macros of NotExpanded in Latex2MathMLCorpusTests:

  • \DeclareMathOperator{\name}{text} (braced or bare name) is \newcommand{\name}{\operatorname{text}}, \DeclareMathOperator* with \operatorname*, through the operator names of LaTeX reader: operator names alone and the amsmath names of two words #22.
  • \newcommand{\f}[n][default]{…}: the first argument is optional, [given] or the default (also for a macro at the end of the input), with the OptionalArgument of \newenvironment.
  • An empty body (\newcommand{\e}{}, \def\e{}, \newcommand{\h}[2]{}) expands to nothing: no ⬚ for the group of the body, while {}_a^b X keeps its empty base.

newcommand-optional-default stays listed, as ExpandedOtherwise: \newcommand{\greeting}[1][Hello]{#1} \greeting{world} is Helloworld in LaTeX (the one argument is the optional one, {world} follows as a group), where latex2mathml reads world.

Tests: 9 new cases of ExpandsMacros. 6806/6806 on net10.0 and net8.0.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SyVio98rJkziNnwWW9T1Mn

@simonebortolin
simonebortolin added this pull request to stack #24 November 9, 2026 19:43
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Pre-release 1.0.5-pr.23.65 is ready: https://github.com/simonebortolin/SharpEquations/releases/tag/pr-23-65-1

NuGet package of c685a8a. Updated on every push, deleted when this PR is closed.

… a default and empty macro bodies

\DeclareMathOperator{\name}{text} (and \DeclareMathOperator\name, starred or not) defines
\name as \operatorname{text} (\operatorname*{text}); a macro of \newcommand{\f}[n][default]
takes its first argument optional, [given] or the default, as \newenvironment does; an
empty body (\newcommand{\e}{}, \def\e{}) expands to nothing, not to an empty group. The
latex2mathml macro cases that were not expanded now are, but for
newcommand-optional-default, where latex2mathml takes the group after a macro whose one
argument is optional as that argument: LaTeX gives it its default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyVio98rJkziNnwWW9T1Mn
@simonebortolin
simonebortolin force-pushed the claude/latex-macro-expansion branch from 3592cf9 to c685a8a Compare November 9, 2026 21:46

This branch has not been deployed

No deployments
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.

2 participants