Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed replacing tex short-hand $$ with latex short-hand \( \)

Tags:

bash

sed

latex

I currently have a problem when editing my manuscript.tex files. So far I have always used the text short-hand $$; however, something comes up and it requires me to replace all $...$ by \( \).

I think "sed" with replacement operation should be a right tool for the task. However, I am not good or familiar with "sed" and regular expression. Therefore, I need hints and helps for doing this.

Supposed the input file is named as manuscript.tex. I need "sed" to replace $ e=mc^2 $ with \( e=mc^2 \). How can I do this ?

like image 499
lengoanhcat Avatar asked Sep 08 '25 01:09

lengoanhcat


2 Answers

If there is never a newline between the dollar signs, you can try something like

sed -e 's/\$\([^$]\+\)\$/\\(\1\\)/g' manuscript.tex > manuscript2.tex
like image 138
choroba Avatar answered Sep 11 '25 23:09

choroba


Other way using sed

sed -re 's/(.*)\$(.*)\$(.*)/\\(\2\\)/g' temp.txt

like image 29
Mirage Avatar answered Sep 11 '25 23:09

Mirage