sagemath / sage

Main repository of SageMath. Now open for Issues and Pull Requests.
https://www.sagemath.org
Other
1.19k stars 411 forks source link

Latex representation of products #38043

Open BenjaminMoraga opened 1 month ago

BenjaminMoraga commented 1 month ago

Problem Description

When writing mathematics, it is usual to denote the product $xy$ between two symbolic variables $x$ and $y$ just by concatenation; this also aplies to the product of a number and a symbolic variable like $2x$. In Sagemath, the latex representation of a product introduce a thin non-separation space between both variables, say $x\, y$ and $2\, x$, respectively. Although this is acceptable, and may be also prefered by some authors, I think there should be an easy manner to modify this behaviour. Also, I would change the default behaviour.

Proposed Solution

Add a method to latex that modifies the representation of products as matrix_delimiters change delimiters of a matrix. Also, the default behaviour should be plain concatenation.

Alternatives Considered

Add a global option that change the way products are represented.

Additional Information

No response

Is there an existing issue for this?

DaveWitteMorris commented 1 month ago

Please provide code that illustrates the issue, because I am not seeing it. There is no thinspace here:

sage: x,y = var("x y")
sage: latex(x * y)
x y

Actually, I think perhaps the default should be to have thinspace because, unlike in usual mathematics, sagemath routinely allows variables to have more than one letter, e.g.:

sage: var("distance rate time")
(distance, rate, time)
sage: latex(distance == rate * time)
\mathit{distance} = \mathit{rate} \mathit{time}

I think there should be something between the two variables on the right-hand side. Probably it should be \times, but a space would be better than nothing.

BenjaminMoraga commented 1 month ago

You are right, there is no thin space between the product of two variables. I think that behaviour is desirable, because most of the times we use one letter variables and is better for copy/paste on LaTeX source. The problem is the inconsistency with the product between an integer and a symbolic variable:

sage: latex(2*x)
2 \, x

I think that the default should be non thin space between coeficients and variables, similar to products of variables. But a function to control that representation should be implemented.