## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• Dec 04 15:02
dependabot[bot] closed #1249
• Dec 04 15:02
dependabot[bot] commented #1249
• Dec 04 15:02
dependabot[bot] labeled #1263
• Dec 04 15:02
dependabot[bot] opened #1263
• Dec 04 15:02
dependabot[bot] closed #1250
• Dec 04 15:02
dependabot[bot] commented #1250
• Dec 04 15:02
dependabot[bot] labeled #1262
• Dec 04 15:02
dependabot[bot] opened #1262
• Dec 04 15:02
dependabot[bot] closed #1246
• Dec 04 15:02
dependabot[bot] commented #1246
• Dec 04 15:02
dependabot[bot] labeled #1261
• Dec 04 15:02
dependabot[bot] opened #1261
• Dec 04 15:01
dependabot[bot] closed #1248
• Dec 04 15:01
dependabot[bot] commented #1248
• Dec 04 15:01
dependabot[bot] labeled #1260
• Dec 04 15:01
dependabot[bot] opened #1260
• Dec 04 15:01
dependabot[bot] closed #1242
• Dec 04 15:01
dependabot[bot] commented #1242
• Dec 04 15:01
dependabot[bot] labeled #1259
• Dec 04 15:01
dependabot[bot] opened #1259
stefnotch
@stefnotch
It might just be related to something with keyboard layouts. On mine, the - is at the top. And the / is between right shift and the dot.
On yours, the - key is apparently where the / is on mine.
Now the question is: What is going wrong
Yay, figured out how to reproduce this!
stefnotch
@stefnotch
1. Use any operating system with any browser (apparently)
2. Have a physical English keyboard (not sure if required)
3. Set your layout to German. Notice how the - is right where the / usually is
4. Type a bunch of -
@hanshs I think opening a GitHub issue with all this info would be a good idea. Helps arnog track this issue and helps other people find it :)
hanshs
@hanshs
Thanks for the investigation! I will open an issue in Github
Arno Gourdol
@arnog
awesome guys, thanks for the detective work to figure out what's going on. I'll have a look at the issue.
Arno Gourdol
@arnog
ok, so, good news. This issue appears to have been fixed a while ago. The code above it using mathlive@0.64.0 from May 2021. The current version is 0.69.7 and does not appear to have this issue (try it in https://cortexjs.io/mathlive/demo/). Updating to the current version should resolve it.
Teemu Helenius
@Temez1
@arnog @hanshs @stefnotch I'm having a similar issue. It was explained well arnog/mathlive#1072 & I'm using mathlive version 0.69.7. The layout changes when re-rendering the mathfield. I have tried a few workarounds without success so far. See my comment on the issue
Arno Gourdol
@arnog
@Temez1 while these issues are about the same thing, I don't think they're the same.
I'm pretty sure the issue that @hanshs encountered has been fixed for a while.
The issue described in #1072 occurs when a mathfield is unmounted and remounted.
Basically what happens is that MathLive tries to understand what keyboard layout you are using in order to map the keys correctly. They are unfortunately no web APIs to get this info, so some heuristics are used to figures this out. Once the keyboard layout has been figured out, MathLive keeps checking that the keyboard input is consistent with what it thinks is the keyboard layout, and adjust if is not. The issue in #1072 was that when remounting a mathfield, MathLive would forget what layout was in use, and restart with the default layout. I believe this has been fixed now, so that they keyboard layout persists across creation of mathfields. However, in baldoaalessandro setup, some issue remained and he was going to look into it, but haven't heard back in a while.
If someone has a simple test case demonstrating the problem, or even better, a PR that addresses it, I'd be happy to look at it again.
Teemu Helenius
@Temez1

@arnog I googled around the internet how folks are doing this and to my surprise, it's messy and there isn't a single answer to this problem. How? I mean everyone faces this but there isn't a common solution? And we are talking about user input. Are the guys at Facebook or Google also guessing what the keyboard user is typing on and then hopefully assume the characters?

Couldn't we simply detect the Unicode character and then don't care what keyboard or layout the user is using? What's the problem with this approach?

Arno Gourdol
@arnog
@Temez1 :) yes, it's very missing. It's just that there's no currently an API for it in the web platform. The problem is that sometimes you want to take into account the modifier keys, so that alt/option + backslash does something special. Or alt+P or... But if you only look at the unicode character, you will only get whatever character gets mapped to that combination, without knowing that the user actually pressed the backslash (or P) key.
Teemu Helenius
@Temez1

@arnog I think that's not a problem. For those keys, you can detect them and then decide what to do(if the certain key was pressed after pressing one of those keys). But for any character, it just seems simpler to detect it as a Unicode character no matter what layout is being used.

So as pseudocode it would be something like

const key
const modifierKey
if (modifierKeys includes modifierKey){
if (shortcuts includes key){
doShortcut(modifierKey, key)
return
}
}
doSomethingWithKey(key)

As said this seems simple. What's missing?

