I want to define sympy symbols such that when I display them I get a bar on them. I tried the following one:
c1bar, c2bar, c3bar, ubar, alphabar = sympy.symbols(r'$\bar{c_1} \bar{c_2} \bar{c_3} \bar{u} \bar{\alpha}$')
I then try to display it: display(alphabar)
but I get: $\displaystyle \bar{\alpha}$$
How to fix this?
Just remove the $
sign: SymPy automatically detect if you provided Latex syntax. So your example becomes:
c1bar, c2bar, c3bar, ubar, alphabar = sympy.symbols(r'\bar{c_1} \bar{c_2} \bar{c_3} \bar{u} \bar{\alpha}')
Note that the bar is trying to cover both the symbol and the subscript, but it falls short. As far as I know, \bar
only cover a single character. You can write:
c1bar, c2bar, c3bar, ubar, alphabar = sympy.symbols(r'\bar{c}_1 \bar{c}_2 \bar{c}_3 \bar{u} \bar{\alpha}')
Or you can replace \bar
with \overline
:
c1bar, c2bar, c3bar, ubar, alphabar = sympy.symbols(r'\overline{c_1} \overline{c_2} \overline{c_3} \overline{u} \overline{\alpha}')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.