Initial commit.

This commit is contained in:
orca 2024-01-16 08:13:37 +01:00
commit 3eec4b236f
Signed by: orca
GPG Key ID: 6923B8DFED96A68A
6 changed files with 285 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.pdf

5
LICENSE Normal file
View File

@ -0,0 +1,5 @@
Copyright (C) 2024 by orca <orcinus_orca@disroot.org>.
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

7
README.md Normal file
View File

@ -0,0 +1,7 @@
# math-typst
A mathematical oriented template for Typst.
## How to use
See the `main.typ` file for an example of the workflow it provides.

14
makefile Normal file
View File

@ -0,0 +1,14 @@
TARGET := ./main.pdf
SOURCE := ./source/main.typ
PDF_VIEWER := zathura
build: $(SOURCE)
@typst c $< $(TARGET)
view: build
@$(PDF_VIEWER) $(TARGET) &
clean:
@rm -f $(shell find . -iname "*.pdf")
.PHONY: build view clean

59
source/main.typ Normal file
View File

@ -0,0 +1,59 @@
#import "template.typ": *
#show: paper => configuration(
title: lorem(5),
authors: (
(
name: "Lorem ipsum.",
affiliation: "Lorem institute",
email: "lorem.ipsum@example.org",
),
),
abstract: lorem(35),
paper
)
= #lorem(6)
#lorem(70)
= #lorem(5)
#lorem(30)
#definition(name: lorem(2))[
#lorem(5)
#lorem(18)
]
== #lorem(4)
#lorem(50)
#theorem(name: lorem(1))[
#lorem(4)
#lorem(20)
#numbered-equation[
$ integral.double_S arrow(A) dot arrow(dif S) $
]
#lorem(7)
]
== #lorem(12)
#lorem(40)
#proposition[
#lorem(10)
$ integral_(a)^(+ oo) f(x) dif x $
#lorem(6)
$ sum f(n) $
#lorem(12)
]

199
source/template.typ Normal file
View File

@ -0,0 +1,199 @@
// This is a fully documented Typst configuration file.
// If something is unclear, check the referece: https://typst.app/docs/reference/.
// Constants.
// Language-specific constants.
#let lang = "fr"
#let outline-title = [Table des matières]
#let abstract-begin = "Résumé"
#let theorem-begin = "Théorème"
#let proposition-begin = "Propostition"
#let lemma-begin = "Lemme"
#let definition-begin = "Définition"
#let proof-begin = "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]
// The QED sign - a square drawn with four strokes.
#let qed = [$square.stroked$]
// Functions.
// Empathize text by putting it in a very light filled gray box.
#let block-emph-fill(body, intensity: 10) = {
rect(
fill: rgb(0, 0, 0, intensity),
width: 100%,
radius: 1pt,
)[#body]
}
// Empathize text by putting it in a very light gray box.
#let block-emph-outline(body, intensity: 18) = {
rect(
stroke: rgb(0, 0, 0, intensity) + 4pt,
width: 100%,
radius: 1pt,
)[#body]
}
// Create a theorem environment.
// We create a counter to be able to index the theorem.
#let theorem-counter = counter("theorem")
// The `name` named variable allows us to give a name to a theorem.
// E.g, `#theorem("Euclid")[<...>]` gives [#theorem-begin (Euclid). <...>].
#let theorem(body, name: "") = {
theorem-counter.step()
let id = if name == "" {
counter(heading).display() + theorem-counter.display()
} else {
"(" + name + ")"
}
block-emph-fill[*#theorem-begin #id.* #body]
}
// Behaves like theorem, but with a different counter.
#let proposition-counter = counter("proposition")
#let proposition(body, name: "") = {
proposition-counter.step()
let id = if name == "" {
counter(heading).display() + proposition-counter.display()
} else {
"(" + name + ")"
}
block-emph-fill[*#proposition-begin #id.* #body]
}
// Behaves like theorem, but with a different counter.
#let lemma-counter = counter("lemma")
#let lemma(body, name: "") = {
lemma-counter.step()
let id = if name == "" {
counter(heading).display() + lemma-counter.display()
} else {
"(" + name + ")"
}
block-emph-fill[*#lemma-begin #id.* #body]
}
// Behaves like theorem, but with a different counter and a different emphasis.
#let definition-counter = counter("definition")
#let definition(body, name: "") = {
definition-counter.step()
let id = if name == "" {
counter(heading).display() + definition-counter.display()
} else {
"(" + name + ")"
}
block-emph-outline[_#definition-begin #id._ #body]
}
// It takes the body of the proof, and formats it by adding the QED
// symbol at the end, and the _#proof-begin._ text at the front.
#let proof(body) = [
_#proof-begin._ #body #h(3em) #place(right, clearance: 20em, dy: -7pt, 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 heading(numbering: "1.")
// 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-begin] \
#v(0.15em)
#abstract
#v(2em)
]
}
outline(indent: auto, title: outline-title)
v(2em)
set align(left)
doc
}