Suggestion: auctex-like siunitx style with org-mode/scimax?
hummuscience opened this issue · 7 comments
I happen to write many SI-units in org-mode that is exported to latex and html. I end up writing a lot of
However, I stumbled onto this: https://github.com/emacsmirror/auctex/blob/master/style/siunitx.el
Which is an auctex style for siunitx that makes the entering of SI-units easier in emacs Auctex mode. Is there a way to introduce this into org-mode and then ship it with scimax? I think many people might benefit from it.
Hi, I think scimax already supports the feature you asked via org-edit-latex: https://github.com/et2010/org-edit-latex
You can try it by M-x org-edit-latex-mode
, and just edit any fragment and write your siunitx macros. You get completion with auctex instantly. No additional setup is needed if you got a working org-preview setting.
Cheers!
How do you use siunitx in latex? does it help write the units? i.e. how would it help with your example above?
I made 2 animated gifs to demonstrate the feature:
First one is to use org-edit-latex
to edit SI macro without creating a master first:
And after we create a master file first (by default, turn on org-edit-latex
will create a master file in the same directory where your org file is), we can complete via auctex and even preview in the latex buffer.
does it help write the units?
Yes, it does. With siunitx, you don't have to worry about the spaces between numbers and units, the face of the units, the character between ranged numbers, etc. etc.
Thank you @et2010 I will try it out with my setup. Does auctex come with the siunitx style or do I need to add/install it somewhere?
Would this also work if the number and unit are in-line/mid sentence and not an equation?
You're welcome.
Does auctex come with the siunitx style or do I need to add/install it somewhere?
Yes, the siunitx style is shipped with auctex.
Would this also work if the number and unit are in-line/mid sentence and not an equation?
Yes, it does.
That said, I think cdlatex is a better approach for completing inline latex. It's not a good idea to open a new buffer just to edit a unit.
To complete siuintx with cdlatex, first you need to install cdlatex, then you can add following to you configuration:
(add-hook 'org-mode-hook 'turn-on-org-cdlatex)
(setq cdlatex-command-alist '(("ang" "Insert \\ang{}"
"\\ang{?}" cdlatex-position-cursor nil t t)
("si" "Insert \\SI{}{}"
"\\SI{?}{}" cdlatex-position-cursor nil t t)
("sl" "Insert \\SIlist{}{}"
"\\SIlist{?}{}" cdlatex-position-cursor nil t t)
("sr" "Insert \\SIrange{}{}{}"
"\\SIrange{?}{}{}" cdlatex-position-cursor nil t t)
("num" "Insert \\num{}"
"\\num{?}" cdlatex-position-cursor nil t t)
("nl" "Insert \\numlist{}"
"\\numlist{?}" cdlatex-position-cursor nil t t)
("nr" "Insert \\numrange{}{}"
"\\numrange{?}{}" cdlatex-position-cursor nil t t)))
After M-x org-cdlatex-mode
, you can complete siunitx macros using above templates. For instance, after typing $
or \(
(This will tell org that you are in a latex fragment), you can type si
then press tab
to get \SI{}{}
. And you can move cursor by pressing tab
.
The tip with cdlatex is a big help already, thank you @et2010. I still wonder if there is a way to combine this cdlatex approach with the auctex style. Specially when I am using a unit I do not know the exact format for in siunitx or to avoid typos (I keep writing celsius wrong >.<).