I have a document mainly Persian with English/French/German characters here and there. I want to append a command before Latin word(s) and a } at the end. Do you think it could be done in emacs?

Suppose there's an English sentence for example Welcome to Emacs I want it to become \lr{Welcome to Emacs}.

*It is a markdown document which in turn is going to be converted to Latex. \lr{} is a local command for a Persian package which renders non-RTL words and sentences correctly. Thank you.


[:ascii:] char class can help.

C-M-% to query replace regexp \(\ *\)\([[:ascii:]]*[a-zA-z]\) with \1\\lr{\2}

If new line character must not be included into sentence then change regexp to replace to \(\ *\)\([a-zA-z ]*[a-zA-z]\)

  • Thanks. It's ok just a minor issue. There's one instance of This is sentence, 111, 111. non-ascii, is there any way to include , 111, 111. ? – nima May 31 '19 at 14:53
  • And what's this [a-zA-z]? – nima May 31 '19 at 14:55
  • \(\ *\)\([[:ascii:]]*[a-zA-z0-9,.]\). a-z it's a character range. More info here – muffinmad May 31 '19 at 15:00
  • No, I meant what's its meaning here? – nima May 31 '19 at 15:02
  • Group 2 select all ascii characters and final characters range must be character and not space – muffinmad May 31 '19 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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