Ask Your Question
2

Escape characters for LaTeX

asked 2020-05-04 11:24:30 -0500

JC gravatar image

updated 2020-05-04 13:00:03 -0500

slelievre gravatar image

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)))

This leads to

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2020-05-04 11:35:16 -0500

rburing gravatar image

How about this?

var('x', latex_name=r"\bbm{x}")
edit flag offensive delete link more
2

answered 2020-05-04 19:26:30 -0500

Juanjo gravatar image

updated 2020-05-09 09:52:20 -0500

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-05-04 11:24:30 -0500

Seen: 67 times

Last updated: May 09