0

I'm trying to evaluate the differences of writing in Org and LaTeX for my Master's thesis. A feature I find very useful in Org is CDLaTeX. To have a unique workflow between the two, I'd like to use CDLaTeX also for LaTeX, instead of LaTeX-math-mode. For what I know (correct me if I'm worng), this is possible in LaTeX (AUCTeX) buffers, but the functionalities of the two packages sometimes conflicts.

My current config for AUCTeX is:

(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq TeX-debug-bad-boxes t)
(setq-default TeX-master nil)
(setq TeX-electric-math (cons "\\(" "\\)"))
(setq LaTeX-electric-left-right-brace t)
(setq prettify-symbols-unprettify-at-point 'right-edge)

(add-hook 'LaTeX-mode-hook 'prettify-symbols-mode)
(add-hook 'latex-mode-hook 'prettify-symbols-mode)

(add-hook 'LaTeX-mode-hook 'turn-on-cdlatex)
(add-hook 'latex-mode-hook 'turn-on-cdlatex)

(defun my--LaTeX-CDLaTeX-utils-setup ()
  "Set up variables and similar that should be active only in LaTeX (AUCTeX) buffers."
  (setq-local cdlatex-takeover-dollar nil
          cdlatex-takeover-parenthesis nil))

(add-hook 'LaTeX-mode-hook 'my--LaTeX-CDLaTeX-utils-setup)
(add-hook 'latex-mode-hook 'my--LaTeX-CDLaTeX-utils-setup)

Since in Italian the apostrophe (') is used as a punctuation mark, I'd like to have cdlatek-math-modify disabled when non in a math environment, so that I can type apostrophized words. Instead, If I type it in a "text" area, it triggers the completion (but I don't really need the basic font formatting functions, as they are already in AUCTeX). How can I make CDLaTeX detect the difference and not kick in in text areas?

My Emacs version is GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.34, cairo version 1.17.6) of 2022-07-31, Org is Org mode version 9.5.4 (release_9.5.4-17-g6e991f @ /usr/share/emacs/29.0.50/lisp/org/)

2 Answers 2

0

One solution would be to change the prefix-key from ' to something, that is used less often in Italian. This can be achieved by, for example:

(setq cdlatex-math-modify-prefix [f7])

Another solution would be to remove the functionality of cdlatex-math-modify in non-math mode, such that when pressing ' b the same happens as when pressing ' w, namely it just gets inserted normally.

This can be achieved by the following:

(setq cdlatex-math-modify-alist-default
  '(
   ( ?\.   "\\dot"               nil        t   t   nil )
   ( ?\:   "\\ddot"              nil        t   t   nil )
   ( ?\~   "\\tilde"             nil        t   t   nil )
   ( ?N    "\\widetilde"         nil        t   t   nil )
   ( ?^    "\\hat"               nil        t   t   nil )
   ( ?H    "\\widehat"           nil        t   t   nil )
   ( ?\-   "\\bar"               nil        t   t   nil )
   ( ?T    "\\overline"          nil        t   nil nil )
   ( ?\_   "\\underline"         nil        t   nil nil )
   ( ?\]    "\\overbrace"         nil        t   nil nil )
   ( ?\}   "\\underbrace"        nil        t   nil nil )
   ( ?\>   "\\vec"               nil        t   t   nil )
   ( ?/    "\\grave"             nil        t   t   nil )
   ( ?\\   "\\acute"             nil        t   t   nil )
   ( ?v    "\\check"             nil        t   t   nil )
   ( ?u    "\\breve"             nil        t   t   nil )
   ( ?m    "\\mbox"              nil        t   nil nil )
   ( ?t    "\\text"              nil        t   nil nil )
   ( ?c    "\\mathcal"           nil        t   nil nil )
   ( ?r    "\\mathrm"            nil        t   nil nil )
   ( ?i    "\\mathit"            nil        t   nil nil )
   ( ?l    nil                   nil        t   nil nil )
   ( ?b    "\\mathbf"            nil        t   nil nil )
   ( ?e    "\\mathem"            nil        t   nil nil )
   ( ?y    "\\mathtt"            nil        t   nil nil )
   ( ?f    "\\mathsf"            nil        t   nil nil )
   ( ?0    "\\textstyle"         nil        nil nil nil )
   ( ?1    "\\displaystyle"      nil        nil nil nil )
   ( ?2    "\\scriptstyle"       nil        nil nil nil )
   ( ?3    "\\scriptscriptstyle" nil        nil nil nil )
   ( ?\(    "\\left( ? \\right)"  nil        nil nil nil )
   ( ?\[    "\\left[ ? \\right]"  nil        nil nil nil )
   ( ?\{    "\\left\\{ ? \\right\\}" nil     nil nil nil )
   ( ?<    "\\left< ? \\right>"  nil        nil nil nil )
   ( ?|    "\\left| ? \\right|"  nil        nil nil nil )
   )
"Default for `cdlatex-math-modify-alist'.")

Note that I just copied the definition of cdlatex-math-modify-alist-default and substituted the commands like "\textrm", which should be executed by Keystrokes like ' r in Textmode, by nil.

(But be aware, that hereby I changed a constant, because cdlatex-math-modify-alist was defined via defconst. Since this is not enforced in emacs-lisp one can change it nevertheless but it is bad style.)

0

Turned out CDLaTeX provides two minor modes: cdlatex-mode and org-cdlatex-mode.

org-cdlatex-mode is the one designed to integrate with Org, and behaves in the same way as in Org buffers (checking if it's inside a math fragment).

cdlatex-mode is wider, gives more keybindings, but works differently. I suppose(?) it is designed as a replacement for LaTeX-math-mode (infos about this are very welcome)

Therefore, changing

(add-hook 'LaTeX-mode-hook 'turn-on-cdlatex)
(add-hook 'latex-mode-hook 'turn-on-cdlatex)

to

(add-hook 'LaTeX-mode-hook 'org-cdlatex-mode)
(add-hook 'latex-mode-hook 'org-cdlatex-mode)

does the trick

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.