2

I have the following lines in my document :

[Ctrl + r] : ..............
[Ctrl + u] : ..............
...
[Ctrl + m] : ..............

What I want (using TeXworks replacement wizard) is to replace all the string matching the pattern [*] by \mycommand{$1} so the lines becomes :

\mycommand{Ctrl + r} : ..............
\mycommand{Ctrl + u} : ..............
...
\mycommand{Ctrl + m} : ..............

How should I proceed ?

  • Use emacs, it has a replace-regexp command. – Alex Feb 24 '13 at 12:49
  • @cgnieder not if i replace only the selection – vdegenne Feb 24 '13 at 13:39
6

TeXworks can replace regular expressions. Use Search->Replace from the menu (or Ctrl+R), then put \[Ctrl ([^]]*)\] in the "Replace" field and \mycommand{Ctrl \1} in the "With" field, and in addition activate the "Regular expression" checkbox.

Pressing "Replace" or "Replace all" will give the desired result.

  • Don't you need to use \\mycommand{Ctrl \1} in the "With" field? – Chaitanya Tappu Feb 7 at 2:08
  • @ChaitanyaTappu It works with one backslash and with two, but the latter could be safer, you're right. – Alex May 29 at 12:07

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.