Skip to content

Commit

Permalink
Merge pull request #8 from FussballAndy/feature/tudaexercise
Browse files Browse the repository at this point in the history
Add tudaexercise template
  • Loading branch information
JeyRunner authored Nov 25, 2024
2 parents e092308 + b1c468a commit 068e1f3
Show file tree
Hide file tree
Showing 20 changed files with 633 additions and 254 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ tudapub*.pdf
example_*.pdf
test*.pdf

!example_tudapub.pdf
!example_tudapub.pdf

.vscode
.DS_Store
.venv
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Typst Template for the Corporate Design of TU Darmstadt :book:
This **unofficial** template can be used to write in [Typst](https://github.com/typst/typst) with the corporate design of [TU Darmstadt](https://www.tu-darmstadt.de/).
# Typst Templates for the Corporate Design of TU Darmstadt :book:
These **unofficial** templates can be used to write in [Typst](https://github.com/typst/typst) with the corporate design of [TU Darmstadt](https://www.tu-darmstadt.de/).

#### Disclaimer
Please ask your supervisor if you are allowed to use typst and this template for your thesis or other documents.
Expand All @@ -18,13 +18,18 @@ For missing features, ideas or other problems you can just open an issue :wink:.
| Template | Preview | Example | Scope |
|----------|---------|---------|-------|
| [tudapub](templates/tudapub/template/tudapub.typ) | <img src="templates/tudapub/preview/tudapub_prev-01.png" height="300px"> | [example_tudapub.pdf](example_tudapub.pdf) <br/> [example_tudapub.typ](example_tudapub.typ) | Master and Bachelor thesis |
| [tuda-exercise](templates/tudaexercise/template/tudaexercise.typ) | <img src="templates/tudaexercise/preview/tudaexercise_prev-1.png" height="300px"> | [example_tudaexercise-TODO.pdf](TODO) <br/> [example_tudaexercise-TODO-.typ](TODO.typ) | Exercises |
| [tudaexercise](templates/tudaexercise/template/tudaexercise.typ) | <img src="templates/tudaexercise/preview/tudaexercise_prev-1.png" height="300px"> | [Example File](templates_examples/tudaexercise/main.typ) | Exercises |

## Usage
Create a new typst project based on this template locally.
```bash
# for tudapub
typst init @preview/athena-tu-darmstadt-thesis
cd athena-tu-darmstadt-thesis

# for tudaexercise
typst init @preview/athena-tu-darmstadt-exercise
cd athena-tu-darmstadt-exercise
```
Or create a project on the typst web app based on this template.

Expand All @@ -35,7 +40,7 @@ For a manual setup create a folder for your writing project and download this te
```bash
mkdir my_thesis && cd my_thesis
mkdir templates && cd templates
git clone https://github.com/JeyRunner/tuda-typst-templates templates/
git clone https://github.com/JeyRunner/tuda-typst-templates
```
</details>

Expand All @@ -48,12 +53,16 @@ cd asssets/logos
./convert_logo.sh
```

Note: The here used `pdf2svg` command might not be available. In this case we recommend a online converter like [PDF24 Tools](https://tools.pdf24.org/en/pdf-to-svg). There also is a [tool](https://github.com/FussballAndy/typst-img-to-local) to install images as local typst packages.

Also download the required fonts `Roboto` and `XCharter`:
```bash
cd asssets/fonts
./download_fonts.sh
```
Now you can install all fonts in the folders in `fonts` on your system.
Optionally you can install all fonts in the folders in `fonts` on your system. But you can also use Typst's `--font-path` option. Or install them in a folder and add the folder to `TYPST_FONT_PATHS` for a single font folder.

Note: wget might not be available. In this case either download it or replace the command with something like `curl <url> -o <filename> -L`

<details>
<summary>Create a main.typ file for the manual template installation.</summary>
Expand Down Expand Up @@ -82,7 +91,7 @@ Some Text
typst --watch main.typ --font-path asssets/fonts/
```

This will watch your file and recompile it to a pdf when the file is saved. For writing, you can use [Vscode](https://code.visualstudio.com/) with these extensions: [Typst LSP](https://marketplace.visualstudio.com/items?itemName=nvarner.typst-lsp) and [Typst Preview](https://marketplace.visualstudio.com/items?itemName=mgt19937.typst-preview). Or use the [typst web app](https://typst.app/) (here you need to upload the logo and the fonts).
This will watch your file and recompile it to a pdf when the file is saved. For writing, you can use [Vscode](https://code.visualstudio.com/) with these extensions: [Tinymist Typst](https://marketplace.visualstudio.com/items?itemName=myriad-dreamin.tinymist). Or use the [typst web app](https://typst.app/) (here you need to upload the logo and the fonts).

Note that we add `--font-path` to ensure that the correct fonts are used.
Due to a bug (typst/typst#2917 typst/typst#2098) typst sometimes uses the font `Roboto condensed` instead of `Roboto`.
Expand Down
3 changes: 2 additions & 1 deletion assets/logos/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.jpeg
*.png
*.svg
*.pdf
*.pdf
!tuda_replace.svg
21 changes: 21 additions & 0 deletions assets/logos/tuda_replace.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions common/colorutil.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#let calc-color-component(srgb) = {
if srgb <= 0.03928 {
return srgb / 12.92
} else {
return calc.pow((srgb + 0.055) / 1.055, 2.4)
}
}

#let calc-relative-luminance(color) = {
let rgb_color = rgb(color.to-hex())
let components = rgb_color.components(alpha: false)

let r_srgb = float(components.at(0))
let b_srgb = float(components.at(1))
let g_srgb = float(components.at(2))
return calc-color-component(r_srgb) * 0.2126 + calc-color-component(b_srgb) * 0.0722 + calc-color-component(g_srgb) * 0.7152
}

#let calc-contrast(rl1, rl2) = {
let l1 = calc.max(rl1, rl2)
let l2 = calc.min(rl1, rl2)
return (l1 + 0.05) / (l2 + 0.05)
}
8 changes: 8 additions & 0 deletions common/dictutil.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#let overwrite-dict(new, base) = {
for key in base.keys() {
if key in new {
base.insert(key, new.at(key))
}
}
return base
}
49 changes: 48 additions & 1 deletion common/headings.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#import "props.typ": tud_heading_line_thin_stroke
#import "props.typ": tud_heading_line_thin_stroke, tud_header_line_height

#let tud_body_line_height = tud_header_line_height / 2

#let tud-heading-with-lines(
heading_margin_before: 0mm,
Expand Down Expand Up @@ -42,4 +44,49 @@
v(10pt)
)
]
}

