With a few caveats, making footnotes and similar cross-references in ebooks is pretty simple. The idea is to use html anchors, which can be inserted directly into your html (if you’re doing it that way…) or by using Sigil (if you have exported an epub file from InDesign, for example). Both your text editor used for editing the html (TextMate, BBEdit, etc) and Sigil support the use of regular expressions for searching, so that the footnotes can be identified in some unique fashion and replaced all at once.
First, the anchors. You can learn more about html anchors elsewhere; this is just a really simple-minded introduction that assumes you have just one file, not several–so I usually do *not* break my epub or html files into chapters. The idea is to go both forward and back–so if you click the link on the note, it takes you to the list of footnotes, but then you can go back again.This works:
At each reference, put in the following:
<a href=”#fn(number)” name=”fr(number)”>[number]</a>
Then at the footnotes themselves:
[<a name=”fn(number)” href=”#fr(number)”>(number)</a>]
where (number) is the number of your footnote, from 1 up to whatever. All this does is make a back-and-forth link to other places within the same html text. If you have other cross-references in the text, they can be handled the same way–just give them a different name, for example, use “app” for appendix instead of “fr.”
OK, that’s easy… but how to get this rather beastly expression around each of your innocent little footnotes, which are often just a number? Here’s where the beauty of regular expressions comes in. You can do a regular expression search for any number of digits “\d+”and bracket that with your reference. Watch out, though, if there are other numbers in your text! Often there is something else that identifies your footnotes: they’re in parentheses, or in superscript, or some other specific format. In my latest example, the footnotes were all in a specific style defined by InDesign. So when I opened the exported Epub in Sigil, all footnotes looked like this:
<span class= “char-style-override 7”>number</span>
So, using regular expressions:
Search: <span class= “char-style-override 7″>(\d+)</span>
Replace: <a href=”#fn\1″ name=”fr\1”>\1</a>
Where “\1” is regular expression-ese for “that same text that you found” (some editors use $1). It’s important to put the “\d+” inside a pair of parentheses–that tells the regular expression search to “capture” the contents of the parentheses for later use. the “\1″ tells the replace to use the contents of the capture. (note that if you have more than one set of capture parentheses, the first one captures into \1 and the second into \2, and so on. That’s a topic for a different day…)
Now that that’s all done, go down to the footnotes themselves. There are lots of numbers in footnotes referring to pages and things, so you don’t want to pick them up by accident. Let’s say the numbers you want to link to are encased in square brackets. Then your life is pretty easy. Do this:
Replace: [<a name=”fn\1″ href=”#fr\1”>\1</a>]
The lesson to take home from this is that if you’re exporting from a program such as Word or InDesign, you want to have tags on your footnotes that make them easily searchable. If they can be identified in a unique fashion, then formatting them for your e-book is as simple as Search & Replace. The most important thing is to be very consistent so the search can find them!
If there are no tags, you have to be very careful using “Replace All,” and may have to scroll through one by one to make sure only the desired targets are chosen, and not some innocent other text with numbers in it.
Happy footnoting! Quack.