[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[AUCTeX] Re: embed preview<ed>-latex into FriCAS mode
From: |
Martin Rubey |
Subject: |
[AUCTeX] Re: embed preview<ed>-latex into FriCAS mode |
Date: |
21 Oct 2008 10:16:45 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
The following message is a courtesy copy of an article
that has been posted to gnu.emacs.help as well.
Dear all,
meanwhile I found a relatively simple method to do most of what I want to,
i.e., embed latex'ed snippets into a non-LaTeX buffer. Since the remaining
questions may just as well be regarded as "pure" gnu-emacs questions, I
crosspost, with apologies.
In the function below I call latex on a minimal LaTeX file (preamble due to
David Kastrup, I believe), and use insert-image and create-image to embed it
into the buffer. The ugly definition of bg is due to the fact that emacs seems
to ignore transparent background (created by dvipng with "-bg Transparent",
transparent with capital "T".)
Now, the following problems remain:
* I'd like to allow the user toggling between LaTeX-sourcecode and the image.
Furthermore, saving the buffer should really save the LaTeX-sourcecode.
* is there a good way to adapt the size of the font used in the image to the
size of the font used in the emacs buffer?
* dvipng seems to clip the latex.
Running (call-process "dvipng" nil nil nil "-bg" bg "-o" png dvi)
where dvi is the file produced by running latex on
\documentclass{article}\usepackage[active,dvips,tightpage,displaymath]{preview}
\begin{document}\begin{preview}$$ \left[ {\left[ {function={\left[ {\left[ x
\sp n \right]}{f \left( {x} \right)} \mbox{\rm : } {{{-{x \ {{f \sb {{\ }} \sp
{,}} \left( {x} \right)}}+{{f \left( {x} \right)} \sp 3} -{{f \left( {x}
\right)} \sp 2}}=0}, \: {{f \left( {0} \right)}={1 \ {{\left( 0 \right)}!}}}}
\right]}}, \: {order=0} \right]} \right] \leqno(6)
$$\end{preview}\end{document}
produces an image that has everything after "order" (found in line -1)
clipped.
Please excuse the crossposting,
Martin
(defvar fricas-TeX-preamble
(concat "\\documentclass{article}"
"\\usepackage[active,dvips,tightpage,displaymath]{preview}"
"\\begin{document}"
"\\begin{preview}"))
(defvar fricas-TeX-postamble "\\end{preview}\\end{document}")
(defun fricas-insert-TeX ()
(let* ((tmp (make-temp-file "fricas" nil ".tex"))
(bas (file-name-sans-extension tmp))
(dir (file-name-directory tmp))
(png (concat bas ".png"))
(dvi (concat bas ".dvi"))
(bg (apply 'format
"rgb %f %f %f"
(mapcar (function (lambda (v) (/ v 65535.0)))
(color-values (face-background
'fricas-algebra)))))
(inhibit-read-only t))
(write-region (concat fricas-TeX-preamble
fricas-TeX-buffer
fricas-TeX-postamble)
nil tmp)
;; TeX the file
(call-process "latex" nil nil nil (concat "-output-directory=" dir) tmp)
;; png the output
(call-process "dvipng" nil nil nil "-bg" bg "-o" png "-D110" dvi)
;; create and insert the image
(insert-image (create-image png 'png nil))
(fricas-insert-ascii "\n" 'fricas-undefined)
(setq fricas-TeX-buffer "")))