LyXProblem with Search and replace in math equations

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Post Reply
soszoe
Posts: 3
Joined: Mon Mar 30, 2015 8:15 pm

Problem with Search and replace in math equations

Post by soszoe »

Briefly:
I want to search and replace the string sn by \sn
inside math equations.
I can't find how to do that, trying different options I get
undesired results.

Now more details:

I have written an article using the special function sn
(Jacobi elliptic function). Example:

Code: Select all

\[  \frac{sn^2(x)}{1+a sn(x)} \]
Afterwards I wanted to use the right typography for mathematical
functions and use the new command \sn.
In the preamble I declared:

\DeclareMathOperator{\sn}{sn}

Then I wanted to replace every "sn" by "\sn". Example:
\[ \frac{\sn^2(x)}{1+a \sn(x)} \].


I'm not able to do this in any way.
Thanks a lot.
Soszoe

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

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

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Problem with Search and replace in math equations

Post by Johannes_B »

Hi and welcome,

since it is quite possible, that you also have the letters sn in normal text, or as well inside an equation, your only chance seems to be interactively change every occurence of the string.


I think the chance of looking out for non letter followed by sn followed by non letter might be unique and more easy to change. But that is something for experienced regular expressions guys. Sadly, i am not one of them.

You could ask on superuser.com or unix.stackexchange.com/. Using sed or awk should get the task done, but this might be quite hard if you have no experience at all and you might be faster by doing manually.
If you decide to ask for help on regular expressions (please crosslink and share the solution with us) you might be faster if there is ever the need to do that again. Regular expressions are always helpful ;-)

On the other hand, this could have been prevented by some more preparation :-p
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
soszoe
Posts: 3
Joined: Mon Mar 30, 2015 8:15 pm

Re: Problem with Search and replace in math equations

Post by soszoe »

Hi Johannes_B, thank you for your reply.
I thought there was an easy way to do that in LyX because for me it should be a common action to search in equations and modified them automatically.
What I think I'm going to do is to edit the file with an external text editor and then search and replace the strings as normal text. I can't figure out why it can't be done inside LyX.
thank you again.
scottkosty
Site Moderator
Posts: 542
Joined: Sat Sep 01, 2012 6:38 am

Re: Problem with Search and replace in math equations

Post by scottkosty »

Note that LyX's Advanced Find (ctrl + shift + f) can search within maths.
soszoe
Posts: 3
Joined: Mon Mar 30, 2015 8:15 pm

Re: Problem with Search and replace in math equations

Post by soszoe »

Yes. I know, I have used it.
The problem is not searching but replacing. When I try to search and replace "sn" by "\sn" I get weird results as LyX doest not paste the plain string \sn straightforwardly.
Post Reply