# Add a text in Latex in front of a result

%display latex var('A, x, y, l, alpha, beta, R, p_x, p_y'); U= Ax^(alpha)y^(beta); show(U)

this print U. But I would like to see "U(x) = ..." in a larger font that the standard one which is too small printed on a large device. More generaly , I would like to print some sentences before to disply a result

edit retag close merge delete

Sort by » oldest newest most voted

That's two (very different) questions in one.

1) To concatenate various $\LaTeX$ (math) elements, the LatexExp function is well suited. In your case,

LatexExpr("U(x)="+latex(U))


yelds:

$$U(x)= A x^{\alpha} y^{\beta}$$.

2) "I would like to print some sentences before to display a result".

Your best bet is to write your text in $\LaTeX$, using Sagetex macros to insert relevant Sage snippets and their results.

This needs some learning ; I'd recommend reading "The not so short introduction to $\LaTeX2\epsilon$" tor deciding if $\LaTeX$ is for you. If you intend to spend more than a few weeks in your life using mathematics or writing structured texts (i. e. witth explicit outlines, cross-references and/or citations, etc..), it is probably worth it.

An alternative solution is to use Sage's Jupyter notebook. This will allow you to intersspede math or graphics "cells" between tet cells, that can receive some Markdown formatting. Markdown is much lighter than $\LaTeX$, therefore faster to learn, and might be sufficient for quick n' dirty tasks. But its possibilities are much more limited.

more

I use BakomaTeX since 20 years and before other Latex systems. My question was only for a notebook presentation

( 2019-09-19 22:22:53 +0200 )edit

I use BakomaTeX since 20 years and before other Latex systems. My question was only for a notebook presentation

Since you already know $\LaTeX$, you might try to (ab)use LatexExpr to create a minipage rendering what you want. But I have trouble seeing the point...

( 2019-09-20 10:02:25 +0200 )edit

You may use something like this:

var('A, x, y, alpha, beta')
U = A*x^(alpha)*y^(beta)
text = fr"""
<h3>This is a title</h3>
<p>This is some text explaining several
interesting things. <strong>HTML</strong> can be used
to format these lines.</p>
<p>Now we write an inline mathematical expression
$U(x,y)={latex(U)}$, as well as a displayed one:
$$\frac{{\partial^2 U}}{{\partial x \partial y}}(x,y)= {latex(diff(U,x,y))}$$</p>
"""
show(html(text))


The result is similar to:

### This is a title

This is some text explaining several interesting things. HTML can be used to format these lines.

Now we write an inline mathematical expression $U(x,y)=A x^{\alpha} y^{\beta}$ as well as a displayed one: $$\frac{{\partial^2 U}}{{\partial x \partial y}}(x,y)=A \alpha \beta x^{\alpha - 1} y^{\beta - 1}$$

more