1

I am trying to write a matrix in Latex in Manim. I would like the matrix components' value to be inserted from variables.

x = 4
y = 1

A = MathTex("\\vec{A}=\\begin{bmatrix} x \\\\ y \\end{bmatrix}")

When I display A, I get A=[x y] (in one column format). What I really want is A=[4 1]. Does anybody know how to pass the values of those variables into a Latex equation?

Meysam
  • 33
  • 6
  • Does this answer your question? [How do I put a variable’s value inside a string?](https://stackoverflow.com/questions/2960772/how-do-i-put-a-variable-s-value-inside-a-string) – mkrieger1 Aug 14 '22 at 19:54
  • You'll probably also need https://stackoverflow.com/questions/5466451/how-do-i-print-curly-brace-characters-in-a-string-while-using-format – mkrieger1 Aug 14 '22 at 19:55

1 Answers1

1

Found the answer:

A = MathTex("\\vec{A}=\\begin{bmatrix}"+ str(x)+" \\\\ "+str(y)+" \\end{bmatrix}")
Meysam
  • 33
  • 6