Kile ⇒ searching in math mode only
searching in math mode only
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
searching in math mode only
Best regards
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: searching in math mode only
Re: searching in math mode only
^[^\$]*\$[^\$]*e[^\$]*\$
will find any e's within the first set of $ ... $ on a given line, but it'll still find things like the e in $\epsilon$, so it's not safe to use as part of a Find and Replace. If you use $...$ more than once on a given line it won't find those. (I could alter it so it does, but then you'd also find things between the $ that ends the first mathmode and the $ that begins the second which isn't useful.)
There may be ways to improve that though, especially with more detailed knowledge about exactly in what contexts your "e" may appear... but I don't know of a search mechanism especially for math mode.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
searching in math mode only
You should have specified that correctly right at the beginning. You only talked about $e$ and not about the variable e in math expressions. But perhaps I misunderstood something.mf205 wrote:Thanks for the reply, but this will only work when e appears by itself; it won't change $e+1$ to $n+1$, for example.
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
searching in math mode only
Just a note that with extended regular expressions one can find all occurrences of e in math mode on the line via the following simple modification:frabjous wrote:Putting the search mode to "regular expressions" and searching for:
^[^\$]*\$[^\$]*e[^\$]*\$
will find any e's within the first set of $ ... $ on a given line, but it'll still find things like the e in $\epsilon$, so it's not safe to use as part of a Find and Replace. If you use $...$ more than once on a given line it won't find those. (I could alter it so it does, but then you'd also find things between the $ that ends the first mathmode and the $ that begins the second which isn't useful.)
There may be ways to improve that though, especially with more detailed knowledge about exactly in what contexts your "e" may appear... but I don't know of a search mechanism especially for math mode.
^([^\$]*\$[^\$]*e[^\$]*\$)+
On the other hand, this won’t find occurrences of e occurring in display math mode, and I haven’t found any way of finding those using just a search with extended regular expressions (though it might be possible).
Alternatively, if you are in a position like me and have to change most occurrences of n inside any kind of math mode in a very long file, it is possible to write a fairly short script using awk, egrep and sed to extract everything in math mode and display math mode, together with original file line numbers, into separate files which you can then search — though this does mean that one’s searching and replacing have to be done in different files. If anybody is interested I can post my version here.