0

yeah i have a problem. So i have a script which puts all footnotes at the end of the document and makes crossreferences from the little number in text to the fitting endnote. now i want to add a backlink, so when i have a long document(book) i dont have to scroll back by hand, but can just click on the endnote and get back.

by now i have managed to get the endnotes as crossref sources, but i struggle with the crossrefdestination

when i use footnote.storyOffset as destination, it screws up the numbering of the footnotes in text. for example the first footnote just disappears from text, then there comes 1,3,3,4,5,7... and so on. why does this happen?? im just using this insertion point as destination and suddenly it screws up everything.

it would also be enough to put the footnote numbers manually into the text, but i dont know how to delete the scrambled numbers in the text. i could also use the next or previous character as insertionPoint, but how do i get there?

Im pretty new to that indesign script stuff. hope somebody can help me.

here is the critical part of the source:

stories[j].insertionPoints[-1].contents = SpecialCharacters.PAGE_BREAK; // add new page for notes
        stories[j].insertionPoints[-1].contents = 'Notes';// title
        footn = stories[j].footnotes;
        for (var i = 0; i < footn.length; i++)
        {
            stories[j].insertionPoints[-1].contents = '\r';
            endnote = footn[i].texts[0].move (LocationOptions.after, stories[j].insertionPoints[-1]);
            endnote.applyParagraphStyle (note_styles.first, false);
            if (i === 0)
            {
                endnote.numberingContinue = false;
                endnote.numberingStartAt = 1;
            }
            if (endnote.paragraphs.length > 1)
            {
                endnote.paragraphs.itemByRange (1,-1).applyParagraphStyle (note_styles.next, false);
            }
            //var stoff = footn[i].storyOffset;
            //stoff.contents = ''+(i+1);
            //stoff.applyCharacterStyle(note_styles.char_style_in_text);
            //stoff.appliedCharacterStyle.position= Position.superscript;

            backlink_destination = doc.paragraphDestinations.add (footn[i].storyOffset); // position of footnote in text
            endnote_destination = doc.paragraphDestinations.add (endnote.insertionPoints[0]);

            try
            {
                crb = app.activeDocument.crossReferenceFormats.add({name:'backlink'+i});
                crb.appliedCharacterStyle = note_styles.char_style_endnote;
                crb.buildingBlocks.add (BuildingBlockTypes.customStringBuildingBlock);
                crb.buildingBlocks.anyItem().customText = endnote.contents;
            }
            catch(_)
            {
                crb = app.activeDocument.crossReferenceFormats.item ('backlink'+i);
            };

            backlink_source = doc.crossReferenceSources.add (endnote, crb); // position of note at end of story
            endnote_source = doc.crossReferenceSources.add (footn[i].storyOffset, note_styles.cr_format);

            doc.hyperlinks.add(backlink_source, backlink_destination, {visible: false}); //add link from notes to text
            doc.hyperlinks.add(endnote_source, endnote_destination, {visible: false});
        } // for
fredlllll
  • 75
  • 8

1 Answers1

0

fixed it:
i just flipped the order of making the crossrefs.

i flipped the following lines

backlink_destination = doc.paragraphDestinations.add (footn[i].storyOffset);
endnote_destination = doc.paragraphDestinations.add (endnote.insertionPoints[0]);

to

endnote_destination = doc.paragraphDestinations.add (endnote.insertionPoints[0]);
backlink_destination = doc.paragraphDestinations.add (footn[i].storyOffset);

and

backlink_source = doc.crossReferenceSources.add (endnote, crb);
endnote_source = doc.crossReferenceSources.add (footn[i].storyOffset, note_styles.cr_format);

to

endnote_source = doc.crossReferenceSources.add (footn[i].storyOffset, note_styles.cr_format);
backlink_source = doc.crossReferenceSources.add (endnote, crb);

and

doc.hyperlinks.add(backlink_source, backlink_destination, {visible: false});
doc.hyperlinks.add(endnote_source, endnote_destination, {visible: false});

to

doc.hyperlinks.add(endnote_source, endnote_destination, {visible: false});
doc.hyperlinks.add(backlink_source, backlink_destination, {visible: false});

i dont know why, but it works when put in this order... this doesnt testify to good software...
how could i expect good software for that price?

giorgian
  • 3,795
  • 1
  • 30
  • 48
fredlllll
  • 75
  • 8