2

I'm trying to automatize giving character styles to the editor given names (not the author names) in literature sources like this one via Find/Change (not GREP styles):

Jacobs, G. A., Boero, J. V., Quevillon, R. P., Todd-Bazemore, E., Elliott, T. L. & Reyes, G. (2002). Floods. In A. M. La Greca, W. K. Silverman, E. M. Vernberg & M. C. Roberts (Eds.), Helping children cope with disasters and terrorism (pp. 157 – 174). Washington, DC: American Psychological Association.

Doing that, I want to grap any capital letter followed by a dot AFTER the word In in a paragraph. Since the regular lookbehind (?<=) won't work with . and + opperators, I use \K

As an additional info to this particular case: Using a fine-tagging script, everything is already tagged with different character and paragraph styles, the script just has problems with the double/multiple given names of the editors which is why I'm trying to find them manually to correct them. I can't post the script here since it's not mine to give.

what I have:

  • I managed to grab all double or more names (singular is for a reason not necessary) which come after the word In:

    (In )\K([\u]\.( [\u]\.)+)

  • I managed to grab double or more names after the first occurence:

    (In [\u]\.( [\u]\.)* .+(\,|\&) )\K([\u]\.( [\u]\.)+)

I have multiple things not working out:

1. finding more than one occurence

The second query only finds the last occurence, not the ones inbetween. Since .+ looks for everything that comes before f.e. M. C., it seems to include any occurence that come before the last. I just can't seem to find a way to grab all occurences. Does anyone know a way or is this simply not possible

2. combining the search with "or" |

Both queries work for themself but I can't combine them with "or". Now in general it does work with simpler test queries but with the ones above. Possibly because the first query is a part of the second.

Does anyone have an idea how this could work?

Thanks in advance

4
  • 1
    Did you say in your comment that the initials of the authors before the In part (Jacobs, Boero, etc.) already have different styles applied? Or are they (at least potentially) completely unstyled? Feb 3, 2021 at 10:12
  • Yes, everything (or nearly everything) has already styles applied. I added that Info to the main post yesterday. (See paragraph before "What I have")
    – SabineR
    Feb 4, 2021 at 11:37
  • 1
    But that changes everything! Can’t you just search for (\u\.), then, and specify Character Style: [None]? If all the other authors are already styled (and perhaps titles as well?), that should only match the ‘in’ authors. You’ll probably get the odd false positive, but if you make the style you’re applying pink or something, you can check through it fairly easily to get rid of those. Feb 4, 2021 at 11:55
  • @JanusBahsJacquet, that sounds promising! (I need closure on this riddle 😅)
    – Wolff
    Feb 4, 2021 at 22:49

2 Answers 2

1
\u\.( \u\.)+(?!.+\. In )

The above finds all occurrences of

  • uppercase letter + period
  • followed by one or more instances of [ space + uppercase letter + period ]
  • that is not followed by one_or_more_chars + period + space + “In” + space

It can be used in the find/replace dialog to apply a character style.

One thing to be aware of: the end of the line must be terminated with a paragraph mark.

Result:

enter image description here


Update 2023-07-01

As OP has pointed out, the idea above is too broad.

This next idea is also not ideal, but it may help. Its weakness is that it also styles the text interspersed between the text we are targeting. The positive of this method is that it overcomes the limitation that Lookbehind cannot apply a regular expression backwards.

  1. First, apply a temporary style to all the text between the first and last initial cap after the ". In " text, using this GREP search: (\. In )\K(\u.*)+(\u\.)

  2. Then apply the actual style to the initial caps within the temporary style, using the Find Format feature and the following GREP search: (\u\.)( \u\.)+

  3. Lastly, find the temporary style and replace with none.

These steps are shown below.

enter image description here

This can all be achieved in one step using the “FindChangeByList.jsx” script, with these lines in the “FindChangeList.txt” file:

grep    {findWhat:"(\\. In )\\K(\\u.*)+(\\u\\.)"}   {appliedCharacterStyle:"temporary"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}
grep    {findWhat:"(\\u\\.)( \\u\\.)+", appliedCharacterStyle:"temporary"}  {appliedCharacterStyle:"actual"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}
grep    {appliedCharacterStyle:"temporary"} {appliedCharacterStyle:"[No character style]"}  {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}
3
  • Thank you. Sadly this does only work if all literature sources were chapters from edited volumes. It also finds sources that don't have the "In"-Parameter. Such as "Rowling, J. K. (1997). Harry Potter. London: Bloomsbury." So I can't use this solution.
    – SabineR
    Jun 26, 2023 at 7:16
  • Yes, I can see that now. So, taking another tack, are there any character styles applied to the characters between initial caps? (In our example: “La Greca,” “Silverman,” and “Vernberg &”.)
    – MG_
    Jun 28, 2023 at 11:57
  • sadly sometimes yes, sometimes no.
    – SabineR
    Jun 29, 2023 at 12:20
0

I can't say for sure that this isn't possible, but I haven't been able to find a way. Instead I can present kind of a workaround.

GREP styles are applied in sequence, so you can first style all capital letters followed by a dot and then afterwards remove the styling up to the word "In" like this.

The result looks like this:

Be aware that you can't just apply [None] to cancel the styling. You have to make another character style that actively reverts whatever styling you have applied.

7
  • 1
    Might be a good idea to make the To Text for the second one .+\. \<In\> or something along those lines, just to avoid it matching someone who has In in their name (say, Josh Ingram) or the word In appearing in the title (a title like ‘Allegory In The Prose Of H. G. Wells’ would wreck it). Jan 29, 2021 at 19:04
  • @JanusBahsJacquet, you are right. But your suggestion still wouldn't work if a title starts with "In" right? Can't really see how to avoid this ...
    – Wolff
    Jan 29, 2021 at 20:20
  • No, if a title (or subtitle, after a full stop) starts with In, there’d be no way to avoid it, you’d have to fix that manually. Jan 29, 2021 at 20:22
  • One could do a manual find/change searching for "In" and insert some character like End Nested Style Here before and then use that in the GREP style. Would require that you examine each instance, but still faster than manually applying the character style.
    – Wolff
    Jan 29, 2021 at 21:49
  • Thank you but apart from that I can't seem to get this to work with the occurences before "In", this work around is not an option for me. Because 1. the other parts also have different character styles for authors and titles and sources etc. And 2. this doesn't apply real character styles as in: when you mark the word, in the character style window the style is not selected. We need this for XML reasons. I really only want to find the occurences to correct what our fine tagging script for literature missed.
    – SabineR
    Feb 1, 2021 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.