Buy this Domain

Discussions

Explore the latest discussions related to this domain.

best practices - Are \( and \) preferable to dollar signs for math mode? - TeX - LaTeX Stack Exchange

Main Post: best practices - Are \( and \) preferable to dollar signs for math mode? - TeX - LaTeX Stack Exchange

December 12, 2015 | Forum: tex.stackexchange.com

syntax - LaTeX: dollar sign vs \( \) - Stack Overflow

Main Post: syntax - LaTeX: dollar sign vs \( \) - Stack Overflow

November 16, 2011 | Forum: stackoverflow.com

Anyone knows how to quickly change math from $ $ to \( \) ?

Main Post:

Hi, newbie here. I am using Emacs and in particular Org mode for almost a month now.

I have some tex document that I want to copy-paste to canvas, but it is a bit of a pain because I need to change say $\tan (x)$ to \(\tan (x) \) and what I do is a bit silly and tedious doing it one by one, and that might be the only way to do it, but I was wondering if there was a quicker way to do it?

Thanks!

Top Comment:

As long as you don't have any other "$" characters in your text, you can solve this with a regular expression replacement.

If all of your matching "$" characters are on a single line, you can call M-x replace-regexp and replace the regexp \$\(.*?\)\$ with \\(\1\\). In case you are not familiar with regular expressions, I can break this one down:

The match:

  1. \$ : match the $ character. (This needs to be escaped because $ matches the end of the line in regular expressions)
  2. .*? : non-greedy match for any non-newline character. This makes sure that the regular expression matches the closest pair of $ characters.
  3. \(.*?\): place the non-greedy match in a grouping so we can use it in our replacement

Replacement:

  1. \\( : insert a backslash and a left parenthesis. The backslash must be escaped.
  2. \1 : insert the first group, which in this case is the match for .*?
  3. \\( : insert a backslash and a right parenthesis

Unfortunately, if you want to call this as an Emacs Lisp function (e.g. with M-:), you have to escape each of these backslashes. This gets pretty hideous pretty quickly.

Replaces $-pairs on the same line: (replace-regexp "\\$\\(.*?\\)\\$" "\\\\(\\1\\\\)")

Replaces $-pairs on the same or multiple lines: (replace-regexp "\\$\\(\\(.\\|\n\\)*?\\)\\$" "\\\\(\\1\\\\)")

You could then save put this code into a function to call whenever you like to replace all of the $-pairs in the document.

(defun my-tex-canvasify () (interactive) (save-excursion (replace-regexp "\\$\\(.*?\\)\\$" "\\\\(\\1\\\\)" nil (point-min) (point-max))))

January 26, 2023 | Forum: r/orgmode

Math typesetting using \( \) instead of the dollars - Mathematics Meta Stack Exchange

Main Post: Math typesetting using \( \) instead of the dollars - Mathematics Meta Stack Exchange

August 28, 2011 | Forum: math.meta.stackexchange.com