Skip to main content
Participating Frequently
November 10, 2011
Answered

Is it possible to make reverse/backward dynamic endnotes?

  • November 10, 2011
  • 2 replies
  • 5548 views

Hello everyone,

I am a beginner of InDesign and I am learning how to use it both for printed books and EPUBs.

I am writing because I was wondering if there was a way, through scripts, to link the endnote text (or just its number) to the endnote reference number in the main text.

The reason is that when exporting to EPUB, InDesign properly makes all the links of the dynamic endnotes, but not the reverse ones, so getting back to the main text after having read the endnote can be a pain when using ereaders that don't have the "go back" function.

My workflow to solve the problem at the moment is to use Peter Kahrel's end2end script to make the dynamic endnotes (and it saves me tons of time!) and then manually do the reverse links either by using the endnote text as the link or by placing a small back arrow at the end of the text, that links to the endnote reference in the main text.

But given that I have hundreds of notes to do, some automatization would be of great help.

All the best


Clemens

This topic has been closed for replies.
Correct answer cramik

Thank you very much.

I just sent you a Private Message with the link to the file and the names.

I am really excited about the idea of php to skip the manual copy and paste work!


Hi Clemens,

I'll put the code online so it may be usefull to others (and mayby someone can improve on it or find an indesign-solution)

You'll have to

  1. create a folder in htdocs
  2. add a folder named "input" and one named "output".
  3. Put your html-files in the input folder.
  4. Put this code in a file in the root of the folder that contains both directories.
  5. Run it in your browser.
  6. Done... You'll find your changed files in the output-folder - they will show up as links so you can check them at once

Take care: if you recompress the files to zip and change back to epub the mimetype file must be added to the archive first and without compression - the other files can then be added with highest compression.

<?php

$filenames = array();

//loop through input directory and put all files in an array

if ($handle = opendir('./input')) {

    while (false !== ($entry = readdir($handle))) {

        if ($entry != "." && $entry != "..") {

            $filenames[]=$entry;

        }

    }

    closedir($handle);

}

//fill variable with contents of each file, one file at a time

$tekst ="";

foreach($filenames as $key => $filename){   

        $startfile = "./input/".$filename;

        if (file_exists($startfile)) {

            $fo = fopen($startfile, "r");

            while ( $line = fgets($fo) ) {

                $tekst .= $line;

            }

//link endnote references in 2 directions   

        //protect class in endnote-text --> not necessary if class of numbers in endnote-text is different from class of numbers in text

        $tekst = str_replace('<p class="Testo-note"><span class="Super">','<p class="Testo-note"><span class="##Super">',$tekst);

        //put anchors before endnote-numbers and link to endnote-text

        $tekst = preg_replace('/(<span class="Super">)(\\d+)/', '<a id="notenumber$2"></a>$1<a href="#notetext$2">$2</a>', $tekst);

        //reverse protection --> not necessary if class of numbers in endnote-text is different from class of numbers in text

        $tekst = str_replace('<p class="Testo-note"><span class="##Super">','<p class="Testo-note"><span class="Super">',$tekst);

        //put anchors before endnote-text and link to endnote-numbers

        $tekst = preg_replace('/(<p class="Testo-note"><span class="Super">)(\\d+)/', '<a id="notetext$2"></a>$1<a href="#notenumber$2">$2</a>', $tekst);

        //change inputfolder to outputfolder and write changed file to outputfolder

        $endfile = str_replace("input","output",$startfile);

        $fo = fopen($endfile, "w");

        fwrite($fo,$tekst);

        $tekst ="";

        }

}

//display changed files as link

if ($handle = opendir('./output')) {

    while (false !== ($entry = readdir($handle))) {

        if ($entry != "." && $entry != "..") {

            echo "<br /><a href='./output/".$entry."'>".$entry."</a>";

        }

    }

    closedir($handle);

}

?>

2 replies

Clemens14Author
Participating Frequently
March 15, 2012

Hello,

I am getting a bit desperate

I really wished there was a script that could transform static endnotes into dynamic bi-directional endnotes or footnotes.

Could anyone at suggest me some good resources to learn how to modify scripts?

It will take me less to learn a new programming language than to manually do all the notes.

Plus it's a skill that might be useful for other things as well in the future.

Al the best.

Inspiring
January 31, 2012

Hi Clemens,

Did you ever get an answer to this question?

I'm struggling with the same problem.

I've solved the EPUB-part of it by doing a grep-search-replace with PHP in the HTML-file of the EPUB-export.

Clemens14Author
Participating Frequently
March 19, 2012

Hi,

unfortunately I haven't got an answer yet, so I am trying to learn indesign scripting. By the way, what was your PHP solution?

All the best

P.s. did you get my PM?

New Participant
June 13, 2012

You're very welcome


cramik

This thread has been most valuable and I've managed to use the code and XAMPP software to create bidirectional endnotes in a single XHTML file using your method.  However, when my epub comprises multiple XHTML files, and I load all the files into the 'Input' folder and get the corresponding files produced in the 'Output' folder, although all the note refs and endnotes are highlighted as links, they do not link to their corresponding detstinations in the other XHTML files.

Am I missing something - if the epub is multiple XHTML files, should I be doing something different?

Thanks

Steve