In InDesign, is there a way to bold a whole word that has one bold character?

525 Views Asked by At

I'm working on an index in InDesign. Some of the page numbers are in bold, others are in italics or regular. During editing, somehow the first numbers of some of the bold page numbers got changed. I've figured out how to highlight those page numbers by coloring the bold numbers and recoloring the page numbers that are correct using a GREP search for bold words (\b\w+\b). What I can't figure out is how to select the "bad" page numbers that have only some numbers and make the entire "word" bold. Any ideas? It would be nice not to have to fix them manually.

3

There are 3 best solutions below

1
On

It's much easier to use the Find/Change interface in Indesign.

0
On

It heavily depends on the text you have. If it's just one first digit that need to change, if you don't use character styles, if you have no digits in your body text, if the font you're using has the common names for styles, if ... there is a lot of 'if's, actually. I'd recommend to share a sample of your file (IDML).

So, here is the script that could do the job (if all of those "if"'s are true):

var doc = app.activeDocument;
var styles = doc.characterStyles;


// STEP 1 -- apply style1 (regular) to all regular numbers \d\d+
var style1 = styles.add();
style1.name = 'digits_regular';
style1.fontStyle = 'Regular';

app.findGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat  = '\\b\\d\\d+'; // two or more digits
app.findGrepPreferences.fontStyle = 'Regular';

app.changeGrepPreferences.changeTo = '$0';
app.changeGrepPreferences.appliedCharacterStyle = style1;

doc.changeGrep();


// STEP 2 -- apply style2 (italic) to all italic numbers \d\d+
var style2 = styles.add();
style2.name = 'digits_italic';
style2.fontStyle = 'Italic';

app.findGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat  = '\\b\\d\\d+';
app.findGrepPreferences.fontStyle = 'Italic';

app.changeGrepPreferences.changeTo = '$0';
app.changeGrepPreferences.appliedCharacterStyle = style2;

doc.changeGrep();


// STEP 3 -- apply style3 (bold) to all unstyled numbers
var style3 = styles.add();
style3.name = 'digits_bold';
style3.fontStyle = 'Bold';

app.findGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '\\b\\d\\d+';
app.findGrepPreferences.appliedCharacterStyle = styles[0]; // syle '[None]'

app.changeGrepPreferences.changeTo = '$0';
app.changeGrepPreferences.appliedCharacterStyle = style3;

doc.changeGrep();


// clean prefs
app.findGrepPreferences = NothingEnum.nothing;

Input:

enter image description here

Result:

enter image description here

Then you can remove the character styles you don't need them. But I'd recommend to use styles. They make the life easier exactly in such cases.

0
On

I just tried this on a document and added a few numbers that were only partially bold.

I was able to fix it by doing a search for only digits with (\b\d+\b), changing all to $1. I left find format blank and change format to regular font. This changed all numbers to regular with no mixed bold and regular.

After that you can run the same find and replace again but switching format to bold. This will change all numbers to be fully bold.