From cfd1b0a33e4076fb14956634708972c76a6ba3ee Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Wed, 18 Feb 2026 21:49:06 -0800 Subject: [PATCH 1/2] Render math in RSS with MathML --- build.scala | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/build.scala b/build.scala index d0be8051..109b4293 100644 --- a/build.scala +++ b/build.scala @@ -283,9 +283,9 @@ object LaikaCustomizations { SpanDirectives.create("math") { import SpanDirectives.dsl.* rawBody.map { body => - RawContent( - NonEmptySet.of("html", "rss"), - KaTeX(body, false) + SpanSequence( + RawContent(NonEmptySet.of("html"), KaTeX(body, false)), + RawContent(NonEmptySet.of("rss"), KaTeX(body, false, "mathml")) ) } } @@ -294,10 +294,13 @@ object LaikaCustomizations { BlockDirectives.create("math") { import BlockDirectives.dsl.* rawBody.map { body => - RawContent( - NonEmptySet.of("html", "rss"), - KaTeX(body, true), - Styles("bulma-has-text-centered") + BlockSequence( + RawContent( + NonEmptySet.of("html"), + KaTeX(body, true), + Styles("bulma-has-text-centered") + ), + RawContent(NonEmptySet.of("rss"), KaTeX(body, true, "mathml")) ) } }, @@ -342,6 +345,13 @@ object LaikaCustomizations { val defaultRenderer = { case (fmt, Title(_, _)) => "" // don't render title b/c it is in the RSS metadata + case (fmt, RawContent(formats, content, options)) => + if (formats.contains("rss")) // only render content designated for RSS + HTML.defaultRenderer( + fmt, + RawContent(NonEmptySet.of("html"), content, options) + ) + else "" case (fmt, elem) => HTML.defaultRenderer(fmt, elem) } @@ -436,12 +446,17 @@ object KaTeX { ctx.getBindings("js").getMember("katex") } - def apply(latex: String, displayMode: Boolean = false): String = + def apply( + latex: String, + displayMode: Boolean = false, + output: String = "htmlAndMathml" + ): String = synchronized { val options = Map( "throwOnError" -> true, "strict" -> true, - "displayMode" -> displayMode + "displayMode" -> displayMode, + "output" -> output ) katex.invokeMember("renderToString", latex, options.asJava).asString } From f10d6751757bd12bc1df81c4a1c23247f9bcf4d2 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Thu, 19 Feb 2026 08:47:50 -0800 Subject: [PATCH 2/2] Link to katex options doc --- build.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/build.scala b/build.scala index 109b4293..f75bb97b 100644 --- a/build.scala +++ b/build.scala @@ -452,6 +452,7 @@ object KaTeX { output: String = "htmlAndMathml" ): String = synchronized { + // https://katex.org/docs/options val options = Map( "throwOnError" -> true, "strict" -> true,