Dynamic tables/computation with inline shortcodes

I realized that I could use inline shortcodes to do math calculations directly in the markdown page. A pretty fun way to use Hugo for pages that involve numerical presentation or analysis.

Here are some examples of dynamic calculations, tables, and latex formulas. I’m sure others could take this a lot farther. In general, I’d say inline shortcodes are an underrated feature.

1 Like

A tip for inline shortcodes that may not be obvious from the documentation is that you can reuse the inline shortcode with the same name later in the same document, e.g.

{{< sum.inline 4.3 3.14 8.23 12.4 >}}Sum: {{ math.Sum .Params }}{{< /sum.inline >}}
{{< sum.inline 3.14159265359 6.324 />}}

The above also exploits that positional shortcode params becomes a slice that can be passed directly to math.Sum.

2 Likes