help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Two short questions about calc


From: Michael Heerdegen
Subject: Re: Two short questions about calc
Date: Thu, 01 Oct 2020 01:52:07 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi Stefan Monnier,

> > also a mode for tex output.  If we already have tex, could we not just
> > ... tex that and insert the picture into the output buffer?  I'm sure
>
> Hmm... is it me, or you forgot to attach the patch to your message?

No, it's you.

Ok - I tried to find anything reusable to do the latex => image part.
Auctex didn't really fit (and I didn't like the coding in preview.el),
so I guess org preview stuff could help to make the image.  And then I
found I can use Calc output filter stuff to change the display text
property to show the image instead.  That works, basically, but it's not
that nice:

#+begin_src emacs-lisp
  (require 'calc-lang)
  ;; (calc-set-language 'big nil 'no-refresh)
  (progn
    (calc-set-language 'latex nil 'no-refresh)
    (defun my-latex-output-filter (s)
      (let (prefix latex-string file-string)
        (if (string-match "\\([ ]+\\)\\(.+\\)" s)
            (setq prefix (match-string 1 s)
                  latex-string (match-string 2 s))
          (setq prefix "" latex-string s))
        (setq file-string
              (with-temp-buffer
                (insert (concat "$" latex-string "$\n"))
                (cl-letf (((plist-get org-format-latex-options :scale) 1.7))
                  (org-format-latex "/tmp/ltximg/org-ltximg"
                                    (point-min) (copy-marker (point-max))
                                    "/tmp/" nil nil 'forbuffer 'dvipng))
                (goto-char (point-min))
                (if (search-forward-regexp "\\[\\[file:\\(.*\\)\\]\\]" nil t)
                    (match-string 1)
                  nil)))
        (concat prefix (if file-string
                           (propertize latex-string 'display
                                       (create-image file-string 'png nil :mask 
'heuristic))
                         latex-string))))

    (put 'latex 'math-output-filter 'my-latex-output-filter))
#+end_src

I works - most of the time -- sometimes I get "image has not been
created, check this and that" messages, I didn't yet investigate.  The
good part is, Calc commands don't seem to interfere at all with this
hack.  That's where I expected the real problems.  Once it really works,
I would make it a separate language of course, "latexed-latex",
probably.


Regards,

Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]