I doubt that you really mean small caps for digits, but perhaps you do. Old Style Figures, if available in the font, are designed for use in running text.
It's not really clear whether the digits themselves are also already italic or whether you want to format all digits, or only those that are preceded or followed by italic text (and would the spaces, if there are any also be italic?) It may be enough to just find digits, but I think we need more information.
Hello Peter, yes, "small caps" is the "old style figures" style.
In a first step I formatted all the italic digits with the "italic old style" character style, then I formatted automatically all the other digits in the "regular old style figures" character style. I don't know why, but some digits that I want in italic are still in regular style, so I need to search the whole book to correct this strange mistake.
Unfortunately the digits I have to set in "italic old style" are not formatted within an italic paragraph style, so I can't do a normal text search.
The question is: in order to do that rapidly and automatically, can I use the GREP search?
Yes, but not easily. It would make more sense to do it with styles.
Does your font have old style figures? Is it an OpenType font? If so, add the figure style to the paragraph style. How are you aplying the italics? Is that a new paragraph style, or a character style? If it's a paragraph style, specifying the OSF in the definition should also work, and if OSF is specified inthe underlying style applying an Italic character style (same one you would apply to any other text) should switch to the italic font style and preserve the figures as oldstyle.
I think you're overthinking this...
Thank you for the reply Peter...
Actually, I'm using three different fonts: one for the regular and italic text, one only for the italic digits and one only for the regular digits... No Open Type.
The italic is applied with a character style... (The wrong figures within the italic paragraph style were easy to find and resolve, and I have already done it).
Yes, maybe it's a little bit "overthinking", but I'm interested in learning the GREP searches, so I'd like to find here a solution with the GREP search...
Can you suggest the steps to follow? I don't know the code yet...
1 person found this helpful
If you read the other thread I suggested you'll see the basic method of finding text that is preceded or followed by text that carries a particular format. Jongware's solution is very elegant, but I don't believe it will work in this case becasue you are trying to find digits that do not carry the same formatting as the surrounding text. To me that means what you need to do is find the last italic character followed by a digit, or the first one preceded by a digit, and mark these in some way so that you can then find the digits in between.
.(?=\d) finds the last character befor a digit, and (?<=\d). finds the first character after one, but these are not necessarily the expressions you want to use sin the . (dot) matches everything, including other digits, punctuation, and whitespace. You would want to make sure, too, that the find formatting is set to Italic.
[\u\l[:punct:]](?<=\d) and (?=\d)[\u\l[:punct:]] would limit the found characters to upper and lower case, and puctuation, but would not find any white space. That's why I asked in my first reponse about whether there was space before or after the digits. I think you can see that making this work for all the cases you might encounter, but not find things you don't want to find, is getting to be pretty complex, and that's only the first part.
So far you're finding the text surrounding the digits, not the digits themselves, and you need to create a tag of some sort to mark these locations then, if <tag> stands for the tag you've added you would replace with $0<tag> or <tag>$0 as appropriate for the tag befor or after the digits. Now you can look for (<tag>)(\d+)(<tag>), set the change formatting to your italics, and replace with $2, or if you have cases where the italics are only before or after the digits you can leave off one of the (<tag) sub-expressions and adjust the change expression to remove the remaining tag.
Sorry Peter, I didn't see the link before...
I think this is the best solution:
Find (?<=[\u\l\d[:punct:]]) (?=[\u\l\d[:punct:]]) in italic and change (for example) with a red X. Then find remaining italic white spaces (which are just before and after elements formatted with different character styles)... You can easily isolate and correct wrong figures. This procedure is not completely automatic but it is the best one to save time... What do you think?
In your last reply perhaps you made a mistake (I'll tell you just to know if I'm learning well). I think that (?<=\d)[\u\l[:punct:]] and [\u\l[:punct:]](?=\d) are correct, aren't they?
Thank you very much for your help
You're right, I flipped the order on the look-ahead and look-behind.
Find (?<=[\u\l\d[:punct:]]) (?=[\u\l\d[:punct:]]) is going to find practically all regular word spaces (give it a try and see), and I don't think that's waht you were tryig to do....