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

GREP Appy Italic in all possible cases

Engaged ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

Hello!

I have an index reference, and I would like to apply the Character Style Italic to all individual letter g . The letter g means glosary.

Is a big risk, please can you help me to config a secure GREP?

EXAMPLES:

human beings g

human beings 3, 13, 78, g

human beings g (See also human)

human beings 2, 6, 89, g (See also human, beings)

MY SCRIPT:

var myDoc = app.activeDocument,   

myCodes = ["g"],  C = myCodes.length,  c;   

app.findTextPreferences = null; 

for ( c = 0; c < C; c++) {      

    app.findTextPreferences.findWhat = myCodes;      

    myFound = myDoc.findText();   

    var F = myFound.length,  f; 

    for ( f = 0; f < F; f++) { 

        myFound.appliedCharacterStyle = myDoc.characterStyles[0]; 

            myFound.appliedCharacterStyle = 'Italic';

    } 

}

thanks so much!

TOPICS
Scripting

Views

1.3K

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

The reason why your expressions don't work (or not correctly) is that you have several unescaped backslashes in the search strings.

But you make things very complicated. Try this:

Find: " +(\\d[–\\d, ]*\\d?) *"

Change to: $1

Votes

Translate

Translate
Community Expert ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

Simply search for g whole-word only and case-sensitive.

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
Engaged ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

but if I do this, the script will apply also the Italic to the words like:

beings

and it is not correct. Also will be nice to use a script because I have 15 script to apply.

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 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

That's why you should do whole-word only. In Grep: "\\bg\\b"

P.

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
Engaged ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

is not working.

I need to use 2 script.jsx one with this:

myCodes = [" g "], C = myCodes.length, c;

and other with:

myCodes = ["g\r"], C = myCodes.length, c;

Thanks!

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 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

Look for "\\sg\\s"

\s covers any space, incuding \r.

Again, get yourself a good book on GREP.

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
Engaged ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

same problem.

thanks for the advice, I am training but are many things to know.

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
Guide ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

For memory, I think Peter Kahrel wrote a book on Grep professionals consider as "the" reference! 

Best,

Michel

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
Engaged ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

HI Michel!

Please, give me the book name or link.

I take this opportunity, why you or Petter no create a deep course in Udemy.com?

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
Guide ,
Aug 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

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 20, 2018 Aug 20, 2018

Copy link to clipboard

Copied

Thanks for mentioning that title, Michel. It's actually out of print at the moment, but a new edition will be published soon by InDesignSecrets.

P.

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
Engaged ,
Aug 21, 2018 Aug 21, 2018

Copy link to clipboard

Copied

Just what I needed.

I look forward to buying it.

Thanks so 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
Engaged ,
Aug 24, 2018 Aug 24, 2018

Copy link to clipboard

Copied

finally, I finish the script. I hope will be useful to someone.

PROTOCOL FOR THE INDEX:

human beings(s)

human beings(s)

human beings(s)  g

human being(s)  g

human beings(s) (See human)

human beings(s) g (See human)

human beings(s) (See also human, beings)

human beings(s) 3, 13, 78

human beings(s) 134–136

human/beings(s) 3, 13, 78

human beings(s) 3, 13, 78, g

human beings(s) 3, 13, 78, g (See human)

human beings(s) 8, g (See human)

human beings(s) 3, 13, 78 (See human)

human beings(s) 8 (See human)

INDESIGN INDEX OPTIONS:

Screen Shot 2018-08-24 at 21.50.08.png

SCRIPT 0: BATCH TO RUN ALL YOUR SCRIPTS:

// http://www.rorohiko.com/wordpress/batch-textexport/

// https://www.indesignjs.de/extendscriptAPI/indesign-latest/#ScriptPreference.html

var thisScript = new File($.fileName);

var containingFolder = new Folder(thisScript.parent.absoluteURI);

//alert("This script is in " + containingFolder.absoluteURI);

var path = containingFolder.absoluteURI;

var appFolder = new Folder(Folder.appPackage.parent.absoluteURI);

//alert("The app folder is at " + Folder.decode(appFolder.absoluteURI));

function batch()

{

    var f1 = File ( path+"/script1.jsx" );

    var f1 = File ( path+"/script2.jsx" );

    var f1 = File ( path+"/script3.jsx" );

    var f1 = File ( path+"/script4.jsx" );

    var f1 = File ( path+"/script5.jsx" );

    var f1 = File ( path+"/script6.jsx" );

    var f1 = File ( path+"/script7.jsx" );

    var f1 = File ( path+"/script8.jsx" );

   app.doScript ( f1 );

   app.doScript ( f2 );

   app.doScript ( f3 );

   app.doScript ( f4 );

   app.doScript ( f5 );

   app.doScript ( f6 );

   app.doScript ( f7 );

   app.doScript ( f8 );

}

