Forum How do I...?

Link footnote callout to the footnote marker & vica versa

allenb
I want my footnote callouts to be linked to the footnote markers at the bottom of the page, and the footnote marker to br linked back to where the footnote callout is located in the text.
Latex do this automatically, is it possible to make a similar behavior using prince?
mikeday
At the moment I do not think it is possible to do this with Prince, although I guess we could add support for it at some point. It seems like it would be a more useful feature for end notes, which are not on the same page.
Alex McKee
I do this, or rather I have the footnote callout link to the footnote in question although I don't link back to the footnote callout from the marker.

I do by using Textile to generate my HTML. Textile has it's own footnotes feature which allows you to place the footnote itself wherever you want. Textile generates a unique ID for the footnote callout and links to the footnote marker. It's then trivial to use float: footnote to have the footnote displayed in the footnotes area.

You do have to remove the duplicate footnote call out generated by Prince but that's easy enough to do:

.footnote::footnote-call {
content: none;
}


You could hack on the Textile library to provide the link back to the callout from the marker.

You'd add a variant of the same ID to the callout:

	function footnoteID($id, $t)
	{
		if (empty($this->fn[$id]))
			$this->fn[$id] = uniqid(rand());
		$fnid = $this->fn[$id];
		return '<sup class="footnote"><a href="#fn'.$fnid.'" id="callout'.$fnid.'">'.$id.'</a></sup>'.$t;
	}


Then modify the code that generates the marker to include a link back to the callout:

if (preg_match("/fn(\d+)/", $tag, $fns)) {
			$tag = 'p';
			$fnid = empty($this->fn[$fns[1]]) ? $fns[1] : $this->fn[$fns[1]];
			$atts .= ' id="fn' . $fnid . '"';
			if (strpos($atts, 'class=') === false)
				$atts .= ' class="footnote"';
			$content = '<a href="#callout' . $fnid . '">^</a>' . $content;
		}


If you're not using PHP Textile is also available in other languages - perl, ruby etc.
Hope this helps.