Add commands to export to PDF.

This works by creating LaTeX first, and then processing it.
This commit is contained in:
Carsten Dominik 2008-10-15 17:21:52 +02:00
parent fd4df45133
commit 52fa7f817b
6 changed files with 106 additions and 28 deletions

View File

@ -291,7 +291,7 @@ Exporting
* The export dispatcher:: How to access exporter commands
* ASCII export:: Exporting to plain ASCII
* HTML export:: Exporting to HTML
* LaTeX export:: Exporting to LaTeX
* LaTeX and PDF export:: Exporting to LaTeX, and processing to PDF
* XOXO export:: Exporting to XOXO
* iCalendar export:: Exporting in iCalendar format
@ -321,9 +321,9 @@ HTML export
* CSS support:: Changing the appearance of the output
* Javascript support:: Info and Folding in a web browser
LaTeX export
LaTeX and PDF export
* LaTeX export commands:: How to invoke LaTeX export
* LaTeX/PDF export commands::
* Quoting LaTeX code:: Incorporating literal LaTeX code
* Sectioning structure:: Changing sectioning in LaTeX output
@ -6930,7 +6930,7 @@ Org mode only supports export, not import of these different formats.
* The export dispatcher:: How to access exporter commands
* ASCII export:: Exporting to plain ASCII
* HTML export:: Exporting to HTML
* LaTeX export:: Exporting to LaTeX
* LaTeX and PDF export:: Exporting to LaTeX, and processing to PDF
* XOXO export:: Exporting to XOXO
* iCalendar export:: Exporting in iCalendar format
@end menu
@ -7454,7 +7454,7 @@ the body text. Any indentation larger than this is adjusted to preserve
the layout relative to the first line. Should there be lines with less
indentation than the first, these are left alone.
@node HTML export, LaTeX export, ASCII export, Exporting
@node HTML export, LaTeX and PDF export, ASCII export, Exporting
@section HTML export
@cindex HTML export
@ -7698,19 +7698,23 @@ You can choose default values for these options by customizing the variable
@code{org-infojs-options}. If you always want to apply the script to your
pages, configure the variable @code{org-export-html-use-infojs}.
@node LaTeX export, XOXO export, HTML export, Exporting
@section LaTeX export
@node LaTeX and PDF export, XOXO export, HTML export, Exporting
@section LaTeX and PDF export
@cindex LaTeX export
@cindex PDF export
Org mode contains a La@TeX{} exporter written by Bastien Guerry.
Org mode contains a La@TeX{} exporter written by Bastien Guerry. With
further processing, this backend is also used to produce PDF output. Since
the LaTeX output uses @file{hyperref} to implement links and cross
references, the PDF output file will be fully linked.
@menu
* LaTeX export commands:: How to invoke LaTeX export
* LaTeX/PDF export commands::
* Quoting LaTeX code:: Incorporating literal LaTeX code
* Sectioning structure:: Changing sectioning in LaTeX output
@end menu
@node LaTeX export commands, Quoting LaTeX code, LaTeX export, LaTeX export
@node LaTeX/PDF export commands, Quoting LaTeX code, LaTeX and PDF export, LaTeX and PDF export
@subsection LaTeX export commands
@table @kbd
@ -7738,6 +7742,12 @@ buffer.
@item M-x org-replace-region-by-latex
Replace the active region (assumed to be in Org mode syntax) by La@TeX{}
code.
@kindex C-c C-e p
@item C-c C-e p
Export as LaTeX and then process to PDF.
@kindex C-c C-e d
@item C-c C-e d
Export as LaTeX and then process to PDF, then open the resulting PDF file.
@end table
@cindex headline levels, for exporting
@ -7757,7 +7767,7 @@ with a numeric prefix argument. For example,
@noindent
creates two levels of headings and does the rest as items.
@node Quoting LaTeX code, Sectioning structure, LaTeX export commands, LaTeX export
@node Quoting LaTeX code, Sectioning structure, LaTeX/PDF export commands, LaTeX and PDF export
@subsection Quoting LaTeX code
Embedded La@TeX{} as described in @ref{Embedded LaTeX} will be correctly
@ -7778,7 +7788,7 @@ All lines between these markers are exported literally
#+END_LaTeX
@end example
@node Sectioning structure, , Quoting LaTeX code, LaTeX export
@node Sectioning structure, , Quoting LaTeX code, LaTeX and PDF export
@subsection Sectioning structure
@cindex LaTeX class
@cindex LaTeX sectioning structure
@ -7792,7 +7802,7 @@ You can change this globally by setting a different value for
structure for each class, as well as defining additonal classes.
@node XOXO export, iCalendar export, LaTeX export, Exporting
@node XOXO export, iCalendar export, LaTeX and PDF export, Exporting
@section XOXO export
@cindex XOXO export
@ -7984,14 +7994,14 @@ and @code{:exclude}.
@cindex action, for publishing
Publishing means that a file is copied to the destination directory and
possibly transformed in the process. The default transformation is to
export Org files as HTML files, and this is done by the function
@code{org-publish-org-to-html} which calls the HTML exporter
(@pxref{HTML export}). But you also can publish your files in La@TeX{} by
using the function @code{org-publish-org-to-latex} instead. Other files
like images only need to be copied to the publishing destination. For
non-Org files, you need to specify the publishing function.
possibly transformed in the process. The default transformation is to export
Org files as HTML files, and this is done by the function
@code{org-publish-org-to-html} which calls the HTML exporter (@pxref{HTML
export}). But you also can publish your files in La@TeX{} by using the
function @code{org-publish-org-to-latex} instead, or as PDF files using
@code{org-publish-org-to-pdf}. Other files like images only need to be
copied to the publishing destination. For non-Org files, you need to provide
your own publishing function:
@multitable @columnfractions 0.3 0.7
@item @code{:publishing-function}

