Footnotes and References in Ebooks

Tags

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=”#fn1″ name=”fr1”>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:

Search: [(d+)]

Replace: [<a name=”fn1″ href=”#fr1″>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.

7 Responses to “Footnotes and References in Ebooks”

  1. Someone says:

    I can’t thank you enough. Before I came across this I had done this all by hand. This will save me soooo much editing time. Thanks !

  2. Wiseguy says:

    Big mistake my friend, instead of \1 it should be $1, did I waste some time looking for what was wrong !!!
    Replace: [\1]

  3. admin says:

    Wiseguy – it depends on what program you’re using and how you’re using it. BBEdit and TextWrangler use \1. Sigil also uses \1. Perl (which we also use a lot for such things) uses \1 if you do the search and replace using the standard s/pattern/replacement_pattern/ method, but if you want to do it in two steps you’d use $1 in the next few lines of code. And we did note in the explanation of the search and replace strings that some editors use \1 and some use $1 (Indesign may use $1, but we don’t do so much grepping in that).

  4. David S says:

    Hello all! I am having some difficulties with footnoting a scholarly book for my employer.

    We have the links working so that you can click an endnote-reference in the body of the text and be redirected to the appropriate spot in the endnote page. And we have backlinking set up so you can click the number on the endnote page and go back to where you were reading in the body of the text.

    However, we are now working on FORMATTING.

    The difficulty I’m having is twofold:

    1.) I want a hanging indent that will look something like this:

    9. Author name. Title. Publisher info and various other text taht would cause text to wrap around to a second which
    will have a hanging indent like this.

    I think I can probably pull this off using a 3em margin and a -3em text indent.

    However, the other problem that is compounding with it is this: we want the numbers to line up by decimal point, not by the first number.

    What I mean is this:

    1.
    10.
    110.

    as opposed to:

    1.
    10.
    110.

    I can just insert spaces to pull it off, but that only works if the person reading uses the same font. If the reader changes fonts and sizes etc., the whole thing is going to look cattywompus!

    I’ve been scouring the web for a simple answer on this and can’t seem to find a straight answer.

    Is there, or is there not a way to get endnumbers to line up like this? Would I basically have to make all of my endnotes ordered lists? If so, I can’t do that because we use an automated .docx-to-HTML process called ScribeNet.

    Thanks for your assistance.

  5. glenn says:

    does the code at the footnote itself act as a “return” button, or does that have to be inserted separately?

  6. BestArlene says:

    I have noticed you don’t monetize bitingduckpress.com, don’t waste your traffic, you can earn extra bucks
    every month with new monetization method. This is the best adsense alternative for any type of website
    (they approve all sites), for more details simply search
    in gooogle: murgrabia’s tools


Leave a Reply

Copyright © 2024 Bitingduck Press. Icons by Wefunction. Designed by Woo Themes