#Get the page width

26 messages · Page 1 of 1 (latest)

sour charm
#

I'd like to set margins dependent on the page width. How to I query properties like page width? (I am a complete beginner)

hallow grove
#

You can try to directly get the page width, but I recommend setting a variable instead that's used to set the width and employed in other calculations:

#let width = 210mm
#let height = 297mm
#set page(width: width, height: height, margin: width / 10)

Otherwise the following is technically possible, but seems to produce an extra page:

#set page(paper: "a4")
#show: doc => context {
  set page(margin: page.width / 10)
  doc
}
sour charm
sour charm
hallow grove
#

what does the code look like

sour charm
#
  let width = context page.width
  let width-trim = width - cbor
  let block-size = width-trim / div
  set page(margin: (inside: block-size + cbor, outside: 2 * block-size, top: block-size, bottom: block-size * 2))

where cbor is a length and div is an integer

#

inside the

#let project(
  title: "",
  authors: (),
  date: none,
  logo: none,
  body,
) = {
...
}

definition that was autogenerated

hallow grove
#

That's because width is in reality a value of type content, which is what context always returns

sour charm
#

cant context return a value?

#

because I cant set page inside context, no?

hallow grove
#

Everything that uses a value specific to the current location needs to be embedded in the context call

#

you can, it just looks ugly

sour charm
#

no, if I do that, nothing happens

umbral karma
sour charm
#

(apart from the empty page that you mentioned)

umbral karma
#

what exactly are cbor and div?

sour charm
#
  let cbor = 1.5cm
  let div = 13
   
  context {
    let width = page.width
    let width-trim = width - cbor
    let block-size = width-trim / div
    set page(margin: (inside: block-size + cbor, outside: 2 * block-size, top: block-size, bottom: block-size * 2))
  } 
umbral karma
#

I think you will have to take the approach with the hard coded page sizes then

sour charm
#

so I look up the dimensions of a4 and do it manually?

umbral karma
#

yes

sour charm
#

😑

umbral karma
sour charm
#

ye

umbral karma
lilac apex