A strange error with $\phi$ as a variable

asked 2022-12-05 15:51:46 +0200

Cyrille gravatar image

I have encountered a strange error. Look at this code

var('π c ϕ')
C(q) = c*q
π(q) = ϕ*q-C(q)
show(LatexExpr(r"C(q) = "),C(q))
show(LatexExpr(r"π(q) = "),π(q))

It generates an error because $\phi$ is interpreted as $\varphi$. If I replace the first by the second there is no error.

edit retag flag offensive close merge delete

Comments

How do you input ϕ on in which front-end ? I suspect Jupyter, but you don't say...

I suspect an homophony not detected by your frontend : there are four Unicode codepoints encoding a "phi" character (see there) : ɸ, Φ, φ,and ϕ.

sage: foo="ɸΦφϕ"
sage: [ord(u) for u in foo]
[632, 934, 966, 981]

Depending of your setup (platform, interface, font, etc...), there is no waranty that you may distinguish them "optically", if you happen to enter one for the other.

Your question may be better addressed to a forum dedicated to your frontend of choice...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-12-05 16:28:07 +0200 )edit

FWIW, you may try (with a lot of cun'n paste to be sure to use the same characters at each use of π and ϕ) :

sage: π, c, ϕ = var('π c ϕ')
sage: C(q) = c*q
sage: π(q) = ϕ*c-C(q)

but, if

sage: view(LatexExpr(r"C(q) = %s"%(C(q))))

works as expected,

sage: view(LatexExpr(r"π(q) = %s"%(π(q))))

doesn't : LaTeX chokes on :

! LaTeX Error: Unicode character π (U+03C0)
               not set up for use with LaTeX.

This might work with (xe|lua)latex and adequate setup (via latex.add_to_preamble), exercise left to the reader as an exercise, after his homework with his interface...

BTW, there is a workaround for this workaround. Also left as an exercise. to the same reader...

HTH,

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-12-05 21:43:50 +0200 )edit