From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: To interrupt org-latex-pdf-process to regexp-replace some string of the .tex intermediate file and continue to export Date: Fri, 25 Apr 2014 09:54:38 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8f234a39872b1104f7de4e8d Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50578) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WdgaQ-0005rh-Ep for emacs-orgmode@gnu.org; Fri, 25 Apr 2014 09:54:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WdgaP-0007nb-52 for emacs-orgmode@gnu.org; Fri, 25 Apr 2014 09:54:42 -0400 Received: from mail-pb0-x229.google.com ([2607:f8b0:400e:c01::229]:43719) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WdgaO-0007nW-PC for emacs-orgmode@gnu.org; Fri, 25 Apr 2014 09:54:41 -0400 Received: by mail-pb0-f41.google.com with SMTP id rr13so3228210pbb.14 for ; Fri, 25 Apr 2014 06:54:39 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Leu Zhe Cc: "emacs-orgmode@gnu.org" --e89a8f234a39872b1104f7de4e8d Content-Type: text/plain; charset=UTF-8 This is how I do what I think you are describing. I just take off the extension, and let (pdf)latex pick the extension it wants. (defun ox-manuscript-remove-image-extensions () "Removes .png extensions from \includegraphics directives in an exported latex file. Run this from an org-buffer after you have exported it to a LaTeX file" (interactive) (let* ((org-file (file-name-nondirectory (buffer-file-name))) (tex-file (replace-regexp-in-string "org$" "tex" org-file)) (tex-contents (with-temp-buffer (insert-file-contents tex-file) (buffer-string)))) (message tex-file) (with-temp-file tex-file (insert (replace-regexp-in-string (concat "\\(\\includegraphics" "\\(\[?[^\].*\]?\\)?\\)" ;; match optional [stuff] "{\\([^}].*\\)\.\\(png\\)}") "\\1{\\3}" tex-contents))))) John ----------------------------------- John Kitchin Associate Professor Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 http://kitchingroup.cheme.cmu.edu On Thu, Apr 24, 2014 at 8:46 AM, Leu Zhe wrote: > I am using org-mode to write some article now. Org-mode is really a great > tool to outline a article with great table and image support. > > Org-mode can display inline .png image but not .pdf file. Because now > org-mode can not control the width or height of shown inline image, so i > use matplotlib to produce low dpi .png image in PNG folder for inline > display and higher dpi pdf image in PDF folder for finally article export. > > In .org file, the image link is like [[file:PNG\*.png]] and > \includegraphics{PNG\*.png}in the produced .tex file. Then emacs will use > org-latex-pdf-process to render it to pdf file. What I want is that > before or in org-latex-pdf-process, a regexp replace function is added to > replace the \includegraphics{PDF\*.pdf}, and then produce the final pdf > file. > > Can anyone give a hand? > --e89a8f234a39872b1104f7de4e8d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
This is how I do what I think you are describing. I just t= ake off the extension, and let (pdf)latex pick the extension it wants.
<= div>
(defun ox-= manuscript-remove-image-extensions ()
<= div class=3D"" id=3D"LC92">=C2=A0=C2=A0"Removes .png = extensions from \includegraphics directives in an exported latex file.

Run this from an org-buffer after you have exported it to a LaTeX f= ile"
=C2=A0=C2=A0(interactive)<= /div>
=C2=A0=C2=A0(let* ((org-file (file-name-nondirectory = (buffer-file-name)))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0(tex-file (replace-regexp-in-string "org$" "tex" org-file))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0(tex-contents (with-temp-buffer (insert-file-contents tex-file) (buffer-string))))
=C2=A0=C2=A0=C2=A0=C2=A0(message tex-file)
=C2=A0=C2=A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C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0&= quot;\\1{\\3}" tex-contents)))))


Joh= n

-----------------------------------
John Kitchin
Associate P= rofessor
Doherty Hall A207F
Department of Chemical Engineering
Car= negie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

<= /div>

On Thu, Apr 24, 2014 at 8:46 AM, Leu Zhe= <lzhes43@gmail.com> wrote:

I am using org-mode to write some article now. Org-mode is really a great t= ool to outline a article with great table and image support.

Org-mode can display inline .png image but not .pdf file. Because now org-m= ode can not control the width or height of shown inline image, so i use mat= plotlib to produce low dpi .png image in PNG folder for inline display and = higher dpi pdf image in PDF folder for finally article export.

In .org file, the image link is like=C2=A0[[file:PNG\*.pn= g]]=C2=A0and=C2=A0\includegraphics{PNG\*.png}in the produced .tex file. Then emacs will use=C2=A0org= -latex-pdf-process=C2=A0to render it to pdf file. What I want is tha= t before or in=C2=A0org-latex-pdf-process, a regex= p replace function is added to replace the=C2=A0\includeg= raphics{PDF\*.pdf}, and then produce the final pdf file.

Can anyone give a hand?


--e89a8f234a39872b1104f7de4e8d--