# Typesetting text in TeX view()

Is there a standard way to typeset TeX formulas together with normal text via view()?

So far I've been using

tex_string = "\hbox{- stationary points: }"
for pt in stats:
tex_string += latex(pt)
tex_string += ", "
view(tex_string)


where stats is a list of some points (defined with formulas).

edit retag close merge delete

Sort by » oldest newest most voted

It has been quite a while since the question was asked, but I seem to have an answer. The key points are to use unescaped strings (avoid \t in \textbf be misinterpreted for a tab) and LatexExpr(). The following is a MWE in my jupyter notebook:

var('x')
stats=((1,2),(3,4),(x,x^2-1))
tex_string = r"\textbf{stationary points: }"
tex_string += ", ".join(map(latex,stats))
show(LatexExpr(tex_string))
view(LatexExpr(tex_string))


This code both shows a typeset version in the notebook (second last command) and opens up a pdf viewer with typeset latex code (last command).

more

You can do the following in a notebook cell:

%latex
Stationary points: $\sage{stats}$

more