Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems you want to do two separate things, nicely display the equation and evaluate it. So you need a tool that does both. Latex is more focus on presentation rather than evaluation, although it is possible to evaluate it (see this answer: <a href="https://stackoverflow.com/questions/1219121/is-there-a-calculator-with-latex-syntax">Is there a calculator with LaTeX-syntax?</a>) at least for a subset. </p> <p>A lot of this depends on how complex you want to make the calculator -- what operations you want to allow. If you're using a small subset (and it sounds like you are) it'd be pretty easy to write the converter by hand. I would look into <a href="http://www.w3.org/Math/" rel="nofollow noreferrer">MathML</a> which has both presentational and semantic markup -- and many available tools. However it may not be the easiest for your users to grasp. </p> <p>If users are familiar with latex, and the subset of included symbols is small then it'd be easy enough to parse latex into a format that can be directly evaluated. </p> <p>I think you need to define exactly what you're allowing the user to access in order for anyone to provide a better example as to what is 'best'. </p> <p><strong>EDIT -- in response to your update</strong></p> <p>Well, you're dangerously close to writing a full programming language (all you need are conditions and loops -- or labels). So reinventing the wheel doesn't sound like a great idea. In this case I definitely don't think you want LaTeX as your input language, ideally you want something more familiar to your users.</p> <p>What follows is what I would do and where I would start if <em>I</em> were going to do this, it's not a definitive answer and I would do a lot more research before starting to make sure I'm not duplicating effort. </p> <p>I'd build a parser that takes a subset of JavaScript, this parser would do two things (or there would be two parsers) one would be to translate the code to LaTeX or MathML and the second would be to evaluate / execute the code. </p> <p>Doing this offline, in C, I'd turn to Lex and Yacc (or Flex and Bison, etc) and a quick Google reveals there's a Javascript equivalent: <a href="http://zaach.github.io/jison/docs/" rel="nofollow noreferrer">Jison</a>. That'll give you the backbone of the parser for the language and you can amend it. </p> <p>Alternatively start with an existing JS parser might help, try this answer: <a href="https://stackoverflow.com/questions/2554519/javascript-parser-in-javascript">JavaScript parser in JavaScript</a>. T</p> <p>Once you have the parse backbone you can keep it simple at first -- translating to a displayable language should be fairly easy and for evaluating you <em>could</em> risk just using <code>eval</code> -- because the parser will have already ensured that the input is only using what you're allowing. However I would advise against that in a production version (it's fine for test) and it doesn't take much extra work to map the tokens to internal functions. </p> <p>After that you might want to look at improving the displayed output, perhaps you want to try and simplify input or reorder it to make more sense. That would require taking the internal representation from your parser and doing some clever stuff on it. But get the first steps working first. </p> <p>You want this to work offline, so my other idea of a server hosting some of the other example programs you cite isn't going to work (and using Wolfram Alpha or Google is a good option there -- but, as you say, what's the point of the program then). But you might also consider if you'd get a better head start writing this in a different base language -- although I'm guessing you want the portability of HTML/JS/CSS. </p> <p>The other things you link are all other possible ideas, I just think you'll get more benefit having your own parser internally rather than relying on 3rd party code for each application. With your own parser you can easily add functionality or language features later on.</p> <p>Final thought, you're not necessarily restricting to Javascript as the input with this method. If you think your users will cope with <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" rel="nofollow noreferrer">Reverse Polish Notation</a> then it's easy to write a parser by hand for -- but you will have to do some work on formatting it nicely for output. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload