Create base template

This commit is contained in:
Kristofers Solo 2025-08-19 15:37:36 +03:00
parent 83c0d25f3a
commit a4bd1afd56
Signed by: kristoferssolo
GPG Key ID: 8687F2D3EEE6F0ED
5 changed files with 371 additions and 45 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
*.pdf

10
bibliography.yml Normal file
View File

@ -0,0 +1,10 @@
typst:
type: Web
title: Typst
author:
- Mädje
- Laurenz
- Haug
- Martin
- Typst Projekta Izstrādātāji
url: {value: "https://typst.app/", date: 2025-01-01}

BIN
example.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 501 KiB

141
main.typ
View File

@ -0,0 +1,141 @@
#import "template.typ": ludf
#show: ludf.with(
authors: (
(
name: "John Doe",
code: "jd00000",
location: [Riga, Latvia],
email: "jd00000@edu.lu.lv",
),
),
advisors: (
(
title: "Mg. dat.",
name: "Jone Doe",
),
),
date: "2025",
place: "Rīga",
bibliography: bibliography("bibliography.yml"),
abstract: (
primary: (
text: [
#lorem(50)
#lorem(30)
#lorem(20)
],
keywords: (
"Foo",
"Bar",
"Baz",
),
),
secondary: (
text: [
#lorem(20)
#lorem(30)
#lorem(50)
],
keywords: (
"foo",
"bar",
"baz",
),
),
),
)
= Document Title
== Headings
This is a paragraph of body text. It should show how normal text looks.
=== Subheading
Another paragraph with _emphasis_, *strong text*, and `inline code`.
== Lists
=== Unordered
- Item one
- Item two
- Nested item
- Another nested item
- Item three
=== Ordered
+ First
+ Sub A
+ Sub i
+ Second
+ Third
== Math
Inline math: $e^(i pi) + 1 = 0$.
Block math:
$
lim_(-oo)^(infinity) e^(-x^2) d x = sqrt(pi)
$ <math-1>
And we can reference @math-1.
== Code
Here is some code:
```rust
fn main() {
println!("Hello, Typst!");
}
```
== Quotes
#quote[This is a blockquote.]
They can span multiple lines.
#quote(attribution: [Plato])[
... ἔοικα γοῦν τούτου γε σμικρῷ τινι αὐτῷ τούτῳ σοφώτερος εἶναι, ὅτι
ἃ μὴ οἶδα οὐδὲ οἴομαι εἰδέναι.
]
#quote(attribution: [from the Henry Cary literal translation of 1897])[
... I seem, then, in just this little thing to be wiser than this man at
any rate, that what I do not know I do not think I know either.
]
== Links
Here is a #link("https://typst.app")[Typst website].
== Table
Heres a simple table:
#figure(
table(
columns: 3,
table.header[Name][Age][Role],
"Alice", "24", "Engineer",
"Bob", "30", "Designer",
"Carol", "28", "Researcher",
),
caption: [Example table],
)
== Figures
#figure(
image("example.png", width: 60%),
caption: [An example image with caption.],
)
== Footnotes
This is a sentence with a footnote. #footnote("This is the footnote text.")
== References
We can reference @typst in text.

View File

