Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
11

Script for chapter margin note number collating

Engaged ,
Nov 17, 2023 Nov 17, 2023

I have a lengthy coffee table-style book where all  footnotes are given as sidenotes (margin notes). These were manually arranged and do not have any automatic collating as note references are added or deleted. Each note number and reference number in the text was added manually. Such sidenote numbering is an ideal candidate for scripting to automatically recollate as notes are added or deleted. Numbering must restart from the beginning for each chapter.

 

Does a script for this exist?

TOPICS
Scripting
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 17, 2023 Nov 17, 2023

In principle it should be straightforward, but it depends on whether the note references and the note numbers (or the notes) can be found unambiguously. Are the note references in a dedicated character style? If they aren't, is there something else that sets them apart from every else? For example, if they're superscripted, are they the only superscript numbers in the document? As to the notes, are they in a dedicated paragraph style? Or in text frames that can be found?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 17, 2023 Nov 17, 2023

Thank you for your response. Yes, the margin notes are in a dedicated paragraph style. As to the exclusive use of superscripting, of all 47 chapters, 45 use superscripting of numerals solely. Two chapters, however, needed superscripted symbols (*, ā€ , ā€”) as well as reference numbers in superscript. 

Additionally, the margin notes are uniquely in 72% grey, if that's another identifier, while body text is black. There are, however, also epigraphs in 72% grey starting each chapter.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2023 Nov 18, 2023

Looks like those notes can be converted by a slight variant of an existing script. Could you post one chapter with Arabic note numbers and one with symbols?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 18, 2023 Nov 18, 2023

Attached is an example of the Arabic reference number notes. I'm perfectly content to manually handle the two exceptional chapters that combined symbols with Arabic note references, however, if you need them to help with avoiding a script that treats all reference markers the same, I'll also put that together (copyrighted material, that has to be Latinized and have images removed). 

Very appreciative. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2023 Nov 18, 2023

Hi,@Typothalamus, I don't have your fonts so it's in pink, but you have one error - 5th SideNote Reference:

RobertTkaczyk_0-1700348604127.png

 

Anchor point is in the wrong place - part of the word before - instead of after the number and superscripted - so dedicated script would fail - if scripting person wouldn't be aware of that.

 

Here is "inside info"  - after converting your local formatting into a CharStyle "SideNote Reference":

RobertTkaczyk_1-1700348910632.png

Top part - 3x "rules" - loaded all the "references" - as mentioned above, 5th is "wrong" - all other occurences of the "SideNote Reference" include AnchorPoint of your SideNote - this little icon after the number.

 

From there - it would be easy - but I would need to see the Arabic things you've mentioned earlier.

 

And just in case, if anyone would be interested - here is a video of the converions of "plain text" Footnotes to "live" ones:

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2023 Nov 18, 2023

@Robert at ID-Tasker :

Anchor point is in the wrong place - part of the word before - instead of after the number and superscripted - so dedicated script would fail 

 

Depends on your approach. The script below searches an anchor,  inserts a note, and removes the anchor and the remaining superscript, so the order of the manual reference and the anchor doesn't matter. But in your approach you can simply search for both orders. The realities of life. Also goes for the space after the number: in this sample document that can be an ordinary space or a third-space.

 

@Typothalamus 

Below is a script to convert notes. It deals with symbol-cued notes as well. It creates a character style for the note cues and sets it in the footnote preferences (makes life easier for you and for me). The style's name is 'Footnote reference' -- if you want to use another name you can change it in the script (scripts are plain-text files).

 

As to the symbols, please check whether all symbols are accounted for in the script. I added only InDesign's default symbols (which you can't change). After the conversion of a symbol-cued document you'll need to set symbols as the numbering style in the footnote options.

 

Since you have 47 documents to convert, you can use this script to do the lot in one go:

https://creativepro.com/files/kahrel/indesign/batch_convert.html

 

