Skip to main content
Participating Frequently
July 2, 2024
Answered

GREP for underlining text in a Table of Contents

  • July 2, 2024
  • 4 replies
  • 2427 views

How can I crate a GREP that will underline a part of an entry in a table of contents?

I know how to bold certain words using a GREP but cannot figure out how to underline certai words!!

Any ideas???

This topic has been closed for replies.
Correct answer James Gifford—NitroPress

It looks as if you are attempting to apply HTML-like formatting markup instead of applying an InDesign Character Style. That might work, in certain circumstances, but it's not the right approach.

 

  • Create an "underline" style that works when you apply it directly.
  • Create a GREP string that finds the word or string you want to underline.
  • Set the GREP style to apply the "underline" style.

 

Don't try to do anything else in the process. It should not be necessary.

 

And, since this is unclear: use a Paragraph Style-based GREP Style, to apply the underline automatically, and not a manual GREP search and replace.

4 replies

pcfilesAuthor
Participating Frequently
July 3, 2024

I figured it out!   I was trying to create a seperate GREP style when I should of been creating the GREP in the actual Paragraph Style that I was using...  i.e.: PARAGRAPH STYLE NAME:  Table of Contents...  GREP had to be added within this style, not as a whole separate Paragraph Style.  

Robert at ID-Tasker
Legend
July 3, 2024
quote

I figured it out!   I was trying to create a seperate GREP style when I should of been creating the GREP in the actual Paragraph Style that I was using...  i.e.: PARAGRAPH STYLE NAME:  Table of Contents...  GREP had to be added within this style, not as a whole separate Paragraph Style.  


By @pcfiles

 

Yes, that's how GREP Styles in Paragraph Styles work - next to Nested and Line Styles.

 

It's on the screenshots for Steps 2) and 4) in the link I and @pixxxelschubser provided:

 

 

We all were under the impression, that you are doing it this way?

That's why we were asking for screenshots - to see what, where and how you were doing. 

 

Robert at ID-Tasker
Legend
July 2, 2024

@pcfiles

 

I think we all have drifted too far from the obvious thing - TOC will retain CharStyles applied in the text...

 

pixxxelschubser
Community Expert
Community Expert
July 2, 2024

This is absolutely correct. Nevertheless, additional (unapplied) attributes can be added with a grep style.

Robert at ID-Tasker
Legend
July 2, 2024

@pcfiles

 

Exactly the same as when you set bold - just a different setting in the CharStyle definition.

 

pcfilesAuthor
Participating Frequently
July 2, 2024

I have a character style setting for "underlined" but it does not work when using the GREP.

 

I need to know what character has to be in...  <XXX>.+?</XXX>    in place of the XXX to make it work.
I use character style constantly in my projects but getting the underline to work in a table of contents is not working.
As soon as I update the TOC the underline goes away if I manually underline the text!!

James Gifford—NitroPress
Legend
July 2, 2024

I know.

 

And I suspect that he is trying to apply this technique https://creativepro.com/using-grep-styles-to-format-html-code-in-indesign/. But that won't get him anywhere. So without real examples, it's just poking around in the dark ...

 


There is clearly confusion between GREP practices and HTML markup, but I can't sort out the end goal here, especially with respect to a TOC.

James Gifford—NitroPress
Legend
July 2, 2024

It should be an identical process except that the applied Character Style adds an underline, which can be defined in the style for optimum appearance.

 

Create and optimize the "underline" style first. Then use GREP to apply it according to your rules.

pcfilesAuthor
Participating Frequently
July 2, 2024

I have done that but do not know what character to use to determine the underline.
For the bold I have: Apply Style: Bold    To Text: <b>.+?</b>

I tried to do the same for underlining...  Apply Style: Underlined    To Text:  <ul>.+?</ul>
But it does not work...   the <ul> and </ul> show up in the text of the table of contents.