batch();

SCRIPT 1: FIX GENERAL ERRORS

replaceTextUsingGREP ("~>"," ");

replaceTextUsingGREP ("~S"," ");

replaceTextUsingGREP ("~|"," ");

replaceTextUsingGREP ("~3"," ");

replaceTextUsingGREP ("~4"," ");

replaceTextUsingGREP ("~%"," ");

replaceTextUsingGREP ("~f"," ");

replaceTextUsingGREP ("\\s+?/\\s+?","/");

function replaceTextUsingGREP (input, output) {

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

    app.findGrepPreferences.findWhat = input;

    app.changeGrepPreferences.changeTo = output;

    //app.activeDocument.changeGrep();

    var changedResults = app.activeDocument.changeGrep();

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

}

SCRIPT 2: FIX ERROR PAGE NUMBERS

var IndexEntryOneWord = "(\^\[\\l\\u\]+?)";

var IndexEntryMultiplesWords = "(\^\[\\l\\u\]+?\\s\[\\l\\u\]+?)";

var type = "((\\(([\\l\\u\])+?\\))?)";

var firstSpace = "\\s+?";

var firstNumberPage = "(\\d+?)";

var nextNumberPage = "(((,\\s\\d+?)+?)?)";

var nextSpace = "((\\s+?)?)";

var endParagraph = "\$";

replaceTextUsingGREP (  //human(s)·20,·7..|    -->      human(s)··20,·7|

    IndexEntryOneWord+

    type+

    firstSpace+

    firstNumberPage+

    nextNumberPage+

    nextSpace+

    endParagraph,

    "$1$2\\s\\s$5$6");

replaceTextUsingGREP (  //human beings(s)·20,·7..|    -->      human beings(s)··20,·7|

    IndexEntryMultiplesWords+

    type+

    firstSpace+

    firstNumberPage+

    nextNumberPage+

    nextSpace+

    endParagraph,

    "$1$2\\s\\s$5$6");

function replaceTextUsingGREP (input, output) {

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

    app.findGrepPreferences.findWhat = input;

    app.changeGrepPreferences.changeTo = output;

    //app.activeDocument.changeGrep();

    var changedResults = app.activeDocument.changeGrep();

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

}

SCRIPT 3: FIX ERROR SPACES

replaceTextUsingGREP ("~>"," ");

replaceTextUsingGREP ("~S"," ");

replaceTextUsingGREP ("~|"," ");

replaceTextUsingGREP ("~3"," ");

replaceTextUsingGREP ("~4"," ");

replaceTextUsingGREP ("~%"," ");

replaceTextUsingGREP ("~f"," ");

replaceTextUsingGREP (", g \r",", g\r");

replaceTextUsingGREP (" / ","/");

function replaceTextUsingGREP (input, output) {

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

    app.findGrepPreferences.findWhat = input;

    app.changeGrepPreferences.changeTo = output;

    //app.activeDocument.changeGrep();

    var changedResults = app.activeDocument.changeGrep();

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

}

SCRIPT 4: FIX LATIN CHARACTERS

replaceTextUsingGREP ("√°","á");

replaceTextUsingGREP ("√Å","Á");

replaceTextUsingGREP ("√©","é");

replaceTextUsingGREP ("√â","É");

replaceTextUsingGREP ("√≠","í");

replaceTextUsingGREP ("√ç","Í");

replaceTextUsingGREP ("√≥","ó");

replaceTextUsingGREP ("√ì","Ó");

replaceTextUsingGREP ("√∫","ú");

replaceTextUsingGREP ("√ö","Ú");

replaceTextUsingGREP ("√±","ñ");

replaceTextUsingGREP ("√ë","Ñ");

function replaceTextUsingGREP (input, output) {

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

    app.findGrepPreferences.findWhat = input;

    app.changeGrepPreferences.changeTo = output;

    //app.activeDocument.changeGrep();

    var changedResults = app.activeDocument.changeGrep();

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing; 

}

SCRIPT 5: FIX THE LETTER G INDICATE THE GLOSARY

var IndexEntryOneWord = "(\^\[\\l\\u\]+?)";

var IndexEntryMultiplesWords = "(\^\[\\l\\u\]+?\\s\[\\l\\u\]+?)";

var type = "((\\(([\\l\\u\])+?\\))?)";

var firstSpace = "\\s+?";

var firstNumberPage = "(\\d+?)";

var nextNumberPage = "(((,\\s\\d+?)+?)?)";

var glosary = "(,?\\s+?g)";

var glosaryWithoutPageNumbers = "(g)";