(function () {
  
  var footnoteReferenceStyle = 'Footnote reference';
  
  // Return all anchored frames.
  // Make sure they're footnotes
  
  function findNotes () {
    var a = [];
    var frame;
    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = '~a';
    var s = app.activeDocument.findGrep();
    app.findGrepPreferences.findWhat = '^[\\d\\*†—§¶\\s\\.]+';
    for (var i = 0; i < s.length; i++) {
      frame = s[i].textFrames[0];
      if (/^Sidenote/.test (frame.characters[0].appliedParagraphStyle.name)) {
        // Delete the manual number
        frame.parentStory.changeGrep();
        a.push (frame);
      }
    }
    return a;
  }


  function checkStyle () {
    var s = app.documents[0].characterStyles.item (footnoteReferenceStyle);
    if (!s.isValid) {
      s = app.documents[0].characterStyles.add ({
        name: footnoteReferenceStyle,
      });
    }
    return s;
  }


  // Convert the sidenotes to footnotes
  
  var fn;
  var sidenotes = findNotes();
  for (var i = sidenotes.length-1; i >= 0; i--) {
    fn = sidenotes[i].parent.insertionPoints[-1].footnotes.add();
    sidenotes[i].texts[0].move (LocationOptions.AFTER, fn.insertionPoints[-1]);
    sidenotes[i].remove();
  }

  // Add and set a style for the cues
  
  app.documents[0].footnoteOptions.footnoteMarkerStyle = checkStyle();

  // Delete the original (manual) cues
  
  app.findGrepPreferences = null;
  app.findGrepPreferences.position = Position.SUPERSCRIPT;
  app.findGrepPreferences.appliedCharacterStyle = 
    app.activeDocument.characterStyles[0];
  app.activeDocument.changeGrep();

}());

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 19, 2023 Nov 19, 2023

I think you've misunderstood OP's request @Peter Kahrel ...

 

I'm pretty sure, @Typothalamus wants to KEEP those notes as SideNotes - in their Anchored TFs - as per design - but wants to automate re-numbering process ?

 

Of course, if I'm mistaken - I can quickly add a new "rule" for my tool.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 19, 2023 Nov 19, 2023

I think you're right, Robert. Let's see what he says.

It'll be a variant of another script šŸ™‚

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 19, 2023 Nov 19, 2023

Hi Peter, I’m guessing @Typothalamus  wants to keep the anchored sidebar "footnote" design, and not move the footnotes to the bottom of the column—I don’t think there is a way to put real footnotes in the anchored frames?

 

To keep the sidebar design, the script would have to get the superscript number from the body text and update the associated number in the anchored frame. The inconsistency of the anchor mark position @Robert at ID-Tasker mentioned would be a problem with that approach.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 19, 2023 Nov 19, 2023

Yes and no, Rob. Keeping the sidenotes in their frames and only apply automatic numbering can be handled by a variant of the script that converts footnotes to sidenotes. The paragraph style applied to the first paragraph in each note frame gets an automatic paragraph number, you set a paragraph destination in the first paragraph of a note frame, and create a cross-reference which will be the note reference. The inconsistency in the order of anchor and manual order is still no problem here.

 

Symbols are a problem in this approach because automatic paragraph numbers don't do symbols, so those two chapters should be handled separately. Typothalamus mentioned he doesn't mind doing that manually.

 

