Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
20 votes
Accepted

sin of pi radians

The Emacs Lisp constant pi is not actually the number 𝜋. Rather, the Emacs Lisp constant pi is an approximation to 𝜋, good to about 16 digits -- pi is exactly 3....
Sūrya Siddhānta's user avatar
6 votes

sin of pi radians

I think this is simply the expected answer. As a float, 1.2246467991473532e-16 is not different from zero, given the floating point error Emacs Lisp can handle. One get the same answer in R for ...
Philopolis's user avatar
  • 1,134
5 votes
Accepted

How to insert mathematical symbols in emacs

You can set the insert method with M-x set-input-method RET tex. Then type \beta and watch it get converted. It can be toggled and set with C-\! Tested and confirmed that it compiles and renders ...
mcp's user avatar
  • 556
5 votes

sin of pi radians

You are doing nothing wrong. This function is working with floating point numbers which have good, but limited, accuracy. 1.2246467991473532e-16 is pretty close to 0 (0.0... with 15 zeros before the ...
Fran Burstall's user avatar
4 votes
Accepted

How can I convert a Lisp expression to a LaTeX math expression?

Here is a toy function: (defvar lisp2latex-need-parens nil) (defun lisp2latex (form) (pcase form (`(+ . ,args) (let ((ret (let ((lisp2latex-need-parens nil)) (mapconcat #'...
sds's user avatar
  • 6,124
4 votes
Accepted

Convert percent to decimal: (/ PERCENT 100)

Your workaround tells the whole story: (/ 1 2) ;=> 0 (/ 1.0 2) ;=>0.5 With integers, emacs does integer arithmetic, with floats it does floating-point arithmetic. See the Elisp manual, node ...
Fran Burstall's user avatar
4 votes
Accepted

Cube root in elisp

There are a couple of ways: (expt 8 (/ 1.0 3.0)) ⇒ 2.0 Or, if you want symbolic results: (require 'calc-arith) (calcFunc-pow 8 (calcFunc-inv 3)) ⇒ (float 2 0) (calcFunc-pow 8 (calcFunc-inv (list 'x)))...
db48x's user avatar
  • 18.2k
4 votes
Accepted

How get decimal values?

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 ...
phils's user avatar
  • 51.5k
3 votes

How to insert mathematical symbols in emacs

I love the accepted answer, but I also wanted to point out that you can insert unicode characters by name using C-x 8 RET. This will bring up a selection list in the minibuffer that lets you type the ...
lmjohns3's user avatar
  • 273
3 votes

Using `string-to-number` causes rounding/precision issue for specific floating point values

What Every Programmer Should Know About Floating-Point Arithmetic is an excellent guide to understanding floating point numbers. I thoroughly recommend reading that in full -- I think it will answer ...
phils's user avatar
  • 51.5k
3 votes
Accepted

How can you automatically translate fractions into their short unicode versions? e.g. ⅔

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-...
Muihlinn's user avatar
  • 2,634
2 votes

How can you automatically translate fractions into their short unicode versions? e.g. ⅔

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 ...
rpluim's user avatar
  • 5,315
2 votes

Insert trigonometric function to org file

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)$...
jue's user avatar
  • 4,576
2 votes

Replace text with latex

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 ...
Tobias's user avatar
  • 33.2k
1 vote

change environment in evil-tex

From the documentation, the environment keymap for multiline* is M. So for example from inside your equation environment in evil-normal-state, you can change the equation environment to multiline* ...
nanowillis's user avatar
1 vote

How do I convert a `matrix` in one form to a `matrix` in another form (like `bmatrix` environment)

I suggest you use Calc. You can set language mode to latex, temporarily by opening a Calc session, or permanently by saving the configuration in the calc.el file. Enable calc-embedded when the point ...
gigiair's user avatar
  • 2,186
1 vote

How do I convert a `matrix` in one form to a `matrix` in another form (like `bmatrix` environment)

EDIT There is/was a bug in the replace-string-in-region function. Using the newest version of that function, your code works alright, except for some unwanted newlines due to the first backslash in ...
dalanicolai's user avatar
  • 7,845
1 vote
Accepted

LaTeX fragments look different to exported PDF (witharrows)

Thanks to @NickD I have found a solution. The solution is to register a custom org-preview-latex-process and run pdflatex/lualatex twice for generating the latex preview image: (setq luamagick '(...
Oma Paloma's user avatar
1 vote

LaTeX fragments look different to exported PDF (witharrows)

[Not a complete answer: in the first part, I show the TeX file for the preview and identify the problematic component of the pipeline, but I don't know why that component misbehaves. In the second ...
NickD's user avatar
  • 30.4k
1 vote
Accepted

Key sequence to automatically make math-mode fragments in org-mode?

I have a yasnippet for this: # -*- mode: snippet; require-final-newline: nil -*- # name: math for Org # key: $$ # binding: direct-keybinding # -- \\($1\\) $0 I type $$ and get what you want: \(_\).
mankoff's user avatar
  • 4,226
1 vote
Accepted

Use LaTeX accents with tex insert method

M-x describe-input-method RET tex RET will tell you the (somewhat depressing) news: lots of letters can be "hatted" but they are Latin letters only. Input methods are limited in the kind of ...
NickD's user avatar
  • 30.4k
1 vote
Accepted

Remove math fragments from buffer in org mode

Just use an C-u prefix: From the docs: (org-latex-preview &optional ARG) Toggle preview of the LaTeX fragment at point. If the cursor is on a LaTeX fragment, create the image and overlay it over ...
student's user avatar
  • 1,109
1 vote
Accepted

Labelling LaTeX sub-equations in org-mode

Your question is a little bit ambiguous - while the snippet in your link provides numbering as (1a), (1b), you ask for specific like (a), (b). Both versions are possible, as below. To solve, you ...
Ian's user avatar
  • 1,483
1 vote
Accepted

Customize org babel execution command in C

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",...
NickD's user avatar
  • 30.4k
1 vote

Evaluate algebraic formula in the buffer in place

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-...
Tom's user avatar
  • 1,260
1 vote
Accepted

Evaluate algebraic formula in the buffer in place

calc provides calc-eval for this kind of use, just pass it a string and receive a string result back.
wasamasa's user avatar
  • 22.2k

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