#let tuda-section-lines(above: 1.8em, below: 1.2em, ruled: true, body) = {
block(
width: 100%,
inset: 0mm,
outset: 0mm,
above: above,
below: below,
{
set block(spacing: 0.2em)
if ruled {
line(length: 100%, stroke: tud_body_line_height)
}
body
if ruled {
line(length: 100%, stroke: tud_body_line_height)
}
}
)
}


/// Creates a section similar to headers
/// But does not add other text or a counter.
/// ```
/// #tuda-section("Lorem ipsum")
/// ```
/// - title (str): The title of this section
#let tuda-section(title) = {
tuda-section-lines(text(title, font: "Roboto", weight: "bold", size: 11pt))
}

/// Creates a subsection similar to level 2 headers.
/// But does not add other text or a counter.
/// ```
/// #tuda-subsection("Lorem ipsum")
/// ```
/// - title (str): The title of this subsection
#let tuda-subsection(title) = {
tuda-section-lines(above: 1.4em, below: 1em, text(title, font: "Roboto", weight: "regular", size: 11pt))
}

#let tuda-subsection-unruled(title) = {
tuda-section-lines(above: 1.4em, below: 1em, ruled: false, text(title, font: "Roboto", weight: "regular", size: 11pt))
}
11 changes: 10 additions & 1 deletion common/props.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#let tud_heading_line_thin_stroke = 0.75pt


#let tud_header_line_height = 1.2pt
#let tud_inner_page_margin_top = 22pt
#let tud_title_logo_height = 22mm