var nextSpace = "((\\s+?)?)";

var endParagraph = "\$";

replaceTextUsingGREP (  //human(s)·20,·7, g..|    -->      human(s)··20,·7,·g|

    IndexEntryOneWord+

    type+

    firstSpace+

    firstNumberPage+

    nextNumberPage+

    glosary+

    nextSpace+

    endParagraph,

    "$1$2\\s\\s$5$6,\\sg");

replaceTextUsingGREP (  //human beings(s)·20,·7, g..|    -->      human beings(s)··20,·7,·g|

    IndexEntryMultiplesWords+

    type+

    firstSpace+

    firstNumberPage+

    nextNumberPage+

    glosary+

    nextSpace+

    endParagraph,

    "$1$2\\s\\s$5$6,\\sg");

replaceTextUsingGREP (  //human(s)·g..|    -->      human(s)··g|

    IndexEntryOneWord+

    type+

    firstSpace+

    glosaryWithoutPageNumbers+

    nextSpace+

    endParagraph,

    "$1$2\\s\\sg");

replaceTextUsingGREP (  //human beings(s)·g..|    -->      human beings(s)··g|

    IndexEntryMultiplesWords+

    type+

    firstSpace+

    glosaryWithoutPageNumbers+

    nextSpace+

    endParagraph,

    "$1$2\\s\\sg");

function replaceTextUsingGREP (input, output) {

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

    app.findGrepPreferences.findWhat = input;

    app.changeGrepPreferences.changeTo = output;

    //app.activeDocument.changeGrep();

    var changedResults = app.activeDocument.changeGrep();

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

}

SCRIPT 6: FIX ERRORS CROSS REFERENCES

var IndexEntryOneWord = "(\^\[\\l\\u\]+?)";

var IndexEntryMultiplesWords = "(\^\[\\l\\u\]+?\\s\[\\l\\u\]+?)";

var type = "((\\(([\\l\\u\])+?\\))?)";

var firstSpace = "\\s+?";

var firstNumberPage = "(\\d+?)";

var nextNumberPage = "(((,\\s\\d+?)+?)?)";

var nextSpace1 = "(\\s+?)";

var crossReference = "(?=\\(véa)";

replaceTextUsingGREP (  //human beings(s)·20,·7·(véase person)..|    -->      //human beings(s)· 20,·7·(véase person)|

    IndexEntryOneWord+

    type+

    firstSpace+

    firstNumberPage+

    nextNumberPage+

   nextSpace1+

    crossReference,

    "$1$2\\s\\s$5$6\\s");

replaceTextUsingGREP (  //human(s)·20,·7·(véase person)..|    -->      //human(s)· 20,·7·(véase person)|

    IndexEntryMultiplesWords+

    type+

    firstSpace+

    firstNumberPage+

    nextNumberPage+

    nextSpace1+

    crossReference,

    "$1$2\\s\\s$5$6\\s");

replaceTextUsingGREP (  //human beings(s)·(véase person)..|    -->      //human beings(s)··(véase person)|

    IndexEntryOneWord+

    type+

    firstSpace+

    crossReference,

    "$1$2\\s\\s");

  

replaceTextUsingGREP (  //human(s)·(véase person)..|    -->      //human(s)··(véase person)|

    IndexEntryMultiplesWords+

    type+

    firstSpace+

    crossReference,

    "$1$2\\s\\s");

function replaceTextUsingGREP (input, output) {

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

    app.findGrepPreferences.findWhat = input;

    app.changeGrepPreferences.changeTo = output;

    //app.activeDocument.changeGrep();

    var changedResults = app.activeDocument.changeGrep();

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

}

SCRIPT 7: CLEAN OVERRIDES

// Clear All Overrides

// Written by TAW. (c) 2014 by Bookraft Solutions, Israel (Id-Extras.com)

// Please do not delete this copyright notice.

//

var myOverrideType = OverrideType.ALL;

// var myOverrideType = OverrideType.CHARACTER_ONLY;

// var myOverrideType = OverrideType.PARAGRAPH_ONLY;

var allStories = app.activeDocument.stories.everyItem();

// Remove overrides from all stories

try{

allStories.clearOverrides(myOverrideType);

}

catch (e){

    //alert ("No stories!")

}

// Remove overrides from all footnotes

try{

allStories.footnotes.everyItem().texts.everyItem().clearOverrides(myOverrideType);

}

catch (e){

    //alert ("No footnotes!")

}

// Remove overrides from all table

try{

allStories.tables.everyItem().cells.everyItem().paragraphs.everyItem().clearOverrides(myOverrideType);

}

catch (e){

    //alert ("No tables!")

}

//alert("Overrides cleared!");

SCRIPT 8: APPLY ITALIC TO THE LETTER G OF GLOSARY

