google / mathsteps

Step by step math solutions for everyone
https://socratic.org
Apache License 2.0
2.12k stars 274 forks source link

Add LaTeX printing #211

Closed ericluap closed 7 years ago

ericluap commented 7 years ago

Follows these steps:

I added some tests for it but I am not sure if I did them correctly. Attempts to resolve #160

ericluap commented 7 years ago

The returned LaTeX does not have the '$' before and after as would normally be had for math mode. I decided to leave them out because the provided 'toTex()' function did not include it. This can easily be added if it turns out it's needed.

ericluap commented 7 years ago

Edit: Fixed it!

Realized now that it only simplifies multiplication for variables a-zA-Z when there is a function in Symbols.js for helping with this. I'll make sure to update the identification of the variables once I wake up tomorrow.

ericluap commented 7 years ago

Edit: Attempted to use the option {implicit: 'hide'} but it didn't work. I also tried adding custom rules but that just seemed to make everything more confusing. I'm leaving it how it was before.

Turns out there are mathjs options for pretty much everything I added. Off to fix this!

evykassirer commented 7 years ago

oooo nice - yay mathjs! I'll wait for your fixes before reviewing ^_^

ericluap commented 7 years ago

Sadly, the mathjs option didn't work. It only makes the multiplication implicit if it was passed in that way. I'm done with all my fixes.

evykassirer commented 7 years ago

don't have time to look in depth, but before I review could you move the printing in latex code to print.js? then we can use it for expressions as well as equations :)

let me know if you have any questions or concerns about that

ericluap commented 7 years ago

Added!

evykassirer commented 7 years ago

oh, and then call that code in the equation code so it's not duplicated ^_^

ericluap commented 7 years ago

Of course, thanks for reminding me

ericluap commented 7 years ago

You're right, the person calling the function should have control over the explicit/implicit multiplication. I just found it ugly and couldn't help myself but remove it entirely. I'll make sure to fix it all up.

evykassirer commented 7 years ago

Hahaha. It can be ugly sometimes but sometimes it's good for teaching to show it explicitly. Thanks for cleaning it up

ericluap commented 7 years ago

So it turns out flattening the tree, or at least calling TestUtil.flattenAndParse(), makes, only where possible, all the explicit multiplication implicit. So all the explicit multiplication is being hidden anyway.

ericluap commented 7 years ago

Should be good now