emacs-orgmode
[Top][All Lists]
Advanced

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

[Orgmode] Adding latex packages


From: Matthieu Lemerre
Subject: [Orgmode] Adding latex packages
Date: Tue, 03 Apr 2007 18:00:25 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.93 (gnu/linux)

Hello,

I wondered if it was possible to include custom Latex packages when
processing embedded LaTeX fragments in org. This would require only a
simple change in org-create-formula-image:

  (defun org-create-formula-image (string tofile options)
    (let* ((tmpdir (if (featurep 'xemacs)
                     (temp-directory)
                   temporary-file-directory))
         (texfilebase (make-temp-name
                       (expand-file-name "orgtex" tmpdir)))
  
  ;(texfilebase (make-temp-file "orgtex"))
  ;      (dummy (delete-file texfilebase))
         (texfile (concat texfilebase ".tex"))
         (dvifile (concat texfilebase ".dvi"))
         (pngfile (concat texfilebase ".png"))
         (scale (number-to-string (* 1000 (or (plist-get options :scale) 1.0))))
         (fg (or (plist-get options :foreground) "Black"))
         (bg (or (plist-get options :background) "Transparent")))
      (with-temp-file texfile
        (insert "\\documentclass{article}
  \\usepackage{fullpage}
  \\usepackage{amssymb}
  \\usepackage[usenames]{color}
  \\usepackage{amsmath}
  \\usepackage{latexsym}
  \\usepackage[mathscr]{eucal}

XXX insert custom packages here

  \\pagestyle{empty}
  \\begin{document}\n" string "\n\\end{document}\n"))
      (let ((dir default-directory))
        (condition-case nil
          (progn
            (cd tmpdir)
            (call-process "latex" nil nil nil texfile))
        (error nil))
        (cd dir))
      (if (not (file-exists-p dvifile))
        (progn (message "Failed to create dvi file from %s" texfile) nil)
        (call-process "dvipng" nil nil nil
                    "-E" "-fg" fg "-bg" bg
                    "-x" scale "-y" scale "-T" "tight"
                    "-o" pngfile
                    dvifile)
        (if (not (file-exists-p pngfile))
          (progn (message "Failed to create png file from %s" texfile) nil)
        ;; Use the requested file name and clean up
        (copy-file pngfile tofile 'replace)
        (loop for e in '(".dvi" ".tex" ".aux" ".log" ".png") do
              (delete-file (concat texfilebase e)))
        pngfile))))
  

This should be global or per-file options. The point is that there are
plenty of good LaTeX environments that it would be useful to have in
org (for instance algorithm or tikz).

One of these environments is tikzpicture, and using tikzpicture in org
would allow to create high-quality graphics in org documents. There is
one remaining difficulty though; tikz pictures aren't extracted with
dvipng.

What do you think?

Thanks,
Matthieu Lemerre




reply via email to

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