How to define a color gradient over multiple paragraphs?

Hi.

Here is an example given in derive-it:

The color looks cool, but different texts have their individual color gradients. How to achieve the effect of a total overall color gradient independent of what text part some character belongs to?

Thanks!

Hi, do you want this?

#set par(justify: true)
#set text(gradient.linear(red, blue, angle: 45deg))
#range(11).map(_ => lorem(55)).intersperse(parbreak()).join()


The package uses a lot of containers, so, if you remove most of them:

Code
    let index = [#(i+1).]

    let tmpWidth = 0pt
    let dependency = ""
    if hasDependencies {
      dependency = text(style: "italic", weight: "regular", [#dep])
      tmpWidth = measure[#dependency #index #bl].width
    } else {
      tmpWidth = measure[#index #bl].width
    }

    if tmpWidth > maxWidth {
      maxWidth = tmpWidth
    }

    let ins = if indent == 0 {(x: 0pt, y: 0.5em)} else {(x: 0pt, y: 0pt)}
    let numInset = if indent == 0 {(x: 0pt, y: 0.0pt)} else {(x: 0pt, y: 5pt)}

    let line = ""
    if hasDependencies {
      line = [#[#dependency #index] #bl]
    }

    tupArr.push((line, rule))
  }
  tupArr = tupArr.map(a => [#box(width: maxWidth + 0em, a.at(0)) #h(1em) #a.at(1)])

  text(weight: "bold",
    block(
      align(start,
        stack(dir: ttb, spacing: 1em, ..tupArr)
      )
    )
  )

Then it looks more or less correct:

image

If all boxes are removed from ded-nat(), then you can get a single source of gradient color:

Code
#let ded-nat(stcolor: black, arr: array) = context {
  let strart = (top: 0em, right: 0em, bottom: 0em, left: 1pt + stcolor)
  let strend = (
    top: 0em,
    right: 0em,
    bottom: 1pt + stcolor,
    left: 1pt + stcolor,
  )

  // check if the first line's array has 4 items (w/dependencies) or not
  let (hasDependencies, lineSize) = if arr.at(0).len() == 4 { (true, 4) } else {
    (false, 3)
  }

  let maxDepWidth = if hasDependencies {
    arr.fold(0pt, (accum, it) => {
      let sz = measure[#it.at(0)].width
      if sz > accum { sz } else { accum }
    })
  } else {
    0pt
  }

  let maxWidth = 0pt
  let tupArr = ()

  for (i, line) in arr.enumerate(start: 0) {
    if i == 0 {
      derive-it-internal-validate-line(line, i + 1)
    }

    let (dep, indent, formula, rule) = if hasDependencies {
      line
    } else {
      ("", line.at(0), line.at(1), line.at(2))
    }


    let isLastIndented = (
      (arr.len() > i + 1)
        and (
          {
            let ix = if hasDependencies { 1 } else { 0 }
            let next-line = arr.at(i + 1)
            derive-it-internal-validate-line(
              next-line,
              i + 1,
              line-size: lineSize,
            )
            next-line.at(ix)
          }
            < indent
        )
    )

    let bl = formula

    for i in range(0, indent) {
      let inset = if i != 0 { 0pt } else { 0pt }

      let str = if i == 0 and isLastIndented {
        strend
      } else { strart }

      if indent > 0 and i < indent - 1 {
        inset = -5pt
      }
    }
    let index = [#(i + 1).]

    let tmpWidth = 0pt
    let dependency = ""
    if hasDependencies {
      dependency = text(style: "italic", weight: "regular", [#dep])
      tmpWidth = measure[#dependency #index #bl].width
    } else {
      tmpWidth = measure[#index #bl].width
    }

    if tmpWidth > maxWidth {
      maxWidth = tmpWidth
    }

    let ins = if indent == 0 { (x: 0pt, y: 0.5em) } else { (x: 0pt, y: 0pt) }
    let numInset = if indent == 0 { (x: 0pt, y: 0.0pt) } else {
      (x: 0pt, y: 5pt)
    }

    tupArr.push(([#dependency #index #bl], rule))
  }
  tupArr = tupArr.map(a => [#a.at(0) #h(1em) #a.at(1)])

  text(weight: "bold", align(start, stack(dir: ttb, spacing: 1em, ..tupArr)))
}
#import "@preview/derive-it:0.1.3": *

#set text(weight: "bold", fill: gradient.linear(red, blue, angle: 45deg))
#ded-nat-boxed(stcolor: gradient.linear(red, blue), arr: (
  ("1", 0, $forall x (P x) and forall x (Q x)$, "PR"),
  ("2", 0, $forall x (P x -> R x)$, "PR"),
  ("1", 0, $forall x (P x)$, "S 1"),
  ("1", 0, $P a$, "IU 3"),
  ("2", 0, $P a -> R a$, "IU 2"),
  ("1,2", 0, $R a$, "MP 4, 5"),
  ("1,2", 0, $forall x (R x)$, "GU 6"),
))

image

So, you either fork it, or ask author for gradient to be able to be uniform.

1 Like

Hi @AprilGrimoire, thanks for your question! If you feel the response you got has sufficiently answered your question, be sure to give it a checkmark :ballot_box_with_check:. This will help others find the solution in the future. If something is missing, please let us know what so we can resolve your issue. Thanks!