6 ms·
Show HN: CalcuLaTeX, a pretty-printing calculator language
- fish45 6y agoHey HN, I created CalcuLaTeX because I was frustrated with my workflow for chemistry and physics homework. Generally, I'd use the Python REPL as a calculator and type each problem into LaTeX to turn it in. CalcuLaTeX merges these two steps and makes it easier to reason about calculations by real time visual feedback. I've posted on r/rust as well (https://www.reddit.com/r/rust/comments/lqn5aa/calculatex_a_pretty_printing_calculator_language/ https://www.reddit.com/r/rust/comments/lqn5aa/calculatex_a_p...), and there seems to be interest in using it for scientific papers and such. The only alternative I know of is PTC MathCAD, which is quite powerful and definitely worth looking into. However, it's quite expensive and Windows only. The main repo (a Rust library and basic CLI) can be found here: https://github.com/mkhan45/CalcuLaTeX https://github.com/mkhan45/CalcuLaTeX The website repo using WASM and very hacky JS can be found here: https://github.com/mkhan45/CalcuLaTeX-Web https://github.com/mkhan45/CalcuLaTeX-Web
- prezjordan 6y agoVery cool! The output looks nice, will definitely give this a whirl for some blog posts.
- fish45 6y agoI'm glad to hear it! Feel free to open an issue if you'd like anything added
- hamaluik 6y agoI'm so glad you made this! I'm also very upset that this didn't exist 10 years ago when I really needed it. Well done!
- RandomWorker 6y agoThis is awesome! Does it do other conversions than weight? mol/lengths/surface/volume/energy?
- fish45 6y agoIt supports every SI unit and many derived units. It doesn't yet support fractional units, e.g. km^3/2 though. AFAIK there aren't any fractional units that have physical meaning but they might appear in intermediate steps sometimes.
- FabHK 6y agoThe unit of volatility is conceptually [time^{-1/2}], most commonly 1/sqrt(year), but that is rarely written. (People speak of a stock with 30% annual vol, not with a sigma = 0.3 a^-0.5 :-)
- fish45 6y agoWeird units are cool. I was pretty mindblown when I realized that radians are basically meters/meters and steradians are meters^2/meters^2
- thaumasiotes 6y ago> I was pretty mindblown when I realized that radians are basically meters/meters This is true in a dimensional analysis way, where e.g. arclength around a circle is equal to the subtended angle times the radius and, since the arclength and the radius have the same dimension, the angle must be dimensionless. But units are more than that. You can't do anything in chemistry without running into quantities like molarity or ppm that appear to be dimensionless but make no sense if you think about them as coefficients rather than as combinations of semantically-distinct units that happen to have the same name. Imagine some subtance that is 5% salt by mass and 8% salt by volume. ppm by mass is just kg / kg, right? And ppm by volume is m^3 / m^3. Those are the same unit -- in fact, no unit at all. Except that the implication of that non-fact is that ppm by volume and ppm by mass are the same thing, which they aren't. Similarly, radians are best conceived of as percentages of a rotation, not as dimensionless coefficients. Then we calculate an arclength around a circle by saying that the ratio between the arclength and the full perimeter is equal to the ratio between the subtended angle and the full rotation. Characterized so, we have both units present twice, canceling each other out on each side of the equation, and we don't need to clean up by saying that the angle has no unit at all. We divided part of a perimeter by all of a perimeter -- producing a dimensionless quantity -- and we divided part of a rotation by all of a rotation -- also producing a dimensionless quantity -- and then we correctly compared two dimensionless quantities to each other. (On this analysis, the equation s = rθ is actually incorrect; it should be written s = rθ/1 . You can extend this -- we all know the area under sin(x) from 0 to pi is 2. 2 whats? Well, the x axis is radians and the y axis is sine values. Sine values are computed by dividing the length of a line segment by the length of another line segment; they are legitimately dimensionless. So the area under sin(x) must be 2 radians.)
- Jakobeha 6y agoThis is cool! I think it can be really useful. My main suggestion is better error handling: make it so that when a calculation is invalid, it shows the error where the result would be (e.g. red text with the error message) instead of failing to compile the whole script.
- fish45 6y agoI definitely agree that error handling should be improved. I'm trying to keep the LaTeX output as portable/minimal as possible though so I'm not sure if highlights are doable. My current plan is to output more diagnostic info and let the JS interface figure it out.
- SamBam 6y agoVery cool! What made you choose LaTeX for the tool? It seems like it wouldn't be too hard (maybe?) to get a proper algebra engine to assign variables. Currently you can do `x = 10` but you can't do `x / 2 = 5`. I feel like this would be very helpful since you're using this for scientific calculations. It could then be possible to extend that further and leave the variable undefined if it doesn't (yet) have enough information to solve it. Then it could theoretically be used to solve simultaneous equations.
- fish45 6y ago> What made you choose LaTeX for the tool? I was originally planning to use MathJax and HTML or Markdown but honestly it wasn't a completely conscious decision. About proper algebraic stuff, it is a long term goal to have at least a basic polynomial solver, but I've no experience in the area and I'm not sure how far it can go.
- croddin 6y agoThis is awesome. It reminds me of the iOS app Calca[1], which is similar. [1] http://calca.io/ http://calca.io/
- nielsbot 6y agoI like Calca, and this looks like a cool project. Could be cool to combine the 2 in an editor similar to Typora. Typora is my favorite Mac Markdown editor: It looks like a plain word processor file, hiding the markdown annotations, but they're still there and can be edited. I think it's ideal.
- fish45 6y agoThat's really cool. I'll definitely look to it for inspiration
- drran 6y agoI use Marker markdown editor + MathJax + embedded JavaScript to achieve similar results.
- FabHK 6y agoThis is awesome! Is there a way to get the LaTeX source with the completed calculation (so that you can copy/paste the whole thing in your local LaTeX installation and, well, hand in your homework)? (sort of a "middle" tab)
- fish45 6y agoThe main export of the Rust/WASM library is just a function which outputs LaTeX; it should be pretty doable to add a button to the website which does what you're asking. I think I'll just add a checkbox to set whether it actually renders or not.
- formerly_proven 6y agoFYI you might find the GNU units(1) tool useful, which has a huge catalog of units and understands about the same set of math operations as a scientific calculators. From the demo I actually thought this was using GNU units in the background.
- fish45 6y agoThat's pretty cool. I did search for a unit calculation library before starting this but since WASM is a priority I wanted to use a Rust one.
- 8note 6y agoTi-89 is a great option, since you can also get the nice formatting while you're doing exams
- kccqzy 6y agoThat's wonderful! When I used to do my math and physics homework, I used Mathematica as a calculator. It has built-in LaTeX formatting available (right click, Copy As > LaTeX). But likewise Mathematica is expensive and proprietary software so it doesn't appeal to everyone.
- hvna 6y agoI use MiktTeX integrated with Spyder to work on homework and export the equations to LaTeX format. Works well, although some preliminary searching has led me to see that other people have had many issues with it. I guess I just got lucky.
- frankenst1 6y agoVery cool, auto-conversion is really awesome, I think I found a bug though: 5 kg + 5 kg = 10 kg but 5 kg + 6 kg = 11.000 kg
- fish45 6y agoYeah that's not intended, although it's a pretty low priority bug since it's still correct. Thanks for letting me know!
- statstutor 6y ago100m/s = 0km/s (an integer division issue? km/h does not appear to work)
- fish45 6y ago> 100m/s = 0km/s yeah that's not supposed to happen. I'm not completely sure what's up there but thanks for the report km/h doesn't work but km/hour does. I haven't added h as an alias for hour since it's also the SI prefix for hecto.
- hardmath123 6y agoYou might like Frink! https://frinklang.org https://frinklang.org
- ducttapecrown 6y agoI think an alternative would be Sympy in a Jupyter notebook.
- irgeek 6y agoThis is very cool. It looks much easier to use than the collection of Makefiles and build scripts I cobbled together in college. One thing that’d make this even more awesome is the ability to drop in a data table and have it show up as a graph. The scripts I built in college allowed me to drop a CSV file into a directory and have it automatically turned into an EPS graph that I could use in LaTeX. It made for pretty easy, but very good looking reports.
- celebrimbor7 6y agoHey, definitely check out Blockpad (https://blockpad.net https://blockpad.net). It does calculations with units, integrated with documents, spreadsheets, and drawing. Speaking from the Blockpad team here, would love to hear your experience. We have Windows app and beta web app. Also Mac app coming soon. It's free for students and otherwise still inexpensive.
- a0-prw 6y agoWordmat is a free, open source extension to MS Word which gives you access to a full CAS from Word. http://www.eduap.com/wordmat/ http://www.eduap.com/wordmat/ https://github.com/Eduap-com/WordMat https://github.com/Eduap-com/WordMat
- breck 6y agoThis is really fun. Nicely done! I love the output of LaTeX but never liked writing it.