diff --git a/classes/resilient/book.lua b/classes/resilient/book.lua index 1d9beb2..a9d468f 100644 --- a/classes/resilient/book.lua +++ b/classes/resilient/book.lua @@ -688,11 +688,20 @@ function class:registerCommands () local letter = content[1] local dropcapSty = self.styles:resolveStyle(style) - local family = dropcapSty.font and dropcapSty.font.family local lines = dropcapSty.special and dropcapSty.special.lines - - SILE.call("use", { module = "packages.dropcaps" }) - SILE.call("dropcap", { family = family, lines = lines, join = join }, { letter }) + if not lines then + -- Fallback to regular style + SILE.call('style:apply', { name = style }, { letter }) + else + local color = dropcapSty.color + local family = dropcapSty.font and dropcapSty.font.family + if dropcapSty.properties or dropcapSty.decoration then + -- I am not convinced the extra complexity is worth it for such an edge case. + SU.warn("Dropcap style does not support properties and decoration") + end + SILE.call("use", { module = "packages.dropcaps" }) + SILE.call("dropcap", { family = family, lines = lines, join = join, color = color }, { letter }) + end end, "Style-aware initial capital letter (normally and internal command)") self:registerCommand("initial-joined", function (options, content) diff --git a/examples/manual-styling/advanced/dropcap.md b/examples/manual-styling/advanced/dropcap.md new file mode 100644 index 0000000..28856fb --- /dev/null +++ b/examples/manual-styling/advanced/dropcap.md @@ -0,0 +1,29 @@ +## Styling initial capitals + +Initial capitals (also known as drop caps) are a typographic feature where the first letter of a paragraph is enlarged and styled differently from the rest of the text. +The **resilient.book** class defines two commands for this purpose: `initial-joined` and `initial-unjoined`. +The former should be used when the initial capital is part of the first word of the paragraph, and the latter when it is a separate character. + +In Markdown or Djot, you may use one or the other directly as a style (although they are rather pseudo-styles, strictly speaking). + +By default, these commands rely on the `dropcap` style, which is a regular character style with an additional `special` property that specifies the number of lines to drop. +The color and font family of the drop cap can be customized as well, but other properties from character styles are ignored. +For instance, here is how a drop cap style using the Zallman Caps font and a somewhat "cerulean" color can be defined. + +```yaml +dropcap: + style: + color: "#66a0b3" + font: + family: "Zallman Caps" + special: + lines: 3 +``` + +Note that the style is supposed to be used on the initial letter of a paragraph. +The implementation does not make any attempt to enforce this, and the result may be unexpected if the style is applied to other characters. +Likewise, you are on your own if you want to style subsequent characters in a certain way --- such as using small capitals for a word or a group of words, as is common in some typographic traditions. Here is a typical example of how to use the `initial-joined` style in a Markdown or Djot document. + +``` +[L]{custom-style=initial-joined}[orem ipsum]{.smallcaps} dolor sit amet... +``` diff --git a/examples/sile-resilient-manual.silm b/examples/sile-resilient-manual.silm index e5d0805..a07c960 100644 --- a/examples/sile-resilient-manual.silm +++ b/examples/sile-resilient-manual.silm @@ -71,6 +71,7 @@ parts: - manual-styling/advanced/toclevels.md - manual-styling/advanced/liststyles.md - manual-styling/advanced/eqno.md + - manual-styling/advanced/dropcap.md - manual-styling/advanced/other.md # unfinished # - manual-styling/captioned.md