Ask Your Question
2

Escape characters for LaTeX

asked 4 years ago

JC gravatar image

updated 4 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
3

answered 4 years ago

rburing gravatar image

How about this?

var('x', latex_name=r"\bbm{x}")
Preview: (hide)
link
2

answered 4 years ago

Juanjo gravatar image

updated 4 years ago

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.

Preview: (hide)
link

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: 4 years ago

Seen: 744 times

Last updated: May 09 '20