Anyway, here's the script to automate the numbering in the sidenotes. As I mentioned, it's a variant of the script that converts footnotes to sidenotes (https://creativepro.com/files/kahrel/indesign/sidenotes.html).

 

@Typothalamus -- Ignore the earlier script. As Robert and Rob pointed out I misread your post. Not to worry, here's a script that automates the numbering in your documents. Symbol-cues aren't handled.

 

Your document contains four Sidenote paragraph styles. In order to get automatic numberiung to work you can use just one. Indictae which one should be used in the second line in the script.

 

To see how you can add sidenotes and how the numbering is set up, check this page:

https://creativepro.com/files/kahrel/indesign/sidenotes.html

 

 

(function () {
  
  var noteReferenceStyle = 'Sidenote reference';
  var noteStyle = 'Sidenote 8.6p 12.5l';
  
  var indd = app.documents.item(0);
  var sidenotes;
  var destination;
  var reference;
  
  
  // Delete the original (manual) cues
  function deleteReferences () {
    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = '\\d+';
    app.findGrepPreferences.position = Position.SUPERSCRIPT;
    app.findGrepPreferences.appliedCharacterStyle = 
      indd.characterStyles[0];
    indd.changeGrep();
  }

  // Return all anchored frames.
  // Make sure they're footnotes
  
  function findNotes () {
    var a = [];
    var frame;
    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = '~a';
    var s = indd.findGrep();
    // Set up a grep for the note number
    app.findGrepPreferences.findWhat = '^[\\d\\s\\.]+';
    for (var i = 0; i < s.length; i++) {
      frame = s[i].textFrames[0];
      if (/^Sidenote/.test (frame.characters[0].appliedParagraphStyle.name)) {
        // Delete the manual number
        frame.parentStory.changeGrep();
        if (frame.parentStory.appliedParagraphStyle.name !== noteStyle) {
          frame.parentStory.applyParagraphStyle (indd.paragraphStyles.item(noteStyle), false);
        }
        if (frame.parentStory.paragraphs.length > 1) {
          frame.parentStory.paragraphs.itemByRange(1,-1).
            applyParagraphStyle (indd.paragraphStyles.item(noteStyle + ' no number', false));
        }
        a.push (frame);
      }
    }
    return a;
  }


  function checkCharacterStyle () {
    var s = indd.characterStyles.item (noteReferenceStyle);
    if (!s.isValid) {
      s = indd.characterStyles.add ({
        name: noteReferenceStyle,
        position: Position.SUPERSCRIPT,
      });
    }
    return s;
  }

  // Create a cross-ref format
  function xrefFormat () {
    var cr = indd.crossReferenceFormats.item ('Sidenote');
    if (!cr.isValid) {
      cr = indd.crossReferenceFormats.add ({
        name: 'Sidenote',
        appliedCharacterStyle: checkCharacterStyle(),
      });
      cr.buildingBlocks.add (BuildingBlockTypes.PARAGRAPH_NUMBER_BUILDING_BLOCK);
    }
    return cr;
  }


  // Duplicate the note paragraph style,
  // change the note style to numbered

  function fixNoteStyle () {
    
    function sidenoteNumberStyle () {
      var s = indd.characterStyles.item ('Sidenote number');
      if (!s.isValid) {
        s = indd.characterStyles.add ({
          name: 'Sidenote number',
        });
      }
      return s;
    }

    function numberedlist () {
      var numlist = indd.numberingLists.item ('Sidenote');
      if (!numlist.isValid) {
        numlist = indd.numberingLists.add ({
          name: 'Sidenote',
          continueNumbersAcrossStories: true,
          continueNumbersAcrossDocuments: true,
        });
      }
      return numlist;
    }

    var nonumber = indd.paragraphStyles.item(noteStyle).duplicate();
    nonumber.name = noteStyle + ' no number';
  
    indd.paragraphStyles.item(noteStyle).properties = {
      appliedNumberingList: numberedlist(),
      bulletsAndNumberingListType: ListType.NUMBERED_LIST,
      tabList: [{position: '12pt', alignment: TabStopAlignment.LEFT_ALIGN}],
      numberingCharacterStyle: sidenoteNumberStyle(),
    }
  
  }

  deleteReferences();
  fixNoteStyle();
  
  // Autonumber the sidenotes

  sidenotes = findNotes();
  for (var i = sidenotes.length-1; i >= 0; i--) {
    destination = indd.paragraphDestinations.add (sidenotes[i].insertionPoints[0]);
    reference = indd.crossReferenceSources.add (
      sidenotes[i].parent.insertionPoints[0], 
      xrefFormat()
    );
    indd.hyperlinks.add (reference, destination, {visible: false});
  }
  indd.crossReferenceSources.everyItem().update()

}());

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 22, 2023 Nov 22, 2023

Thanks @Peter Kahrel et al. Must admit, it takes me awhile to absorb the info and trace steps.
Though committed earlier to a choice of sidenote paragraph style, we're reconsidering slightly lowering its point size from 8.6 to ~8.3 and increasing leading from 12.5 to 12.6. All this incremental adjustment has been eyeballed/scrutinized in dozens of printouts at length a year ago and again now. So I must settle on one sidenote paragraph style, but again, justification varies according to a complex pattern, so I'm not quite sure how that gets to become a single paragraph style when always needing to vary the justification — will that obstruct the script?

Most of my placeholder superscripted reference numbers in the actual document are just "0s" for now, but I understand that the script, to run correctly, needs that anchor to be located just after the superscripted reference number in the body text. That's the first thing to to do. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2023 Nov 22, 2023

> So I must settle on one paragrah style, but again, justification varies according to a complex pattern, so I'm not quite sure how that gets to become a single paragraph style when always needing to vary the justification — will that obstruct the script?

 

Settle on a single paragraph style before you run the script that applies the automatic numbering. Once that's done you can apply the paragraph style with the different justification. (It's not necessary to apply that style in the notes, the script does that, using the style name you provide in the script as outlined earlier.)

 

If you can formulate a rule for how and where that second style should be applied, a script can be done for that. If it depends on the sidedness of the page (recto or verso) or on the position of the note relative to the main text, then it's a simple operation.

> Most of my placeholder superscripted reference numbers in the actual document are just "0s" for now, but I understand that the script, to run correctly, needs that anchor to be located just after the superscripted reference number in the body text. That's the first thing to to do. 

 

No: the script looks for superscripted numbers, and since zeros are numbers the script will find them. And since the script doesn't care what those numbers are it doesn't matter whether all or some are 0 or whatever number. That is, the script doesn't try to match cue numbers and note numbers.

 

