Skip to content

Commit

Permalink
ape:0.3.0 and ape:0.3.1 (#1748)
Browse files Browse the repository at this point in the history
  • Loading branch information
gris-chat authored Feb 20, 2025
1 parent 7752964 commit 268ac1c
Show file tree
Hide file tree
Showing 23 changed files with 1,392 additions and 0 deletions.
93 changes: 93 additions & 0 deletions packages/preview/ape/0.3.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Ape for Typst



Tired of documents that look like they were formatted by a troop of baboons? Try Ape for Typst!



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.



**Key Features:**



* **Flexible Title Numbering:** Offers a variety of numbering styles for headings and subheadings

* **Table of Contents Customization:** Provides enhanced outline

* **Front Page Design:** Offers a pre-designed front page templates

* **Easy Integration:** Simple to integrate into your Typst documents with clear and concise functions and components.

* **Helpful function:** function to highlight information (in boxes), shortcuts, plotting, etc.






**Functionalities:**


* Starting a new document
```typst
#import "@preview/ape:0.3.1": *
#show: doc.with(
lang: "en",
title: "Title",
authors: ("Author1", "Author2"),
style: "numbered",
title-page: true,
outline: true,
smallcaps: true,
)
```


*Exemple 1 : (Style : numbered)*
![Exemple 1](exemples/Exemple1.png)

*Exemple 2 : (Style : colored)*

*Soon...*


## Further informations
Some shortcuts are currently only available in french.

* Available style
- Numbered
- Plain
- Colored
- Presentation

* Formatting Functions
- `para(name, content)`: Create a named paragraph with custom content
- `rq(content)`: Create a "Remarque" (note) paragraph
- `ex(content)`: Create an "Exemple" (example) paragraph
- `arrow-list(items)`: Create a list with arrow bullets
- `inbox(content)`: Create a box with gray background and border
- There are a lot of varient accesible with `inbox2`, `inbox3`, `inbox4`

* Drawing and Plotting
- `plotting(functions, domain, samples, steps, axis-style, axis, size)`: Plot mathematical functions with customizable options
- `point(coordinates)`: Draw a point at given coordinates
- `point-name(coordinates, name, offset)`: Draw a named point with custom offset
- `quadratic(a, b, c)`: Calculate roots of quadratic equation
- `base(coordinates, name1, name2, angle)`: Draw a base with custom angle
- `spring(x0, y0, xf, yf, repetitions, amplitude)`: Draw a spring

* Mathematical Shortcuts
- `recurrence(property, domain, initialization, heredity, conclusion)`: Format mathematical recurrence proofs
- `dt`, `dx`, `dtheta`: Differential notations
- `ar(content)`: Arrow notation
- `nar(content)`: Norm of arrow notation
- `dot2`, `dot3`: Double and triple dot notations
- `grad`: Gradient notation
- `cste`: Constant notation
27 changes: 27 additions & 0 deletions packages/preview/ape/0.3.1/document/apply-style.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#import "styles/numbered.typ": *
#import "styles/colored.typ": *
#import "styles/plain.typ": *
#import "styles/presentation.typ": *

#let apply-style(style, content) = {
set heading(numbering: "I)1)a)i)")

if style == "numbered" {
return numbered(content)
} else if style == "colored" {
return colored(content)
} else if style == "plain" {
return plain(content)
} else if style == "presentation" {
return presentation(content)
} else {
return numbered(content)
}
}

#let get-small-title(style, title) = {
import "styles/" + style + ".typ" as current-style

return current-style.get-small-title(title)

}
55 changes: 55 additions & 0 deletions packages/preview/ape/0.3.1/document/code-display.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#import "../tools/miscellaneous.typ": content-to-string

#let code-display(content) = {
// Code

