Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: auctex-like siunitx style with org-mode/scimax? #117

Closed
hummuscience opened this issue Aug 3, 2017 · 7 comments
Closed

Suggestion: auctex-like siunitx style with org-mode/scimax? #117

hummuscience opened this issue Aug 3, 2017 · 7 comments

Comments

@hummuscience
Copy link

I happen to write many SI-units in org-mode that is exported to latex and html. I end up writing a lot of $\SI{5}{\ng\per\ul}$ for example and it is pretty tedious. I know I could figure out a way using yasnippets to make things easier...

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.

@et2010
Copy link
Contributor

et2010 commented Aug 4, 2017

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!

@jkitchin
Copy link
Owner

jkitchin commented Aug 7, 2017

How do you use siunitx in latex? does it help write the units? i.e. how would it help with your example above?

@et2010
Copy link
Contributor

et2010 commented Aug 8, 2017

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:
demo1

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.
demo2

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.

@hummuscience
Copy link
Author

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?

@et2010
Copy link
Contributor

et2010 commented Aug 8, 2017

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.

@et2010
Copy link
Contributor

et2010 commented Aug 9, 2017

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.

@hummuscience
Copy link
Author

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 >.<).

@jkitchin jkitchin closed this as completed Jan 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants