X Tutup
Skip to content

Change bold and italics typst source generation#303

Merged
sinaatalay merged 14 commits intorendercv:mainfrom
lczyk:strong-and-emph
Jan 20, 2025
Merged

Change bold and italics typst source generation#303
sinaatalay merged 14 commits intorendercv:mainfrom
lczyk:strong-and-emph

Conversation

@lczyk
Copy link
Contributor

@lczyk lczyk commented Jan 10, 2025

Fixes #293 and, coincidentally fixes #294.

Does not conflict with #299.

Changes

  • Added translation from * to #sym.ast.basic. Sometimes a zero-width joiner is also added (if asterisk appears in the middle of a word).
  • Changed the templater to generate #strong[] and #emph[] instead of #[**] and #[__] respectively. This means that the typst templates are more robust to multilines.
  • Added greedy_on_not_found: bool = True kwarg to replace_placeholders_with_actual_values. The default preserves previous behaviour in jinja template mode.
  • input_template_to_typst now strips a bunch of extra special characters from beginning and end of the string. This is in order to (mostly) preserve the previous behaviour, but ought to be removed later when a better solution is implemented.
  • Updated tests/testdata (that's most of the lines diff: +10251, -10251).

Notes

Bar one minor difference, all the pdf files are pixel-identical. Checked with diff-pdf on default settings. The minor difference is in engineeringresume and moderncv templates, where the comm in the middle of the template used to be gobbled up (in mu opinion unnecessarily) by replace_placeholders_with_actual_values in input_template_to_typst.

Old: Bogaziçi University in Mechanical Engineering: - Istanbul, Turkey
New: Bogaziçi University, in Mechanical Engineering: - Istanbul, Turkey

Screenshot 2025-01-10 at 20 30 06

The whole business with gobbling up non-alphanumeric characters by replace_placeholders_with_actual_values shoudl, in my opinion, be done differently. I assume it happens like that to make the way it works jinja templates easier, or maybe to cater for situations like **NAME** -- **LOCATION**, when NAME is not specified. The replace_placeholders_...func would then gobble up the--. I don't think that's a good way of doing it though. It's clever but it introduces more issues than it's worth and it's really unexpected. I've left it behind a flag here, but I would suggest in the future to completely remove it and follow the example of the template for EducationEntry.j2.typwhich just lists a bunch of cases with (very helpful)// YES DATE, YES DEGREE, // YES DATE, NO DEGREE, etc. It's a bunch of work but I think it'd make that part of the code cleaner. I've re-added kind-of gobbling at the end of input_template_to_typstwithoutput = re.sub(r"^[^\w\s#\[\]\n\(\)]*", "", output)akalstrip not (word or space or # or [ or ] or newline or ( or ). I think, after removing the gobble from replace_placeholders_...` this should go too. It's there just to retain the current behaviour.


Overall, I really like the codebase, it's really clean and it was really fun to work on this! 😃 Thanks for an amazing project!

lczyk added 11 commits January 10, 2025 21:07
Change templater to use #strong and #emph instead of * and _ respectively.
engineeringresumes_empty_long_second_row.pdf
0 of 1 pages differ.
engineeringresumes_empty_short_second_row.pdf
0 of 1 pages differ.
engineeringresumes_filled_long_second_row.pdf
13 of 39 pages differ.
engineeringresumes_filled_short_second_row.pdf
14 of 45 pages differ.

The diff is one extra comma which tbh, was probably supposed to be there anyway:

Old: `Bogaziçi University in Mechanical Engineering: - Istanbul, Turkey`
New: `Bogaziçi University, in Mechanical Engineering: - Istanbul, Turkey`
moderncv_empty_long_second_row.pdf
0 of 1 pages differ.
moderncv_empty_short_second_row.pdf
0 of 1 pages differ.
moderncv_filled_long_second_row.pdf
14 of 46 pages differ.
moderncv_filled_short_second_row.pdf
14 of 46 pages differ.

Same diff as for engineeringresumes -- one extra comma which, was probably supposed to be there anyway:

Old: `Bogaziçi University in Mechanical Engineering: - Istanbul, Turkey`
New: `Bogaziçi University, in Mechanical Engineering: - Istanbul, Turkey`
@lczyk
Copy link
Contributor Author

lczyk commented Jan 10, 2025

+10400, -10281 ups... 😅 it's just because of the tests/testdata changes though. A filtered diff (git diff efe308ae 93e8dff --compact-summary -- . ':!tests/testdata') gives a much more reasonable +149, -30.

Filtered:

 rendercv/renderer/templater.py | 102 +++++++++++++++++++++++++++++++----------
 tests/test_renderer.py         |  77 +++++++++++++++++++++++++++++--
 2 files changed, 149 insertions(+), 30 deletions(-)

Full:

$ git diff 93e8dff efe308ae --compact-summary
rendercv/renderer/templater.py                     |  102 +-
tests/test_renderer.py                             |   77 +-
.../test_create_a_typst_file/classic_filled.typ    | 1226 +++++------
.../engineeringclassic_filled.typ                  | 1226 +++++------
.../engineeringresumes_filled.typ                  | 1098 +++++-----
.../test_create_a_typst_file/moderncv_filled.typ   | 1098 +++++-----
.../test_create_a_typst_file/sb2nov_filled.typ     | 2186 ++++++++++----------
.../classic_filled_long_second_row/John_Doe_CV.typ | 1226 +++++------
.../John_Doe_CV.typ                                | 1226 +++++------
.../John_Doe_CV.typ                                | 1226 +++++------
.../John_Doe_CV.typ                                | 1226 +++++------
.../John_Doe_CV.typ                                | 1098 +++++-----
.../John_Doe_CV.typ                                | 1098 +++++-----
.../John_Doe_CV.typ                                | 1098 +++++-----
.../John_Doe_CV.typ                                | 1098 +++++-----
.../sb2nov_filled_long_second_row/John_Doe_CV.typ  | 2186 ++++++++++----------
.../sb2nov_filled_short_second_row/John_Doe_CV.typ | 2186 ++++++++++----------
.../classic_empty_long_second_row.pdf              |  Bin 11573 -> 11573 bytes
.../classic_empty_short_second_row.pdf             |  Bin 11573 -> 11573 bytes
.../classic_filled_long_second_row.pdf             |  Bin 391668 -> 391668 bytes
.../classic_filled_short_second_row.pdf            |  Bin 387470 -> 387470 bytes
.../engineeringclassic_empty_long_second_row.pdf   |  Bin 8725 -> 8725 bytes
.../engineeringclassic_empty_short_second_row.pdf  |  Bin 8725 -> 8725 bytes
.../engineeringclassic_filled_long_second_row.pdf  |  Bin 240983 -> 240983 bytes
.../engineeringclassic_filled_short_second_row.pdf |  Bin 270517 -> 270517 bytes
.../engineeringresumes_empty_long_second_row.pdf   |  Bin 10716 -> 10716 bytes
.../engineeringresumes_empty_short_second_row.pdf  |  Bin 10716 -> 10716 bytes
.../engineeringresumes_filled_long_second_row.pdf  |  Bin 218962 -> 218919 bytes
.../engineeringresumes_filled_short_second_row.pdf |  Bin 239838 -> 239822 bytes
.../moderncv_empty_long_second_row.pdf             |  Bin 9361 -> 9361 bytes
.../moderncv_empty_short_second_row.pdf            |  Bin 9361 -> 9361 bytes
.../moderncv_filled_long_second_row.pdf            |  Bin 255185 -> 255169 bytes
.../moderncv_filled_short_second_row.pdf           |  Bin 255185 -> 255169 bytes
.../sb2nov_empty_long_second_row.pdf               |  Bin 12077 -> 12077 bytes
.../sb2nov_empty_short_second_row.pdf              |  Bin 12077 -> 12077 bytes
.../sb2nov_filled_long_second_row.pdf              |  Bin 386938 -> 386938 bytes
.../sb2nov_filled_short_second_row.pdf             |  Bin 398126 -> 398126 bytes
37 files changed, 10281 insertions(+), 10400 deletions(-)

@lczyk lczyk changed the title Strong and emph Change bold and italics typst source generation Jan 10, 2025
@frdysf
Copy link

frdysf commented Jan 16, 2025

Ran into the original issue with typing asterisks, solved in seconds by installing this pull request into my env. Thank you!

Copy link
Member

@sinaatalay sinaatalay left a comment

Choose a reason for hiding this comment

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

This was very helpful, thank you. I made some changes here following your comments. I'm glad you loved the code!

@sinaatalay sinaatalay merged commit bf38e29 into rendercv:main Jan 20, 2025
12 checks passed
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.

Generate invalid typst source for multiline titles in 2.0 Asterisk needs translation in 2.0

3 participants

X Tutup