Skip to content

Conversation

@rocky
Copy link
Member

@rocky rocky commented Jan 20, 2026

Use proper character names LeftBoubleBracket and RightDoubleBracket.
Also, add amslatext-named-characters: named characters that are defined in AMS-LaTeX.

These should be picked up in mathics-core.

rocky added 2 commits January 20, 2026 12:17
Add a list of named characters that are defined in AMSLaTeX
@rocky rocky requested a review from mmatera January 23, 2026 01:17
@rocky rocky changed the title {Left,Right}Part -> {Left,Right}DoubleBracket {Left,Right}Part -> {Left,Right}DoubleBracket and AMSLaTeX named characters Jan 23, 2026
@rocky rocky merged commit ae13029 into master Jan 23, 2026
12 checks passed
@rocky rocky deleted the correct-DoubleBracket-names branch January 23, 2026 03:09
}

# WL to AMS LaTeX characters
amslatex_named_characters = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Something that is going to be necessary to use this in mathics.format.render.latex is to distinguish if the LaTeX command works on math or text mode.
Notice we have two dicts in that module:
https://github.com/Mathics3/mathics-core/blob/c5388232f77b053012f20b7fe4ab2e53932d3c16/mathics/format/render/latex.py#L48
https://github.com/Mathics3/mathics-core/blob/c5388232f77b053012f20b7fe4ab2e53932d3c16/mathics/format/render/latex.py#L67

Depending on the context, encode_tex uses one dict or the other: https://github.com/Mathics3/mathics-core/blob/c5388232f77b053012f20b7fe4ab2e53932d3c16/mathics/format/render/latex.py#L83

Copy link
Member Author

Choose a reason for hiding this comment

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

In what ways is this different from whether the symbol is surrounded by TeX math-mode or math-display-mode symbols $ and $$?

Copy link
Member Author

@rocky rocky Jan 23, 2026

Choose a reason for hiding this comment

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

I suspect what is done by rendering TeXForm hasn't been completely thought out. So while there may be additional information that needs to be added, proper changes might be different from how that code is currently working.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suppose you have this expression:

{Infix[{2,2}, "\[Times]"],"A\[Times]A"}//TeXForm

In WMA you get

\{2\times 2, \text{A$\times$A}\}

In the second element, since it is an String, the output is inside a \text block, which contains the command \times which only works in math mode. In Mathics3 we get the same, except for the irrelevant \left \right commands preceding the curl brackets.

Now, compare with this other expression:

{\[Alpha], "\[Alpha]>3"} //TeXForm

In WMA we get

\{\alpha ,\text{ This is $\alpha $}\}

while in Mathics3

\left\{ \alpha , \text{α>3}\right\}

Here, if \[Alpha] is alone, it is considered an operator and then is picked from the mathics-scanner table, but if is inside a string, it is left alone. If we just use the replacement we would get

\left\{ \alpha , \text{\alpha>3}\right\}

which is wrong (does not compile). A solution would be to take into account that in the second case we are inside a text block, and just add $ around.
Now consider this other case:

{\[Aacute], "\[Aacute]>3"} //TeXForm

Now we get it wrong:

\left\{\'a, \text{$\'a$>3}\right\}

which fails to compile in both occurrences. WMA returns for this case

\{\text{\' a},\text{$\{$a $\#$ {\' a}$\}$}\}

So in some way it tracks when a symbol works on text mode or math mode.

Copy link
Member Author

@rocky rocky Jan 23, 2026

Choose a reason for hiding this comment

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

This suggests that no changes are needed in named-characters.yml. Whether the output should use TeX's math or display math mode is not encoded in character information. Instead, that is a boxing aspect.

One purpose of boxing is to provide contextual information. In that respect, it is similar to parsing.

It shouldn't be surprising that the Mathics boxing code has been flawed at a conceptual and design level.

Copy link
Member Author

Choose a reason for hiding this comment

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

Strictly, both $\alpha$ and $\'a$ are LaTeX, not amslatex.

Yes, you are correct for these symbols. I used amslatex originally, because it uses definitions that are not in LaTeX.

So to be clear, how about 3 fields: LaTeX-text-mode, LaTeX-math-mode, and AMSLaTeX-math-mode?

Also, in the back of my mind, in mathics core we should rename from op-tables.json to character-tables.json (or something like this). Here in mathics-scanner, this is called character-tables because this information is more about the named characters, rather than the operators.

Copy link
Contributor

Choose a reason for hiding this comment

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

That could work. The only detail is that it introduces some redundancy ($\alpha$ would be in AMSLaTeX-math-mode too?, what is the context where it would be relevant to discriminate AMSLaTeX from plane LaTeX?)
Regarding the change of name, I think it is OK.

Copy link
Member Author

Choose a reason for hiding this comment

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

That could work. The only detail is that it introduces some redundancy ( α would be in AMSLaTeX-math-mode too?,

Yes, because we have to distinguish symbols that are in text-mode only, math-mode only, and in both text and math mode.

What is the context where it would be relevant to discriminate AMSLaTeX from plane LaTeX?) Regarding the change of name, I think it is OK.

I do add this only because you point out that while some AMSLaTeX characters are exclusive to AMSLaTeX, some are not.

I'm okay with dropping LaTeX-math-mode, and adding that at some point in the future where a distinction is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rocky, as you prefer. In any case, the tables are not so large. The question is how much work it would take to add these fields.

Copy link
Member Author

Choose a reason for hiding this comment

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

@rocky, as you prefer. In any case, the tables are not so large. The question is how much work it would take to add these fields.

I don't know. I'll try to get started on this, though.

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.

3 participants