GithubHelp home page GithubHelp logo

Comments (4)

afalaize avatar afalaize commented on May 29, 2024

Hi;

Thank you for your interest, and, please, note that standard rules of politeness apply here ;)

In short: It is not possible to use latex syntax in python(/sympy). In some cases (e.g. matplotlib plot titles and legends), it is possible to render in math mode "$\pi$". We could build a wrapper in pyphs that would basically escapes every backslashes when necessary, but it is not a priority.

I don't understand why you "need" latex symbols.

If you are looking for fancy printing in python interpreter, you can use this sympy module, or simply the capabilities of sympy regarding pretty printing of maths:

>>> import sympy
>>> sympy.init_printing()  # activate sympy pretty printing
>>> pi = sympy.symbols('pi_1')  # notice there is no backslash
>>> pi   # display nicely most latex symbols
π₁

I you want LaTeX commands for symbols in the generated LaTeX files, I suggest that (i) you use standard names for symbols in pyphs (e.g. "pi_i"), and (ii) make a query/replace in the generated LaTeX file to get the proper command (e.g. search "pi_i" => replace by "\pi_i").

Sorry, no solution out of the box, but this a standard python/sympy/pyphs behavior, not an issue.
I close, and you can open a thread in the mailing list to ask other pyphs users.

from pyphs.

FabricioS avatar FabricioS commented on May 29, 2024

Hi Antoine, Hi Victor,
as mentioned by Antoine, Sympy handles (under the hood) many latex symbols, including greek letters. For instance
xk, k = core.symbols([ '\\xi_i','k' ])
can simply be changed to
xk, k = core.symbols([ 'xi_i','k' ])
and the xk python variable will be represented by the appropriate $\xi_i$ in the ipython shell, jupyter notebook and the latex report generated by PyPHS.

Best regards

from pyphs.

WetzelVictor avatar WetzelVictor commented on May 29, 2024

Hi Antoine, Hi Fabrice

Thank you for your answers! You solved my problems :)

from pyphs.

afalaize avatar afalaize commented on May 29, 2024

Hi!
@FabricioS The rendering of symbols in the latex report generated by PyPHS is controlled in the symbol_names function (line 14 in pyphs/pyphs/misc/latex/tools.py):

def symbol_names(core):
    sn = {}
    for var in [r'x', 'dx', r'w', r'u', r'y', r'cy', r'p', r'o', r'g', r'z_symbols']:
        for symb in geteval(core, var):
            string = str(symb)
            lab = string[1:]
            sn.update({symb: string[0]+r'_{\mathrm{'+lab+r'}}'})
    for symb in core.subs.keys():
        string = str(symb)
        lab = string[1:]
        sn.update({symb: string[0]+r'_{\mathrm{'+lab+r'}}'})
return sn

In short, the (nowhere written) rule is: the first character of the symbol's string is the variable, the remaining part is the variable label: the symbol "xstiff" will be rendered as $x_{\mathrm{stiff}}$.

@WetzelVictor you can redesign the function symbol_names to your needs, and submit it as a pull request if you think it's worth it.

I admit we could do a lot regarding the rendering of PyPHS structures, but again this is not a priority.

All the best;

Antoine

from pyphs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.