0

I'm currently programming in Javascript, I figured this would be the best place to put it. I'm very very new to TeX, in fact I discovered it within the past hour. I was wondering if I could convert something like this:

$$ (3\times10^{4})\times(7\times10^{2})  $$

Into something like this:

(8*10^−9)*(7*10^3)

I've been looking at some things about MathJax, but I'm not sure it's right for me.

It needs to be in Javascript.

Thanks.

closed as off-topic by egreg, Phelype Oleinik, dexteritas, Stefan Pinnow, TeXnician Oct 31 '18 at 20:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center." – egreg, Phelype Oleinik, dexteritas, Stefan Pinnow, TeXnician
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    This is not a site where asking JavaScript questions. – egreg Oct 31 '18 at 13:24
  • @egreg I thought not, but I couldn't find where I would put this question. Could you possible point me in the right direction? – aabbccsmith Oct 31 '18 at 13:28
  • What exactly is your question related to TeX/LaTeX here? Is it about understanding syntax or semantics of the LaTeX code? For other questions about the actual JS implementation this site is really the wrong place – siracusa Oct 31 '18 at 13:47
  • @siracusa you are indeed right. However I have been unable to find such a place to propose my question. I figured if I were to post it here, somebody may be able to direct me in the right direction as to where it should go. – aabbccsmith Oct 31 '18 at 13:50
  • Question about programming should go to stackoverflow. – dexteritas Oct 31 '18 at 20:02
1

This may be a slightly of topic question, and while this isn't a complete answer this is the approach I would take

If you simply need to be able to evaluate the result, then this is the approach I'd use

Part 1 — Deal with matching {…} pairs

  1. Read string L → R, and keep track of how many { and } there have been
  2. It's probably also worth keeping track of when LaTeX commands are started and ended
  3. When a latex command is completed, or when an opening curly bracket is closed run Part 2 on the enclosed string

Part 2 — Make replacements

  1. Identify the LaTeX commands you want to be able to process
  2. Identify appropriate JS replacements, using RegEx
  3. Create an object representing the strings and replacements
  4. Appy to string, return new string

Part 3 — Evaluate String

Use new Fuction() (better than eval())

Closing Words

This should at least give you an idea of where to start. I'd be interested to know what you end up with so please send me a message letting me know how you go. I may even be interested in helping with this at some point (when I'm less busy).

P.S.

You may be interested in taking a look at this: https://github.com/arthanzel/evaluatex

  • Awesome, thanks so much. It will just be pure TeX. No LaTeX. – aabbccsmith Oct 31 '18 at 15:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.