Latexify functions with specific units Unitful

I am trying to make a Pluto notebook that is easy to compare the functions made in Pluto and the Codes (in this case AISC 360). Also, it should be as easy to use as possible for everyone to use.

I want the notebook fuunctions look as close as possible to the ones in the Codes, and be hard to use them incorrectly.

begin
	using Latexify
	using Unitful
	import Unitful: 𝐋, 𝐌
end
Markdown.parse("""
#### Tensile yielding

Calculate the tensile yielding in the gross section.

$(
	@latexrun P_ny(
		F_y, 
		A_g
	) = F_y * A_g 
)

##### Arguments 
- ``F_y``: specified minimum yield stress, ``𝐌/𝐋^2``.
- ``A_g``: gross area of member, ``𝐋^2``.
""")

that it renders as

it looks wonderful, but I would like to improve/add the following:

  • function only accepts specific units.
  • add the function a Label (i.e. this function is (D2-1)).
  • remove the arguments when displaying.

and I am struggling to do it by myself, or finding documentation to help me do this.

To only accepts specific units, I tried to add the following:

@latexrun P_ny(
	F_y::Unitful.Quantity{<:Real, 𝐌 / 𝐋^2, }, 
	A_g::Unitful.Quantity{<:Real, Unitful.𝐋^2, }
) = F_y * A_g

and get the following error Latexify.jl's latexoperation does not know what to do with one of the expressions provided (<:Real).

In the future, I would like to make it to a Pkg and use Handcalcs.jl when using it in real projects.

Any advice or comments are welcome.

Thanks,
Eduardo

See AISCSteel.jl and Handcalcs.jl and StructualUnits.jl

2 Likes

I’ll send you a Pluto notebook I made utilizing these packages. Your goals seem to align well with mine. We actually have a structural engineering channel on slack. Please join!

1 Like

Do you want something like this?

Markdown.parse("""
#### Tensile yielding

Calculate the tensile yielding in the gross section.

$(
	@latexify P_ny(
		F_y, 
		A_g
	) = F_y * A_g 
)

##### Arguments 
- ``F_y``: specified minimum yield stress, ``𝐌/𝐋^2``.
- ``A_g``: gross area of member, ``𝐋^2``.

##### Reference
- AISC360 D2-1
""")
P_ny(
	F_y::Unitful.Quantity{<:Real, 𝐌 / 𝐋^2, }, 
	A_g::Unitful.Quantity{<:Real, Unitful.𝐋^2, }
) = F_y * A_g

One of my goals for Handcalcs is to parse that reference part out into the LaTeX expression when unrolling functions, and it would be a setting you can turn off and on.

2 Likes

That is amazing!

AISCSteel.jl is something similar of what I am trying to achieve. And love Handcalcs.jl it is so useful.

Sure, I will join the slack channel. Let me know how to join, please.

In Pluto it should look like this (maybe custom numbering)
image

and the julia code be

P_n(
	F_y::Unitful.Quantity{<:Real, 𝐌 / 𝐋^2, }, 
	A_g::Unitful.Quantity{<:Real, 𝐋^2, }
) = F_y * A_g

I found a function that can remove the arguments of the function

"""
Removes the function argument list from the latex equation,
so equations are shorter and better match the source text.
"""
function remove_arguments(s::LaTeXString)
    r = r"\\left\(.*?\\right\)|\(\)"
    return LaTeXString(replace(s, r=>"", count=1))
end
1 Like

It looks like you may have already found this since I use that exact remove_arguments function lol, but nonetheless my notebooks with similar goals are here and here. You can wrap your @latexrun expressions in remove_arguments without affecting the underlying function definition. Then the function definitions displayed nicely in the notebook are all available by loading the package.


I’m just doing this with markdown headers currently.


I also just got an answer on how to dispatch on specific units here:


Looks like we are all doing similar things! :laughing:

2 Likes

It looks like you are already in that channel, but I will post it here for anyone who finds this and is interested: stuctual-engineering channel

Here is that Pluto notebook:
HandcalcsDemo.jl (73.0 KB)

Hopefully it will be a featured notebook on Pluto’s website. I am just waiting for it to be merged.

1 Like

I will take a look to post linked above, and try it. It seems it will make me understand better how Unitful.jl works.

I couldn’t find out where I saw remove_arguments function when making this post, sorry about that!

It is nice to see many people working in similar stuff and sharing their findings!

2 Likes

Thanks! I have join the channel.

The Pluto notebook seems amazing and really clear, I will take a closer look at the notebook and your AISCSteel.jl pkg.

1 Like