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

image
Like this

Hi there! Welcome to the Forum.
I have something cheezy that kinda works, but I’m absolutely not proud of the code:

Excess matrix
#v(1em)

$A + B + C = #h(1em) mat(
  4, 3, 2, 1, 0;
  2, 1, 0, 1, 6;
  4, 2, 1, 1, 0;
  5, 2, 6, 0, 1;
  1, 4, 2, 0, 1
)
#place(dx: -6.3em, dy: -1.68em, $vec(delim: #none, 5, 8, 5, 8, 5)$)
#place(dx: -5em, dy: -3.4em, $ mat(delim: #none, 0, 0, 0, 0, 0)$)
#[
#set math.mat(column-gap: 0.3em)
#place(dx: -3.8em, dy: 2.7em, $mat(delim: #none,  "", "", T, T, T)$)
]
$

grafik

So apparently you can create matrices without the brackets, so I created separate matrices/vectors for the overflow elements and positioned them using the place function. The positioning is relative to the position of the matrix (therefore I put everything in a math block), so it should be possible to add content around it (like the equation in my example). The letter T seems to be wider than the numbers, so I shrinked the column-gap down to 0.3em. The “#[…” is needed for the set “#set math.mat(column-gap: 0.3em)” to only affect the following line (see here). Alternatively, you could set the gap back to the default of 0% + 0.2em below the matrix entry.

If you’d like me to, I could try to create a custom function for it so you can input other values, although the alignment will most likely not always fit this well, especially when using letters, although you could use mono-space letters for better generalization.
I think it might be worth it to open a new Issue on Github for a native support of this. I think it would be a Compiler Feature Request.

A solution suggested by @Fe_Y in How can I label the columns and rows of a matrix? - #2 by Fe_Y is to use a table in math mode.

For some reason, $lr(“(”, size: #875%)$ doesn’t work with typst 0.13. A possible solution is to draw parentheses using the curve function, for example,

curve(
curve.move((5pt, -5pt)),
curve.quad((0pt, 35pt), (5pt, 75pt))
)

Did you mean to post here in this topic? It seems to fit better in the topic linked by quachpas.

As for using the lr function in Typst 0.13, the following is working for me in the web editor (version 0.13.1):

$lr(( a ), size: #875%)$

When in doubt about a function not working, I find it’s extremely useful to check the documentation.

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