#Center items using stack

124 messages ยท Page 1 of 1 (latest)

south nimbus
#

Hello! I have the following code:

#

but i want the item with items above and down to be centered with the + and the rest

#

?r `
#let item(i: 1, p: 0) = {
if(p == 0) {
stack(
dir: ttb,
spacing: 0.5em,
text(0.5em)[i=#i],
[i],
)
} else {
stack(
dir: ttb,
spacing: 0.5em,
text(0.5em)[i=#i],
[i],
text(0.5em)[p=#p]
)
}
}

#align(horizon)[
#box[#item(i: 1, p: 12)] + 1
]
`

tender swift
#

you can use the baseline parameter for box

#

though to be honest i'd just use math mode if possible

#

?r $ limits(i)_(p=12)^(i = 1) + 1 $

novel ploverBOT
south nimbus
#

Why the limits function?

tender swift
south nimbus
#

I see

#

I thought limits was for that, limits, didn't think it could be used like this

#

Thanks!

tender swift
#

yeah I think the idea is that it "behaves like a limit" or something but idk

#

unfortunately the mathemagicians have outsmarted me here

#

im gonna ping the master mathemagician just in case

#

@crisp kernel

#

no prob

south nimbus
#

also, why does this block not render the results themselves?

#

?r ```typst
#let item = {
range(2).map(n => {
let p = n+1
$limits(n)_(p=p)^(p=n)$
})
}

$item$

tender swift
#

cuz you're not displaying the results

#

you're displaying an array

#

you probably meant to .join() after the map

#

which does like array.at(0) + array.at(1) + ... + array.last()

south nimbus
#

ah

#

didn't know that

#

thanks!

tender swift
#

alternatively you can write

for n in range(2) {
  let p = n + 1
  $ something $
}
#

and it will automatically join all of the results

south nimbus
#

does that have to be in a code block?

#

like #{}?

tender swift
#

i mean

#

if you dont enter code mode it will display that literally in your text

#

but you can just write #for

#

and that should be enough

south nimbus
#

also, this does output like this

#

how can i replace the inner n with the actual number?

tender swift
#

#

south nimbus
#

the only solution i found is using a #box[#n]

tender swift
#

?r

#let x = 5

$ #x + 10 $
novel ploverBOT
south nimbus
#

?r `
#let item = {
range(2).map(n => {
let p = n+1
$limits(#n)_(p=p)^(p=n)$
}).join("+")
}

#item
`

novel ploverBOT
south nimbus
#

this is the error i get

tender swift
#

yeah limits is picky about what it gets

#

you can cast it to content with #[#n]

#

or

#

you can do something like #math.limits(n)

#

but yeah

south nimbus
#

using box seems to work also

#

lemme try

tender swift
#

it's unnecessary

#

#[#n] is enough

#

as in, wrapping that in a box doesnt do much

south nimbus
#

oh

#

shouldnt [#n] be enough to cast to content or am i missing something here?

tender swift
#

no

#

[ ] in math mode are literal brackets

#

so you need to go into code mode

south nimbus
#

oh

#

that makes sense

tender swift
#

#$#n$ would probably work too

#

in this particular case (for math)

south nimbus
#

yes it does

#

thanks

#

i'm new here

#

just using typst for my college reports

tender swift
#

nice, welcome ๐Ÿ‘

south nimbus
#

what's the difference between doing $math_here$ and $ math here $?

#

(and why does it not center on screen when combined with a #block?)

crisp kernel
# tender swift <@399269065388195842>

Limits are also used in the sense of "limite of an integral" or "limits of a series", which is what it means here. The corresponding macro in LaTeX is also \limits

crisp kernel
crisp kernel
south nimbus
crisp kernel
south nimbus
#

oh

south nimbus
#

?r ```typst
#block[$ F(x) = sum_(x=x)^s "long expression"
= "more code"
$]

south nimbus
#

it centers at the new line again

crisp kernel
#

Why are you putting it in a block in the first place?

south nimbus
#

if not they show a little different

#

?r $sum_(x = x)^y$\ #block[$ sum_(x=x)^y $]

south nimbus
#

i want it to show like the one in the bottom

crisp kernel
#

there's an xy problem here

#

what you actually want is left-aligned block math

#

?render ```
#show math.equation: set align(left)
$
F(x) = sum_(x=x)^s "long expression"
= "more code"
$

south nimbus
#

didn't know i could do this

crisp kernel
#

If instead you actually want inline math with display style limits, you can use limits(sum)instead of simply sum

south nimbus
#

i'm not really familiar with show instructions

crisp kernel
#

?render ```
$sum_(n=0)^oo 1/(n^2)$ vs $limits(sum)_(n=0)^oo 1/(n^2)$

crisp kernel
#

though it's not recommended to actually use that inline, since it'll be so tall that it'll affect line spacing

south nimbus
#

wow

#

this is really good

#

i have to use it more

#

thanks ^^

crisp kernel
#

there's also

#

?render $display(sum_(n=0)^oo 1/(n^2))$

crisp kernel
#

if you truly want inline math that looks like block math

south nimbus
#

no

#

i want left aligned block math

south nimbus
#

also, doesn't #show instructions give parameters? like #show: doc => ...

crisp kernel
south nimbus
#

thats cool ngl

#

thanks

#

ok, now inline equations get formatted into their own lines ._.

#

is there a way to have block equations aligned to the left and inline equations like normal?

#

?r ```typst
#show math.equation: set align(left)

This is an $F(x) = "equation"$ inlined

crisp kernel
#

?r ```typst
#show math.equation.where(block: true): set align(left)

This is an $F(x) = "equation"$ inlined

This is block $ 1 + 1 $

crisp kernel
#

My bad

south nimbus
#

ooh

#

yep

#

that worked

#

thanks