Also, the script doesn't require the anchor and the superscript number to be in a particular order, or indeed to be adjacent. The automatic number is inserted at the anchor's position. In fact, the script doesn't use the superscripted numbers. It just deletes them.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 30, 2023 Nov 30, 2023

Went ahead and attempted to use the script on an older version of the book, anticipating there'd be issues. Ctrl Z does not undo the action. There's much amiss, much to unscramble. Some questions and a description of what it looks like now follow:

1. Numbering needs to restart at each chapter, not run consecutively through ~400 notes. 
2. There's an odd new spacing (far too large - it needs to be like a 'third space') introduced between note number and note text, erratically appearing. It's also bunching up some note text in an odd fashion, as if with reduced tracking.
3. Apparently all surplus notes variations that are not in the layout but retained outside the margins on the pasteboard and which not anchored to anything are intervening now in the numbering. I did not want to delete them but... a necessity?
4. Numbering is erratic, presumably due to draft notes intervening but perhaps more.
5. Notes that begin with an italicized term now have their note numbers incorrectly in italics too.
6. All note reference numbers in body text are gone. Nothing in their place. The reference numerals follow a specific style — modified in superscript height, mostly but not all tabular. 

There's likely more. See attached screenshots. 

I decided to just get hands wet rather than first clarify this in an earlier response: 

"Settle on a single paragraph style before you run the script [If we assume that size, leading, color, are settled - but other modifications that result in a "+" sign are there, do we need to worry about that?] that applies the automatic numbering. Once that's done you can apply the paragraph style [but paragraph style is currently applied - don't follow] with the different justification. (It's not necessary to apply that style in the notes, the script does that, using the style name you provide in the script as outlined earlier.)

 

"If you can formulate a rule for how and where that second style should be applied, a script can be done for that. If it depends on the sidedness of the page (recto or verso) or on the position of the note relative to the main text, then it's a simple operation."  [I really don't want the script trying to handle my justfication choices - best to leave it out and do it manually.]


Screenshot (8744).pngScreenshot (8743).pngScreenshot (8742).pngScreenshot (8741).png



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2023 Nov 30, 2023

You are only Mac user and with CS6, right?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 30, 2023 Nov 30, 2023

Close ā€” CS6, yes, but on Windows. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2023 Nov 30, 2023

Right, I've misread your post on priv. 

 

Tomorrow, I'll dig up CS6 box with DVDs and S/N and install it - so version of my tool for CS6 should be ready by Monday.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 01, 2023 Dec 01, 2023

Thank you. A single clear question in need of clarification: Peter Kahrel mentions that "unattached sidenotes" (which I leave on the pasteboard as I draft hundreds of notes and wish to keep until they're no longer needed) are easy to deal with, in terms of their interfering with numbering. How to deal with that?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2023 Dec 01, 2023

With my tool - it's extremely easy - you either start with loading only Anchored TFs - or if looking for a specific ParaStyle - like Peter is doing in his code - filter out TFs with parent as Page or Pasteboard - and that's what would have to be added in Peter's script - checking and ignoring TFs when Parent of the found TF isn't a Character.

 

I could try to modify his code - but I'm replying from my phone so maybe later. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 03, 2023 Dec 03, 2023
quote

Close ā€” CS6, yes, but on Windows. 


By @Typothalamus

 

After I've realised that I still have CS6 installed on my laptop... 

 

Quick question - do you have Photoshop installed as well? 

Because there are some rules that can interact with Photoshop - but it might fail to run if you don't have Photoshop installed. 

 

Or... I'll just prepare two versions - ID only and ID+PS+IL. 

 

And then probably more versions will be needed ... for interacting with WORD / Excel / PowerPoint / CorelDRAW etc.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 03, 2023 Dec 03, 2023

I do have the entire suite installed, yes. Also Excel, Word of course, but not Corel.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2023 Nov 30, 2023

The script I posted worked fine on the sample you provided. Given that the file that you used it on is different I'm not surprised that there are some problems. E.g. unattached sidenotes; these are easy to deal with.

 

The notes use InDesign's paragraph numbering, so numbering can be restarted at any point, and formatting such as the space between note number and text (and any punctuation after the number) can be specified in the paragraph style used for the notes.

 

Anyway, there's no point two people dealing with this, so I leave you in Robert's hands.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 01, 2023 Dec 01, 2023

Thank you for your assistance. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2023 Dec 01, 2023

I could try to modify his code - but I'm replying from my phone so maybe later.

 

Why bother with my code if you have your tool? 'Leaving in Robert's hands' included your tool, not someone else's script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2023 Dec 01, 2023

I know, but it would be a bit quicker to modify your script - rather than waiting for me to prepare CS6 version?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines