Skip to content

Commit c3f1579

Browse files
gris-chatelegaanz
andauthored
ape:0.4.3 (#3717)
Co-authored-by: Ana Gelez <[email protected]>
1 parent ffe7428 commit c3f1579

27 files changed

+1863
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Ape for Typst
2+
3+
4+
5+
Tired of documents that look like they were formatted by a troop of baboons? Try Ape for Typst!
6+
7+
8+
9+
This Typst package provides a comprehensive set of tools for structuring and styling academic course documents across various disciplines. It simplifies the process of creating good looking and consistent layouts, allowing students to focus on content creation.
10+
11+
_It mainly supports French (especially for shortcuts)._
12+
13+
**Key Features:**
14+
15+
16+
17+
* **Flexible Title Numbering:** Offers a variety of numbering styles for headings and subheadings
18+
19+
* **Table of Contents Customization:** Provides enhanced outline
20+
21+
* **Front Page Design:** Offers a pre-designed front page templates
22+
23+
* **Easy Integration:** Simple to integrate into your Typst documents with clear and concise functions and components.
24+
25+
* **Helpful function:** function to highlight information (in boxes), shortcuts, plotting, etc.
26+
27+
28+
29+
30+
31+
32+
**Functionalities:**
33+
34+
35+
* Starting a new document
36+
```typst
37+
#import "@preview/ape:0.4.3": *
38+
39+
#show: doc.with(
40+
lang: "en",
41+
42+
title: "Title",
43+
authors: ("Author1", "Author2"),
44+
style: "numbered",
45+
46+
title-page: true,
47+
outline: true,
48+
smallcaps: true,
49+
)
50+
```
51+
52+
53+
*Exemple 1 : (Style : numbered)*
54+
![Exemple 1](exemples/Exemple1.png)
55+
56+
*Exemple 2 : (Style : colored)*
57+
58+
*Soon...*
59+
60+
61+
## Further informations
62+
Some shortcuts are currently only available in french.
63+
64+
* Available style
65+
- Numbered (or numbered-book)
66+
- Plain
67+
- Colored
68+
- Presentation
69+
70+
* Formatting Functions
71+
- `para(name, content)`: Create a named paragraph with custom content
72+
- `rq(content)`: Create a "Remarque" (note) paragraph
73+
- `ex(content)`: Create an "Exemple" (example) paragraph
74+
- `arrow-list(items)`: Create a list with arrow bullets
75+
- `inbox(content)`: Create a box with gray background and border
76+
- There are a lot of varient accesible with `inbox2`, `inbox3`, `inbox4`
77+
78+
* Drawing and Plotting
79+
- `plotting(functions, domain, samples, steps, axis-style, axis, size)`: Plot mathematical functions with customizable options
80+
- `point(coordinates)`: Draw a point at given coordinates
81+
- `point-name(coordinates, name, offset)`: Draw a named point with custom offset
82+
- `quadratic(a, b, c)`: Calculate roots of quadratic equation
83+
- `base(coordinates, name1, name2, angle)`: Draw a base with custom angle
84+
- `spring(x0, y0, xf, yf, repetitions, amplitude)`: Draw a spring
85+
86+
* Mathematical Shortcuts
87+
- `recurrence(property, domain, initialization, heredity, conclusion)`: Format mathematical recurrence proofs
88+
- `dt`, `dx`, `dtheta`: Differential notations
89+
- `ar(content)`: Arrow notation
90+
- `nar(content)`: Norm of arrow notation
91+
- `dot2`, `dot3`: Double and triple dot notations
92+
- `grad`: Gradient notation
93+
- `cste`: Constant notation
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#import "styles/numbered.typ": *
2+
#import "styles/colored.typ": *
3+
#import "styles/plain.typ": *
4+
#import "styles/presentation.typ": *
5+
#import "styles/book.typ": *
6+
7+
#let apply-style(style, content) = {
8+
set heading(numbering: "I)1)a)i)")
9+
10+
if style == "numbered" or style == "numbered-book" {
11+
return numbered(content, style)
12+
} else if style == "book" {
13+
return book(content)
14+
} else if style == "colored" {
15+
return colored(content)
16+
} else if style == "plain" {
17+
return plain(content)
18+
} else if style == "presentation" {
19+
return presentation(content)
20+
} else {
21+
return numbered(content)
22+
}
23+
}
24+
25+
#let get-small-title(style, title, authors) = {
26+
if (style == "numbered-book") {
27+
style = "numbered"
28+
}
29+
import "styles/" + style + ".typ" as current-style
30+
31+
return current-style.get-small-title(title, authors)
32+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#import "../tools/miscellaneous.typ": content-to-string
2+
3+
#let code-display(content) = {
4+
// Code
5+
show raw: it => context {
6+
if ("py", "python", "ocaml", "ml", "sql").contains(it.lang) {
7+
let breakableVar = false
8+
let lines = (..it.lines,)
9+
10+
11+
// Remove empty lines at the beginning and end
12+
while lines.len() > 0 and content-to-string(lines.first()).trim() == "" {
13+
let _ = lines.remove(0)
14+
}
15+
while lines.len() > 0 and content-to-string(lines.last()).trim() == "" {
16+
let _ = lines.remove(-1)
17+
}
18+
19+
if (lines.len() >= 15) {
20+
breakableVar = true
21+
}
22+
23+
24+
block(
25+
clip: true,
26+
radius: calc.min(9pt, 4pt + 2pt * lines.len()),
27+
stroke: text.fill.lighten(50%) + 0.5pt,
28+
align(
29+
center,
30+
block(
31+
breakable: breakableVar,
32+
grid(
33+
columns: (measure([#lines.len()]).width + 10pt, 20fr),
34+
column-gutter: 0pt,
35+
inset: ((left: 5pt, right: 5pt, rest: 3pt), (left: 10pt, rest: 3pt)),
36+
align: (horizon + left, left),
37+
fill: (text.fill.lighten(75%), text.fill.lighten(88%)),
38+
[],
39+
[],
40+
..for i in range(lines.len()) {
41+
let l = lines.at(i)
42+
(str(i + 1), l.body)
43+
},
44+
[],
45+
[],
46+
),
47+
),
48+
),
49+
)
50+
} else {
51+
it
52+
}
53+
}
54+
content
55+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#import "outline.typ": *
2+
#import "apply-style.typ": *
3+
#import "header-footer.typ": *
4+
#import "front-pages.typ": *
5+
#import "../tools/shortcuts.typ": *
6+
#import "code-display.typ": *
7+
#import "quote-display.typ": *
8+
#import "../tools/formatting.typ": *
9+
#import "../tools/date.typ": *
10+
11+
= Documents
12+
13+
14+
/*
15+
Labels :
16+
- <title>
17+
- <section>
18+
- <subsection>
19+
*/
20+
21+
/*
22+
Style :
23+
- Numbered
24+
- Colored
25+
- Plain
26+
*/
27+
28+
#let doc(
29+
lang: "fr",
30+
title: "Titre",
31+
authors: (),
32+
style: "numbered",
33+
title-page: false,
34+
outline: false,
35+
local-outline: false,
36+
outline-max-depth: 5,
37+
smallcaps: true,
38+
content,
39+
) = context {
40+
set page(margin: 1.5cm)
41+
set text(lang: lang, font: "New Computer Modern")
42+
43+
show: apply-style.with(style)
44+
45+
let (first-real-pages, custom-outline) = get-outline(lang, smallcaps, outline-max-depth)
46+
47+
48+
if (first-real-pages.len() == 0) {
49+
first-real-pages.push(0)
50+
}
51+
52+
53+
show: header-footer.with(style, smallcaps, first-real-pages, title, authors)
54+
55+
front-pages(style, smallcaps, title, title-page, authors, outline, local-outline, custom-outline)
56+
57+
show: shows-shortcuts
58+
show: code-display
59+
show: quote-display
60+
61+
// Pre-set
62+
set table(inset: 10pt, stroke: 0.4pt + text.fill.lighten(20%), align: center + horizon, fill: (x, y) => if (x == 0)
63+
or (y == 0) { text.fill.lighten(90%) })
64+
65+
66+
set grid(column-gutter: 10pt, align: horizon)
67+
68+
69+
show image: it => {
70+
align(center, it)
71+
}
72+
73+
show table: it => {
74+
block(clip: true, radius: 0.75em, stroke: it.stroke, it)
75+
}
76+
// content
77+
set par(justify: true)
78+
79+
counter(heading).update(0)
80+
81+
82+
content
83+
}
84+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#import "apply-style.typ": get-small-title
2+
#import "outline.typ": get-local-outline
3+
4+
#let front-pages(style, small-caps, title, title-page, authors, outline, local-outline, custom-outline) = {
5+
let sc(c) = {
6+
if small-caps == true {
7+
return smallcaps(c)
8+
} else {
9+
return c
10+
}
11+
}
12+
13+
if title-page {
14+
align(
15+
center + horizon,
16+
[
17+
18+
#{
19+
if type(title) == str {
20+
par(leading: 2em, spacing: 3em, text(size: 5em, hyphenate: false, (strong(title))))
21+
} else {
22+
par(leading: 1.7em, text(size: 5em, hyphenate: false, (strong(title.at(1)))))
23+
par(leading: 1em, spacing: 3em, text(size: 3.25em, hyphenate: false, (title.at(0))))
24+
}
25+
}
26+
#v(1em)
27+
28+
#{
29+
if type(authors) == array {
30+
if authors.len() > 0 {
31+
[
32+
#text(size: 1.55em, sc(authors.at(0)))
33+
\
34+
]
35+
}
36+
if authors.len() > 1 {
37+
[
38+
#text(size: 1.55em, authors.slice(1).map(sc).join(" - "))
39+
]
40+
}
41+
} else {
42+
[
43+
#text(size: 1.55em, sc(authors))
44+
]
45+
}
46+
}
47+
48+
],
49+
)
50+
51+
pagebreak()
52+
if outline {
53+
custom-outline
54+
pagebreak()
55+
}
56+
57+
get-small-title(style, title, authors)
58+
if local-outline {
59+
get-local-outline()
60+
}
61+
62+
} else {
63+
if outline {
64+
custom-outline
65+
pagebreak()
66+
}
67+
68+
get-small-title(style, title, authors)
69+
if local-outline {
70+
get-local-outline()
71+
}
72+
v(20pt)
73+
}
74+
}

0 commit comments

Comments
 (0)