-
Notifications
You must be signed in to change notification settings - Fork 724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mathquill for input area #423
Comments
Hi @zagannath! You can set the I created this demo showing how to use virtual keyboard events to update mathquill renders. I hope that is what you had in mind! HTML <textarea id="keyboard"></textarea>
<br>
<div id="mathquill"></div> CSS /* position keyboard at bottom of the screen - jQuery UI isn't even loaded! */
.ui-keyboard {
border-radius: 0;
left: 0;
top: auto;
bottom: 0;
position: fixed;
width: 100%;
} Script $(function() {
var mathquill = $('#mathquill').mathquill();
$('#keyboard')
.on('visible keyboardChange hidden', function(e, keyboard, el) {
mathquill.mathquill('latex', keyboard.$preview.val());
})
.keyboard({
usePreview: false
})
// activate the typing extension
.addTyping({
showTyping: true,
delay: 250
});
}); I actually think it would be really cool to make a custom layout which has predefined LaTeX keys like |
To add images, set a background image on the span inside the button. You'll also need to hide the text and set a width to maintain the span's width (demo): .ui-keyboard-frac span {
background-image: url('https://cloud.githubusercontent.com/assets/2561440/12258775/26781542-b937-11e5-88b9-4a0b926dc8c0.png');
background-position: -10px -5px;
text-indent: -99em;
width: 1.2em;
}
.ui-keyboard-sqrt span {
background-image: url('https://cloud.githubusercontent.com/assets/2561440/12258775/26781542-b937-11e5-88b9-4a0b926dc8c0.png');
background-position: -203px -5px;
text-indent: -99em;
width: 1.2em;
} Script with 2 basic action keys $(function() {
$.extend($.keyboard.keyaction, {
'frac': function(kb) {
kb.insertText('\\frac{}{}');
var caret = $.keyboard.caret(kb.$el);
kb.saveCaret(caret.start - 3, caret.start - 3);
},
'sqrt': function(kb) {
kb.insertText('\\sqrt{}');
var caret = $.keyboard.caret(kb.$el);
kb.saveCaret(caret.start - 1, caret.start - 1);
},
});
var mathquill = $('#mathquill').mathquill();
$('#keyboard')
.on('visible keyboardChange hidden', function(e, keyboard, el) {
mathquill.mathquill('latex', keyboard.$preview.val());
})
.keyboard({
usePreview: false,
layout: 'custom',
customLayout: {
'default': [
'sin cos tan \u03c0 {b}',
'7 8 9 + -',
'4 5 6 * frac',
'1 2 3 ^ sqrt',
'0 . , {left} {right}',
'< > = {clear} {a}'
]
},
useCombos: false
})
// activate the typing extension
.addTyping({
showTyping: true,
delay: 250
});
}); |
You are amazing, Thank you very much. is it not possible to render input characters in box(<textarea id="keyboard"></textarea>) rather then separate div, this last thing will complete my implementation . |
Do you mean have the keyboard work directly inside the mathquill box like Desmos? It might be possible, but I'd have to dig into the code since worrying about caret position and how to deal with backspace and delete are important. Honestly, I don't really have the free time right now. |
Yes thats what I wanted.. no problem you already helped me alot.. |
Hey! I'm reopening this discussion because I'm trying to achieve exactly the same thing. I've started to play around I've managed to improve your jsfiddle, you can see the result here: http://jsfiddle.net/yLo3nf83/3/ On the things I've made:
Both those last 2 points allows to handle the caret position as mathquill expects it to be in its input (like you were wondering). The problem is that I end up with a useless (and desynchronized) text-input while mathquill-input is as expected. I haven't had the time to hide this text-input or see how to directly send input to the mathquill-input but that will be my next step. I was wondering, would you like to see this kind of work included into virtual-keyboard? Do you have any pointers on how to do my next steps? Fyi, I'm not going to work on it in the next days because I have an urgency but I'm going back on it just after. Thanks for this lib :) |
Hi @Psycojoker! Thank you for taking the time to work on the demo! I'll need to think more on how to get the interaction to work better... so far, I think we might need to save the input values into an array, like I've done in this demo for issue #372. So pressing delete will remove the entire block instead of one letter at a time. Then we'll probably need to find "key" caret positions for each latex command - like inside the curly brackets for |
hey @Mottie :) I've been looking at your demo but something is not clear for me, what would be the benefit (or even the usage) of storing all those input and refinding the caret position for those kind of input? If you play a bit with my update jsfiddle (like adding a square root, some stuff in it, then playing with the left and right and backspace) you'll see that mathquill handles all this without any problems (but there is a desynchronisation between the content of the textarea and mathquill area). From my point of view, it would be simplier to remove this textarea and directly send the input to mathquill instead of redoing all mathquill work in an intermediate layer. But well, I might be totally wrong since I haven't played yet with virtual-keyboard internal/api to see if this is possible Thanks for your quick answer :) |
Well I messed around with the demo: http://jsfiddle.net/Mottie/yLo3nf83/4/ I hid the textarea and made the keyboard open when the mathquill box was clicked and it all seems to work pretty well. I added an up & down arrow key so the layout is a bit messed up, but I don't have time this morning to add any more commands. |
Wow, that's really great, thanks a lot! I can now start to build things with that :) I'll work on that next week. Do you plan/want to integrate that into virtual-keyboard? Can I help? |
Sure! We could build a Mathquill extension, or something. |
@Mottie - This was super helpful for me. Quick q - I'm trying to make this work with multiple input fields but having trouble. I've got the keypad opening on click, but not sure if I need to create multiple textareas for the keypad to insert text into. Here's my markup & code:
js:
Any help would be much appreciated. Thanks!! |
I'm not sure, I thought Mathquill created the inputs dynamically. |
Hi Rob thank you for awesome keyboard , really appreciate you work,Im wondering is it possible to input laTex expression in your text field by enabling mathquill(https://github.com/mathquill/mathquill) and is it possible to separate keyboard and text box as I'm developing for iPad it will allow more control over UX.
I tried to add class on UI component like .addClass( 'mathquill-editable') but its not working can you please tell me another workaround.
The text was updated successfully, but these errors were encountered: