Skip to content
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
1 change: 0 additions & 1 deletion templates/tudaexercise/template/lib.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#import "tudaexercise.typ": tudaexercise, tuda-gray-info, task, subtask, task-points-header, point-format, difficulty-format
#import "title-sub.typ" as title-sub
#import "common/headings.typ": tuda-section, tuda-subsection
#import "common/tudacolors.typ": tuda_colors, text_colors as tuda_text_colors
#import "common/props.typ": *
Expand Down
2 changes: 1 addition & 1 deletion templates/tudaexercise/template/locales.typ
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
panic("Unsupported locale: " + locale + ". Supported locales are: " + dicts.keys().join(", ", last: " and "))
}
dict
}
}
140 changes: 0 additions & 140 deletions templates/tudaexercise/template/title-sub.typ

This file was deleted.

131 changes: 106 additions & 25 deletions templates/tudaexercise/template/title.typ
Original file line number Diff line number Diff line change
@@ -1,11 +1,90 @@
#import "common/format.typ": format-date
#import "locales.typ": *

#let resolve-title-sub(title-sub, info, dict) = if type(title-sub) == content {
title-sub
} else if type(title-sub) == function {
title-sub(info, dict)
} else {
panic("title-sub has unsupported type. Expected content, function or none. Got " + type(title-sub))
/// Creates the subline content. If `info-layout` is a dict, the subline gets filled following
/// the order specified by the keys in the `info-layout` dict. If a key is present in the
/// `info` but not in `info-layout`, it does not show up in the subline.
///
/// - exercise-type (string): The type of exercise specified
/// - info (dict): The info dict containing all relevant data for the subline
/// - info-layout (dict, boolean): A dict specifying the layout of the subline. If `false`
/// the value of `#info.custom-subline` gets returned as content
/// - dict (dict): A language dict to translate standard/pre-defined strings.
/// -> Returns content filling the subline of the title
#let resolve-info-layout(exercise-type, info, info-layout, dict) = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function is quite complex, I would add a bit of documentation. The original submission function had very good documentation.

if info-layout == none {
if "custom-subline" in info {
return [#info.custom-subline]
}
return none
}
let title_keys = ("title", "subtitle", "author")
let default_keys_exercise = ("term", "date", "sheet")
let default_keys_submission = ("group", "tutor", "lecturer")
let default_keys = if exercise-type == "exercise" {
default_keys_exercise
} else {
default_keys_exercise + default_keys_submission
}

// filter out standard title keys
for key in title_keys {
_ = info.remove(key)
}

// Check if info actually contains any items
if info.len() == 0 {
return none
}

/// Checks if `filter-key` is present in `info-dict` and appends it to `target-list`
/// if that is the case. Also format the value of key `date` to match the locale.
let sort-info-to-list(target-list, info-dict, filter-key) = {
for (info-key, info-value) in info-dict.pairs() {
if info-key in default_keys {
if info-key == filter-key {
if info-key == "date" {
target-list.push([#format-date(info-value, dict.locale)])
} else {
target-list.push([#dict.at(info-key) #info-value])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hence the dict now doesn't contain the separator anymore it would need to be added here.
Additionally I would like to have the exercise type be as close to the LaTeX template as possible. This would make it s.t. the date becomes "Due: X.Y.Z" whereas in LaTeX it is only displayed as X.Y.Z

}
}
} // This case makes sure the default submission keys don't get mistaken for custom keys
// I.e. we don't want submission keys ("group", "tutor", "lecturer") showing up, if
// exercise-type isn't "submission"!
else if info-key not in default_keys_submission {
if info-key == filter-key {
target-list.push([#info-value])
}
}
}
return target-list
}
Comment on lines +42 to +62
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire function could maybe be changed s.t. instead of constantly appending a single element to a list, it rather takes in an array of all the keys and then returns an array with the corresponding content.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#let sort-info-to-list(wanted, info-dict) = {
  return wanted
    .filter(key => key in info-dict and (key in default_keys or not key in default_keys_submission))
    .map(key => if key == "date" {
      format-date(info-dict.at(key), dict.locale)
    } else {
      [#dict.at(key, default: key) #info-dict.at(key)]
    })
}

This could do the trick



let left-items = ()
let right-items = ()
assert(
exercise-type in ("exercise", "submission"),
message: "Exercise template only supports types 'exercise' and 'submission'",
)
// Handle layouting, right first then default the rest to left
if "right" in info-layout {
for layout-key in info-layout.at("right") {
right-items = sort-info-to-list(right-items, info, layout-key)
}
}
if "left" in info-layout {
for layout-key in info-layout.at("left") {
left-items = sort-info-to-list(left-items, info, layout-key)
}
}

grid(
columns: (1fr, 1fr),
align: (alignment.left, alignment.right),
left-items.join(linebreak()), right-items.join(linebreak()),
)
}

#let tuda-make-title(
Expand All @@ -18,8 +97,9 @@
logo_element,
logo_height,
info,
title-sub,
dict
info-layout,
exercise-type,
dict,
) = {
let text_on_accent_color = if colorback {
on_accent_color
Expand All @@ -28,7 +108,7 @@
}

let text_inset = if colorback {
(x:3mm)
(x: 3mm)
} else {
(:)
}
Expand All @@ -46,7 +126,7 @@
set text(fill: text_on_accent_color)

box(
fill: if colorback {accent_color},
fill: if colorback { accent_color },
width: 100%,
outset: 0pt,
{
Expand All @@ -55,9 +135,10 @@
v(logo_height / 2)
grid(
columns: (1fr, auto),
box(inset: (y:3mm),{
box(inset: (y: 3mm), {
set text(font: "Roboto", weight: "bold", size: 12pt)
grid(row-gutter: 1em,
grid(
row-gutter: 1em,
inset: text_inset,
if "title" in info {
text(info.title, size: 20pt)
Expand All @@ -69,44 +150,44 @@
if type(info.author) == array {
for author in info.author {
if type(author) == array {
[#author.at(0)
[#author.at(0)
#text(weight: "regular", size: 0.8em)[(Mat.: #author.at(1))]]
linebreak()
} else {
author
linebreak()
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 title-sub != none {
let subline-content = resolve-info-layout(exercise-type, info, info-layout, dict)
if subline-content != none {
block(
inset: text_inset,
resolve-title-sub(title-sub, info, dict)
subline-content,
)
line(length: 100%, stroke: stroke)
}
}
},
)
}
}
Loading