Home About me Blog Po polsku

Content AND Presentation

2014-09-20 Smart ties in Emacs

As all TeX users know, in all flavors of TeX you use the tilde (~), called a “tie” in The TeXbook, to denote non-breakable spaces. Of course, if you use Emacs, you may use some helpers, like tildify to insert them interactively or after typing/yanking some text. But what I sometimes do is yank some short fragments of text from various sources, or just forget to type a tie (though I trained myself to type them after e.g. all one-letter prepositions, which – according to Polish rules of typesetting – should not dangle at the end of the line by themselves). Then, I prefer to insert the tie by hand. The problem is, I had to delete the space and then press ~; two keystrokes instead of one. Blechhh. So I wrote this short piece of Elisp, and tied (pun intended) it to ~ (thanks to this answer on StackOverflow, I learned how to bind it using eval-after-load).

(defun electric-tie ()
  "Inserts a tilde at point unless the point is at a space
character(s), in which case it deletes the space(s) first."
  (while (equal (char-after) ?\s) (delete-char 1))
  (while (equal (char-before) ?\s) (delete-char -1))
  (call-interactively 'self-insert-command))

(eval-after-load 'tex '(define-key TeX-mode-map "~" 'electric-tie))

(Note: the quoted answer contains some suggestions of improving this code in terms of style. While I didn’t bother to do that, reading that answer is probably a good idea.)

CategoryEnglish, CategoryBlog, CategoryEmacs

Komentarze na tej stronie

2014-09-13 TeX input method

Some time ago, someone on the Emacs mailing list asked about entering a letter not present on a (typical) keyboard. There are a few ways to do it, some at the OS level and some on the editor level. The usual Emacs way is C-x 8 " o to get ö etc. (Incidentally, there seems to be no analogous command for œ, which was asked in that question! Also, I strongly recommend hitting C-x 8 C-h and at least skimming through the results, and checking out C-x 8 RET.) I was a bit surprised, though, that nobody mentioned the TeX input method. Input methods are Emacs’ ways of entering “complicated” characters. (Many of them are designed to enter Chinese, Japanese or Korean languages.) In my setup, I have the TeX input method as the default (this can be achieved e.g. by putting (setq default-input-method "TeX") in your init.el). (Normally, you don’t have any input method turned on; C-\ toggles between no input method and your default one, and C-x RET C-\ sets the default one.) Now, typing \"o instead of C-x 8 " o is a small (but noticeable) gain. The real strength of the TeX input method is in typing math symbols. Try it yourself: not only \alpha (α), \beta (β) and other Greek letters work, but also all the Unicode goodness like \int (∫), \infty (∞), \in (∈), \subset (⊂), \aleph (ℵ), \heartsuit (♥) and lots of other ones. (Also, some sub- and superscripts work, like \aleph_0 (ℵ₀) or \pi r^2 (π r²).)

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryTeX

Komentarze na tej stronie

2014-09-01 Quick opening of the init file

Since I’m continuously tweaking my Emacs configuration, I found myself repeatedly opening my init file, hitting C-x C-f init RET (with a few moments of waiting before RET, so that ido has a chance to recall where my init.el resides). Since I was a bit tired of that, I finally looked for some undefined key, found C-h C-i (maybe not the best combo, but who cares), and did this:

(global-set-key (kbd "C-h C-i")
		(lambda ()
		  (orgstruct-mode 1)))

As you can see, I’m turning Orgstruct mode here. It seems that it’s the easiest way to ``orgify’’ one’s init file, and I didn’t want to turn Orgstruct mode on with a file-local variable, since then Emacs would load Org before my customization of e.g. org-export-backends (or at least I think so, in fact, I didn’t check it). Of course, I also did

(setq orgstruct-heading-prefix-regexp ";; ")

and now I can fold and unfold sections of my init file. Finally!
CategoryEnglish, CategoryBlog, CategoryEmacs

Komentarze na tej stronie


(Więcej means More in Polish; click it to see older entries.)

CategoryEnglish, CategoryBlog