Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
skriptum committed Jul 18, 2024
0 parents commit 2b648ff
Show file tree
Hide file tree
Showing 10 changed files with 360 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.code-workspace
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Gaspard Lambrechts

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, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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.
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Diatypst

*easy slides in typst*

Features:

- easy delimiter for slides and sections (just use headings)
- sensible styling
- dot counter in upper right corner (like LaTeX beamer)
- adjustable color-theme
- default show rules for terms, code, lists, ... that match color-theme

Example Presentation

| Title Slide | Section | Content | Outline |
| ----------------------------------------------- | --------------------------------------------------- | ----------------------------------------------- | ----------------------------------------------- |
| ![Example-Title](screenshots/Example-Title.png) | ![Example-Section](screenshots/Example-Section.png) | ![Example-Slide](screenshots/Example-Slide.png) | ![Example-Section](screenshots/Example-TOC.png) |

can be found in `example/example.typ`in the GitHub Repo


## Usage

To start a presentation, initialize it in your typst document:

```typst
#show: slides.with(
title: "Diatypst", // Required
subtitle: "easy slides in typst",
date: "01.07.2024",
authors: ("Marten Walk"),
)
...
```

Then, insert your content.

- Level-one headings corresponds to new sections.
- Level-two headings corresponds to new slides.

```typst
...
#outline()
= First Section
== First Slide
Terms created with ```typc / Term: Definition```
/ *Term*: Definition
A code block
```

## Options

all available Options to initialize the template with

| Keyword | Description | Default |
| ------------- | ------------------------------------------------------------ | -------------------- |
| *title* | Title of your Presentation, visible also in footer | `none` but required! |
| *subtitle* | Subtitle, also visible in footer | `none` |
| *date* | a normal string presenting your date | `none` |
| *authors* | either string or array of strings | `none` |
| *layout* | one of "small", "medium", "large", adjusts sizing of the elements on the slides | `"medium"` |
| *ratio* | aspect ratio of the slides, e.g 16/9 | `4/3` |
| *title-color* | Color to base the Elements of the Presentation on | `blue.darken(50%)` |
| *counter* | whether to display the dots for pages in upper right corner | `true` |
| *footer* | whether to display the footer at the bottom | `true` |



## Inspiration

this template is inspired by [slydst](https://github.com/glambrechts/slydst), and takes part of the code from it. If you want simpler slides, look here!

The word *Diatypst* is inspired by the ease of use of a [**Dia**-projektor](https://de.wikipedia.org/wiki/Diaprojektor) (German for Slide Projector) and the [Diatype](https://en.wikipedia.org/wiki/Diatype_(machine))
Binary file added example/example.pdf
Binary file not shown.
35 changes: 35 additions & 0 deletions example/example.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#import "../src/lib.typ": *

#show: slides.with(
title: "Diatypst", // Required
subtitle: "easy slides in typst",
date: "01.07.2024",
authors: ("Marten Walk"),
)

#outline()

= First Section

== First Slide

Terms created with ```typc / Term: Definition```

/ *Term*: Definition

A code block

```python
// Example Code
print("Hello World!")
```

a table



= Second Section

== Summary

#align(center+horizon)[_Le Fin_]
Binary file added screenshots/Example-Section.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/Example-Slide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/Example-TOC.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/Example-Title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
224 changes: 224 additions & 0 deletions src/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
#let layouts = (
"small": ("height": 9cm, "space": 1.4cm),
"medium": ("height": 10.5cm, "space": 1.6cm),
"large": ("height": 12cm, "space": 1.8cm),
)