show raw: it => context {
if ("py", "python", "ocaml", "ml").contains(it.lang) {
let breakableVar = false
let lines = (..it.lines,)

while lines.len() > 0 and content-to-string(lines.first()).trim() == "" {
lines.remove(0)
}
while lines.len() > 0 and content-to-string(lines.last()).trim() == "" {
lines.remove(-1)
}

if (it.lines.len() >= 15) {
breakableVar = true
}



block(
clip: true,
radius: calc.min(9pt, 4pt + 2pt * lines.len()),
stroke: text.fill.lighten(50%) + 0.5pt,
align(
center,
block(
breakable: breakableVar,
grid(
columns: (measure([#lines.len()]).width + 10pt, 20fr),
column-gutter: 0pt,
inset: ((left: 5pt, right: 5pt, rest: 3pt), (left: 10pt, rest: 3pt)),
align: (horizon + left, left),
fill: (text.fill.lighten(75%), text.fill.lighten(88%)),
[],
[],
..for i in range(lines.len()) {
let l = lines.at(i)
(str(i + 1), l.body)
},
[],
[],
),
),
),
)
} else {
it
}
}
content
}
75 changes: 75 additions & 0 deletions packages/preview/ape/0.3.1/document/doc.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#import "outline.typ": *
#import "apply-style.typ": *
#import "header-footer.typ": *
#import "front-pages.typ": *
#import "../tools/shortcuts.typ": *
#import "code-display.typ": *
#import "../tools/formatting.typ": *


= Documents

/*
Style :
- Numbered
- Colored
- Plain
*/

#let doc(
lang: "fr",
title: "Titre",
authors: (),
style: "numbered",
title-page: false,
outline: false,
smallcaps: true,
content,
) = context {
set text(lang: lang, font: "New Computer Modern")

show: apply-style.with(style)

let (first-real-page, custom-outline) = get-outline(lang, smallcaps)

show: header-footer.with(style, smallcaps, first-real-page, authors)

front-pages(style, smallcaps, title, title-page, authors, outline, custom-outline)

show: shows-shortcuts
show: code-display

// Pre-set

set table(
inset: 10pt,
stroke: 0.4pt + text.fill.lighten(20%),
align: center + horizon,
fill: (x, y) => if (x == 0) or (y == 0) { text.fill.lighten(90%) },
)





set grid(column-gutter: 10pt, align: horizon)


show image: it => {
align(center, it)
}

show table: it => {
block(clip: true, radius: 0.75em, stroke: it.stroke, it)
}
// content
set par(justify: true)

[= audhzifoduiygzbcjlxmwmwpadpozieuhgb]

counter(heading).update(0)


content
}

72 changes: 72 additions & 0 deletions packages/preview/ape/0.3.1/document/front-pages.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#import "apply-style.typ" : get-small-title

#let front-pages(style, small-caps, title, title-page, authors, outline, custom-outline) = {
let sc(c) = {
if small-caps == true {
return smallcaps(c)
} else {
return c
}
}



if title-page {
align(
center + horizon,
[
#{
if type(title) == text {
text(size: 6em, [*#title*])
} else {
[
#par(leading: 0.38em, text(size: 5em, hyphenate: false, (strong(title.at(1)))))
#v(-3em)
#par(text(size: 3.25em, hyphenate: false, (title.at(0))))
]
}
}
#v(1em)
#{
if type(authors) == array {
if authors.len() > 0 {
[
#text(size: 1.55em, sc(authors.at(0)))
\
]
}
if authors.len() > 1 {
[
#text(size: 1.55em, authors.slice(1).map(sc).join(" - "))
]
}
} else {
[
#text(size: 1.55em, sc(authors))
]
}
}



],
)

pagebreak()
if outline {
custom-outline
pagebreak()
}

get-small-title(style, title)
} else {
if outline {
custom-outline
pagebreak()
}

get-small-title(style, title)

v(15pt)
}
}
48 changes: 48 additions & 0 deletions packages/preview/ape/0.3.1/document/header-footer.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#import "../tools/miscellaneous.typ": to-array
#let header-footer(style, small-caps, first-real-page, authors, content) = {



if style == "presentation" {
return content
}

let sc(c) = {
if small-caps == true {
return smallcaps(c)
} else {
return c
}
}


set page(
header: context {
if (counter(page).get().at(0) > first-real-page and to-array(authors).len() > 0) {
[
#set text(size: 9pt)
#grid(
columns: (1fr, 2fr),
align(left, sc(to-array(authors).at(0))), align(right, to-array(authors).slice(1).map(sc).join(" - ")),
)
#place(dy: 3.5pt, line(length: 100%, stroke: 0.5pt + text.fill))
]
}
},

footer: context {
if (counter(page).get().at(0) >= first-real-page) {
[
#place(dy: -0.25cm, line(length: 100%, stroke: 0.5pt + text.fill))
#set align(center)


_Page #counter(page).display() / #counter(page).final().at(0)_

]
}
},
)

content
}
Loading

0 comments on commit 268ac1c

Please sign in to comment.