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

Assign / automate font colors based on letter patterns?

Advocate ,
May 23, 2024 May 23, 2024

Copy link to clipboard

Copied

I have a document for which I'm creating custom symbols as a font.  I'm using the custom font in a character style, and I need to be able to change colors of the fonts based on the order in which they appear. So, for example, I have a # symbol as the letter A, and the ampersand as the letter B.

I type "AB" and apply my symbol font character style, and get #&.

Based on the colors I need (and am currently applying manually), it should look like:

#&

However, sometimes, the characters (but not the colors) are reversed:
&#

and I will always need the second letter (and any after that) to be orange.

Is there a way to do this so as to avoid manually applying color to every instance? 

Or, somehow, of programmatically applying the color so that when I clear overrides, the font colors remain?

I think the answer may be somewhere in GREP, but I haven't used it enough yet to... know how to do it 🙂 I searched a bit, but am not sure what GREP functions would be used. I assume it would be something like telling GREP that every time text has a specific character style, any letters after the first should have a duplicate character style with a specific color applied. Something like that?

 

Any thoughts?

TIA

 

 

 

 

 

 

TOPICS
Type

Views

288

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 ,
May 23, 2024 May 23, 2024

Copy link to clipboard

Copied

Is there any other character BEFORE the black one, in the same paragraph? A simple nested style could be the solution.

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
Advocate ,
May 23, 2024 May 23, 2024

Copy link to clipboard

Copied

Hi  - thanks - yes, it does come after other characters in the same paragraph, frequently, such as:


Serro moluptur, cum quaspicab ima cusdanis cupta aut #& fugia vendipiene oditatus, cor re, ius aut optios aut abo. 

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 ,
May 24, 2024 May 24, 2024

Copy link to clipboard

Copied

LATEST

Maybe it's because English is not my native language but I don't understand 2 things:

  • why do yo need to use a custom font for this?
  • why don't you use a simple nested style like this?

Capture d’écran 2024-05-24 à 17.04.15.png

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 ,
May 23, 2024 May 23, 2024

Copy link to clipboard

Copied

A find-replace operation could consider the style. You'd manually repeat it by script.

Otherwise, as you already make a font, maybe you can work with a color font where the follow-up glyphs are substituted by colored alternatives? Not sure though how you will fare in print, e.g. whether SVG related limitations (rgb colors) apply to those fonts.

 

https://helpx.adobe.com/fonts/using/ot-svg-color-fonts.html

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 ,
May 23, 2024 May 23, 2024

Copy link to clipboard

Copied

Depending on the complexity of their use, a GREP style might work. And if you are tagging these with a Character style to apply that different font amid body or running text... it should be almost trivial to add this color variation.


┋┊ 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
Advocate ,
May 23, 2024 May 23, 2024

Copy link to clipboard

Copied

Hey James - thanks - 

The use isn't very complex, I think; currently I'm building the font (let's call it Map Symbol).

I have two Character Styles for this - Map Symbol, for the initial symbol, and Map Symbol Orange, which applies to any number of symbols coming immediately after the first.

This applies through the entire volume. I've just been applying them manually.

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 ,
May 23, 2024 May 23, 2024

Copy link to clipboard

Copied

This GREP method can work provided your custom font characters are not used anywhere else in the text ("A" and "B" won't work, "@" and "#" might, and are the examples I'm using here):

You'll want two character styles, let's say "MyFont" that applies your custom font, and "Orange" that applies the orange color. If you use this GREP expression in a GREP style, it will apply your style to the second character of the pair: 
(?<= [\@\#])[\@\#]

Screenshot 2024-05-23 124703.png

I've used @ and # assuming they don't occur anywhere in your text (regardless of font) other than in the special symbols. You'll need to select your own. They have backslashes because they have special meanings in grep and the backslash says "Take this literally. Ignore the special meaning." The square brackets mean "any of these," so you're not restricted to just two characters, but, again, this only works if all your custom font characters don't appear in the regular text.

The overall expression means "If this character is one of the special set @#, look at the previous character. If that is a @ or a # then we have a match" and the Orange character style will be applied.

Screenshot 2024-05-23 124901.png
This takes advantage of the fact that you can apply a character style on top of another one using GREP styles. Normally, you can apply only one character style at a time.
GREP doesn't know anything about character or paragraph styles, so you can't include them in a GREP expression. This works around that problem and leaves you free to apply your "Orange" character style to other text.

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
Advocate ,
May 24, 2024 May 24, 2024

Copy link to clipboard

Copied

Thanks Alan!

I'll read this & see if I can understand it 🙂 

 

Ok... pretty cool, but need it to work on a predefined character style (containing a different font) within paragraphs of the main font.

 

So, without GREP recognizing paragraph styles, I'll have to figure out if there's a convenient workflow to get around the limitation.

Part of the convenience of the custom font is single keypresses to get the symbols, since the symbols appear very frequently throughout the volume(s).

 

That said, I'm going to experiment with opt-keypresses since that would work with symbols that are unused elsewhere in the copy.... †˙å˜˚ß.

 

Edit: I think that because each instance uses two character styles, the GREP rules need to be modified to identify symbols both before and after other related symbols, and apply the style to each. I'll see if I can figure that out.

 

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