Ask Your Question

Escape characters for LaTeX

asked 2020-05-04 18:24:30 +0200

JC gravatar image

updated 2020-05-04 20:00:03 +0200

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.


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2020-05-04 18:35:16 +0200

rburing gravatar image

How about this?

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

answered 2020-05-05 02:26:30 +0200

Juanjo gravatar image

updated 2020-05-09 16:52:20 +0200

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



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 

Sortie: $\sage{sortie}$


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


Asked: 2020-05-04 18:24:30 +0200

Seen: 485 times

Last updated: May 09 '20