-- Leo's gemini proxy

-- Connecting to rkta.srht.site:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

Rene Kita's weblog


Blog[0] About[1] RSS[2] Links[3]


HTML footnotes with m4


2023-01-05


When I worked with LaTeX I used a lot of footnotes. I don't know why but I love them!


Manually taking care of the numbering can be tedious and I felt like I should learn a little bit more m4. So I added two macros#0 to my Static Site Generator[4] that I use to build my blog.


Let's have a look:


$ nl stddef.m4 | grep __fn
15	define(`__fnc', 0)
16	define(`FN', `$1<a href=`#'__fnc>`#'__fnc</a>define(`__fnc', incr(__fnc))')
17	define(`__fnlc', 0)
18	define(`FNL', `<li id=__fnlc>__fnlc: $1</li>define(`__fnlc', incr(__fnlc))')

In a nutshell: We have two counter variables __fnc and __fnlc and two macros FN and FNL. FN is used to mark the word the footnote is attached to and FNL to create a list entry at bottom of the page.


<p>Some text inside a HTML document that needs a footnote`'FN.</p>
...
<ul>
FNL(Nothing to see here)
</ul>

I don't want a space between the word and the footnote marker. m4 would not recognize the macro if I would write footnoteFN. One way to circumvent this is to use an empty quoted string like you see above. As I did design the macro to take a parameter you could also use FN(footnote).


The trick is that the macro we call contains a redefinition of the counter variable in which we increase the counter variable every time we invoke the macro. That way I only#1 need to keep the actual foot note entries in the correct order.


0: Actually four macros

1: Yeah, well, only...


Last modified: 2023-01-05T10:20:16Z


E-mail: mail@rkta.de[5] IRC: #rkta[6] on Libera.Chat[7]

Copyright (c) 2017-2024 Rene Kita


[0] Blog

[1] About

[2] RSS

[3] Links

[4] Static Site Generator

[5] mail@rkta.de

[6] #rkta

[7] Libera.Chat

-- Response ended

-- Page fetched on Fri May 10 16:40:58 2024