Replies: 2 comments 1 reply
-
Here's how I would write your example: #block(stroke: 1pt + red, inset: 1em, {
set align(center)
set text(fill: red)
lorem(50)
}) It's of course subjective, but I think this is clearer than the CSS-like alternative you posted. In the CSS model, there are often quirks because of the interaction of certain properties. For example, the Another thing that is important in my opinion, is that set rules separate configuration of properties from creation of elements with that properties. For example, with your proposed Last, but not least, I think the scoped approach is much more composable. We want to add user-defined types/elements to Typst in the future (read more here). Set rules will naturally work with these, whereas global attributes would be sort of limited to built-in ones from the start. |
Beta Was this translation helpful? Give feedback.
-
Would you mind just explaining how that example works exactly? In particular, how come we can't also just do |
Beta Was this translation helpful? Give feedback.
-
One of the things that's bugged me the most in trying out typst is how different attributes of text are segregated to different functions. This is very unlike the CSS model, in which attributes are universal. Let me explain - say we want to have an element which has a red border and red center aligned text. I start out with just my text:
Now I need to make it red. I look it up and find out the
text()
function has a text color attribute:Okay, now the red border. Coming from CSS I might try something like just passing an extra
border: 1px red
argument or something totext()
, but of course that doesn't work. I look up thetext()
function and find it has no border parameter. Eventually I find theblock
function has one:And now to center-align the contents. Oh, the
block()
function doesn't even have analign
attribute? Alright then:Each new attribute I want to set introduces a new layer of nesting. The indentation hell can be mitigated by either not indenting every time or by using
set()
calls, but still, this is very verbose. Maybe more importantly, I have to remember way more information. With CSS I just have to remember the names of the attributes, here I have to remember the attributes and the mapping of attributes onto the functions that own them. And this mapping feels deeply arbitrary, and so is hard to remember.I would much rather just write:
Which is effectively the CSS model. Translating the Typst model to HTML + CSS, it would be as if each HTML tag had its own unique set of CSS attributes. Instead, in CSS we have a universal "pool" of attributes, and really all an HTML tag is (for the most part) is just a bag of default settings of those attributes, as a short hand. Except for things like
<video>
that have special behavior, you could get away with just one universal tag called<tag>
purely as a hook for your CSS.Beta Was this translation helpful? Give feedback.
All reactions