From 0d371ba816ca3976c7a6df23dc7136aa2406c01c Mon Sep 17 00:00:00 2001 From: Omikhleia Date: Sat, 4 Feb 2023 12:09:24 +0100 Subject: [PATCH 1/3] feat(classes): Implement the`\code` command in the plain class --- classes/plain.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/classes/plain.lua b/classes/plain.lua index 26af3b9b5..8f5015912 100644 --- a/classes/plain.lua +++ b/classes/plain.lua @@ -243,6 +243,19 @@ function class:registerCommands () SILE.call("font", { weight = 700 }, content) end) + self:registerCommand("code", function (options, content) + -- IMPLEMENTATION NOTE: + -- The \code command came from the url package, though used in plenty of + -- places. It was referring to the verbatim:font from the verbatim + -- package, which _should_ be sort of unrelated. + -- Trying to untangle the things here, by introducing the + -- definition from the former, but it's of sub-quality... + -- The ugly -3 size is a HACK of sorts. + options.family = options.family or "Hack" + options.size = options.size or SILE.settings:get("font.size") - 3 + SILE.call("font", options, content) + end) + self:registerCommand("nohyphenation", function (_, content) SILE.call("font", { language = "und" }, content) end) From 8f6235d0e995b3f684fc5ba9f4646494800fb37a Mon Sep 17 00:00:00 2001 From: Omikhleia Date: Sat, 4 Feb 2023 12:10:22 +0100 Subject: [PATCH 2/3] feat(packages): Introduce urlstyle hook in the url package --- packages/url/init.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/url/init.lua b/packages/url/init.lua index 31f93bfc6..62ff54bdf 100644 --- a/packages/url/init.lua +++ b/packages/url/init.lua @@ -147,13 +147,13 @@ function package:registerCommands () secondaryPenalty = secondaryPenalty, worsePenalty = worsePenalty }) - SILE.call("code", {}, result) + SILE.call("urlstyle", {}, result) end) end, "Inserts penalties in an URL so it can be broken over multiple lines at appropriate places.") - self:registerCommand("code", function (options, content) - SILE.call("verbatim:font", options, content) - end) + self:registerCommand("urlstyle", function (options, content) + SILE.call("code", options, content) + end, "Hook that may be redefined to change the styling of URLs") end @@ -177,6 +177,10 @@ To typeset an URL and at the same type have it as active hyperlink, one can use but with the URL passed as argument. The breaks are controlled by two penalty settings, \autodoc:setting{url.linebreak.primaryPenalty} for preferred breakpoints and, for less acceptable but still tolerable breakpoints, \autodoc:setting{url.linebreak.secondaryPenalty} —its value should logically be higher than the previous one. + +The \autodoc:command{\urlstyle} command hook may be overridden to change the style of URLs. +By default, they are typeset as “code”. + \end{document} ]] From c1954ee75698adb4cfad1f210ad7b6b158ad53e1 Mon Sep 17 00:00:00 2001 From: Omikhleia Date: Sat, 4 Feb 2023 12:11:31 +0100 Subject: [PATCH 3/3] test(packages): Add non-regression test for urlstyle --- tests/feat-urlstyle.expected | 52 ++++++++++++++++++++++++++++++++++++ tests/feat-urlstyle.sil | 11 ++++++++ 2 files changed, 63 insertions(+) create mode 100644 tests/feat-urlstyle.expected create mode 100644 tests/feat-urlstyle.sil diff --git a/tests/feat-urlstyle.expected b/tests/feat-urlstyle.expected new file mode 100644 index 000000000..d3ff99ad1 --- /dev/null +++ b/tests/feat-urlstyle.expected @@ -0,0 +1,52 @@ +Set paper size 297.6377985 419.5275636 +Begin page +Mx 14.8819 +My 26.2947 +Set font Hack;7;400;;normal;;;LTR +T 156 211 211 198 205 w=21.0718 (https) +Mx 35.9537 +T 583 w=4.2144 (:) +Mx 40.1680 +T 599 w=4.2144 (/) +Mx 44.3824 +T 599 w=4.2144 (/) +Mx 48.5967 +T 205 158 172 139 w=16.8574 (sile) +Mx 65.4542 +T 656 w=4.2144 (-) +Mx 69.6685 +T 211 233 198 139 205 139 211 211 139 201 w=42.1436 (typesetter) +Mx 111.8121 +T 592 w=4.2144 (.) +Mx 116.0264 +T 184 201 151 w=12.6431 (org) +Mx 128.6695 +T 599 w=4.2144 (/) +Mx 14.8819 +My 38.2947 +Set font Gentium Plus;10;400;;normal;;;LTR +T 31 w=4.3896 (<) +Mx 19.2715 +T 75 87 87 83 86 w=21.5625 (https) +Mx 40.8340 +T 29 w=2.2900 (:) +Mx 43.1241 +T 18 w=4.6924 (/) +Mx 47.8165 +T 18 w=4.6924 (/) +Mx 52.5088 +T 86 76 79 72 w=13.9014 (sile) +Mx 66.4102 +T 16 w=3.3691 (-) +Mx 69.7794 +T 87 92 83 72 86 72 87 87 72 85 w=42.2363 (typesetter) +Mx 112.0157 +T 17 w=2.2900 (.) +Mx 114.3057 +T 82 85 74 w=13.8672 (org) +Mx 128.1729 +T 18 w=4.6924 (/) +Mx 132.8653 +T 33 w=4.3896 (>) +End page +Finish diff --git a/tests/feat-urlstyle.sil b/tests/feat-urlstyle.sil new file mode 100644 index 000000000..0008562cc --- /dev/null +++ b/tests/feat-urlstyle.sil @@ -0,0 +1,11 @@ +\begin[papersize=a6]{document} +\neverindent +\nofolios +\use[module=packages.url] + +\url{https://sile-typesetter.org/} + +\define[command=urlstyle]{<{\process}>} +\url{https://sile-typesetter.org/} + +\end{document}