@ -1,70 +1,245 @@
#let project(
title: "",
abstract: [],
#let indent = 1cm
#let indent-par(body) = par(h(indent) + body)
#let merge(a, b) = {
let result = a
for (k, v) in b { result.at(k) = v }
result
}
#let render-abstract(role, abstract) = {
// Define role-based defaults
let defaults = if role == "primary" {
(
lang: "lv",
title: "Anotācija",
keyword-title: "Atslēgvārdi",
text: [],
keywords: [],
)
} else {
(
lang: "en",
title: "Abstract",
keyword-title: "Keywords",
text: [],
keywords: [],
)
}
// Merge defaults with overrides
let abs = merge(defaults, abstract)
context [
#set text(lang: abs.lang)
#heading(
level: 1,
outlined: false,
numbering: none,
abs.title,
)
// Abstract body text
#abs.text
// Keywords
#par(first-line-indent: 0cm)[
*#abs.keyword-title*: #abs.keywords.join(", ").
]
]
}
// This function gets your whole document as its `body` and formats
// it as an article in the style of the IEEE.
#let ludf(
title: [Paper Title],
// An array of authors. For each author you can specify a name,
// location, and email. Everything but but the `name` and `code` is optional.
authors: (),
advisors: (),
// The paper's abstract. Can be omitted if you don't have one.
abstract: (
primary: (
title: "Anotācija",
keyword-title: "Atslēgvārdi",
lang: "lv",
text: [],
keywords: [],
),
secondary: (
title: "Abstract",
keyword-title: "Keywords",
lang: "en",
text: [],
keywords: [],
),
),
// The result of a call to the `bibliography` function or `none`.
bibliography: none,
university: "Latvijas Universitāte",
faculty: [Eksakto zinātņu un tehnoloģiju fakultāte\ Datorikas nodaļa],
thesis-type: "Bakalaura darbs",
date: none,
place: none,
logo: none,
outline-title: "SATURS",
replace-math-dot-with-comma: true,
body,
) = {
// Set the document's basic properties.
set document(author: authors, title: title)
// Set document metadata.
set document(title: title, author: authors.map(author => author.name))
// Set the body font.
set text(
font: ("Times New Roman", "New Computer Modern", "TeX Gyre Termes"),
size: 12pt,
hyphenate: auto,
lang: "lv",
region: "lv",
)
// Configure the page.
set page(
margin: (left: 30mm, right: 20mm, top: 20mm, bottom: 20mm),
numbering: "1",
number-align: center,
paper: "a4",
)
set text(font: "Libertinus Serif", lang: "lv")
set heading(numbering: "1.1.")
// Set run-in subheadings, starting at level 3.
show heading: it => {
if it.level > 2 {
parbreak()
text(11pt, style: "italic", weight: "regular", it.body + ".")
// Configure equation numbering and spacing.
set math.equation(numbering: "(1)")
show math.equation: set block(spacing: 0.65em)
// show math.equation: set text(weight: 400)
// replace `.` with `,`
if replace-math-dot-with-comma == true {
show math.equation: it => {
show regex("\d+\.\d+"): num => {
show ".": math.class("normal", ",")
num
}
it
}
}
// Configure appearance of equation references
show ref: it => {
if it.element != none and it.element.func() == math.equation {
// Override equation references.
link(it.element.location(), numbering(
it.element.numbering,
..counter(math.equation).at(it.element.location()),
))
} else {
// Other references as usual.
it
}
}
// Title page.
// The page can contain a logo if you pass one with `logo: "logo.png"`.
v(0.6fr)
if logo != none {
align(right, image(logo, width: 26%))
// Configure lists and terms.
set list(marker: ([•], [--], [\*], [·]))
set enum(numbering: "1aiA)")
set terms(separator: [ -- ])
// Headings
set heading(numbering: "1.1.")
show heading: set block(spacing: 1.5em)
show heading: it => {
if it.level == 1 {
pagebreak(weak: true)
text(14pt, align(center, upper(it)))
} else {
text(12pt, it)
}
""
v(-indent)
}
v(9.6fr)
text(1.1em, date)
v(1.2em, weak: true)
text(2em, weight: 700, title)
// Author information.
pad(top: 0.7em, right: 20%, grid(
columns: (1fr,) * calc.min(3, authors.len()),
gutter: 1em,
..authors.map(author => align(start, strong(author))),
))
// Style bibliography.
// show std.bibliography: set block(spacing: 0.5em)
set std.bibliography(title: "Izmantotā literatūra un avoti")
v(2.4fr)
pagebreak()
set quote(block: true)
// Abstract page.
v(1fr)
align(center)[
#heading(outlined: false, numbering: none, text(0.85em, smallcaps[Abstract]))
#abstract
]
v(1.618fr)
pagebreak()
// Table of contents.
outline(depth: 3, indent: true)
pagebreak()
show table.cell.where(y: 0): strong
// Main body.
set par(justify: true)
set par(
justify: true,
leading: 1.5em,
first-line-indent: indent,
spacing: 1.5em,
)
// Display the paper's title and authors at the top of the page,
// spanning all columns (hence floating at the scope of the
// columns' parent, which is the page).
// The page can contain a logo if you pass one with `logo: "logo.png"`.
align(center, upper(text(size: 16pt, [
#university\
#faculty
])))
v(1fr)
align(center, upper(text(20pt, weight: "bold", title)))
v(0.2fr)
align(center, upper(text(size: 16pt, thesis-type)))
v(1fr)
// Author information
align(right, [
#text(
weight: "bold",
"Darba " + if authors.len() > 1 { "autori:" } else { "autors:" },
)\
#authors.map(author => [#author.name, #author.code]).join("\n")
#v(1em)
#if advisors.len() > 0 [
#text(
weight: "bold",
"Darba " + if advisors.len() > 1 { "vadītāji:" } else { "vadītājs:" },
)\
#advisors.map(advisor => [#advisor.title #advisor.name]).join("\n")
]
])
v(0.5fr)
align(center, upper([#place #date]))
// Start page numbering
set page(numbering: "1", number-align: center)
// Display abstract and keywords.
if abstract != none {
render-abstract("primary", abstract.primary)
render-abstract("secondary", abstract.secondary)
}
// Table of contents.
// Uppercase 1st level headings in ToC
show outline.entry.where(level: 1): it => {
upper(it)
}
outline(depth: 3, indent: indent, title: text(size: 14pt, outline-title))
// Display the paper's contents.
body
// Display bibliography.
bibliography
}