Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Suppose I want to replace

x^{n_{1}}y^{n_{2}}z^{n_{3}}

with

x^{m_{1}}y^{m_{2}}z^{m_{3}}

Is there a fast way to do this? I am certainly missing this feature from LaTeX editors like gvim and kile. If I use the Ctrl+F dialog to find and replace "n" with "m", it does it on the whole document, and the change is so massive it won't let me revert (Ctrl+z)! So, I've learned to save before using that dialog.

share|improve this question
    
Perhaps you should define your search string more precisely. How about searching for {n_{ and replacing this with {m_{? That way it will only pertain to math-related subscripts. Also, most editors (I'm assuming LyX included) would allow search-and-replace to pertain to an entire file, or only a selection. –  Werner Oct 13 '11 at 5:32
    
@Werner You'd think, I haven't found the option to replace in a selection though. –  gatoatigrado Oct 13 '11 at 6:56
    
@gatoatigrado Remember that you can edit LaTeX with whatever you like. Lyx is different, as while it uses LaTeX, the native Lyx format is not LaTeX. –  Joseph Wright Oct 13 '11 at 7:18
    
@Joesph, yeah, I know that, I'm asking about replacement features in LyX. –  gatoatigrado Oct 13 '11 at 19:31
    
@Werner May you turn your comment into an answer? –  egreg Nov 5 '11 at 20:39
show 1 more comment

3 Answers

This wasn't a feature in LyX 1.6, when I asked the question, but LyX 2.0.1 allows find and replace in Math mode. To do this, hit Ctrl+Shift+F (advanced find and replace), then Ctrl+M (insert math mode) and type in an equation as you would in the main editor. Click "Settings" and uncheck "Ignore format". This will make it only search in math formulas.

Sadly, there doesn't seem to be an "in selection only" option. Of course, one could copy the desired text to a new editor window, do the replace, and copy it back, but this is a little cumbersome.

share|improve this answer
add comment

This is typically not an inherent feature of an editor. However, you can define your search more precisely to exactly find/replace what you're after. For example, search for {n_{ and replace this with {m_{. This way it will only pertain to math-related subscripts. It may also be required that you only apply this search-and-replace to a selection rather than the entire file.

For more elaborate search-and-replace routines, you could look into sed. It is a steam editor that can parse an input stream and modify its contents based on regular expressions.

share|improve this answer
    
Sorry, as I said in the comment, I'm looking for something that works in LyX –  gatoatigrado Nov 6 '11 at 5:30
add comment

Search&Replace within LyX has its limits, even though the situation has become a lot better with Lyx 2.0. I understand that the OP prefers a LyX-only solution. Nevertheless, whenever some complicated S&R task is not achievable in LyX directly, it is generally a good workaround to open the .lyx file in your favorite text editor (vim, emacs, ...) and edit the LyX source code directly. (Of course, one should make a backup first!)

My general approach is as follows:

  • "Save" the file in LyX
  • "Save as..." the file in LyX (create working copy)
  • Open the last saved file in vim while keeping it open in LyX
  • Do the S&R task in vim and save
  • Do a "Revert to saved" to check the results in LyX
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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