Skip to content

Conversation

@St0rml
Copy link

@St0rml St0rml commented Jul 30, 2025

As mentioned in #20 this PR aims to simplify the way the exercise type selection between "exercise" and "submission" is done.
This PR includes changes to the template_example main.typ to communicate the new method to select type, specify info key-value-pairs as well as information on how the layout of the info-box (title-sub) can be modified.

I tried to make the two most basic cases ("exercise" or "submission" type with default key-value-pairs already supplied in the template_example) really un-conmplicated. The user can now just change the top-level parameter exercise-type to exercise or submission and the info-box (title-sub) will adapt accordingly.

Please let me know what you think!

Also, this Branch includes the fix proposed in #19

@St0rml St0rml force-pushed the change_exercise_selection_model branch from 1bcbaef to 03a9058 Compare July 30, 2025 17:05
@St0rml
Copy link
Author

St0rml commented Jul 30, 2025

Sorry for the commit history. Git is hard. I accidently pushed to the wrong bransh...

Copy link
Owner

@JeyRunner JeyRunner left a comment

Choose a reason for hiding this comment

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

@St0rml thank you for your contribution! Adding a parameter to differentiate between submission and exercise looks like a good addition. I added some review comments. Also @FussballAndy as the original author of the exercise template should have a look.

lecturer: "Lecturer",
term: "Term",
date: "Due"
group: "Exercise group:",
Copy link
Owner

@JeyRunner JeyRunner Aug 2, 2025

Choose a reason for hiding this comment

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

I would not put the separation character in the translation dict since it's the same for both languages.

} else {
panic("title-sub has unsupported type. Expected content, function or none. Got " + type(title-sub))
}
#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.

///
/// - body (content):
#let tudaexercise(
exercise-type: "exercise",
Copy link
Owner

Choose a reason for hiding this comment

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

Add some doc for the new parameter (including possible values).

lecturer: none,
),

info-layout: (
Copy link
Owner

Choose a reason for hiding this comment

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

Add some doc for the new parameter.

@St0rml St0rml force-pushed the change_exercise_selection_model branch from 6308689 to 0c9d7a6 Compare August 3, 2025 22:03
} 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be broken into multiple lines



let default_keys_exercise = ("term", "date", "sheet")
let default_keys_submission= ("group", "tutor", "lecturer")
Copy link
Contributor

Choose a reason for hiding this comment

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

A space before the = would add more consistency

Comment on lines 53 to 55
if exercise-type not in ("exercise", "submission") {
panic("Exercise template only supports types 'exercise' and 'submission'")
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe change this into an assert, thus the if nesting also becomes redundant

/// - `author`
///
/// Additionally the following items are used by the `exercise` `title-sub`:
/// Additionally the following items are used by the `exercise-type` `submission`:
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless I misunderstood the code, the items are used by both types, thus making this line a bit redundant. It was originally there to signal that with the default subline style the following items were taken into account.

Comment on lines 58 to 63
for layout-key in info-layout.at("right") {
right-items = sort-info-to-list(right-items, info, layout-key)
}
for layout-key in info-layout.at("left") {
left-items = sort-info-to-list(left-items, info, layout-key)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

A check whether left and right is present would probably be a good idea. Alternatively provide default values

if info-key == "date" {
info-value = format-date(info-value, dict.locale)
}
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

v(6pt)
line(length: 100%, stroke: stroke)
if title-sub != none {
if info-layout != none {
Copy link
Contributor

Choose a reason for hiding this comment

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

One thing I noticed too late in the title-sub approach was that when no keys beside the ones for the headline were present there would be an empty bar rendered. I think this could be a nuisance for users. Perhaps we should also check whether info actually contains keys to be displayed in the subline.

Comment on lines 38 to 40
// 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"!
Copy link
Contributor

Choose a reason for hiding this comment

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

This behaviour should probably also be noted in the doc comment for tudaexercise

@St0rml
Copy link
Author

St0rml commented Aug 9, 2025

Okay, so I implemented the changes you suggested. Thank you for your detailed feedback and being kind with my beginner-mistakes (it is my first "real" typst project)
let me know if I can change anything else :)

Copy link
Contributor

@FussballAndy FussballAndy left a comment

Choose a reason for hiding this comment

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

One thing I noticed is that maybe there is a slight misunderstanding on what submission should actually do. The main idea was to not just use submission specific keys and allow aligning content left and right, but rather to also add a different style of how the keys are displayed. The entire thing is mostly based on Rubos-TUDA-Template. And what it does is that it displays the keys more like this:
Exert test-compilation of Rubos TUDA Template
So sort of [*key*: value].

Whereas exercise was supposed to still look like the original LaTeX template.

This should perhaps still be reflected.

///
/// - title-sub (content, function, none): The content of the subline in the title card.
/// By default the `title-sub.exercise` style.
/// them. Furthermore items `term`, `date` and `sheet` will only show when using
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you listed the wrong items here

/// ```
/// Left aligns left, and vice versa. The order of the keywords in the list, defines the
/// order of the info displayed in the subline.
/// For complete customization set `info-layout: false` and define any content in the
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be none instead of false now?

Comment on lines +42 to +62
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])
}
}
} // 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
}
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

@FussballAndy
Copy link
Contributor

Hi, are there any updates on this? I am planning to do some updates to the template and this is a bigger rework that could potentially influence other things.
If you currently have no time, for a temporary solution I would propose that

  • we rename title-sub to info-layout as I feel like that is a more intuitive name (both the argument and the file/export name)
  • reorganise the title-sub module/exports to only have exercise and submission exported
  • make it so that no additional info results in no title-sub/info bar. (maybe come up with a better name for the region?)
    I feel like those would already add some usability improvement whilst still keeping the original intact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants