#Titlepage with automatically scaled text

12 messages · Page 1 of 1 (latest)

ebon notch
#

I like title pages where the title is in an oblong (box) and the text fills it from side to side. If a line's too long, it is scaled down; if it's too short, it is scaled up, see the pictures.

I can do it by manually setting the size of individual lines, like so:

#box(
  stroke: white,
  width: 95%,
  [
    #text(size: 5.68em, hyphenate: false)[K proměnám] \
    #v(0.5mm)
    #text(size: 8.21em, hyphenate: false)[odborné] \
    #v(1mm)
    #text(size: 9.475em, hyphenate: false)[češtiny] \
    #v(-4mm)
    #text(size: 3.76em, hyphenate: false)[v letech 1917–2016]
  ]
)

The problem is that, if I change the title or the font, I'll have to do it all over again. Any ideas how to automatically scale the lines, so they fit the width of the box?

pale wharf
#

@ebon notch čau, I didn't give this much of any critial thought but can you declare a variable

#let scale = 1

and then multiply your text and spacing elements by scale as needed?

#text(size: scale * 5.68em, hyphenate: false)[K proměnám] \

#

#box(
  stroke: white,
  width: 95%,
  [
    #text(size: scale * 5.68em, hyphenate: false)[K proměnám] \
    #v(scale * 0.5mm)
    #text(size: scale * 8.21em, hyphenate: false)[odborné] \
    #v(scale * 1mm)
    #text(size: scale * 9.475em, hyphenate: false)[češtiny] \
    #v(scale * -4mm)
    #text(size: scale * 3.76em, hyphenate: false)[v letech 1917–2016]
  ]
)```
something like this?
ebon notch
#

This can scale the text, so it fills e.g. just half of the box, but if I change the font (so the lines have different lengths), the text under- and overflows. :\

#

(the FILOZOFICKÁ FAKULTA is always the same size)

pale wharf
#

Maybe measuring each #text element?

I'm not sure, I'm very new to typst

#
#let scale = 1.10
#set align(center)

#let mybox = box(
  stroke: red,
  width: scale * 75%,
  [
    #text(size: scale * 5.68em, hyphenate: false)[K proměnám] \
    #v(scale * 0.5mm)
    #text(size: scale * 8.21em, hyphenate: false)[odborné] \
    #v(scale * 1mm)
    #text(size: scale * 9.475em, hyphenate: false)[češtiny] \
    #v(scale * -4mm)
    #text(size: scale * 3.76em, hyphenate: false)[v letech 1917–2016]
  ]
)

#mybox

#let boxsize = context{mybox}

width = #mybox.width
#

Probably wont help at all but gives you an idea of how measure is working to show the width I guess

ebon notch
#

It works! I can change the font and the text freely and it will automatically rescale it!

#let l1 = text(size: 1em, hyphenate: false)[K proměnám]
#let l2 = text(size: 1em, hyphenate: false)[odborné]
#let l3 = text(size: 1em, hyphenate: false)[češtiny]
#let l4 = text(size: 1em, hyphenate: false)[v letech 1917–2016]
#context {
    let l1_w = measure(l1).width
    let l2_w = measure(l2).width
    let l3_w = measure(l3).width
    let l4_w = measure(l4).width

    let l1_scaling_factor = (13.4cm / l1_w)
    let l2_scaling_factor = (13.4cm / l2_w)
    let l3_scaling_factor = (13.4cm / l3_w)
    let l4_scaling_factor = (13.4cm / l4_w)

    box(
      stroke: red,
      width: 100%,
      [
      #scale(x: l1_scaling_factor * 100%, y: l1_scaling_factor * 100%, reflow: true)[#l1] \
      #scale(x: l2_scaling_factor * 100%, y: l2_scaling_factor * 100%, reflow: true)[#l2] \
      #scale(x: l3_scaling_factor * 100%, y: l3_scaling_factor * 100%, reflow: true)[#l3] \
      #scale(x: l4_scaling_factor * 100%, y: l4_scaling_factor * 100%, reflow: true)[#l4]
    ]
  )
}

Only imperfections are the iffy spacing between the lines and the hard-set page width (13.4cm) in the scaling factors.

#

Thanks for being my rubber duck, @pale wharf!

crude gust
# ebon notch It works! I can change the font and the text freely and it will automatically re...

?r
You can get the proper width from layout, and get better spacing (maybe, depending on taste) if you remove the line breaks and adjust the text top-edge and bottom-edge:

#set page(height: 12cm) // auto doesn't work?
#let scale-lines(..lines) = layout(size => {
  set text(bottom-edge: "bounds")
  for l in lines.pos() {
    let factor = size.width / measure(l).width
    scale(x: factor * 100%, y: factor * 100%, reflow: true, l)
  }
})

#box(stroke: red, width: 100%, scale-lines(
  [K proměnám],
  [odborné],
  [češtiny],
  [v letech 1917–2016],
))