LaTeX-niques for HSC

If you have used LaTeX ([Lamport85], [Knuth79]), you will find HTML fairly lacking in a lot of areas. For example, managing your bibliography and citations is a breeze in LaTeX; you can insert footnotes in the text right where they refer to and they still appear where they belong at the bottom of the page; you can move sections and subsections around as you like and they always get the correct numbering and entries in a table of contents, if you want one. Looking at these pages you will have guessed already that the former two things are exactly what HSC can do for you in HTML! And there will be a solution for the latter problem too...

The whole problem is basically about reordering text blocks: stuff has to disappear from where you put it in your source and appear elsewhere, possibly reformatted. LaTeX uses several files for this purpose, ending in .toc, .aux, .lof etc., where it puts the table of contents, bibliography information and the "list of figures" respectively, and which it reads in again on the next compiler run. That means that if you add a new entry to the bibliography and refer to it in the text, you will get an error in the first run where the reference is still unknown when LaTeX processes the \cite{} directive. It is then added to the aux-file and will be known in the next run. In a system that doesn't have an "overview" of the entire text but goes through it from top to bottom in one run, this is the only possibility to propagate information upwards in the text. HSC works in a similar way, however, we can exploit an advantage of HTML over paper that saves us this hassle at least for simple bibliographic references.

But let's postpone this for a while and start with footnotes, both because they are more interesting and because unless you're going to write your seminar papers in HTML1 you're less likely to need literature lists than footnotes, which are quite useful even in, say, online tutorials and manuals :-)

To be as TeXy as possible, I wanted a container macro that behaves like the LaTeX macro "\footnote{This is a footnote!}" that where it appears turns into a little superscript number and the text gets moved to the bottom of the page. Of course we don't know where the bottom of the page is in HTML as it all depends on the browser's layout, so the bottom of the document will have to do. So, let's make a simple container:

<$macro FOOTNOTE /CLOSE>
</$macro>

The macro will have to add its contents to some sort of accumulator, which could be a file, but as HSC deals nicely with arbitrarily long strings we can just as well save the overhead and use a simple string variable. We don't want to have to define it beforehand though, but just use <FOOTNOTE> and let the macro handle the rest. So <FOOTNOTE> has to check whether the accumulator variable exists already, and define it if it doesn't. And while we are at defining variables: we'll need another one that counts the footnotes on the current page, to get the right links and lables. Both should have fairly long names so it's unlikely they'll clash with anything a user might define—after all, they're GLOBAL variables!

<$macro FOOTNOTE /CLOSE>
  <$if COND=(defined the_footnote_counter)>
    <$let the_footnote_counter=(the_footnote_counter & "1")>
  <$else>
    <$define the_footnote_counter:num/GLOBAL=1>
    <$define the_footnote_bucket:string/GLOBAL=''>
  </$if>
</$macro>

There are two alternatives in this macro: either this is the first footnote in the text, in which case "(defined the_footnote_counter)" will be FALSE, or there have been footnotes before. If the variable is not yet defined, the macro creates both the counter and the string to store all footnotes in. If it is, the counter is just incremented2.

Now that we have a counter that starts at one with the first note and then increases, we can start to process the actual footnote text. As we're doing hypertext, a link to the note is a must, so the reader doesn't have to remember the current position when scrolling to read the footnotes. Let's create a name for the note:

<$define ftnname:string/CONST=('footnote' + the_footnote_counter) >

This is a local constant. Now for the variable: the_footnote_bucket. Because the footnotes should appear sorted at the bottom of the document, an ordered list (<OL>) lends itself naturally to this task. So each note has to be a list element with an anchor for a named location, like this:

<A NAME="footnote1"></A><LI>The note</LI>3

All that has to be done is to add this line to the accumulator variable and emit the current counter as a superscripted number.

<$let the_footnote_bucket = (the_footnote_bucket +
  '<A NAME="' + ftnname + '"></A><LI>' +
    Hsc.Content + '</LI>' + HSC.LF)>
<SMALL><SUP>
<A HREF=('#' + ftnname)><(the_footnote_counter)></A>
</SUP></SMALL>

This builds the above list entry as a string, appended to the_footnote_bucket, and outputs something like <SMALL><SUP>1</SUP></SMALL> as the macro's result. The linefeed (HSC.LF) at the end of the string is not really necessary, it just improves the readability of the output before you treat it to your favorite HTML-compactor.

After running a document with a bunch of footnotes through HSC, we have them nicely replaced by little numbers, but they don't appear anywhere yet, and HSC complains about all those unknown IDs that the numbers link to. Right —the string that we filled so carefully with the notes has to go somewhere! Basically, all we have to do is open a list, insert its contents and close the list. Oh, and wrap all that in a macro of course, so we don't have to type it every time:

<$macro FOOTNOTES>
  <OL>
  <(the_footnote_bucket)>
  </OL>
</$macro>

Straightforward. Perhaps you'd like to insert this into your <WEBPAGE> macro, so it not only closes the <BODY> and <HTML> tags but also inserts all footnotes if there are any?
Hm. If...and if not? "error 20: unknown attribute the_footnote_bucket"! OK, one more <$if> seems to be required. Do you also want a title, like "Footnotes"? Or a ruler above it, as TeX thinks it should be? There's still a bit to improve about this basic macro!

2 b continued!

Bibliography

[Knuth79]Donald E. Knuth: TeX and Metafont, New Directions in Typesetting. Bedford, MA, The American Mathematical Society and Digital Press: 1979
[Lamport85]Leslie Lamport: LaTeX – A Document Preparation System – User's Guide and Reference Manual. Reading, Addison-Wesley: 1985
[W3C-99]The W3 Committee: HTML 4.01 Strict DTD: 1999

Footnotes
  1. Which is what I developed these macros for :)  [back]
  2. Yes, that's an addition. HSC uses "+" for string concatenation! [back]
  3. The </A>-tag could also be after the </LI>, but this would disallow the use of links in a footnote, because anchors don't nest [W3C-99].  [back]

Last change: 28-Apr-2006, 10:50

You are not supposed to see this—arachnoids only: nude metal goth porn tits video i phone thai hentai gangbang girls i touch lolita emo slutsparis ghettoschlampen arschgeficktgay geigh salope enculée pédé