Hot answers tagged

4

Assuming you're happy with floating point arithmetic then you just need to make one of the numbers a float. e.g.: (/ 15.0 6) => 2.5 Refer to C-hig (elisp)Arithmetic Operations each of these functions accepts both integer and floating-point arguments, and returns a floating-point number if any argument is floating point.


3

You could use prettify-symbols-mode with something, evaluable in your sratch buffer, like this: (progn (push '("2/3" . ?⅔) prettify-symbols-alist) (prettify-symbols-mode -1) (prettify-symbols-mode +1)) It only adds that particular fraction and it's unicode counterpart to the list of symbols to prettify, then resets the mode If it works as expected, ...


2

Yes, by using Latex and preview that. Have a read at the org-mode manual org-latex-preview section. There are embedded formulae like $\sin(r) = 3\sin\left(\frac r3\right)-4\sin^3\left(\frac r3\right)$ or displayed formulae like \begin{align} \sin(r) = 3\sin\left(\frac r3\right)-4\sin^3\left(\frac r3\right) \label{eq:MyFirstLaTeXEquation} \end{align} ...


2

Go to the beginning of your text and press C-M-%. That key sequence is bound to the command query-replace-regexp. Give \([+-]?[0-9]+\|\_<[[:alpha:]]\)/\([+-]?[0-9]+\|[[:alpha:]]\_>\) as search string and {\1 \\over \2} as replacement and press RET. Note that this searches for integers maybe composed of several digits and with optional sign + or -. ...


2

If you're willing to have the text change, you can use one of Emacs' many input methods. With e.g. rfc3145, you could type that as &23 or with TeX it would be \\frac23 Use C-\ to choose your input method.


1

Use the :flags or :libs header to pass flags to the compiler (or libraries to the linker): #+begin_src C :libs -lm #include <stdio.h> #include <math.h> int main(){ printf("Square = %f", pow(4,2)); return 0; } #+end_src See the Working with source code/Languages section of the Org mode manual. That contains a link to a page on Worg with ...


1

For reference I'm posting my solution based on wasamasa's answer: (save-excursion (beginning-of-line) (if (re-search-forward " *=.*" (line-end-position) t) (replace-match "")) (end-of-line) (insert " = " (calc-eval (buffer-substring-no-properties (line-beginning-position) (line-end-position) ...


1

calc provides calc-eval for this kind of use, just pass it a string and receive a string result back.


Only top voted, non community-wiki answers of a minimum length are eligible