View File

@ -1,5 +1,12 @@
2008-10-15 Carsten Dominik <dominik@science.uva.nl>
* org-publish.el (org-publish-org-to): Handle case when
org-export-to-pdf does return a file name, not a buffer.
(org-publish-org-to-pdf): New function.
* org-export-latex.el (org-export-as-pdf)
(org-export-as-pdf-and-open): New commands.
* org-table.el (org-table-eval-formula): Avoid parsing Calc's HMS
forms as ranges.

View File

@ -1009,6 +1009,8 @@ value of `org-export-run-in-background'."
\[x] export as XOXO
\[l] export as LaTeX
\[p] export as LaTeX and process to PDF
\[d] export as LaTeX, process to PDF, and open the resulting PDF document
\[L] export as LaTeX to temporary buffer
\[i] export current file as iCalendar file
@ -1029,6 +1031,8 @@ value of `org-export-run-in-background'."
(?R org-export-region-as-html nil)
(?x org-export-as-xoxo t)
(?l org-export-as-latex t)
(?p org-export-as-pdf t)
(?d org-export-as-pdf-and-open t)
(?L org-export-as-latex-to-buffer nil)
(?i org-export-icalendar-this-file t)
(?I org-export-icalendar-all-agenda-files t)
@ -1042,6 +1046,9 @@ value of `org-export-run-in-background'."
(delete-other-windows)
(with-output-to-temp-buffer "*Org Export/Publishing Help*"
(princ help))
(if (fboundp 'fit-window-to-buffer)
(fit-window-to-buffer (get-buffer-window
"*Org Export/Publishing Help*")))
(message "Select command: ")
(setq r1 (read-char-exclusive)))
(setq r2 (if (< r1 27) (+ r1 96) r1))

View File

@ -36,6 +36,8 @@
;; The interactive functions are similar to those of the HTML exporter:
;;
;; M-x `org-export-as-latex'
;; M-x `org-export-as-pdf'
;; M-x `org-export-as-pdf-and-open'
;; M-x `org-export-as-latex-batch'
;; M-x `org-export-as-latex-to-buffer'
;; M-x `org-export-region-as-latex'
@ -232,6 +234,18 @@ Don't remove the keys, just change their values."
:group 'org-export-latex
:type 'coding-system)
(defgroup org-export-pdf nil
"Options for exporting Org-mode files to PDF, via LaTeX."
:tag "Org Export LaTeX"
:group 'org-export-latex
:group 'org-export)
(defcustom org-export-pdf-remove-logfiles t
"Non-nil means, remove the logfiles produced by PDF production.
These are the .aux, .log, .out, and .toc files."
:group 'org-export-latex
:type 'boolean)
;;; Autoload functions:
;;;###autoload
@ -462,6 +476,39 @@ when PUB-DIR is set, use this as the publishing directory."
(current-buffer))
(set-window-configuration wcf))))
(defun org-export-as-pdf (arg &optional hidden ext-plist
to-buffer body-only pub-dir)
"Export as LaTeX, then process through to PDF."
(interactive "P")
(message "Exporting to PDF...")
(let* ((wconfig (current-window-configuration))
(lbuf (org-export-as-latex arg hidden ext-plist
to-buffer body-only pub-dir))
(file (buffer-file-name lbuf))
(base (file-name-sans-extension (buffer-file-name lbuf)))
(pdffile (concat base ".pdf")))
(and (file-exists-p pdffile) (delete-file pdffile))
(message "Processing LaTeX file...")
(shell-command (format "pdflatex -interaction nonstopmode %s;pdflatex -interaction nonstopmode %s" file file))
(message "Processing LaTeX file...done")
(if (not (file-exists-p pdffile))
(error "PDF file was not produced")
(set-window-configuration wconfig)
(when org-export-pdf-remove-logfiles
(dolist (ext '("aux" "log" "out" "toc"))
(setq file (concat base "." ext))
(and (file-exists-p file) (delete-file file))))
(message "Exporting to PDF...done")
pdffile)))
(defun org-export-as-pdf-and-open (arg)
"Export as LaTeX, then process through to PDF, and open."
(interactive "P")
(let ((pdffile (org-export-as-pdf arg)))
(if pdffile
(org-open-file pdffile)
(error "PDF file was not produced"))))
;;; Parsing functions:
(defun org-export-latex-parse-global (level odd)

View File

@ -482,19 +482,20 @@ PUB-DIR is the publishing directory."
(plist (cons :buffer-will-be-killed (cons t plist)))
(init-buf (or visiting (find-file filename)))
(init-point (point))
(init-buf-string (buffer-string)) export-buf)
(init-buf-string (buffer-string)) export-buf-or-file)
;; run hooks before exporting
(run-hooks 'org-publish-before-export-hook)
;; export the possibly modified buffer
(setq export-buf
(setq export-buf-or-file
(funcall (intern (concat "org-export-as-" format))
(plist-get plist :headline-levels)
nil plist nil nil pub-dir))
(set-buffer export-buf)
;; run hooks after export and save export
(and (run-hooks 'org-publish-after-export-hook)
(if (buffer-modified-p) (save-buffer)))
(kill-buffer export-buf)
(when (and (bufferp export-buf-or-file) (buffer-live-p export-buf-or-file))
(set-buffer export-buf-or-file)
;; run hooks after export and save export
(and (run-hooks 'org-publish-after-export-hook)
(if (buffer-modified-p) (save-buffer)))
(kill-buffer export-buf-or-file))
;; maybe restore buffer's content
(set-buffer init-buf)
(when (buffer-modified-p init-buf)
@ -510,6 +511,11 @@ PUB-DIR is the publishing directory."
See `org-publish-org-to' to the list of arguments."
(org-publish-org-to "latex" plist filename pub-dir))
(defun org-publish-org-to-pdf (plist filename pub-dir)
"Publish an org file to PDF (via LaTeX).
See `org-publish-org-to' to the list of arguments."
(org-publish-org-to "pdf" plist filename pub-dir))
(defun org-publish-org-to-html (plist filename pub-dir)
"Publish an org file to HTML.
See `org-publish-org-to' to the list of arguments."

View File

@ -1140,6 +1140,7 @@ See `org-file-apps'.")
'(
(auto-mode . emacs)
("\\.x?html?\\'" . default)
("\\.pdf\\'" . default)
)
"External applications for opening `file:path' items in a document.
Org-mode uses system defaults for different file types, but