Is this preamble OK (I know Typst does not have preambles)

I have enclosed a main.typ and an auxiliary file footnote.typ. Would someone please care to glance at the syntax? It is working, but I feel it is not pretty.
footnotes.typ (253 Bytes)
main.typ (2.4 KB)

Hello @Shashidhar_R,
This feels like a question about using Typst. Please take your time to read through the post below, and edit your post accordingly. Notably:

  • Change your post to Questions
  • Change your topic’s title to match your question, e.g., “How to make my code more readable?”
  • Enclose your code directly in your post, as a working, minimal example if possible. See the post below for details on how to do that!

Thank you!

2 Likes

Do I re post my question?

I will change your topic to Questions, it’s fine, if you just reply to your topic if you can’t modify it anymore

main.typ
#set page(
paper: "a4",
margin: (inside: 1in, outside: 1in, y: 1in),
)

#set par(
leading: 1.1em,
spacing: 1.6em,
justify: true,
linebreaks: "simple",
first-line-indent: 2em,
)


#import "footnotes.typ": foot

#set quote(
block: true)
#show quote.where(block: true): set par(leading: 0.65em)
#show quote: set block(above: 1.8em)
#show quote: set pad(x: 2.5em)

#set heading()
#show heading: set par(leading: 0.45em)
#show heading: set block(above: 2.8em)
#show heading: set block(below: 1.5em)
#show heading: set text(
font: "Adamina",
size: 14pt)

#set list(indent: 1.5em)

#set text(
font: "Adamina",
size: 11pt,
hyphenate: auto,
)

#let title = [Pack My Box with Five Dozen Liquor Jugs]
#let authors = ("Beer Drinker",)
#align(center, text(size: 16pt, strong(title)))
#for author in authors { // TODO: would be better in a grid
align(center, text(size: 12pt,strong(author)))
}

= Introduction
Lorem ipsum dolor sit amet, consectetur adipiscing elit.#foot(1) Vestibulum consequat mi quis pretium semper. Proin luctus orci ac neque venenatis, quis commodo dolor posuere. Curabitur dignissim sapien quis cursus egestas. Donec blandit auctor arcu, nec pellentesque eros molestie eget. In consectetur aliquam hendrerit. Sed cursus mauris vitae ligula pellentesque, non pellentesque urna aliquet. Fusce placerat mauris enim, nec rutrum purus semper vel. Praesent tincidunt neque eu pellentesque pharetra.#foot(2) Fusce pellentesque est orci.

#quote[Integer sodales tincidunt tristique. Sed a metus posuere, adipiscing nunc et, viverra odio. Donec auctor molestie sem, sit amet tristique lectus hendrerit sed. Cras sodales nisl sed orci mattis iaculis.#foot(3) Nunc eget dolor accumsan, pharetra risus a, vestibulum mauris. Nunc vulputate lobortis mollis. Vivamus nec tellus faucibus, tempor magna nec, facilisis felis. Donec commodo enim a vehicula pellentesque. Nullam vehicula vestibulum est vel ultricies.]

Aliquam velit massa, laoreet vel leo nec, volutpat facilisis eros. Donec consequat arcu ut diam tempor luctus.#foot(4) Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent vitae lacus vel leo sodales pharetra a a nibh. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nam luctus tempus nibh, fringilla dictum augue consectetur eget. Curabitur at ante sit amet tortor pharetra molestie eu nec ante. Mauris tincidunt, nibh eu sollicitudin molestie, dolor sapien congue tortor, a pulvinar sapien turpis sed ante.


footnotes.typ
// footnotes.typ
#let footnotes = (
[Pack my box with five dozen liqur jugs.],

[Pack my box with five dozen liquor jugs],

[Pack my box with five dozen liquor jugs],

[Pack my box with five dozen liquor jugs],
)
#let foot(n) = footnote(footnotes.at(n))

OK is not a precise term, but I would say it’s good enough, so you can say it’s OK. Though the document doesn’t compile because of out of bounds error on footnote array.

Some fields already set to default value and only clutter the settings. Stuff like text(size: 10pt) can be omitted to text(10pt), but this I think is exclusive to text.size and text.fill.

Without specifications, I won’t add any safeguards or other modifications like creating a template function that might be unnecessary.
Here is a cleaned up version.

#let foot(n) = footnote((
  [Pack my box with five dozen liqur jugs.],
  [Pack my box with five dozen liquor jugs],
  [Pack my box with five dozen liquor jugs],
  [Pack my box with five dozen liquor jugs],
).at(n - 1))

// #import "footnotes.typ": foot

#set page(paper: "a4", margin: (inside: 1in, outside: 1in, y: 1in))
#set text(11pt, font: "Adamina")
#set list(indent: 1.5em)
#set par(
  leading: 1.1em,
  spacing: 1.6em,
  justify: true,
  linebreaks: "simple",
  first-line-indent: 2em,
)

#show heading: set text(14pt)
#show heading: set block(above: 2.8em, below: 1.5em)

#set quote(block: true)
#show quote: set block(above: 1.8em)
#show quote: set pad(x: 2.5em)
#show quote.where(block: true): set par(leading: 0.65em)

#{
  let title = [Pack My Box with Five Dozen Liquor Jugs]
  let authors = ("Author One", "Author Two")
  set align(center)
  show: strong
  text(16pt, title)
  grid(gutter: 0.6em, ..authors.map(author => text(12pt, author)))
}

= Introduction
Lorem ipsum dolor sit amet, consectetur adipiscing elit.#foot(1) Vestibulum consequat mi quis pretium semper. Proin luctus orci ac neque venenatis, quis commodo dolor posuere. Curabitur dignissim sapien quis cursus egestas. Donec blandit auctor arcu, nec pellentesque eros molestie eget. In consectetur aliquam hendrerit. Sed cursus mauris vitae ligula pellentesque, non pellentesque urna aliquet. Fusce placerat mauris enim, nec rutrum purus semper vel. Praesent tincidunt neque eu pellentesque pharetra.#foot(2) Fusce pellentesque est orci.

#quote[Integer sodales tincidunt tristique. Sed a metus posuere, adipiscing nunc et, viverra odio. Donec auctor molestie sem, sit amet tristique lectus hendrerit sed. Cras sodales nisl sed orci mattis iaculis.#foot(3) Nunc eget dolor accumsan, pharetra risus a, vestibulum mauris. Nunc vulputate lobortis mollis. Vivamus nec tellus faucibus, tempor magna nec, facilisis felis. Donec commodo enim a vehicula pellentesque. Nullam vehicula vestibulum est vel ultricies.]

Aliquam velit massa, laoreet vel leo nec, volutpat facilisis eros. Donec consequat arcu ut diam tempor luctus.#foot(4) Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent vitae lacus vel leo sodales pharetra a a nibh. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nam luctus tempus nibh, fringilla dictum augue consectetur eget. Curabitur at ante sit amet tortor pharetra molestie eu nec ante. Mauris tincidunt, nibh eu sollicitudin molestie, dolor sapien congue tortor, a pulvinar sapien turpis sed ante.

Since there is a lot of small things that I’ve changed I’m not sure if you want to know every little bit of detail or not. You can ask for it. Knowing that some default won’t change 99.999% percent, it can be stripped a bit further:

#let title = [Pack My Box with Five Dozen Liquor Jugs]
#let authors = ("Author One", "Author Two")

#set page(margin: (inside: 1in, outside: 1in, y: 1in))
#set text(font: "Adamina")
#set list(indent: 1.5em)
#set par(
  leading: 1.1em,
  spacing: 1.6em,
  justify: true,
  linebreaks: "simple",
  first-line-indent: 2em,
)

#show heading: set text(14pt)
#show heading: set block(above: 2.8em, below: 1.5em)

#set quote(block: true)
#show quote: set block(above: 1.8em)
#show quote: set pad(x: 2.5em)
#show quote.where(block: true): set par(leading: 0.65em)

#{
  set align(center)
  show: strong
  text(16pt, title)
  grid(gutter: 0.6em, ..authors.map(author => text(12pt, author)))
}

The only problems I see:

  • set page(margin: (inside: 1in, outside: 1in)) used but no left/right pagebreak is used, so here it should be left/right.
  • set quote(block: true) makes all quotes block-level by default, but no inline quote is used. So for block quotes, show quote: set pad(x: 2.5em) won’t work because quotes are not inline.
  • If multiple files are used anyway, then I would still create a template function that does all of the above, since there are still a lot of things.
  • I can’t work without a formatter, which is one of many reasons why I don’t use the web app. Typstyle
1 Like

Andrew, Many thanks. I knew I was clumsy, but I am learning. Suggestions much appreciated.

1 Like