2

I am working on literate programming in LaTeX. Actually, I am coding a lot of dtx files, which contain both the code and its documentation.

When working in Emacs, it uses AUCTeX and switches into TeXDoc-mode.

Quite often, I have to insert docstrip options or tags, which look like this:

%<*option> ... %</option> 

(That is: a percent sign in the first column and than the tag which is enclosed in less/greater brackets <>. The opening tag begins with a asteriks *, the closing tag has a slash /. Of course, the name of the tag (here: option) has to be spelled identically.)

I would love to have some kind of Emacs function, which inserts this special kind of enviroment. Using the classical LaTeX-environment is not suited, as it inserts \begin and '\end`, which is not what I need.

I didn't find a hint in the manual.

Edit: I had a second question related to this theme.

1 Answer 1

2

You could write your own function and hook it into docTeX mode with a key binding, e.g. C-c g

(defun my/docTeX-guards () (interactive) (let ((guard (TeX-read-string "Guard: "))) (LaTeX-newline) (unless (equal (char-before) ?%) (insert "%")) (insert (concat "<*" guard ">")) (newline) (save-excursion (newline) (insert (concat "%</" guard ">"))))) (add-hook 'docTeX-mode-hook (lambda () (define-key docTeX-mode-map "\C-cg" #'my/docTeX-guards))) 
3
  • Thank you very much. This works pretty well! I am very happy! Commented Mar 7, 2017 at 19:22
  • @Jan - You're welcome. Happy TeXing. Commented Mar 8, 2017 at 19:46
  • Arash, thank you very much. I added an newline after the last insert. It works fine. I am very happy with it. Commented Mar 11, 2017 at 11:55

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.