Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tudaexercise template #8

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ -29,6 +30,10 @@
/common/
/assets/

.DS_Store
.venv
.vscode

"""

# template folder names
Expand Down Expand Up @@ -56,7 +61,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 @@ -75,7 +80,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 @@ -134,7 +147,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"
)
103 changes: 103 additions & 0 deletions templates/tudaexercise/template/title.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#import "common/format.typ": format-date

#let tuda-make-title(
inner_page_margin_top,
title_rule,
accent_color,
on_accent_color,
text_color,
colorback,
logo_element,
logo_height,
info,
dict
) = {
let text_on_accent_color = if colorback {
on_accent_color
} else {
text_color
}

let text_inset = if colorback {
(left:3mm)
} else {
()
}

let stroke = (paint: text_color, thickness: title_rule / 2)

v(-inner_page_margin_top + 0.2mm) // would else draw over header

box(
fill: if colorback {accent_color},
width: 100%,
outset: 0pt,
{
// line creates a paragraph spacing
set par(spacing: 4pt)
v(logo_height / 2)
grid(
columns: (1fr, auto),
box(inset: (y:3mm),{
set text(font: "Roboto", weight: "bold", size: 12pt, fill: text_on_accent_color)
grid(row-gutter: 1em,
inset: text_inset,
if info.title != none {
text(info.title, size: 20pt)
},
if info.subtitle != none {
info.subtitle
},
if info.author != none {
if type(info.author) == array {
for author in info.author {
author
linebreak()
}
} else {
info.author
}
}
)

v(.5em)
}
),
{
if logo_element != none {
move(
dx: 6mm,
{
set image(height: logo_height)
logo_element
}
)
}
}
)
v(6pt)
line(length: 100%, stroke: stroke)
if info.term != none or info.date != none or info.sheetnumber != none {
set text(fill: text_on_accent_color)
grid(
inset: text_inset,
row-gutter: 0.4em,
if info.term != none {
info.term
},
if info.date != none {
if type(info.date) == datetime {
format-date(info.date, dict.locale)
} else {
info.date
}
},
if info.sheetnumber != none {
dict.sheet + " " + str(info.sheetnumber)
}
)
line(length: 100%, stroke: stroke)
}
}
)
}
Loading