• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

GREP for endnote reference chains

Community Expert ,
Aug 25, 2024 Aug 25, 2024

Copy link to clipboard

Copied

I am processing a textbook that has a formatting situation I've never had to deal with in bulk  — multiple endnote references in a row. I've  encountered books with the occasional twofer, and those are easy enough to spot and adjust during normal formatting, but this book has a dozen or more per chapter, and for all reasons of efficiency and consistency I'd like to automate the process.

 

Here's a typical clip—

JamesGiffordNitroPress_0-1724606418649.png

 

The text style is BODY and may be one of several variants.

 

The endnote style REFS is applied by the Endnote setup of the document, which puts all elements in the style (i.e., leaves the reference marker Normal, not superscripted). It can be assumed that there will be two to five markers in a row, with a comma but no spaces between them. (There should be NO spaces ahead of markers, and one ONLY after the last.)

 

(Poorly chosen example, perhaps, in that the comma ahead of the first marker is common and needs to remain as is, but most markers will follow word text or normal punctuation. Also, the red highlight is just a formatting convenience that will be changed to black or 80%K in the final.)

 

All I want to do is apply REFS to those commas. and I've found partial solutions, but neither lookahead nor lookbehind seems to be able to handle the ~U marker wildcard.


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋
TOPICS
How to , Scripting , Type

Views

523

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Aug 25, 2024 Aug 25, 2024

~U,

 

Votes

Translate

Translate
Community Expert ,
Aug 25, 2024 Aug 25, 2024

Copy link to clipboard

Copied

Find:

 

~U,~U

 

Change to:

(apply char style REFS)

 

Votes

Translate

Translate

Report

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 ,
Aug 25, 2024 Aug 25, 2024

Copy link to clipboard

Copied

O so simple... but doesn't quite work and despite tinkering, I can't figure out why.

 

For a chain of refs like this —

20,30,40,50,60

that search or GREP will find 20,30 and 40,50 but not the other two commas. I think the partial overlap in the search keeps it from seeing 40 as a first element. Same for chains of three  — the third REF and its leading comma are skipped.

 

And ,^U finds examples where the ref follows a text comma.

 

This should be trivial and I've gone through a dozen iterations. Look/ahead/behind not working really limits options.


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

Votes

Translate

Translate

Report

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 ,
Aug 25, 2024 Aug 25, 2024

Copy link to clipboard

Copied

There was a thread about that few months / years ago... 

 

What if you run:

 

~U,~U,~U

 

2x and 3x should cover all situations?

 

 

OR... 

 

As long as you won't have comma AFTER... 

 

~U,

 

Votes

Translate

Translate

Report

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 ,
Aug 25, 2024 Aug 25, 2024

Copy link to clipboard

Copied

Well, there are any number of solutions that are semi-automatic, and as this is a one-and-done project I can do it that way. But with nineteen long chapters and hundreds of refs in each one, used as often in combination as singularly... one reliable trick would be nice. 🙂


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

Votes

Translate

Translate

Report

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 ,
Aug 25, 2024 Aug 25, 2024

Copy link to clipboard

Copied

~U,

 

Votes

Translate

Translate

Report

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 ,
Aug 25, 2024 Aug 25, 2024

Copy link to clipboard

Copied

That seems to work and wouldn't be too onerous to step through — to be cautious — once on each chapter. Call it a solution.


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

Votes

Translate

Translate

Report

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 ,
Aug 25, 2024 Aug 25, 2024

Copy link to clipboard

Copied

How about this one:

(~U,?)+

It applies REFS to series of ~U, -- the question mark is needed to match the last reference because that one isn't followed by a comma.

Votes

Translate

Translate

Report

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 ,
Aug 25, 2024 Aug 25, 2024

Copy link to clipboard

Copied

That works, too, but the actual ref markers already have the character style applied from the document defaults.

 

This is getting a bit more complex than I first thought, as the usual sloppy Word manuscript can have almost any combination of space, comma and ref marker, in any order. I'm about to do an iterative restart of the layout and need to analyze the pattern to see if there's a consistent set of Find/Replace/GREP that will fix all problems without damaging any other content. Sigh.


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

Votes

Translate

Translate

