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.

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)))
  • Thank you very much. This works pretty well! I am very happy! – Jan Mar 7 '17 at 19:22
  • @Jan - You're welcome. Happy TeXing. – Arash Esbati Mar 8 '17 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. – Jan Mar 11 '17 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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