Closed truebluepl closed 9 months ago
I can't really tell what you're talking about, but if you're talking about "1,2", according to LaTeX rules, there is indeed a space before and after the comma. If you want to use it as a decimal separator, you should use "1{,}2". You can also change the decimal separator in MathLive. See https://cortexjs.io/mathlive/guides/customizing/#decimal-marker
Yes, I'm talking about 1,2. I use comma as decimal separator by setting MathfieldElement.decimalSeparator = ",". So even if it set, space is added after comma?
1{,}2 gives me 2 (["Multiply", 1, "Nothing", "Nothing", 2]) when evaluated in ComputeEngine.
It's working for me. Here's what I get after setting MathfieldElement.decimalSeparator = ","
:
The MathJSON is also correct:
I suspect that the code to change the decimal format is not being executed.
Could you output to the console the value of MathfieldElement.decimalSeparator
before evaluating with the compute engine?
Also, if you select the formula and press ESC you should see this:
I'm sorry, I had latex "," property set as keycup, not label "[,]". Now there is no space.
But underlying values are:
3{,}14
- .value
['Multiply', 3, 'Nothing', 'Nothing', 14]
- ce.parse(expr).json
42
- .N().value
How did you get proper 3.1415 value?
I don't know where you got the ce
instance from. Did you set it to use a comma as a decimal separator?
MathfieldElement.decimalSeparator = ",";
console.log(mf.expression.value);
Ok, here is the code:
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<script defer src="https://unpkg.com/mathlive"></script>
<script defer src="https://unpkg.com/@cortex-js/compute-engine"></script>
<meta name="viewport" content="initial-scale=1, width=device-width" />
</head>
<body>
<math-field id="mf"></math-field>
<button id="button">Console</button>
<script>
window.addEventListener('DOMContentLoaded', function() {
MathfieldElement.decimalSeparator = ",";
const ce = new ComputeEngine.ComputeEngine();
document.getElementById('button').addEventListener('click', function(){
const mf=document.getElementById('mf');
console.log(mf.value);
console.log(ce.parse(mf.value).simplify().latex);
console.log(ce.parse(mf.value).N().latex);
});
});
</script>
</body>
</html>
Oh, wow, thank you! This is so much easier when I can read the code that is giving you trouble rather than having to guess.
In this case you are using a custom instance of the Compute Engine. It's not clear to me why. You could use ce = MathfieldElement.computeEngine;
that is the instance of Compute Engine shared by the mathfields.
When you set the decimal separator of the mathfield, the mathfield also updates its Compute Engine instance so that this compute engine instance knows how to interpret decimal separators.
Since you're using a custom Compute Engine instance, it defaults to interpreting "." as the decimal separator. You need to configure your custom Compute Engine with:
ce.latexOptions.decimalMarker = '{,}';
Or you could just use ce = MathfieldElement.computeEngine
.
Yes! Now it's clear and works properly. Thank you for your support and time:)
There is something strange in the field while typing comma.
When you type 1 comma 2
using virtual keyboard, there is no space after comma - which is OK.
Deleting all using backspace or selecting all and deleting, and typing 1 comma 2
using physical keyboard, causes no space after comma.
Sorry, I don't follow. What seems to be the problem?
After typing comma using virtual keyboard there is no space after typed comma from physical keyboard. Steps to reproduce:
I can't reproduce this. Is that something you're seeing when using https://cortexjs.io/mathlive/demo/? Or is that with a mathfield you've created? If so, what configuration are you using with this mathfield?
What is the layout of your keyboard?
At step (3), you press the comma keycap that's on the Symbols keyboard or somewhere else?
I don't understand why you would expect not to have a space after the comma at step (3). It should be the same as step (1).
Ok. My fault was setting decimal separator while activating virtual keyboard (inside onClick event). That was the cause. So space after comma at first typing from physical keyboard is not standard behaviour. I thought when typing from physical keyboard space is added always, and from virtual there is no space.
Current behaviour.
Typing comma puts space after it and before next cypher.
Expected behaviour.
There shouldn't be space after comma decimal separator.