mathquill / mathquill

Easily type math in your webapp
http://mathquill.com
Mozilla Public License 2.0
2.66k stars 703 forks source link

$('mathquill-textbox').mathquill('write', latex) is failtastic #32

Open magicvinni opened 13 years ago

magicvinni commented 13 years ago

Hello,

I've 2 problems : I've a mathquill-textbox to ask user to enter a text. I record the .mathquill('latex') on the serveur. (exemple : "Un try ${\frac{1}{2}}" . It works !). which is not the good syntax, so when I want to display later the content in a mathquill-textbox it don't word.

Other question : is it possible to display a non-editable mathquill-textbox, just to display the formula ?

Thanks

magicvinni commented 13 years ago

For the moment I've done this fonction which give the good syntaxe : function goodsyntax($t){ $r=$t; while (strpos($r,'${')){ $i=strpos($r,'${'); $r[$i+1]='§'; $n=0;$pos=$i; while (($n>=0)and($pos<strlen($r))){ if ($r[$pos]=='{') $n++; if ($r[$pos]=='}') $n--; $pos++; } if ($n==-1) $r[$pos-1]='$'; } return str_replace('$§','$',$r); } But the textbox stays editable, thanks

laughinghan commented 13 years ago

(in reverse order)

  1. non-editables are mathquill-rendered-latex, the e^{i\pi}+1=0 in the first paragraph of the demo page is an example of this.
  2. ooh .mathquill('write') and .mathquill('latex') might be broken on mathquill-textboxes, I'll look into that

Han

On Sat, Apr 30, 2011 at 7:24 AM, magicvinni < reply@reply.github.com>wrote:

Hello,

I've 2 problems : I've a mathquill-textbox to ask user to enter a text. I record the .mathquill('latex') on the serveur. (exemple : "Un try ${\frac{1}{2}}" . It works !). which is not the good syntax, so when I want to display later the content in a mathquill-textbox it don't word.

Other question : is it possible to display a non-editable mathquill-textbox, just to display the formula ?

Thanks

Reply to this email directly or view it on GitHub: https://github.com/laughinghan/mathquill/issues/32

pesasa commented 13 years ago

For your issue 2. .mathquill('latex') broken on 'mathquill-textbox'

Maybe following repairs it? In baseclasses.js the _.latex() -function for MathCommand change:

_.latex = function() {
  return this.foldChildren(this.cmd, function(latex, child) {
    return latex + '{' + (child.latex() || ' ') + '}';
  });
};

to:

_.latex = function() {
  return this.foldChildren(this.cmd, function(latex, child) {
    if (latex == '$') {
        return '$' + (child.latex() || ' ') + '$';
    }
    return latex + '{' + (child.latex() || ' ') + '}';
  });
};

This seems to help.

laughinghan commented 13 years ago

$('.mathquill-textbox').mathquill('latex') should be fixed: http://laughinghan.github.com/mathquill/dev/demo.html