I want to replace all hard column widths in several LaTeX-documents, e.g. replace {90mm}
by {0.75\textwidth}
. I already found out that you can use \,
and #1
to so arithmetics on captured groups, like e.g. here. But I can't get it to work in a lisp function. I tried several things to no avail, and now would like if this is possible at all, and if yes, how.
Here's something that I came up with that doesn't work:
(defun colum-width-relative ()
""
(interactive)
(beginning-of-buffer)
(save-excursion
(query-replace-regexp
"{\\([0-9]+\\)mm}"
(concat "{0." \,(/ (* #1 100) 120) "\\\\textwidth}"))))
query-replace-regexp
is intended for interactive use, the way to do this is to usere-search-forward
in a loop, based on(match-string 1)
make a decision about the new value of text width, and then usereplace-match
to substitute it with the new value. – wvxvw Jun 22 '17 at 8:25