How to input an excess matrix, where elements "overflow" the parentheses?

Yes. It fits better in the topic How can I label the columns and rows of a matrix?.
I didn’t mean https://typst.app/docs/reference/math/lr not working in general. What I meant is that it is no longer working in the solution I gave in the linked topic.

However, an alternative solution is to use the function pinit-place() from the package pinit – Typst Universe to place the labels.

#import "@preview/pinit:0.2.2": *

#let row-label-top(a, label) = pinit-place(dy: - 2em, a, label)
#let row-label-bottom(a, label) = pinit-place(dy: 1em, a, label)
#let col-label(a, label) = pinit-place(dx: -1.5em, dy: -0.7em, a, label)

#for i in (11,12,13,14,15){
  row-label-top(i, $0$)
}

#for i in (11, 31, 51) {
  col-label(i, $5$)
}

#for i in (21, 41) {
  col-label(i, $8$)
}
#for i in (53, 54, 55) {
  row-label-bottom(i, $T$)
}

$ 
mat(
  column-gap: #1em,
  row-gap: #0.4em,
  #pin(11)#text(blue)[$4$]#pin("11r"), #pin(12)#text(blue)[$3$]#pin("12r"), #pin(13)2, #pin(14)1, #pin(15)0;
  #pin(21)#text(blue)[$2$]#pin("21r"), #pin(22)#text(green)[$1$]#pin("22r"), 0, 1, 6;
  #pin(31)#text(blue)[$4$]#pin("31r"), #pin(32)#text(blue)[$2$]#pin("32r"), 1, 1, 0;
  #pin(41)#text(blue)[$5$]#pin("41r"), #pin(42)#text(blue)[$2$]#pin("42r"), 6, 0, 1;
  #pin(51)#text(green)[$1$]#pin("51r"), #pin(52)#text(blue)[$4$]#pin("52r"), #pin(53)2, #pin(54)0, #pin(55)1
)
$

image

1 Like