Escape characters for LaTeX

I am using SageTeX and LaTeX to produce several variations of an exam, with a script that makes several iterations. I do this:

var('x, y, z')
v = vector([x, y, z])
a = vector([1, -2, -1])


These will change from one iteration to the next.

sortie = str(latex(a.dot_product(v)))


x - 2 \\, y - z


which is correct, and I would like to turn into

\bbm{x} -2 \\, \bbm{y} - \bbm{z}


for the LaTeX processing so that x, y and z are shown like vectors.

Suggestions?

edit retag close merge delete

Sort by » oldest newest most voted

var('x', latex_name=r"\bbm{x}")

more

This is a minimal working example that makes what you want, using @rburing suggestion:

\documentclass{article}
\usepackage{sagetex}

\begin{document}

\begin{sagesilent}
var("x", latex_name=r"\mathbf{x}")
var("y", latex_name=r"\mathbf{y}")
var("z", latex_name=r"\mathbf{z}")
v = vector([x, y, z])
a = vector([1, -2, -1])
sortie = a*v
\end{sagesilent}

Sortie: $\sage{sortie}$

\end{document}


Please, note that you can replace a.dot_product(v) by a*v. Likewise, for boldface letters, I suggest to use \mathbf. Finally, if you define sortie = str(latex(a.dot_product(v))) inside a sagesilent or sageblock environment, later, a command like \sage{sortie} or $\sage{sortie}$will just print a string, or even produce an error, instead of yielding the expected mathematical expression.

more