>> On Thu, 22 Mar 2012 20:58:17 +0100, Lars Magne Ingebrigtsen wrote: > Uwe Brauer writes: >> For example the function gnus-article-fill-cited-article runs on an >> article. How could I write a function based on >> TeX-to-char-paragraph-or-region which does what I want. > Start with a simpler function, like > (defun article-treat-ansi-sequences () > "Translate ANSI SGR control sequences into overlays or extents." > (interactive) > (save-excursion > (when (article-goto-body) > (let ((inhibit-read-only t)) > (ansi-color-apply-on-region (point) (point-max)))))) > And just replace the ansi stuff with the function you want to call. Cool! That works nicely for the TeX-to-char-paragraph-or-region function. However for the org-preview function it does not! Here is the code (defun article-treat-org-preview () "Translate ANSI SGR control sequences into overlays or extents." (interactive) (save-excursion (when (article-goto-body) (let ((inhibit-read-only t)) (org-preview-latex-fragment nil))))) And the documentation of org-preview-latex-fragment ,---- | `org-preview-latex-fragment' is an interactive Lisp function | -- loaded from "org" | (org-preview-latex-fragment &optional SUBTREE) | | Documentation: | Preview the LaTeX fragment at point, or all locally or globally. | If the cursor is in a LaTeX fragment, create the image and overlay | it over the source code. If there is no fragment at point, display | all fragments in the current text, from one headline to the next. With | prefix SUBTREE, display all fragments in the current subtree. With a | double prefix arg C-u C-u, or when the cursor is before the first headline, | display all fragments in the buffer. `---- I obtain an error whose bug trace I attach. I had the following trivial function (defun org-preview-article () "Saves the article to temporary buffer and apply `org-preview-latex-fragment'." (interactive) (let* ((tempfile "/tmp/texfile")) (shell-command (format "touch %s" tempfile)) (delete-file tempfile) (with-current-buffer gnus-article-buffer (write-region (point-min) (point-max) tempfile nil nil nil 'utf-8-unix) (find-file tempfile) (org-preview-latex-fragment nil)))) which sort of works but is not what I want.