Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Script to surround word with quotes

Return to Member Forum

  • Author
    Posts
    • #1177497
      Anonymous
      Inactive

      Actually not quotation marks, but rather Chinese title marks. I have a bunch of endnotes with book and journal titles in Chinese. Currently there is nothing around the titles, so I can’t do a find and replace. And there are other Chinese characters in the endnotes that are NOT book and journal titles, so I can’t blanket change all Chinese to have the title marks, just some. So I’m looking for a script that will act on selected text and insert marks at front and back.

    • #14324393

      I think you can do this with Find and Replace. In the GREP tab you have to enter .+ in the Search field and in the replace field you have to enter your quotation marks and §0 between them. I think you cannot type it directly but you have to choose it from the menu that pops up by clicking on the @ symbol right beside the Search field. Be aware that the Find Replace is only applied for the selection and not for document or story.

    • #14324392
      James Welsh
      Member

      Couldn’t you just search for Chinese within a style or only in footnotes? The find change dialogue allows you to limit to or include footnotes.

      Or you could make the change within Word before you import into ID.

    • #14324391
      Anonymous
      Inactive

      Thanks Dieter and James. Dieter’s solution works as long as Find Format and Change Format are both set to the appropriate character style, in this case one for a simplified Chinese font. For some reason, if the Change Format is kept blank, the first Chinese title mark is not formatted in the Chinese font.

    • #14324388
      David Goodrich
      Participant

      I specialize in setting type for scholarly works requiring CJK characters, where the text is mostly alphabetic with occasional strings of mostly Chinese characters, especially in references. Over the years I’ve written a bunch of GREP queries for InDesign to do things like check strings of chars. lest they begin or end with a letter or digit — in other words, to add an ASCII space — or to pull spaces from within a C or J string. My basic building block is to GREP search for codes, usually with [\x{2E80}-\x{9FBB}]+. That doesn’t get everything, but I know what it misses and I’m less sure of what the might be missed using InDesign’s metacharacter for searching Kanji, ~K (tilde CapK). There are some very useful tidbits in a piece David Blattner posted ten years ago https://indesignsecrets.com/search-for-foreign-language-characters-in-text.php, with the ~K mentioned in the comments.

      If your “nothing around the title” holds true, you could GREP search for [\x{2E80}-\x{9FBB}]+ (or perhaps ~K+) and replace with \x{300A}$0\x{300B} (where 300A and 300B are the Unicode values for double Chinese guillemets — substitute as necessary), with the additions picking up the font characteristics of the Chinese string. For most Chinese fonts, each guillemet adds half-a-character-width of whitespace on the outer side. That is often excessive where the string starts, and can look even worse at the end if the closing guillemet is followed by punctuation or a footnote number left dangling. The Japanese fonts bundled with InDesign automatically collapse this extra space, which is fine for Japanese text but can look odd elsewhere. Adobe’s open-source Source Han fonts (Google calls their versions Noto) can also narrow the extra space (these have smarts about the assigned language/locale, but I have not checked whether this affects spacing around guillemets). Also, the guillemets look very different for Adobe Ming (i.e., traditional chars.) and Adobe Song (simplified): many of my jobs use both fonts, but I prefer Adobe Ming’s guillemets, and make them all consistent — and have a char. style on hand with negative tracking to collapse the extra space; on the other hand, Adobe Ming’s double-width period, comma, etc. recall early days, when one form had to work both vertically and horizontally, so now I generally swap in Adobe Song. All of which is a long way of say Chinese punctuation ain’t simple.

      Good luck!
      David

    • #14324378

      Just a week or so ago I wrote a two-line script to add parentheses around selected text: https://forums.adobe.com/thread/2613893 (*)

      Here it is:

      app.selection[0].insertionPoints[-1].contents = ')';
      app.selection[0].insertionPoints[0].contents = '(';

      – don’t worry, as it is, it inserts round parentheses, but you can replace them with any text you want. For example (as I don’t know the codes for the Chinese marks), curly quotes would be

      app.selection[0].insertionPoints[-1].contents = '\u201c';
      app.selection[0].insertionPoints[0].contents = '\u201d';

      (*) (Am I the only one thinking you really must be desperate for help to post as large as possible? :)

Viewing 5 reply threads
  • You must be logged in to reply to this topic.
Forum Ads