korsbo / Latexify.jl

Convert julia objects to LaTeX equations, arrays or other environments.
MIT License
544 stars 55 forks source link

Would like a macro that executes the expression, and latexifies the expression together with symbols, then with values of symbols, then with resulting value. #275

Closed co1emi11er2 closed 4 months ago

co1emi11er2 commented 6 months ago

Hi,

First off, thank you for the amazing package. It is very helpful.

I had a feature that I wanted to request.

@latexdefine executes the expression, and latexifies the expression together with its value.

Could you implement another macro (or modify @latexdefine) that executes the expression, and latexifies the expression together with symbols, then with values of symbols, then with resulting value?

For example, here is a package in python that does this called handcalcs: image

This package can also be used to parse and latexify functions. decorator

Another huge feature is the ability to add comments to the side of equations. image

I am a structural engineer who is starting to see some of the downsides to excel, and I am trying to decide the best programming language to use to develop tools with. I really like some of the things I have heard about Julia, and I like what Pluto offers over Jupyter. If there was a package like this, I think it would give me some runway to start writing in Julia.

Thanks, Cole

gustaphe commented 6 months ago

I think this will be very difficult to do. How does Latexify know to expand a but not sqrt?

You could have some kind of "special kind of Symbol" that gets interpolated in the first step, but you'll get to the point where it's probably easier to just say LaTeXString("x = \\sqrt{a-b} = \\sqrt{$a-$b} = $(x = sqrt(a-b))").

If someone has a good idea for implementation it would be cool, but I don't think I'll try.

ChrisRackauckas commented 6 months ago

Use Symbolics.jl? It uses Latexify to render. What you're looking for is just a symbolic library that renders to Latex?

co1emi11er2 commented 6 months ago

Does Symbolics.jl do it all in one line? Numeric substitution and all? I thought Symbolics.jl would do the symbols and then you would later have to define the variables afterwards?

It looks like I was able to get a rough version working. I have written this same functionality in excel vba, but with latexify I can render in latex. This needs to be cleaned up but here is a first example. The only thing left is to get the h to evaluate.

Here is excel version: progiftools-FormulaExpand_crop-border

Here is rough julia version. image

co1emi11er2 commented 6 months ago

It seems like I got things working quite well. It even works with Unitful!

I am very new to julia (couple days), so I could use some help on path forward. Should this be implemented here or should I create a new package? I only modified/added 2 lines to the latexdefine macro to get this working. I could use a little help too since I was wanting to get multiple lines (begin and end cells) to work as well.

image

korsbo commented 6 months ago

That looks pretty cool 🙂 It's a form of usage that I've not really paid much attention to. What's the modification that you made?

co1emi11er2 commented 6 months ago

It was originally just 2 modified lines, but I've tweeked it a bit. Here is the code. the highlighted portion is what is different from latexdefine. image

I wanted to add the ability to add a reference to the side of the calc or any helpful comments. This is a video of the process so far. I am able to parse multiple lines, but it doesn't compute unless I call lines individually. Here is an example video of what I am trying to workout currently.

https://github.com/korsbo/Latexify.jl/assets/143426779/cac07086-1828-4be6-81bd-cd22eadba63a

co1emi11er2 commented 4 months ago

I developed my own package for this. See Handcalcs.jl if interested.