Arno Gourdol
@arnog
yes, it used to be like this, but then some shortcuts would not work on non-US keyboard. The problem is that sometimes shortcuts depend on the physical key (i.e. regardless of what label it has), and sometimes it depends on the label associated with the key, regardless of its physical location on the keyboard.
Believe me, if I could make keyboard handling simpler, I would be happy to do so. But unfortunately, after looking around at other projects handling keyboard shortcuts (Visual Studio Code, for example), we've all come to the same conclusion...
stefnotch
@stefnotch
I'm assuming that simply looking at the relevant KeyboardEvent property doesn't solve everything either?
As in, looking at KeyboardEvent.key and KeyboardEvent.code depending on whether it's a typical keyboard input or a shortcut.
Teemu Helenius
@Temez1
@arnog Managed to reproduce the issue when remounting. Weird thing is, that it happens locally even without remounting the mathfield. That I yet wasn't able to reproduce in the sandbox. See my comment
Gatis Celmins
Can anyone show, how to use compute-engine with variables. Something like
const formula = '\\sqrt{x} + y^3'
const parsedFormula = parse(formula)
const forCalculation = replace(parsedFormula , {x: 5, y:7})
const result = compute(forCalculation )
Arno Gourdol
@arnog
@berserks03_twitter that's close. For now, you'd want to use ce.parse() (where ce is a ComputeEngine instance), then ce.replace() and ce.N() (instead of compute()). This will change in an upcoming update to the API where the result of parse() will be an expression object that you can call replace() and N() on.
Gatis Celmins

I tried that, but

const formula = '\\sqrt{x} + y^3'
const parsedFormula = ce.parse(formula) // this returns ['Add', ['Sqrt', 'x'], ['Power', 'y', 3]]
const forCalculation = ce.replace(parsedFormula , {x: 5, y:7}) //this returns {x: 5, y: 7}
const result = ce.N(forCalculation) // this also returns {x: 5, y: 7}, not 345.2360679774998

what could I be doing wrong?
If simply

const formula = '\\sqrt{5} + 7^3'
const parsedFormula = ce.parse(formula) // this returns ['Add', ['Sqrt', '5'], ['Power', '7', 3]]
const result = ce.N(parsedFormula) // this returns 345.2360679774998
Gatis Celmins
What to add, so that ce.N returns number without 'd' at the end?
Viktor Sandberg
@Sandmountain
Hello everyone!
I was wondering if anyone has tried to use Mathlive inside another WYSIMYG editor before? That is the Mathlive editor, within another editor.
I have tried to implement the Mathlive editor inside Froala, and I've not been able to get any of the events that's happening within Mathlive. Seems like Froala is blocking everything. I'm assuming that it is not really possible, but maybe someone has gotten it to work? If so, I would really appreciate if that person could enlighten me on how it can be done 😀
Arno Gourdol
@arnog
hi @Sandmountain . I know of a few. There's a plugin for CKEditor (but I don't think it's public) and one for Quill (https://www.npmjs.com/package/quill-mathlive-blot). I'm not familiar with Froala, but I would assume it's possible. Is the problem that the events emitted by MathLive do not bubble up?
Viktor Sandberg
@Sandmountain
Hi there @arnog, and thank you for your answer! Yeah, exactly. I don't really know what happens, but it's like how you explain it, adding event listeners on the Mathlive instance doesn't seem to fire, like "input" and "keydown" 🤔
Arno Gourdol
@arnog
@Sandmountain What happens when you use a <textarea> element instead of a <mathfield>? Do the events bubble then?
Viktor Sandberg
@Sandmountain
@arnog If I add a <textarea>, the events do fire!
Viktor Sandberg
@Sandmountain
Hi there again, just wanted to say that I think the issue was just a referencing error. It seems to be working as expected now :)
Sébastien COGEZ
@seb-cogez
Hello, when I type the NumpadEnter key of my Keyboard, Mathlive write Enter :(
Arno Gourdol
@arnog
@seb-cogez that seems like a bug :) Could you file an issue about it?
Sébastien COGEZ
@seb-cogez
It seems coming from my computer. I tried with another one a couldn't reproduce it !( I will look forward. Thx
Arno Gourdol
@arnog
👍
yo
i love this project
Arno Gourdol
@arnog
hanshs
@hanshs
Hey all! I am also having a issues using the ce.replace function, I think I am passing the rules: RuleSet<number> argument correctly (at least there are no type errors)
const ce = new ComputeEngine();
const parsed = ce.parse('x + y + z');
const result = ce.replace([['x', 1], ['y', 2], ['z', 3]], parsed);
console.log(result);  // ['Add', 'x', 'y', 'z']
hanshs
@hanshs
If @berserks03_twitter needs a quick workaround, heres my replace function I've been using so far
export function replace(
expr: Expression<number>,
rules: { [key: string]: Expression<number> }
): Expression<number> {
for (const key of Object.keys(rules)) {
if (expr === key) {
return rules[key];
}
}

if (Array.isArray(expr)) {
const [operator, ...tail] = expr;

if (tail.length) {
const replaced = [];

for (const ex of tail) replaced.push(replace(ex, rules));

return [operator, ...replaced];
}
}

return expr;
}

// replace(ce.parse('\\sqrt{x} + y^3'), { x: 5, y: 7 });
// => ['Add', ['Sqrt', 5], ['Power', 7, 3]]
yig
@trueneutralocto:matrix.org
[m]
Hey @arnog , I know there's a comment on a PR that the codebase is in refactor mode. Is there anything I can try to work on?
Arno Gourdol
@arnog
The Compute Engine is in refactor mode, but MathLive is pretty stable. If you're interested in working on Compute Engine, one potentially interesting feature would be a MathJSON to MathML emitter (or vice-versa, for that matter). MathJSON is stable. If you're interested in working on MathLive, you can have a look at any of the open, unassigned issues.
stefnotch
@stefnotch
@arnog I recently found two interesting projects and thought that you might be slightly interested:
Cyrus Cuenca
@cyruscuenca
Hello!
Is there any way to customize the focus border on a math-field?
I've tried disabling it with CSS and I can't seem to target it
even with .ML__focused
Thanks!