It depends on what you intend to do with the expression. If you're
only interested in having it print correctly, you can write a custom
function that defines LaTeX printing in the way you want (see
https://docs.sympy.org/latest/guides/custom-functions.html#printing).
For example

class F(Function):
    @classmethod
    def eval(cls, p, f):
        pass

    def _latex(self, printer):
        p, f = self.args
        _p, _f = printer._print(p), printer._print(f)
        return r'\left | %s \right | {L^{%s}}' % (_p, _f)

And use it like

p, f = symbols('p f')
F(p, f)

However, the issue here is that f isn't really a function, it's a
symbol. In SymPy it's currently not possible to represent Function
objects as symbolic objects (see
https://github.com/sympy/sympy/issues/4787). So if you want to later
use f as a SymPy function that you can call with other arguments,
you'll have to structure it differently.

Aaron Meurer


On Thu, Sep 1, 2022 at 3:42 PM Yang Liu <micat...@gmail.com> wrote:
>
> I am trying to define a Sympy function $F(p,f)=|f|{L^p}$ symbolically. So it 
> take Symbol("p") and Function f and output is in latex form of $|f|{L^p}$. 
> Any idea of how to do it?
>
> Thanks a lot!
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sympy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/fb7bab86-69f5-49a2-9a49-73b1a03d033fn%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6LR2oo73EJQQLSXtm_b6zAuy_XPN6mg%2B%2BZhV8d9pdwtbw%40mail.gmail.com.

Reply via email to