Restructured the template.

Broke up the template.typ file into multiple ones, and added the
possibility of syncing the template with a custom project in main.typ.
This commit is contained in:
orca 2024-01-21 10:03:43 +01:00
parent b9949d86c6
commit a295f1ef6a
Signed by: orca
GPG Key ID: 6923B8DFED96A68A
7 changed files with 170 additions and 156 deletions

View File

@ -4,4 +4,8 @@ A mathematical-oriented template for Typst.
## How to use
See the `main.typ` file for an example of the workflow it provides.
Clone the repository, and start writing your paper in `source/main.typ`.
See the `example.typ` file for an example of the workflow it provides.
If there is any updates, run `git pull`.

View File

@ -1,5 +1,6 @@
TARGET := ./main.pdf
SOURCE := ./source/main.typ
EXAMPLE := ./source/example.typ
PDF_VIEWER := zathura
build: $(SOURCE)
@ -14,4 +15,7 @@ clean:
watch:
@typst w $(SOURCE) $(TARGET) &> /dev/null
example: $(EXAMPLE)
@typst c $< $(TARGET)
.PHONY: build view clean

View File

@ -1,4 +1,4 @@
#import "template.typ": *
#import "template/template.typ": *
#show: paper => configuration(
title: lorem(5),

View File

@ -1,154 +0,0 @@
// This is a fully documented Typst configuration file.
// If something is unclear, check the Typst docs or file an issue.
// ===============================================================
// Constants.
// ----------
/* The QED sign - a square drawn with four strokes. */
#let qed = [$square.stroked$]
// Language-specific constants.
#let lang = "fr"
/* Environments name. */
#let outline-title = [Table des matières]
#let abstract-text = "Résumé"
#let proposition-text = "Propostition"
#let lemma-text = "Lemme"
#let theorem-text = "Théorème"
#let corollary-text = "Corollaire"
#let definition-text = "Définition"
#let remark-text = "Remarque"
#let example-text = "Exemple"
#let proof-text = "Démonstration"
/* Number the equations starting with the heading hierarchy before them.
E.g. if we are looking at the 6th equation in the 4th subheading
of the 2nd heading, it will show "(2.4.6)" in the right. */
#let numbering-equation(equation) = [(#counter(heading).display()#equation)]
#let numbered-equation(body) = math.equation(numbering: numbering-equation, block: true)[#body]
// Functions.
// ----------
/* Emphasize a block by placing it in a decorated rectangle. */
#let block-emph(body, way: "") = {
if way == "fill" {
rect(fill: rgb(0, 0, 0, 10), width: 100%, radius: 1pt)[#body]
} else if way == "outline" {
rect(stroke: rgb(0, 0, 0, 18) + 4pt, width: 100%, radius: 1pt)[#body]
} else {
[#body]
}
}
/* The `name` named variable allows us to give a name to be displayed instead of the numbers. */
#let math-block(body, name: "", id: "", emphasis: "bold", decoration: "fill") = {
/* We create a counter to be able to index the environment. */
let current-counter = counter(id)
let name = if name == "" {
current-counter.step()
counter(heading).display() + current-counter.display()
} else {
"(" + name + ")"
}
if emphasis == "bold" {
block-emph(way: decoration)[*#id #name.* #body]
} else if emphasis == "italics" {
block-emph(way: decoration)[_#id #name._ #body]
} else {
block-emph(way: decoration)[#id #name. #body]
}
}
// Functions we will directly use.
#let proposition(body, name: "") = math-block(body, name: name, id: proposition-text)
#let lemma(body, name: "") = math-block(body, name: name, id: lemma-text)
#let theorem(body, name: "") = math-block(body, name: name, id: theorem-text)
#let corollary(body, name: "") = math-block(body, name: name, id: corollary-text)
#let definition(body, name: "") = math-block(body, name: name, id: definition-text, emphasis: "italics", decoration: "outline")
#let remark(body, name: "") = math-block(body + v(0.5em), name: name, id: remark-text, decoration: "none")
#let example(body, name: "") = math-block(body + v(0.5em), name: name, id: example-text, decoration: "none")
/* It takes the body of the proof, and formats it by adding the QED
symbol at the end, and the _#proof-text._ text at the front. */
#let proof(body) = [_#proof-text._ #body #h(1fr) #qed ]
// Configuration of the paper.
// ---------------------------
#let configuration(title: none, authors: (), abstract: [], doc) = {
set document(title: title, author: if authors.len() != 0 {
for data in authors {
data.name + " "
}
} else {
"unknown"
})
set page(paper: "a4", margin: (x: 1.8cm, y: 2.6cm), numbering: "1")
set text(lang: lang, font: "New Computer Modern", size: 10pt)
/* Similar formatting to LaTeX. */
set par(leading: 0.55em, justify: true)
set table(stroke: 0.1pt)
set heading(numbering: "1.")
/* Mathematics. */
set math.mat(delim: "[", row-gap: 0.65em, column-gap: 1em)
set math.vec(delim: "[", gap: 0.65em)
/* Show headings like in asmart. */
show heading: it => {
set block(above: 1.8em, below: 1.2em)
set align(center)
set text(10pt, weight: "regular")
if it.body == outline-title {
block(smallcaps(it.body))
} else {
block(counter(heading).display() + " " + smallcaps(it.body))
}
/* We want equations to be local to their heading. */
counter(math.equation).update(0)
}
set align(center)
text(12pt)[#smallcaps(title)]
v(1em)
/* We print authors' information in a grid. */
let count = authors.len()
let ncols = calc.min(count, 3)
grid(columns: (1fr,) * ncols, row-gutter: 24pt, ..authors.map(author => [
#author.name \
#author.affiliation \
#link("mailto:" + author.email)
]))
v(2em)
if abstract != [] {
par(justify: false)[
#smallcaps[#abstract-text] \
#v(0.15em)
#abstract
#v(2em)
]
}
outline(indent: auto, title: outline-title)
v(2em)
set align(left)
doc
}

View File

@ -0,0 +1,22 @@
// This file keeps track of constants.
// -----------------------------------
/* The QED sign - a square drawn with four strokes. */
#let qed = [$square.stroked$]
// Language-specific constants.
#let lang = "fr"
/* Environments name. */
#let outline-title = [Table des matières]
#let abstract-title = "Résumé"
#let proposition-text = "Propostition"
#let lemma-text = "Lemme"
#let theorem-text = "Théorème"
#let corollary-text = "Corollaire"
#let definition-text = "Définition"
#let remark-text = "Remarque"
#let example-text = "Exemple"
#let proof-text = "Démonstration"

View File

@ -0,0 +1,55 @@
// This file keeps track of functions that create mathematic environments.
// We need the name of our environments.
#import "constants.typ": *
/* Emphasize a block by placing it in a decorated rectangle. */
#let block-emph(body, way: "") = {
if way == "fill" {
rect(fill: rgb(0, 0, 0, 10), width: 100%, radius: 1pt)[#body]
} else if way == "outline" {
rect(stroke: rgb(0, 0, 0, 18) + 4pt, width: 100%, radius: 1pt)[#body]
} else {
[#body]
}
}
/* The `name` named variable allows us to give a name to be displayed instead of the numbers. */
#let math-block(body, name: "", id: "", emphasis: "bold", decoration: "fill") = {
/* We create a counter to be able to index the environment. */
let current-counter = counter(id)
let name = if name == "" {
current-counter.step()
counter(heading).display() + current-counter.display()
} else {
"(" + name + ")"
}
if emphasis == "bold" {
block-emph(way: decoration)[*#id #name.* #body]
} else if emphasis == "italics" {
block-emph(way: decoration)[_#id #name._ #body]
} else {
block-emph(way: decoration)[#id #name. #body]
}
}
// Functions we will directly use.
#let proposition(body, name: "") = math-block(body, name: name, id: proposition-text)
#let lemma(body, name: "") = math-block(body, name: name, id: lemma-text)
#let theorem(body, name: "") = math-block(body, name: name, id: theorem-text)
#let corollary(body, name: "") = math-block(body, name: name, id: corollary-text)
#let definition(body, name: "") = math-block(body, name: name, id: definition-text, emphasis: "italics", decoration: "outline")
#let remark(body, name: "") = math-block(body + v(0.5em), name: name, id: remark-text, decoration: "none")
#let example(body, name: "") = math-block(body + v(0.5em), name: name, id: example-text, decoration: "none")
/* It takes the body of the proof, and formats it by adding the QED
symbol at the end, and the _#proof-text._ text at the front. */
#let proof(body) = [_#proof-text._ #body #h(1fr) #qed ]
/* Number the equations starting with the heading hierarchy before them.
E.g. if we are looking at the 6th equation in the 4th subheading
of the 2nd heading, it will show "(2.4.6)" in the right. */
#let numbering-equation(equation) = [(#counter(heading).display()#equation)]
#let numbered-equation(body) = math.equation(numbering: numbering-equation, block: true)[#body]

View File

@ -0,0 +1,83 @@
// This is a fully documented Typst configuration file.
// If something is unclear, check the Typst docs or file an issue.
// ===============================================================
#import "environments.typ": proposition, lemma, theorem, corollary, definition, remark, example, proof, numbered-equation
// Configuration of the paper.
// ---------------------------
#let configuration(title: none, authors: (), abstract: [], doc) = {
set document(title: title, author: if authors.len() != 0 {
for data in authors {
data.name + " "
}
} else {
"unknown"
})
import "constants.typ": lang, outline-title, abstract-title
set page(paper: "a4", margin: (x: 1.8cm, y: 2.6cm), numbering: "1")
set text(lang: lang, font: "New Computer Modern", size: 10pt)
/* Similar formatting to LaTeX. */
set par(leading: 0.55em, justify: true)
set table(stroke: 0.1pt)
set heading(numbering: "1.")
/* Mathematics. */
set math.mat(delim: "[", row-gap: 0.65em, column-gap: 1em)
set math.vec(delim: "[", gap: 0.65em)
/* Show headings like in asmart. */
show heading: it => {
set block(above: 1.8em, below: 1.2em)
set align(center)
set text(10pt, weight: "regular")
if it.body == outline-title {
block(smallcaps(it.body))
} else {
block(counter(heading).display() + " " + smallcaps(it.body))
}
/* We want equations to be local to their heading. */
counter(math.equation).update(0)
}
set align(center)
text(12pt)[#smallcaps(title)]
v(1em)
/* We print authors' information in a grid. */
let count = authors.len()
let ncols = calc.min(count, 3)
grid(columns: (1fr,) * ncols, row-gutter: 24pt, ..authors.map(author => [
#author.name \
#author.affiliation \
#link("mailto:" + author.email)
]))
v(2em)
if abstract != [] {
par(justify: false)[
#smallcaps[#abstract-title] \
#v(0.15em)
#abstract
#v(2em)
]
}
outline(indent: auto, title: outline-title)
v(2em)
set align(left)
doc
}