From d33823ddfcbd126c722c9ef406ee88109b828770 Mon Sep 17 00:00:00 2001 From: your name Date: Sat, 27 Jan 2024 22:42:06 -0500 Subject: [PATCH 1/5] Add typst support (#31) --- _extensions/fontawesome/fontawesome.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/_extensions/fontawesome/fontawesome.lua b/_extensions/fontawesome/fontawesome.lua index ff64dca..e3309b8 100644 --- a/_extensions/fontawesome/fontawesome.lua +++ b/_extensions/fontawesome/fontawesome.lua @@ -10,6 +10,14 @@ local function ensureHtmlDeps() }) end +local function ensure_typst_font_awesome() + if included_font_awesome then + return + end + included_font_awesome = true + quarto.doc.include_text("in-header", "#import \"@preview/fontawesome:0.1.0\": *") +end + local function isEmpty(s) return s == nil or s == '' end @@ -77,6 +85,13 @@ return { else return pandoc.RawInline('tex', "{\\" .. size .. "\\faIcon{" .. icon .. "}}") end + elseif quarto.doc.is_format("typst") then + ensure_typst_font_awesome() + if isEmpty(isValidSize(size)) then + return pandoc.RawInline('typst', "#fa-icon(\"" .. icon .. "\")") + else + return pandoc.RawInline('typst', "#fa-icon(\"" .. icon .. "\", size: ", size, ")") + end else return pandoc.Null() end From 6161b0eae13e57b0e6f6a133a67f0617cf085ba3 Mon Sep 17 00:00:00 2001 From: your name Date: Sun, 28 Jan 2024 14:24:27 -0500 Subject: [PATCH 2/5] Correct handling of size parameter --- _extensions/fontawesome/fontawesome.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/_extensions/fontawesome/fontawesome.lua b/_extensions/fontawesome/fontawesome.lua index e3309b8..a6be2f3 100644 --- a/_extensions/fontawesome/fontawesome.lua +++ b/_extensions/fontawesome/fontawesome.lua @@ -85,12 +85,13 @@ return { else return pandoc.RawInline('tex', "{\\" .. size .. "\\faIcon{" .. icon .. "}}") end + -- detect typst elseif quarto.doc.is_format("typst") then ensure_typst_font_awesome() - if isEmpty(isValidSize(size)) then + if isEmpty(size) then return pandoc.RawInline('typst', "#fa-icon(\"" .. icon .. "\")") else - return pandoc.RawInline('typst', "#fa-icon(\"" .. icon .. "\", size: ", size, ")") + return pandoc.RawInline('typst', "#fa-icon(\"" .. icon .. "\", size: " .. size .. ")") end else return pandoc.Null() From 9fa25353519bc9ae30cd10dccc0f0e240c211306 Mon Sep 17 00:00:00 2001 From: your name Date: Sat, 3 Feb 2024 00:58:01 -0500 Subject: [PATCH 3/5] Add support for relative sizes for Typst Also adds support for brands group + fill parameter --- _extensions/fontawesome/fontawesome.lua | 50 +++++++++++++++++++++++-- example.qmd | 3 +- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/_extensions/fontawesome/fontawesome.lua b/_extensions/fontawesome/fontawesome.lua index a6be2f3..d1242e2 100644 --- a/_extensions/fontawesome/fontawesome.lua +++ b/_extensions/fontawesome/fontawesome.lua @@ -43,6 +43,33 @@ local function isValidSize(size) return "" end +local function convert_fa_relative_size(size) + local validSizes = { + "2xs", + "xs", + "sm", + "lg", + "xl", + "2xl" + } + + local relativeSizes = { + "0.625em", + "0.75em", + "0.875em", + "1.25em", + "1.5em", + "2em" + } + + for i, v in ipairs(validSizes) do + if v == size then + return relativeSizes[i] + end + end + return size +end + return { ["fa"] = function(args, kwargs) @@ -88,10 +115,27 @@ return { -- detect typst elseif quarto.doc.is_format("typst") then ensure_typst_font_awesome() - if isEmpty(size) then - return pandoc.RawInline('typst', "#fa-icon(\"" .. icon .. "\")") + + local fill = pandoc.utils.stringify(kwargs["fill"]) + if not isEmpty(fill) then + fill = ", fill: " .. fill + end + + if not isEmpty(size) then + size = convert_fa_relative_size(size) + size = ", size: " .. size + end + + if group == "brands" then + return pandoc.RawInline( + 'typst', + "#fa-icon(\"" .. icon .. "\", fa-set: \"Brands\"" .. size .. fill .. ")" + ) else - return pandoc.RawInline('typst', "#fa-icon(\"" .. icon .. "\", size: " .. size .. ")") + return pandoc.RawInline( + 'typst', + "#fa-icon(\"" .. icon .. "\"" .. size .. fill .. ")" + ) end else return pandoc.Null() diff --git a/example.qmd b/example.qmd index e03a0f2..6ceb344 100644 --- a/example.qmd +++ b/example.qmd @@ -5,7 +5,7 @@ format: pdf: default --- -This extension allows you to use font-awesome icons in your Quarto HTML and PDF documents. +This extension allows you to use font-awesome icons in your Quarto HTML and PDF LaTeX and Typst documents. It provides an `{{{< fa >}}}` shortcode: - Mandatory ``: @@ -35,4 +35,5 @@ Note that the icon sets are currently not perfectly interchangeable across forma - `html` uses FontAwesome 6.4.2 - `pdf` uses the `fontawesome5` package, based on [FontAwesome 5](https://ctan.org/pkg/fontawesome5). +- `typst` uses the `typst-fontawesome` package - Other formats are currently not supported, but PRs are always welcome! \ No newline at end of file From 09fa6c1bb9b39f80be990206c7c771190f04fc23 Mon Sep 17 00:00:00 2001 From: your name Date: Wed, 21 Feb 2024 12:36:49 -0500 Subject: [PATCH 4/5] Fix issue w/ icons in Typst format table Also adds support for tiny to Huge size specification for typst and adds documentation of fill parameter and other format-specific parameters to the README --- _extensions/fontawesome/fontawesome.lua | 51 ++++++++++++++++--------- example.qmd | 33 +++++++++++++--- 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/_extensions/fontawesome/fontawesome.lua b/_extensions/fontawesome/fontawesome.lua index d1242e2..abcbc9c 100644 --- a/_extensions/fontawesome/fontawesome.lua +++ b/_extensions/fontawesome/fontawesome.lua @@ -50,7 +50,17 @@ local function convert_fa_relative_size(size) "sm", "lg", "xl", - "2xl" + "2xl", + "tiny", + "scriptsize", + "footnotesize", + "small", + "normalsize", + "large", + "Large", + "LARGE", + "huge", + "Huge" } local relativeSizes = { @@ -59,7 +69,17 @@ local function convert_fa_relative_size(size) "0.875em", "1.25em", "1.5em", - "2em" + "2em", + "0.125em", + "0.5em", + "0.625em", + "0.75em", + "0.875em", + "1.25em", + "1.5em", + "2em", + "2.5em", + "3em" } for i, v in ipairs(validSizes) do @@ -117,26 +137,23 @@ return { ensure_typst_font_awesome() local fill = pandoc.utils.stringify(kwargs["fill"]) - if not isEmpty(fill) then - fill = ", fill: " .. fill - end - if not isEmpty(size) then size = convert_fa_relative_size(size) - size = ", size: " .. size + size = "size: " .. size end - if group == "brands" then - return pandoc.RawInline( - 'typst', - "#fa-icon(\"" .. icon .. "\", fa-set: \"Brands\"" .. size .. fill .. ")" - ) - else - return pandoc.RawInline( - 'typst', - "#fa-icon(\"" .. icon .. "\"" .. size .. fill .. ")" - ) + if not isEmpty(fill) then + fill = "fill: " .. fill + + if not isEmpty(size) then + size = size .. ", " + end end + + return pandoc.RawInline( + 'typst', + "#fa-" .. icon .. "(" .. size .. fill .. ")" + ) else return pandoc.Null() end diff --git a/example.qmd b/example.qmd index 6ceb344..fc0e0be 100644 --- a/example.qmd +++ b/example.qmd @@ -3,9 +3,11 @@ title: Font Awesome Quarto Extension format: html: default pdf: default + typst: default --- -This extension allows you to use font-awesome icons in your Quarto HTML and PDF LaTeX and Typst documents. +This extension allows you to use font-awesome icons in your Quarto HTML, PDF LaTeX, and Typst documents. + It provides an `{{{< fa >}}}` shortcode: - Mandatory ``: @@ -13,11 +15,13 @@ It provides an `{{{< fa >}}}` shortcode: {{{< fa >}}} ``` -- Optional ``, ``, and ``: +- Optional ``, ``, ``, ``, and ``: ``` markdown - {{{< fa >}}} + {{{< fa >}}} ``` +The `title` and `label` parameters are only supported for the `html` format. The `fill` parameter is only supported for the `typst` format. The `typst` format also supports brand icons without any requirement to specify a `group` parameter. + For example: | Shortcode | Icon | @@ -26,10 +30,27 @@ For example: | `{{{< fa folder >}}}` | {{< fa folder >}} | | `{{{< fa chess-pawn >}}}` | {{< fa chess-pawn >}} | | `{{{< fa brands bluetooth >}}}` | {{< fa brands bluetooth >}} | -| `{{{< fa brands twitter size=2xl >}}}` (HTML only) | {{< fa brands twitter size=2xl >}} | +| `{{{< fa battery-half size=Huge >}}}` | {{< fa battery-half size=Huge >}} | + +::: {.content-visible when-format="html"} +HTML and Typst format-specific examples: + +| Shortcode | Icon | +| -------------------------------------------------- | ----------------------------------------- | +| `{{{< fa brands twitter size=2xl >}}}` (HTML and Typst only) | {{< fa brands twitter size=2xl >}} | | `{{{< fa brands github size=5x >}}}` (HTML only) | {{< fa brands github size=5x >}} | -| `{{{< fa battery-half size=Huge >}}}` | {{< fa battery-half size=Huge >}} | -| `{{{< fa envelope title="An envelope" >}}}` | {{< fa envelope title="An envelope" >}} | +| `{{{< fa envelope title="An envelope" >}}}` (HTML only) | {{< fa envelope title="An envelope" >}} | +::: + +::: {.content-visible when-format="typst"} +HTML and Typst format-specific examples: + +| Shortcode | Icon | +| -------------------------------------------------- | ----------------------------------------- | +| `{{{< fa brands twitter size=2xl >}}}` (HTML and Typst only) | {{< fa brands twitter size=2xl >}} | +| `{{{< fa pizza-slice size=2xl fill="red">}}}` (Typst only) | {{< fa pizza-slice size=2xl fill="red">}} | + +::: Note that the icon sets are currently not perfectly interchangeable across formats: From 6f978fdc08600e21c94db17c46c015ef8a607e51 Mon Sep 17 00:00:00 2001 From: your name Date: Wed, 21 Feb 2024 12:41:11 -0500 Subject: [PATCH 5/5] Rename fill arg to color Renamed for consistency w/ PR for color icons in HTML and LaTeX PDF formats --- _extensions/fontawesome/fontawesome.lua | 8 ++++---- example.qmd | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/_extensions/fontawesome/fontawesome.lua b/_extensions/fontawesome/fontawesome.lua index abcbc9c..cf6af4b 100644 --- a/_extensions/fontawesome/fontawesome.lua +++ b/_extensions/fontawesome/fontawesome.lua @@ -136,14 +136,14 @@ return { elseif quarto.doc.is_format("typst") then ensure_typst_font_awesome() - local fill = pandoc.utils.stringify(kwargs["fill"]) + local color = pandoc.utils.stringify(kwargs["color"]) if not isEmpty(size) then size = convert_fa_relative_size(size) size = "size: " .. size end - if not isEmpty(fill) then - fill = "fill: " .. fill + if not isEmpty(color) then + color = "fill: " .. color if not isEmpty(size) then size = size .. ", " @@ -152,7 +152,7 @@ return { return pandoc.RawInline( 'typst', - "#fa-" .. icon .. "(" .. size .. fill .. ")" + "#fa-" .. icon .. "(" .. size .. color .. ")" ) else return pandoc.Null() diff --git a/example.qmd b/example.qmd index fc0e0be..dac14ec 100644 --- a/example.qmd +++ b/example.qmd @@ -15,12 +15,12 @@ It provides an `{{{< fa >}}}` shortcode: {{{< fa >}}} ``` -- Optional ``, ``, ``, ``, and ``: +- Optional ``, ``, ``, ``, and ``: ``` markdown - {{{< fa >}}} + {{{< fa >}}} ``` -The `title` and `label` parameters are only supported for the `html` format. The `fill` parameter is only supported for the `typst` format. The `typst` format also supports brand icons without any requirement to specify a `group` parameter. +The `title` and `label` parameters are only supported for the `html` format. The `color` parameter is only supported for the `typst` format. The `typst` format also supports brand icons without any requirement to specify a `group` parameter. For example: @@ -48,7 +48,7 @@ HTML and Typst format-specific examples: | Shortcode | Icon | | -------------------------------------------------- | ----------------------------------------- | | `{{{< fa brands twitter size=2xl >}}}` (HTML and Typst only) | {{< fa brands twitter size=2xl >}} | -| `{{{< fa pizza-slice size=2xl fill="red">}}}` (Typst only) | {{< fa pizza-slice size=2xl fill="red">}} | +| `{{{< fa pizza-slice size=2xl color="red">}}}` (Typst only) | {{< fa pizza-slice size=2xl color="red">}} | :::