#let slides(
content,
title: none,
subtitle: none,
date: none,
authors: (),
layout: "medium",
ratio: 4/3,
title-color: none,
counter: true,
footer: true,
) = {

// Parsing
if layout not in layouts {
panic("Unknown layout " + layout)
}
let (height, space) = layouts.at(layout)
let width = ratio * height

// Colors
if title-color == none {
title-color = blue.darken(50%)
}
let body-color = title-color.lighten(80%)
let header-color = title-color.lighten(65%)
let fill-color = title-color.lighten(50%)

// Setup
set document(
title: title,
author: authors,
)
set heading(numbering: "1.a")
set page(
width: width,
height: height,
margin: (x: 0.5 * space, top: space, bottom: 0.6 * space),
header: [
#context {
let page = here().page()
let headings = query(selector(heading.where(level: 2)))
let heading = headings.rev().find(x => x.location().page() <= page)
if heading != none {
set align(top)
set text(1.4em, weight: "bold", fill: title-color)
v(space / 2)
block(heading.body +
if not heading.location().page() == page [
#{numbering("(i)", page - heading.location().page() + 1)}
]
)
}
}
// Counter
#if counter == true {
v(-space/1.5)
align(right+top)[
// Dots before the current slide
#context {
let before = query(selector(heading).before(here()))
for i in before {
[
#link(i.location())[
#box(circle(radius: 0.08cm, fill: fill-color, stroke: 1pt+fill-color))
]
]
}
}
// current slide
#context {
let current = query(selector(heading).after(here())).first()
link(current.location())[
#box(circle(radius: 0.08cm, fill: fill-color, stroke: 1pt+fill-color))
]
}
// Dots after current slide
#context {
let after = query(selector(heading).after(here())).slice(1)
for i in after {
[
#link(i.location())[
#box(circle(radius: 0.08cm, stroke: 1pt+fill-color))
]
]
}
}
]
}
],
header-ascent: 0%,
// Footer
footer: [
#if footer == true {

set text(0.7em)
box()[#line(length: 50%, stroke: 2pt+fill-color )]
box()[#line(length: 50%, stroke: 2pt+body-color)]
v(-0.3cm)
grid(
columns: (1fr, 1fr),
align: (right,left),
inset: 4pt,
[#smallcaps()[#title]],
[ #if subtitle != none {
subtitle
} else if authors != none {
if (type(authors) != array) {authors = (authors,)}
authors.join(", ", last: " and ")
} else [#date]
],

)
}
],
footer-descent:0.8em,
)

// Outline
set outline(
// target: heading.where(level: 1),
indent: true,
title: "Table of Contents"
)
show outline: set heading(level: 2)

set bibliography(
title: none
)


// Section Slides
show heading.where(level: 1): x => {
set page(header: none,footer: none, margin: 0cm)
set align(horizon)
grid(
columns: (1fr, 3fr),
inset: 10pt,
align: (right,left),
fill: (title-color, white),
[#block(height: 100%)],[#text(1.2em, weight: "bold", fill: title-color)[#x]]
)

}
show heading.where(level: 2): pagebreak(weak: true)
show heading: set text(1.1em, fill: title-color)

// Title Slide
if (title == none) {
panic("A title is required")
}
else {
if (type(authors) != array) {
authors = (authors,)
}
set page(footer: none, header: none, margin: 0cm)
block(
inset: (x:0.5*space, y:1em),
fill: title-color,
width: 100%,
height: 60%,
align(bottom)[#text(2.0em, weight: "bold", fill: white, title)]
)
block(
height: 30%,
width: 100%,
inset: (x:0.5*space,top:0cm, bottom: 1em),
if subtitle != none {[
#text(1.4em, fill: title-color, weight: "bold", subtitle)
]} +
if subtitle != none and date != none { text(1.4em)[ \ ] } +
if date != none {text(1.1em, date)} +
align(left+bottom, authors.join(", ", last: " and "))
)
}



// Additional Styling (Term, Code)
show terms.item: it => {
set block(width: 100%, inset: 5pt)
stack(
block(fill: header-color, radius: (top: 0.2em, bottom: 0cm), strong(it.term)),
block(fill: body-color.lighten(20%), radius: (top: 0cm, bottom: 0.2em), it.description),
)
}

show raw.where(block: false): it => {
box(fill: body-color.lighten(40%), inset: 1pt, radius: 1pt, baseline: 1pt)[#text(size:8pt ,it)]
}

show raw.where(block: true): it => {
block(radius: 0.5em, fill: body-color.lighten(40%),
width: 100%, inset: 1em, it)
}

show list: set list(marker: (
text(fill: title-color)[•],
text(fill: title-color)[‣],
text(fill: title-color)[-],
))

show table: set table(
stroke: (x, y) => (
x: none,
bottom: 0.8pt+black,
top: if y == 0 {0.8pt+black} else if y==1 {0.4pt+black} else { 0pt },
)
)

show table.cell.where(y: 0): set text(
style: "normal", weight: "bold") // for first / header row

set table.hline(stroke: 0.4pt+black)
set table.vline(stroke: 0.4pt)
// Content
content
}

0 comments on commit 2b648ff

Please sign in to comment.