#How to create a function to format a matrix

11 messages · Page 1 of 1 (latest)

fickle willow
#

I'm trying to create a function which would render the Heisenberg matrix. This is the code
#let heis(a, b, c) = $mat(1, a, c; 0, 1, b; 0, 0, 1)$
The problem is that calling #heis(1,2,3) renders a matrix [1, a, c; 0, 1, b; 0, 0, 1] without replacing the variables. What am I doing wrong?

I have also tried #let heis(a, b, c) = $mat(1, #a, #c; 0, 1, #b; 0, 0, 1)$ but that seems broken.

This one kinda works but the single numbers are wrapped in parentheses.
#let heis(a, b, c) = $mat(1, (#a), (#c); 0, 1, (#b); 0, 0, 1)$

weak steeple
#

#a is the correct way to reference a parameter or variable. The # is mandatory for variables with one-letter names in math mode.

#

what is broken about #let heis(a, b, c) = $mat(1, #a, #c; 0, 1, #b; 0, 0, 1)$?

#

?r

#let heis(a, b, c) = $mat(1, #a, #c ; 0, 1, #b ; 0, 0, 1)$
$heis(x, y, z)$
weak steeple
#

oh I see (the semicolon in #a; was eaten by code mode, to finish it, and didn't have its intended effect to finish an array/row in the math mode function call)

#

that's annoying. I added spaces. I think one-letter variable names are a bit quirky and maybe i'd prefer to give the parameters two-letter long names in this case. Unfortunately.

#

?r Now we don't need # or code mode and it's a bit more consistent..

#let heis(aa, bb, cc) = $mat(1, aa, cc; 0, 1, bb; 0, 0, 1)$
$heis(x, y, z)$
weak steeple
fickle willow
#

nice, thanks