#let tud_page_margin_title_page = (
Expand Down Expand Up @@ -31,4 +33,11 @@
left: 25mm,
right: 25mm,
bottom: 15mm - 1mm // should be 20mm according to guidelines
)

#let tud_exercise_page_margin = (
top: 15mm,
left: 15mm,
right: 15mm,
bottom: 20mm,
)
51 changes: 51 additions & 0 deletions common/tudacolors.typ
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,55 @@
"9d": "961C26",
"10d": "732054",
"11d": "4C226A",
)

#let text_colors = (
"0a": black,
"0b": white,
"0c": white,
"0d": white,
"1a": white,
"1b": white,
"1c": white,
"1d": white,
"2a": white,
"2b": white,
"2c": white,
"2d": white,
"3a": white,
"3b": white,
"3c": white,
"3d": white,
"4a": black,
"4b": white,
"4c": white,
"4d": white,
"5a": black,
"5b": black,
"5c": black,
"5d": white,
"6a": black,
"6b": black,
"6c": white,
"6d": white,
"7a": black,
"7b": black,
"7c": white,
"7d": white,
"8a": white,
"8b": white,
"8c": white,
"8d": white,
"9a": white,
"9b": white,
"9c": white,
"9d": white,
"10a": white,
"10b": white,
"10c": white,
"10d": white,
"11a": white,
"11b": white,
"11c": white,
"11d": white
)
19 changes: 16 additions & 3 deletions scripts/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shutil
import pathlib
import re
import sys



Expand All @@ -31,6 +32,10 @@
/common/
/assets/
.DS_Store
.venv
.vscode
"""

# template folder names
Expand Down Expand Up @@ -58,7 +63,7 @@
description='Copies this repo to typst local packages or locally cloned typst-packages while not copying the ignored files.'
)
parser.add_argument('--local', action='store_true',
help='copy to $HOME/.local/share/typst/packages/local/<PACKAGE_NAME>/<VERSION>.99')
help='copy to $TYPST_PACKAGE_ROOT/typst/packages/local/<PACKAGE_NAME>/<VERSION>.99')
parser.add_argument('--clean-dist-folder-force', action='store_true',
help='Delete the contents of the destinatio folder before copying without asking. ')
parser.add_argument('--universe', type=str,
Expand All @@ -77,7 +82,15 @@
exit(0)

if args.local:
copy_dest_dir = str(pathlib.Path.home()) + "/.local/share/typst/packages/local/"
if sys.platform.startswith("linux"):
copy_dest_dir = str(pathlib.Path.home()) + "/.local/share/typst/packages/local/"
elif sys.platform.startswith("win32"):
copy_dest_dir = os.getenv("APPDATA") + "/typst/packages/local/"
elif sys.platform.startswith("darwin"):
copy_dest_dir = str(pathlib.Path.home()) + "/Library/Application Support/typst/packages/local/"
else:
print('Error: Unsupported platform')
exit(0)
elif args.universe is not None:
copy_dest_dir = args.universe + '/packages/preview/'

Expand Down Expand Up @@ -136,7 +149,7 @@ def copy_template(copy_dest_dir, template_folder_name = 'tudapub'):
/templates_examples/*/logos/*
!/templates_examples/*/logos/*.sh
/templates_examples/*/fonts/*
!/template_examples/*/fonts/*.sh
!/templates_examples/*/fonts/*.sh
""")


Expand Down
Binary file modified templates/tudaexercise/preview/tudaexercise_prev-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions templates/tudaexercise/template/lib.typ
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import "tudaexercise.typ": tuda-exercise
#import "common/tudacolors.typ": tuda_colors
#import "tudaexercise.typ": tudaexercise
#import "common/headings.typ": tuda-section, tuda-subsection
#import "common/tudacolors.typ": tuda_colors, text_colors as tuda_text_colors
#import "common/props.typ": *
11 changes: 11 additions & 0 deletions templates/tudaexercise/template/locales.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#let dict_de = (
sheet: "Übungsblatt",
task: "Aufgabe",
locale: "ger"
)

#let dict_en = (
sheet: "Sheet",
task: "Task",
locale: "eng"
)
Loading

0 comments on commit 068e1f3

Please sign in to comment.