#Indent entire sections?
71 messages · Page 1 of 1 (latest)
Too many arguments were passed
Render the given code as an image.
Syntax: ?render [pagesize=<page size>] [theme=<theme>] <code block>
Flags
-
pagesizecan beauto(default) ordefault. -
themecan bedark(default),light, ortransparent.
To be clear, the full default preamble is:
// Begin preamble
// Page size:
#set page(width: auto, height: auto, margin: 10pt)
// Theme:
#set page(fill: rgb(49, 51, 56))
#set text(fill: rgb(219, 222, 225))
// End preamble
To remove the preamble entirely, use pagesize=default theme=transparent.
Examples
?render `hello, world!`
?render pagesize=default theme=light ```
= Heading!
And some text.
#lorem(100)
```
?render `
= My document
== Some section
Some words
== Another section
Other words
`
TLDR; indent entire subheadings and subheading content
Something like this:
#show heading.where(level: 2): it => {
h(1in)
it.body
}
kind of gets there, but is still very wrong
?render `
= My document
#show: pad.with(left: 1cm)
== Some section
Some words
== Another section
Other words
`
is that what you want?
btw, level 1 headings are still section titles, semantically, and should not be used as document titles
Could I do this for every 2-level heading in the document?
From my understanding of typst, you have 4 ways to affect things: the #let, #set, and #show built-ins, which can have non-local effects, and function calls, which affect exclusively their arguments. Everything that effects anything not explicitly passed to it must, at the top level, be a #show or #set rule.
You could probably pass your entire document to a function via a show rule which then traverses the contents via some kind of loops and finds all the headings, but I'm not sure of a nice way to do it
Unless you just mean indenting the headings themselves?
Sorry, I misunderstood, it does affect the entire document
I get this error, which is a bit annoying
I'd have to wrap each individual part in its own function that means
replace pagebreak() by colbreak()
workaround for now
also see #quick-questions message for some prior art
though
i think this should become a built-in feature of sorts
Oh right, you can set paragraph indent, that's neat
not sure how i'd go about implementing that though
Is your function better?
I tried it and I'm having issues with images and bullet points, where images aren't indented and bullet points are super indented
idk
hmm
can u show what u mean?
though
thinking this through, it's likely cuz there are separate par elements at play
and for images there just might not be a par element
honestly doing this manually would produce the best results
in the end
you'd likely need some form of preprocessor to have something automatic here
since show rules are local to their scopes
so you cant just #show heading: (some show rule on the whole document like that one)
I'm trying to get something that iterates the the contents of the file and splits them up by blocks separated by depth 2 headings, put a show rule at the top of each of those
I gotta run for now though, so I'll come back to it later
problem with this is that it only indents one layer deep
but works much more consistently
yeah you'll need to add that show rule under every heading you want to apply indentation for
you could open a feature request issue like easier way for document-wide padding or smth
and show your concrete case in the issue
manual works, but my only issue is that the show rule isn't scoped to the heading, it's global to everything beneath it
will have to dedent at the end, wish there was a way to scope it
?render
#let should_indent = state("should_indent", false)
#show par: it => should_indent.display(s => if s {
pad(left: 1cm, it)
} else {
it
})
#show heading.where(level: 1): it => [
#should_indent.update(false)
#it
]
#show heading.where(level: 2): it => [
#should_indent.update(true)
#it
]
= Section
== Level 2
Text in here!
=== Level 3
And also here
== Level 2 again
And even here!
= Level 1 again
Here too
== Yet another level 2
This text is indented!
Another approach
well
that will only work for one nesting level
if you update it to increase the state's value instead of having it be a boolean, then it will be equivalent to the solution i linked to earlier using heading levels
Yeah, I guess it's effectively the same thing as just referencing the existing heading counter yeah
With the notable advantage(?) of not requiring locate or query so it should be single pass and friendlier to the compiler?
nah, state is introspection in the same way 🙂
with that i mean, your solution could certainly be faster, but theres no immediate way to tell without proper measurements
Fair enough
At least it guarantees no accidental look-forward so this approach shouldn’t be able to cause something that doesn’t converge?
Am I understanding that right?
probably yeah
?render
#let indent-level = state("indent-level", 0)
#show par: it => indent-level.display(il => pad(left: il * 1cm, it))
#show heading: it => {
indent-level.update(it.level)
it
}
= Section
== Level 2
Text in here!
=== Level 3
And also here
== Level 2 again
And even here!
= Level 1 again
Here too
== Yet another level 2
This text is indented!
@split mesa how about this version of @solar sinew 's solution?
Probably want it.level - 1 in the update
But also it has the exact same problems that Pg's does
It's functionally the same, with ~maybe~ some more performance(?) due to the lack of explicit queries
oh sorry, should have read the previous discussion more properly 😅
I suppose it would be slightly easier to manually handle the things that aren't par
?render
#let indent-level = state("indent-level", 0)
#let display-indent(it) = indent-level.display(il => pad(left: il * 1cm, it))
#show par: display-indent
#show figure: display-indent
#show heading: it => {
indent-level.update(it.level - 1)
it
}
= Section
== Level 2
Text in here!
=== Level 3
And also here
== Level 2 again
And even here!
= Level 1 again
Here too
== Yet another level 2
This text is indented!
There should be a way to scope code within headers and an additional way to indent header levels