-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for native Julia functions? #28
Comments
I'm dropping this for the foreseeable future. The code that I once wrote was for Julia 0.6 and is no longer functional. This would take a long time and it would most likely never be as general as one would like. |
The following works for later Julia versions. using MacroTools
using Latexify
f(x, y, z) = x * x / (y + z)
c = @code_lowered f(1., 1., 1.)
exparr = [postwalk(x -> x isa Core.SlotNumber ? c.slotnames[x.id] : x, expr) for expr in c.code]
exparr = [postwalk(x -> x isa Core.GlobalRef ? x.name : x, expr) for expr in exparr]
for i = 1:length(exparr)
exparr[i] = postwalk(x -> x isa Core.SSAValue ? exparr[x.id] : x, exparr[i])
end
ex = exparr[end].args[1]
latexify(ex) I have not tested this for any more complicated functions yet. |
Required changes to the above for current Julia versions: using MacroTools: postwalk
ex = exparr[end-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In Julia, one can inspect the expressions that build up a method with
@code_lowered
. The returned object does have all the information required to deduce what the method does. I have been playing around with latexifying simple julia functions. The code for this can be found in thefunction_support
branch.I have implemented rudimentary support for latexifying some simple functions:
(I need to pass a tuple or array of arguments to my
gamma_pdf
so that Julia can figure out which method to use)A multi-line example:
\begin{equation}
\begin{array}{l}
\textrm{du}\left[1\right] = p\left[1\right] \cdot u\left[2\right] \\
\textrm{du}\left[2\right] = - u\left[1\right] \\
\end{array}
\end{equation}
However, this is a bit of a house of cards in two repects: One is that the code is hard to read/understand, which makes the package harder to maintain. The other respect is that It breaks for any operation that is not explicitly defined in
latexoperation
.For example:
will error.
Support for very simple stuff is achievable. Support for truly general functions should be theoretically possible, but I can't see it being feasible.
Does anyone have feedback on this/is anyone willing and able to implement a better version than I have done myself?
Also, is this worth working further on at all? It has already been a bit of a time-sink.
The text was updated successfully, but these errors were encountered: