Skip to content

Commit

Permalink
ilm:1.1.3 (#833)
Browse files Browse the repository at this point in the history
  • Loading branch information
talal committed Jul 24, 2024
1 parent 1135641 commit b02ae88
Show file tree
Hide file tree
Showing 7 changed files with 537 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/preview/ilm/1.1.3/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
MIT No Attribution

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
87 changes: 87 additions & 0 deletions packages/preview/ilm/1.1.3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# ‘Ilm

> ‘Ilm (Urdu: عِلْم) is the Urdu term for knowledge. It is pronounced as [/ə.ləm/](https://en.wiktionary.org/wiki/%D8%B9%D9%84%D9%85#Urdu).
A versatile, clean and minimal template for non-fiction writing. The template is ideal for
class notes, reports, and books.

It contains a title page, a table of contents, and indices for different types of figures;
images, tables, code blocks.

Dynamic running footer contains the title of the chapter (top-level heading).

See the [example.pdf](https://github.com/talal/ilm/blob/main/example.pdf) file to see how it looks.

## Usage

You can use this template in the Typst web app by clicking "Start from template" on the
dashboard and searching for `ilm`.

Alternatively, you can use the CLI to kick this project off using the command

```sh
typst init @preview/ilm
```

Typst will create a new directory with all the files needed to get you started.

This template uses the [Iosevka] font for raw text. In order to use Iosevka, the font must
be installed on your computer. In case Iosevka is not installed, as will be the case for
Typst Web App, then the template will fall back to the default "Fira Mono" font.

## Configuration

This template exports the `ilm` function with the following named arguments:

| Argument | Default Value | Type | Description |
| --- | --- | --- | --- |
| `title` | `Your Title` | [content] | The title for your work. |
| `author` | `Author` | [content] | A string to specify the author's name |
| `paper-size` | `a4` | [string] | Specify a [paper size string] to change the page size. |
| `date` | `none` | [datetime] | The date that will be displayed on the cover page. |
| `date-format` | `[month repr:long] [day padding:zero], [year repr:full]` | [string] | The format for the date that will be displayed on the cover page. By default, the date will be displayed as `MMMM DD, YYYY`. |
| `abstract` | `none` | [content] | A brief summary/description of your work. This is shown on the cover page. |
| `preface` | `none` | [content] | The preface for your work. The preface content is shown on its own separate page after the cover. |
| `table-of-contents` | `outline()` | [content] | The result of a call to the [outline function][outline] or none. Setting this to `none` will disable the table of contents. |
| `bibliography` | `none` | [content] | The result of a call to the [bibliography function][bibliography] or none. Specifying this will configure numeric, IEEE-style citations. |
| `chapter-pagebreak` | `true` | [bool] | Setting this to `false` will prevent chapters from starting on a new page. |
| `figure-index` | `(enabled: false, title: "Index of Figures")` | [dictionary] | Setting this to `true` will display a index of image figures at the end of the document. |
| `table-index` | `(enabled: false, title: "Index of Tables")` | [dictionary] | Setting this to `true` will display a index of table figures at the end of the document. |
| `listing-index` | `(enabled: false, title: "Index of Listings")` | [dictionary] | Setting this to `true` will display a index of listing (code block) figures at the end of the document. |

> [!NOTE]
> The language setting for text (`lang` parameter of `text` function) should be defined before the `ilm` function so that headings such as table of contents and bibliography will be defined as per the text language.
The function also accepts a single, positional argument for the body.

The template will initialize your package with a sample call to the `ilm` function in a
show rule. If you, however, want to change an existing project to use this template, you
can add a show rule like this at the top of your file:

```typ
#import "@preview/ilm:1.1.3": *
#show: ilm.with(
title: [Your Title],
author: "Max Mustermann",
date: datetime(year: 2024, month: 03, day: 19),
abstract: [],
preface: [],
bibliography: bibliography("refs.bib"),
figure-index: (enabled: true),
table-index: (enabled: true),
listing-index: (enabled: true)
)
// Your content goes below.
```

[iosevka]: https://typeof.net/Iosevka/
[bibliography]: https://typst.app/docs/reference/model/bibliography/
[outline]: https://typst.app/docs/reference/model/outline/
[bool]: https://typst.app/docs/reference/foundations/bool/
[content]: https://typst.app/docs/reference/foundations/content/
[datetime]: https://typst.app/docs/reference/foundations/datetime/
[dictionary]: https://typst.app/docs/reference/foundations/dictionary/
[paper size string]: https://typst.app/docs/reference/layout/page#parameters-paper
[string]: https://typst.app/docs/reference/foundations/str/
268 changes: 268 additions & 0 deletions packages/preview/ilm/1.1.3/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
// Workaround for the lack of an `std` scope.
#let std-bibliography = bibliography
#let std-smallcaps = smallcaps
#let std-upper = upper

// Overwrite the default `smallcaps` and `upper` functions with increased spacing between
// characters. Default tracking is 0pt.
#let smallcaps(body) = std-smallcaps(text(tracking: 0.6pt, body))
#let upper(body) = std-upper(text(tracking: 0.6pt, body))

// Colors used across the template.
#let stroke-color = luma(200)
#let fill-color = luma(250)

// This function gets your whole document as its `body` and formats it as a simple
// non-fiction paper.
#let ilm(
// The title for your work.
title: [Your Title],

// Author's name.
author: "Author",

// The paper size to use.
paper-size: "a4",

// Date that will be displayed on cover page.
// The value needs to be of the 'datetime' type.
// More info: https://typst.app/docs/reference/foundations/datetime/
// Example: datetime(year: 2024, month: 03, day: 17)
date: none,

// Format in which the date will be displayed on cover page.
// More info: https://typst.app/docs/reference/foundations/datetime/#format
date-format: "[month repr:long] [day padding:zero], [year repr:full]",

// An abstract for your work. Can be omitted if you don't have one.
abstract: none,

// The contents for the preface page. This will be displayed after the cover page. Can
// be omitted if you don't have one.
preface: none,

// The result of a call to the `outline` function or `none`.
// Set this to `none`, if you want to disable the table of contents.
// More info: https://typst.app/docs/reference/model/outline/
table-of-contents: outline(),

// The result of a call to the `bibliography` function or `none`.
// Example: bibliography("refs.bib")
// More info: https://typst.app/docs/reference/model/bibliography/
bibliography: none,

// Whether to start a chapter on a new page.
chapter-pagebreak: true,

// Display an index of figures (images).
figure-index: (
enabled: false,
title: "",
),

// Display an index of tables
table-index: (
enabled: false,
title: "",
),

// Display an index of listings (code blocks).
listing-index: (
enabled: false,
title: "",
),

// The content of your work.
body,
) = {
// Set the document's metadata.
set document(title: title, author: author)

// Set the body font.
// Default is Linux Libertine at 11pt
set text(font: ("Libertinus Serif", "Linux Libertine"), size: 12pt)

// Set raw text font.
// Default is Fira Mono at 8.8pt
show raw: set text(font: ("Iosevka", "Fira Mono"), size: 9pt)

// Configure page size and margins.
set page(
paper: paper-size,
margin: (bottom: 1.75cm, top: 2.25cm),
)

// Cover page.
page(align(left + horizon, block(width: 90%)[
#let v-space = v(2em, weak: true)
#text(3em)[*#title*]

#v-space
#text(1.6em, author)

#if abstract != none {
v-space
block(width: 80%)[
// Default leading is 0.65em.
#par(leading: 0.78em, justify: true, linebreaks: "optimized", abstract)
]
}

#if date != none {
v-space
// Display date as MMMM DD, YYYY
text(date.display(date-format))
}
]))

// Configure paragraph properties.
// Default leading is 0.65em.
set par(leading: 0.7em, justify: true, linebreaks: "optimized")
// Default spacing is 1.2em.
show par: set block(spacing: 1.35em)

// Add vertical space after headings.
show heading: it => {
it
v(2%, weak: true)
}
// Do not hyphenate headings.
show heading: set text(hyphenate: false)

// Show a small maroon circle next to external links.
show link: it => {
// Workaround for ctheorems package so that its labels keep the default link styling.
if type(it.dest) == label { return it }
it
h(1.6pt)
super(box(height: 3.8pt, circle(radius: 1.2pt, stroke: 0.7pt + rgb("#993333"))))
}

// Display preface as the second page.
if preface != none {
page(preface)
}

// Indent nested entires in the outline.
set outline(indent: auto)

// Display table of contents.
if table-of-contents != none {
table-of-contents
}

// Configure heading numbering.
set heading(numbering: "1.")

// Configure page numbering and footer.
set page(
footer: context {
// Get current page number.
let i = counter(page).at(here()).first()

// Align right for even pages and left for odd.
let is-odd = calc.odd(i)
let aln = if is-odd { right } else { left }

// Are we on a page that starts a chapter?
let target = heading.where(level: 1)
if query(target).any(it => it.location().page() == i) {
return align(aln)[#i]
}

// Find the chapter of the section we are currently in.
let before = query(target.before(here()))
if before.len() > 0 {
let current = before.last()
let gap = 1.75em
let chapter = upper(text(size: 0.68em, current.body))
if current.numbering != none {
if is-odd {
align(aln)[#chapter #h(gap) #i]
} else {
align(aln)[#i #h(gap) #chapter]
}
}
}
},
)

// Configure equation numbering.
set math.equation(numbering: "(1)")

// Display inline code in a small box that retains the correct baseline.
show raw.where(block: false): box.with(
fill: fill-color.darken(2%),
inset: (x: 3pt, y: 0pt),
outset: (y: 3pt),
radius: 2pt,
)

// Display block code with padding.
show raw.where(block: true): block.with(
inset: (x: 5pt),
)

// Break large tables across pages.
show figure.where(kind: table): set block(breakable: true)
set table(
// Increase the table cell's padding
inset: 7pt, // default is 5pt
stroke: (0.5pt + stroke-color)
)
// Use smallcaps for table header row.
show table.cell.where(y: 0): smallcaps

// Wrap `body` in curly braces so that it has its own context. This way show/set rules will only apply to body.
{
// Start chapters on a new page.
show heading.where(level: 1): it => {
if chapter-pagebreak { colbreak(weak: true) }
it
}
body
}

// Display bibliography.
if bibliography != none {
pagebreak()
show std-bibliography: set text(0.85em)
// Use default paragraph properties for bibliography.
show std-bibliography: set par(leading: 0.65em, justify: false, linebreaks: auto)
bibliography
}

// Display indices of figures, tables, and listings.
let fig-t(kind) = figure.where(kind: kind)
let has-fig(kind) = counter(fig-t(kind)).get().at(0) > 0
if figure-index.enabled or table-index.enabled or listing-index.enabled {
show outline: set heading(outlined: true)
context {
let imgs = figure-index.enabled and has-fig(image)
let tbls = table-index.enabled and has-fig(table)
let lsts = listing-index.enabled and has-fig(raw)
if imgs or tbls or lsts {
// Note that we pagebreak only once instead of each each
// individual index. This is because for documents that only have a couple of
// figures, starting each index on new page would result in superfluous
// whitespace.
pagebreak()
}

if imgs { outline(title: figure-index.at("title", default: "Index of Figures"), target: fig-t(image)) }
if tbls { outline(title: table-index.at("title", default: "Index of Tables"), target: fig-t(table)) }
if lsts { outline(title: listing-index.at("title", default: "Index of Listings"), target: fig-t(raw)) }
}
}
}

// This function formats its `body` (content) into a blockquote.
#let blockquote(body) = {
block(
width: 100%,
fill: fill-color,
inset: 2em,
stroke: (y: 0.5pt + stroke-color),
body
)
}
Loading

0 comments on commit b02ae88

Please sign in to comment.