This might help. But it won't do the final "mathy" job of putting the giant parentheses/brackets around the values in rows and columns. For that you do need LaTek or maybe MathML.
> p <- 'p' # need a value (not necessarily "p") for the unquoted symbol - `p`
> q <- 'q'
> PX <- matrix(c(0, p, 0, 0, q, 0,
+ q, 0, 0, p, 0, 0,
+ q, 0, 0, 0, 0, p,
+ 0, 0, q, 0, 0, p,
+ 0, 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 0, 1), nrow = 6, ncol = 6, byrow = TRUE)
> PX
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] "0" "p" "0" "0" "q" "0"
[2,] "q" "0" "0" "p" "0" "0"
[3,] "q" "0" "0" "0" "0" "p"
[4,] "0" "0" "q" "0" "0" "p"
[5,] "0" "0" "0" "0" "1" "0"
[6,] "0" "0" "0" "0" "0" "1"
> print(PX, quote=FALSE)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0 p 0 0 q 0
[2,] q 0 0 p 0 0
[3,] q 0 0 0 0 p
[4,] 0 0 q 0 0 p
[5,] 0 0 0 0 1 0
[6,] 0 0 0 0 0 1
It would also be possible to define rownames and colnames, so if you wanted to suppress the "cody" bracketed numbers, you could define all the names to be "".
> colnames(PX) <- rep("",6)
> rownames(PX) <- rep("",6)
> print(PX, quote=FALSE)
0 p 0 0 q 0
q 0 0 p 0 0
q 0 0 0 0 p
0 0 q 0 0 p
0 0 0 0 1 0
0 0 0 0 0 1
c(0, 0, "p", 0, "q")
etc.