var myDoc = app.activeDocument,   

myCodes = [" g\r"],  C = myCodes.length,  c;   

app.findTextPreferences = null; 

for ( c = 0; c < C; c++) {      

    app.findTextPreferences.findWhat = myCodes;      

    myFound = myDoc.findText();   

    var F = myFound.length,  f; 

    for ( f = 0; f < F; f++) { 

        myFound.appliedCharacterStyle = myDoc.characterStyles[0]; 

            myFound.appliedCharacterStyle = 'Italic';

    } 

Thanks, Peter and Michele.

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
Engaged ,
Aug 26, 2018 Aug 26, 2018

Copy link to clipboard

Copied

I had some issues with the range numbers. Please, some help?

Really are patter combination is possible, but here are the most cases (the dot means SPACE and the vertical bar the END OF PARAGRAPH 😞

human··17··|

human·17··|

human··17,·56,·56··|

human···17,·18–21,·56······|

human··17–21,·56,·61··|

human·17–21,·56–61······|

human·17–21,·56–61,·660······|

I expect:

human··17|

human··17|

human··17,·56,·56|

human··17,·18–21,·56|

human··17–21,·56,·61|

human··17–21,·56–61|

human··17–21,·56–61,·660|

But the result is (in color red the erros):

human··17|

human··17|

human··17,·56,·56|

human···17,·18–21,·56······|

human··17–21–21,·56,·56|

human·17–21,·56–61······|

human·17–21,·56–61,·660······|

Here my script:

var IndexEntryOneWord = "(\^\[\\l\\u\]+?)";

var IndexEntryMultiplesWords = "(\^\[\\l\\u\]+?\\s\[\\l\\u\]+?)";

var type = "((\\(([\\l\\u\])+?\\))?)";

var firstSpace = "\\s+?";

var firstNumberPage = "(\\d+?)";

var dash = "((\~\=\\d+?)?)";

var nextNumberPage = "(((,\\s\\d+?)+?)?)";

var nextSpace = "((\\s+?)?)";

var endParagraph = "\$";

replaceTextUsingGREP (  //human(s)·20,·7..|    -->      human(s)··20,·7|

    IndexEntryOneWord+

    type+

    firstSpace+

    firstNumberPage+

    dash+

    nextNumberPage+

    nextNumberPage+

    nextSpace+

    endParagraph,

    "$1$2\\s\\s$5$6$7$8$9");

function replaceTextUsingGREP (input, output) {

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

    app.findGrepPreferences.findWhat = input;

    app.changeGrepPreferences.changeTo = output;

    //app.activeDocument.changeGrep();

    var changedResults = app.activeDocument.changeGrep();

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

}

Thanks you.

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

Copy link to clipboard

Copied

The reason why your expressions don't work (or not correctly) is that you have several unescaped backslashes in the search strings.

But you make things very complicated. Try this:

Find: " +(\\d[–\\d, ]*\\d?) *"

Change to: $1

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
Engaged ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

amazing Peter!

finally based in your example I did this for the cross-references:

INCORRECT:

human·g·|

human·17, g (See also person)··|

human·17,·18–21,·(See person)·|

CORRECT:

human··g|

human··17, g|

human··17, g (See also person)|

human··17,·18–21,·(See person)|

THE SCRIPT:

replaceTextUsingGREP ("\\s+?/\\s+?","/");

replaceTextUsingGREP (" +(\\d[–\\d, ]*\\d?) *", "\\s\\s$1"); // numbers

replaceTextUsingGREP (" +([g\\(véa*])","\\s\\s$1");

replaceTextUsingGREP (" +(g)(\\(véa*)","\\s\\s$1\\s$2");

replaceTextUsingGREP ("\\s+\\r", "\\r");

replaceTextUsingGREP (",\\s\\sg",",\\sg");

replaceTextUsingGREP ("(,\\sg\\s)\\s(\\(véa*)","$1$2");

replaceTextUsingGREP ("(\\d\\s)\\s","$1");

Thanks a lot!

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
Guru ,
Aug 28, 2018 Aug 28, 2018

Copy link to clipboard

Copied

https://forums.adobe.com/people/Peter+Kahrel  wrote

Thanks for mentioning that title, Michel. It's actually out of print at the moment, but a new edition will be published soon by InDesignSecrets.

P.

How does an ebook go out of print?

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 28, 2018 Aug 28, 2018

Copy link to clipboard

Copied

LATEST

> How does an ebook go out of print?

I'm just showing my age! The epub is in fact still available from O'Reilly, the PDF is not.

GREP in InDesign [Book]

An updated edition of the PDF and a new Epub will be available from InDesignSecrets soon.

P.

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