Math & Science ⇒ Best package/environment for calculations
Best package/environment for calculations
My current application is just doing Physics/Math homework where I typeset the equations in TeX and then, sometimes, have actual numbers to plug into the final equation. It would be great if I could just copy the equation environment line, tell LaTeX the value of variables, and have LaTeX do the final calculation. But, if I have to rewrite the line, that's okay.
What do you suggest I start learning if I want to be able to do this and more complicated things down the road?
I've tried fp, xint, and l3fp, already, in fact. fp worked okay, but is poorly documented and I actually gave the wrong result in once case and I couldn't figure out why. xint is pretty nice, and seems to be well documented, but latex crashed when I tried to create a constant value in my personal .sty file, like pi, and it seems to be unable to calculate exponents < 1. l3fp sounds like a good one, but I couldn't getting it to work at all, although I gave it the least effort, to be fair. I haven't tried pgfmath, but I think I will, next. I love TikZ.
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Best package/environment for calculations
Lua might be more suited and can be combined with LaTeX, see LuaLaTeX.
Letting a program calculate and input the result on the spot can be dangerous. Consider the following example
If you are looking for a cure to some desease ... Looking for a weapon of mass destruction? You achieved to kill 170\,% of something, congratulations, special badge crazy scientist unlocked. Typos can happen to everyone, leading to crazy results.Test series B showed good result, only 17.000 mice died which is 170\,% of the whole population, whereas series B showed the disappointing amount of 13 dead mice. That is an incredible .13\,% of the population.
As you may notice, no, i am really not a fan of that stuff.
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
Best package/environment for calculations
Re: Best package/environment for calculations
If I end up agreeing with you, that the TeX build env is the wrong tool, how might I construct an alternative scheme? Say I do the calculation externally. Then, what is the best way to give TeX the results for type setting? Do others have something like this working, already?
For argument's sake, let's take the case of making exams with randomly chosen problem parameters and solutions with calculated values. This is one scenario I already know I want to tackle. How should I do this?
I can imagine having each calculated value in a separate file, somewhere, and then importing each file in TeX. That seems a little clunky; I'd have to design and maintain the filename scheme and import them, individually, at the right place, which would make eq environments ugly, if I understand how that would work. Or, maybe I could have one imported file with a macro for each calculated value; but this seems even worse since I'd have to make the calculation program output TeX syntax. (This is why I figure TeX should do it.)
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
Best package/environment for calculations
In your case it can be much simpler.
There's also Python-TeX which could be used.
Stefan