Skip to content

Commit

Permalink
Collapse whitespace after single letter ligature macros (siefkenj#106)
Browse files Browse the repository at this point in the history
* Collapse whitespace after single letter ligature macros

* Add ligature macro pairs for \' + single letter macro ligature

---------

Co-authored-by: arne <[email protected]>
  • Loading branch information
rrrnld and arne authored Aug 2, 2024
1 parent 473cdcd commit 9fc9cb5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/support-tables/ligature-macros.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
["\\\" w", ""],
["\\\" y", "ÿ"],
["\\\" Y", "Ÿ"],
["\\' i", "í"],
["\\' A", "Á"],
["\\' a", "á"],
["\\' C", "Ć"],
Expand All @@ -51,16 +50,23 @@
["\\' G", "Ǵ"],
["\\' g", "ǵ"],
["\\' I", "Í"],
["\\' i", "í"],
["\\' \\i", "í"],
["\\' \\j", ""],
["\\' K", ""],
["\\' k", ""],
["\\' L", "Ĺ"],
["\\' \\L", "Ł́"],
["\\' l", "ĺ"],
["\\' \\l", "ł́"],
["\\' M", ""],
["\\' m", "ḿ"],
["\\' N", "Ń"],
["\\' n", "ń"],
["\\' O", "Ó"],
["\\' \\O", "Ǿ"],
["\\' o", "ó"],
["\\' \\o", "ǿ"],
["\\' P", ""],
["\\' p", ""],
["\\' R", "Ŕ"],
Expand Down
6 changes: 6 additions & 0 deletions packages/unified-latex-util-ligatures/libs/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export function createMatchers() {
if (match.group(arg) && arg.content.length === 1) {
nodesToTest[1] = arg.content[0];
}

// whitespace directly after one-letter macros like `\o` should
// be skipped
if (nodes[0].content.length === 1 && nodesToTest[1].type === 'whitespace') {
nodesToTest.length = 1
}
}
return ligatureToUnicode(nodesToTest);
},
Expand Down
3 changes: 3 additions & 0 deletions packages/unified-latex-util-ligatures/tests/ligatures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ describe("unified-latex-util-ligatures", () => {

ast = strToNodes("a\\v sb");
expect(printRaw(parseLigatures(ast))).toEqual("ašb");

ast = strToNodes("r\\o y");
expect(printRaw(parseLigatures(ast))).toEqual("røy");
});

it("can replace macro ligatures with an argument in a group", () => {
Expand Down

0 comments on commit 9fc9cb5

Please sign in to comment.