emacs-wiki-discuss
[Top][All Lists]
Advanced

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

[emacs-wiki-discuss] Scheme for publishing Wiki to PDF


From: John Wiegley
Subject: [emacs-wiki-discuss] Scheme for publishing Wiki to PDF
Date: Wed, 10 Mar 2004 16:35:37 -0700
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (darwin)

I have been toying around with a scheme for auto-publishing Wiki to
both HTML and PDF (via LaTeX).  It seems to be working fine so far, so
here is the code for others to play with.

First, you will need a new version of emacs-wiki.el, and also
latex-markup.el.  Then, the code below.

Once installed, if any of the pages that match
emacs-wiki-my-publish-regexp need publishing, they will automatically
be converted to LaTeX after publishing to HTML, and from there will be
generated to PDF and copied to the configured output directory.

John

Attachment: emacs-wiki.el
Description: emacs-wiki.el

Attachment: latex-markup.el
Description: latex-markup.el

(defvar emacs-wiki-my-publish-regexp
  "/Writings/\\(journal\\|essays\\|stories\\)")
(defvar emacs-wiki-my-publish-pdf "~/Public/pdf")

(defun emacs-wiki-my-publish (file output-path)
  ;; Publish first to HTML, using the ordinary method
  (emacs-wiki-publish-current file output-path)
  ;; Publish then to LaTeX, and from there to PDF, if applicable
  (when (string-match emacs-wiki-my-publish-regexp file)
    (let* ((emacs-wiki-publishing-file-suffix latex-publishing-file-suffix)
           (emacs-wiki-publishing-directory latex-publishing-directory)
           (latex-output
            (emacs-wiki-published-file (emacs-wiki-page-name file)))
           success)
      (message "Generating LaTeX from Wiki...")
      (condition-case err
          (progn
            (latex-markup-publish-current file latex-output)
            (setq success t))
        (error (message "Generating LaTeX from Wiki...failed")))
      (when success
        (message "Generating LaTeX from Wiki...done")
        ;; Publish to PDF if the LaTeX generation succeeded
        (message "Generating PDF from LaTeX...")
        (let ((default-directory emacs-wiki-publishing-directory))
          (if (/= 0 (shell-command (concat "pdflatex " latex-output)))
              (message "Generating PDF from LaTeX...failed")
            (shell-command (concat "pdflatex " latex-output))
            (shell-command (concat "pdflatex " latex-output))
            (message "Generating PDF from LaTeX...done")
            (let* ((page-name (file-name-sans-extension
                               (emacs-wiki-page-name file)))
                   (pdf-name (concat page-name ".pdf"))
                   (pdf-public (expand-file-name pdf-name
                                                 emacs-wiki-my-publish-pdf)))
              (when (or (not (file-exists-p pdf-public))
                        (file-newer-than-file-p pdf-name pdf-public))
                (copy-file pdf-name pdf-public t t)
                (message "Wrote %s" pdf-public)))))))))

(when (load "emacs-wiki" t)
  (load "latex-markup")
  (setq emacs-wiki-publishing-directory "~/Public/"
        latex-publishing-directory "~/tex/"
        emacs-wiki-my-publish-pdf "~/Public/pdf/"
        emacs-wiki-publish-function 'emacs-wiki-my-publish))

reply via email to

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