#Indent entire sections?

71 messages · Page 1 of 1 (latest)

split mesa
#

?render `
= My document
== Some section
Some words

== Another section
Other words
`
How can I indent the entire "Some section" heading and it's content, "Some words," by a set amount? Same with the subheading below it?

marble ironBOT
#

Too many arguments were passed
Render the given code as an image.

Syntax: ?render [pagesize=<page size>] [theme=<theme>] <code block>

Flags

  • pagesize can be auto (default) or default.

  • theme can be dark (default), light, or transparent.

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)
``‌`
split mesa
#

?render `
= My document
== Some section
Some words

== Another section
Other words
`

split mesa
#

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

tacit knoll
#

?render `
= My document
#show: pad.with(left: 1cm)
== Some section
Some words

== Another section
Other words
`

tacit knoll
#

is that what you want?

#

btw, level 1 headings are still section titles, semantically, and should not be used as document titles

split mesa
solar sinew
#

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?

split mesa
#

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

obsidian lion
#

workaround for now

#

also see #quick-questions message for some prior art

#

though

#

i think this should become a built-in feature of sorts

solar sinew
#

Oh right, you can set paragraph indent, that's neat

obsidian lion
#

not sure how i'd go about implementing that though

split mesa
#

I tried it and I'm having issues with images and bullet points, where images aren't indented and bullet points are super indented

obsidian lion
#

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

obsidian lion
#

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)

solar sinew
#

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

split mesa
#

but works much more consistently

obsidian lion
#

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

split mesa
#

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

solar sinew
#

?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!
solar sinew
#

Another approach

obsidian lion
#

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

solar sinew
#

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?

obsidian lion
#

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

solar sinew
#

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?

obsidian lion
#

probably yeah

tacit knoll
#

?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!
tacit knoll
#

@split mesa how about this version of @solar sinew 's solution?

solar sinew
#

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

tacit knoll
#

oh sorry, should have read the previous discussion more properly 😅

solar sinew
#

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!
split mesa
#

There should be a way to scope code within headers and an additional way to indent header levels