-
Notifications
You must be signed in to change notification settings - Fork 8
Change exercise type selection and allow for more flexible info box layout #21
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
base: main
Are you sure you want to change the base?
Conversation
1bcbaef to
03a9058
Compare
|
Sorry for the commit history. Git is hard. I accidently pushed to the wrong bransh... |
JeyRunner
left a comment
There was a problem hiding this 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:", |
There was a problem hiding this comment.
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) = { |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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: ( |
There was a problem hiding this comment.
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.
6308689 to
0c9d7a6
Compare
| } 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. |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
| if exercise-type not in ("exercise", "submission") { | ||
| panic("Exercise template only supports types 'exercise' and 'submission'") | ||
| } else { |
There was a problem hiding this comment.
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`: |
There was a problem hiding this comment.
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.
| 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) | ||
| } |
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this 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 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.
| // 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"! |
There was a problem hiding this comment.
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
|
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) |
FussballAndy
left a comment
There was a problem hiding this 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:

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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
| 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 | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
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.
|
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.typto 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-typetoexerciseorsubmissionand the info-box (title-sub) will adapt accordingly.Please let me know what you think!
Also, this Branch includes the fix proposed in #19