bjornregnell / taggy

A Scala 3 library for tagging text and making nice slides.
Apache License 2.0
1 stars 0 forks source link

custom dimensions #4

Open urbanchr opened 1 month ago

urbanchr commented 1 month ago

Not an issue, but I found it useful to add explicit "LaTeX" dimensions as in

enum Dim {
    case CM(x: Double)
    case MM(x: Double)
    case PT(x: Double)
    case EM(x: Double)

    override def toString: String = this match {
        case CM(x) => s"${x}cm"
        case MM(x) => s"${x}mm"
        case PT(x) => s"${x}pt"
        case EM(x) => s"${x}em"
    }
}

import Dim.toString

extension (x: Double) {
    def pt: Dim = Dim.PT(x)
    def mm: Dim = Dim.MM(x)
    def cm: Dim = Dim.CM(x)
    def em: Dim = Dim.EM(x)
}

and then let LaTeX commands like

textSize(7.5.pt,10.5.pt)
space(2.cm)

take these Dim(ensions) as arguments. In this way one does not need to hardcode pt's and em's. The definition for textSize becomes

def textSize(fontSize: Dim, lineSpace: Dim): TreeContext =
      leaf(TextSize, "", FontSize -> fontSize.toString, LineSpace -> lineSpace.toString)

Maybe of help. Christian

bjornregnell commented 1 month ago

Thanks! Looks like a nice idea for increased type safety. I'll consider including that.