Report

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 ,
Aug 26, 2024 Aug 26, 2024

Copy link to clipboard

Copied

> That works, too, but the actual ref markers already have the character style applied from the document defaults. That doesn't hurt, does it?

Votes

Translate

Translate

Report

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 ,
Aug 25, 2024 Aug 25, 2024

Copy link to clipboard

Copied

Hi @James Gifford—NitroPress, I wonder if you have run into a bug?

 

FindGrep ~U works fine:

Screenshot 2024-08-26 at 13.30.02.png

But I get strange behaviour when I search for a character before the endnote ref, eg k~U:

Screenshot 2024-08-26 at 13.30.28.png

 

Can anybody reproduce my test? If this is truly a bug, then it explains your difficulty!

- Mark

 

EDIT: I found something else:

k\x{0004}

This works, ie finds "k" and then the endnote symbol (unicode 0004). So I tried to do the normal grep via the UI but now I cannot do a capture group replacement with it. Using a lookahead, eg.

\s+(?=\x{0004})

 worked, and targeted only the offending space(s), but I couldn't remove them or replace them (the replacement just didn't happen, with no error). This behaviour might be part of the bug.

Votes

Translate

Translate

Report

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 ,
Aug 26, 2024 Aug 26, 2024

Copy link to clipboard

Copied

I wonder if you have run into a bug?

 

Indeed, ~U doesn't like lookarounds very much.

Votes

Translate

Translate

Report

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 ,
Aug 26, 2024 Aug 26, 2024

Copy link to clipboard

Copied

LATEST

Yep, I found the bug report. Only has a hand-full of votes, so please vote if you can.

Votes

Translate

Translate

Report

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 ,
Aug 25, 2024 Aug 25, 2024

Copy link to clipboard

Copied

By the way @James Gifford—NitroPress since you did tag scripting (haha do I need an excuse?! No I don't!) ...

 

Here is a scripting approach. Maybe you can adjust to suit, but this might cover most of your cases. See screen shot below.

- Mark

 

NOTE: the script currently uses the selection, so be careful—if you select a text frame, it will only find/change within the contents of that frame. If you want the whole story, select the whole story. If you want the whole document, change target to doc.

 

demo.gif

/**
 * @file Clean Up Endnote Symbols.js
 *
 * @author m1b
 * @version 2024-08-26
 * @discussion https://community.adobe.com/t5/indesign-discussions/grep-for-endnote-reference-chains/m-p/14820927
 */
function main() {

    var doc = app.activeDocument,
        endNoteStyle = doc.characterStyles.itemByName('REFS'),
        target = doc.selection[0],
        showResult = true,
        counter = 0;

    if (
        undefined == target
        || undefined == target.findGrep
    )
        return alert('Please select some text and try again.');

    app.findChangeGrepOptions.includeFootnotes = false;
    app.findGrepPreferences = NothingEnum.NOTHING;
    app.changeGrepPreferences = NothingEnum.NOTHING;
    app.findGrepPreferences.findWhat = '~U';

    var found = target.findGrep();

    for (var i = found.length - 1; i >= 0; i--) {

        var er = found[i],
            index = er.index,
            story = er.parentStory;

        while (
            story.characters[index + 1].isValid
            && story.characters[index + 2].isValid
            && ' ' === story.characters[index + 1].contents
            && ' ' === story.characters[index + 2].contents
        ) {
            // remove extra trailing space
            story.characters[index + 1].remove();
            counter++;
        }

        while (
            story.characters[index - 1].isValid
            && ' ' === story.characters[index - 1].contents
        ) {
            // remove leading space
            story.characters[--index].remove();
            counter++;
        }

        if (
            story.characters[index + 1].isValid
            && story.characters[index + 2].isValid
            && ',' === story.characters[index + 1].contents
            && SpecialCharacters.FOOTNOTE_SYMBOL === story.characters[index + 2].contents
        )
            // style comma when between endnote symbols
            story.characters[index + 1].appliedCharacterStyle = endNoteStyle;

    }

    if (showResult)
        alert('Removed ' + counter + ' unwanted characters.');

};

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Clean Up Endnote Symbols');

 

Votes

Translate

Translate

Report

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