latexify_py icon indicating copy to clipboard operation
latexify_py copied to clipboard

Breaking on function with docstring

Open fccoelho opened this issue 3 years ago • 4 comments

I am getting the error below for the following function:

@latexify.function(use_math_symbols=True)
def model(t: float, y: list, params: dict) -> list:
        """
        SIR Model.
        :param t: time step
        :param y: state of the model at time t
        :param params: parameter dictionary
        :return:
        """
        S, I, R = y
        beta, gamma, N = params['beta'], params['gamma'], params['N']
        return [
            -beta * S * I / N,
            beta * S * I / N - gamma * I,
            gamma * I
        ]
LatexifyNotSupportedError: Codegen supports only Assign nodes in multiline functions, but got: Expr

If I remove the docstring, it works as expected

fccoelho avatar Nov 14 '22 19:11 fccoelho

@fccoelho Thank you for reporting the issue!

Yes this is somewhat expected: the Expr represents the docstring and we should ignore the first Expr statement with string values in the codegen. Let me raise the bug level to "major".

odashi avatar Nov 14 '22 21:11 odashi

I encountered the same issue and removing the docstring resolved it. Thanks for raising the issue @fccoelho! Indeed, it would be nice to keep docstrings and latexify functionality all at once😌

PS cheers for maintaining this package @odashi et al., it's awesome!

soosub avatar Nov 15 '22 22:11 soosub

cc:@lakeblair

Maybe you can investigate this issue

Casper-Guo avatar Nov 15 '22 23:11 Casper-Guo

@odashi Hi! I can take a look at this issue and see if I can find a solution to it.

LakeBlair avatar Nov 16 '22 03:11 LakeBlair

Hi @LakeBlair , feel free to propose a pull request for this issue.

odashi avatar Nov 17 '22 23:11 odashi

Resolved by #126.

odashi avatar Nov 20 '22 10:11 odashi