Need a simple regex for LaTeX

In my LaTeX files, I have literally thousands of occurrences of the following construction:

$\displaystyle{...math goes here...}$

I would like to replace them

\mymath{...math goes here...}

Note that $ disappears, but curly braces remain --- if not for the final $, this will be the base find and replacement. If I knew any regular expression, I am sure that he will cope with it without problems. What does regular expression need to make this happen?

Thank you very much in advance.

Edit: There were some problems and questions, so let me clarify:

  • Yes, it $\displaystyle{ ... }$can appear several times on the same line.
  • No, nested }$(for example $\displaystyle{...{more math}$...}$) cannot be. I suppose it's possible if you put it in \mboxor something like that, but I can't imagine why anyone ever did this inside a construct $\displaystlye{}$whose purpose is to display a math string with text. In any case, this is not what I have ever done or can do.
  • I tried using the perl clause, but until the shell objected, the files remained unaffected.
  • sed, " " ( ". sed (" man sed " ), : , .tex, " sed s/\$\\displaystyle({[^}]+})\$/\\mymath\1/g *.tex". . sed , ?

.

+3
3

:

s/\$\\displaystyle({[^}]+})\$/\\mymath\1/g
+4

REGEX : REGEX .

REGEX - ; , "{... math is here here...}" if - , , - "{more math} $" "math ". a - !

, , REGEX , " ", , .

... !

+4
perl -pi -e 's/$\\displaystyle({.*)}\$/\\mymath$1}/g' *.tex

} $ , :

perl -pi -e 's/$\\displaystyle({.*?)}\$/\\mymath$1}/g' *.tex
+1

Source: https://habr.com/ru/post/1730224/


All Articles