Move new export framework files into core
[org-mode.git] / contrib / lisp / ox-groff.el
blobdb62e451ecf30e82d7dd612f594d0c57aacc9730
1 ;; ox-groff.el --- Groff Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Author: Luis R Anaya <papoanaya aroba hot mail punto com>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;;
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; This library implements a Groff Memorandum Macro back-end for Org
25 ;; generic exporter.
27 ;; To test it, run
29 ;; M-: (org-export-to-buffer 'groff "*Test Groff*") RET
31 ;; in an org-mode buffer then switch to the buffer to see the Groff
32 ;; export. See ox.el for more details on how this exporter works.
34 ;; It introduces two new buffer keywords: "GROFF_CLASS" and
35 ;; "GROFF_CLASS_OPTIONS".
37 ;;; Code:
39 (eval-when-compile (require 'cl))
40 (require 'ox)
42 (defvar orgtbl-exp-regexp)
45 ;;; Define Back-End
47 (org-export-define-backend groff
48 ((bold . org-groff-bold)
49 (center-block . org-groff-center-block)
50 (clock . org-groff-clock)
51 (code . org-groff-code)
52 (drawer . org-groff-drawer)
53 (dynamic-block . org-groff-dynamic-block)
54 (entity . org-groff-entity)
55 (example-block . org-groff-example-block)
56 (export-block . org-groff-export-block)
57 (export-snippet . org-groff-export-snippet)
58 (fixed-width . org-groff-fixed-width)
59 (footnote-definition . org-groff-footnote-definition)
60 (footnote-reference . org-groff-footnote-reference)
61 (headline . org-groff-headline)
62 (horizontal-rule . org-groff-horizontal-rule)
63 (inline-src-block . org-groff-inline-src-block)
64 (inlinetask . org-groff-inlinetask)
65 (italic . org-groff-italic)
66 (item . org-groff-item)
67 (keyword . org-groff-keyword)
68 (line-break . org-groff-line-break)
69 (link . org-groff-link)
70 (paragraph . org-groff-paragraph)
71 (plain-list . org-groff-plain-list)
72 (plain-text . org-groff-plain-text)
73 (planning . org-groff-planning)
74 (property-drawer . org-groff-property-drawer)
75 (quote-block . org-groff-quote-block)
76 (quote-section . org-groff-quote-section)
77 (radio-target . org-groff-radio-target)
78 (section . org-groff-section)
79 (special-block . org-groff-special-block)
80 (src-block . org-groff-src-block)
81 (statistics-cookie . org-groff-statistics-cookie)
82 (strike-through . org-groff-strike-through)
83 (subscript . org-groff-subscript)
84 (superscript . org-groff-superscript)
85 (table . org-groff-table)
86 (table-cell . org-groff-table-cell)
87 (table-row . org-groff-table-row)
88 (target . org-groff-target)
89 (template . org-groff-template)
90 (timestamp . org-groff-timestamp)
91 (underline . org-groff-underline)
92 (verbatim . org-groff-verbatim)
93 (verse-block . org-groff-verse-block))
94 :export-block "GROFF"
95 :menu-entry
96 (?g "Export to GROFF"
97 ((?g "As GROFF file" org-groff-export-to-groff)
98 (?p "As PDF file" org-groff-export-to-pdf)
99 (?o "As PDF file and open"
100 (lambda (a s v b)
101 (if a (org-groff-export-to-pdf t s v b)
102 (org-open-file (org-groff-export-to-pdf nil s v b)))))))
103 :options-alist
104 ((:groff-class "GROFF_CLASS" nil org-groff-default-class t)
105 (:groff-class-options "GROFF_CLASS_OPTIONS" nil nil t)
106 (:groff-header-extra "GROFF_HEADER" nil nil newline)))
110 ;;; User Configurable Variables
112 (defgroup org-export-groff nil
113 "Options for exporting Org mode files to Groff."
114 :tag "Org Export Groff"
115 :group 'org-export)
117 ;;; Preamble
119 (defcustom org-groff-default-class "internal"
120 "The default Groff class."
121 :group 'org-export-groff
122 :type '(string :tag "Groff class"))
124 (defcustom org-groff-classes
125 '(("file" ".MT 1"
126 (:heading 'default :type "memo" :last-section "toc"))
127 ("internal" ".MT 0"
128 (:heading 'default :type "memo" :last-section "toc"))
129 ("programmer" ".MT 2"
130 (:heading 'default :type "memo" :last-section "toc"))
131 ("engineer" ".MT 3"
132 (:heading 'default :type "memo" :last-section "toc"))
133 ("external" ".MT 4"
134 (:heading 'default :type "memo" :last-section "toc"))
135 ("letter" ".MT 5"
136 (:heading 'default :type "memo" :last-section "sign"))
137 ("custom" ".so file"
138 (:heading custom-function :type "custom" :last-section "toc"))
139 ("dummy" ""
140 (:heading 'default :type "memo"))
141 ("ms" "ms"
142 (:heading 'default :type "cover" :last-section "toc"))
143 ("se_ms" "se_ms"
144 (:heading 'default :type "cover" :last-section "toc"))
145 ("block" "BL"
146 (:heading 'default :type "letter" :last-section "sign"))
147 ("semiblock" "SB"
148 (:heading 'default :type "letter" :last-section "sign"))
149 ("fullblock" "FB"
150 (:heading 'default :type "letter" :last-section "sign"))
151 ("simplified" "SP"
152 (:heading 'default :type "letter" :last-section "sign"))
153 ("none" "" (:heading 'default :type "custom")))
155 ;; none means, no Cover or Memorandum Type and no calls to AU, AT, ND and TL
156 ;; This is to facilitate the creation of custom pages.
158 ;; dummy means, no Cover or Memorandum Type but calls to AU, AT, ND and TL
159 ;; are made. This is to facilitate Abstract Insertion.
161 "This list describes the attributes for the documents being created.
162 It allows for the creation of new "
163 :group 'org-export-groff
164 :type '(repeat
165 (list (string :tag "Document Type")
166 (string :tag "Header")
167 (repeat :tag "Options" :inline t
168 (choice
169 (list :tag "Heading")
170 (function :tag "Hook computing sectioning"))))))
172 ;;; Headline
174 (defconst org-groff-special-tags
175 '("FROM" "TO" "ABSTRACT" "APPENDIX" "BODY" "NS"))
177 (defcustom org-groff-format-headline-function nil
178 "Function to format headline text.
180 This function will be called with 5 arguments:
181 TODO the todo keyword (string or nil).
182 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
183 PRIORITY the priority of the headline (integer or nil)
184 TEXT the main headline text (string).
185 TAGS the tags as a list of strings (list of strings or nil).
187 The function result will be used in the section format string.
189 As an example, one could set the variable to the following, in
190 order to reproduce the default set-up:
192 \(defun org-groff-format-headline (todo todo-type priority text tags)
193 \"Default format function for an headline.\"
194 \(concat (when todo
195 \(format \"\\fB%s\\fP \" todo))
196 \(when priority
197 \(format \"[\\#%c] \" priority))
198 text
199 \(when tags
200 \(format \" %s \"
201 \(mapconcat 'identity tags \":\"))))"
202 :group 'org-export-groff
203 :type 'function)
205 ;;; Timestamps
207 (defcustom org-groff-active-timestamp-format "\\fI%s\\fP"
208 "A printf format string to be applied to active timestamps."
209 :group 'org-export-groff
210 :type 'string)
212 (defcustom org-groff-inactive-timestamp-format "\\fI%s\\fP"
213 "A printf format string to be applied to inactive timestamps."
214 :group 'org-export-groff
215 :type 'string)
217 (defcustom org-groff-diary-timestamp-format "\\fI%s\\fP"
218 "A printf format string to be applied to diary timestamps."
219 :group 'org-export-groff
220 :type 'string)
222 ;;; Links
224 (defcustom org-groff-inline-image-rules
225 '(("file" . "\\.\\(jpg\\|png\\|pdf\\|ps\\|eps\\|pic\\)\\'")
226 ("fuzzy" . "\\.\\(jpg\\|png\\|pdf\\|ps\\|eps\\|pic\\)\\'"))
227 "Rules characterizing image files that can be inlined into Groff.
229 A rule consists in an association whose key is the type of link
230 to consider, and value is a regexp that will be matched against
231 link's path.
233 Note that, by default, the image extensions actually allowed
234 depend on the way the Groff file is processed. When used with
235 pdfgroff, pdf, jpg and png images are OK. When processing
236 through dvi to Postscript, only ps and eps are allowed. The
237 default we use here encompasses both."
238 :group 'org-export-groff
239 :type '(alist :key-type (string :tag "Type")
240 :value-type (regexp :tag "Path")))
242 (defcustom org-groff-link-with-unknown-path-format "\\fI%s\\fP"
243 "Format string for links with unknown path type."
244 :group 'org-export-groff
245 :type 'string)
247 ;;; Tables
249 (defcustom org-groff-tables-centered t
250 "When non-nil, tables are exported in a center environment."
251 :group 'org-export-groff
252 :type 'boolean)
254 (defcustom org-groff-tables-verbatim nil
255 "When non-nil, tables are exported verbatim."
256 :group 'org-export-groff
257 :type 'boolean)
259 (defcustom org-groff-table-scientific-notation "%sE%s"
260 "Format string to display numbers in scientific notation.
261 The format should have \"%s\" twice, for mantissa and exponent
262 \(i.e. \"%s\\\\times10^{%s}\").
264 When nil, no transformation is made."
265 :group 'org-export-groff
266 :type '(choice
267 (string :tag "Format string")
268 (const :tag "No formatting")))
270 ;;; Text markup
272 (defcustom org-groff-text-markup-alist
273 '((bold . "\\fB%s\\fP")
274 (code . "\\fC%s\\fP")
275 (italic . "\\fI%s\\fP")
276 (strike-through . "\\fC%s\\fP") ; Strike through and underline
277 (underline . "\\fI%s\\fP") ; need to be revised.
278 (verbatim . "protectedtexttt"))
279 "Alist of Groff expressions to convert text markup.
281 The key must be a symbol among `bold', `code', `italic',
282 `strike-through', `underline' and `verbatim'. The value is
283 a formatting string to wrap fontified text with it.
285 If no association can be found for a given markup, text will be
286 returned as-is."
287 :group 'org-export-groff
288 :type 'alist
289 :options '(bold code italic strike-through underline verbatim))
291 ;;; Drawers
293 (defcustom org-groff-format-drawer-function nil
294 "Function called to format a drawer in Groff code.
296 The function must accept two parameters:
297 NAME the drawer name, like \"LOGBOOK\"
298 CONTENTS the contents of the drawer.
300 The function should return the string to be exported.
302 For example, the variable could be set to the following function
303 in order to mimic default behaviour:
305 \(defun org-groff-format-drawer-default \(name contents\)
306 \"Format a drawer element for Groff export.\"
307 contents\)"
308 :group 'org-export-groff
309 :type 'function)
311 ;;; Inlinetasks
313 (defcustom org-groff-format-inlinetask-function nil
314 "Function called to format an inlinetask in Groff code.
316 The function must accept six parameters:
317 TODO the todo keyword, as a string
318 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
319 PRIORITY the inlinetask priority, as a string
320 NAME the inlinetask name, as a string.
321 TAGS the inlinetask tags, as a list of strings.
322 CONTENTS the contents of the inlinetask, as a string.
324 The function should return the string to be exported.
326 For example, the variable could be set to the following function
327 in order to mimic default behaviour:
329 \(defun org-groff-format-inlinetask \(todo type priority name tags contents\)
330 \"Format an inline task element for Groff export.\"
331 \(let ((full-title
332 \(concat
333 \(when todo
334 \(format \"\\fB%s\\fP \" todo))
335 \(when priority (format \"[\\#%c] \" priority))
336 title
337 \(when tags
338 \(format \":%s:\"
339 \(mapconcat 'identity tags \":\")))))
340 \(format (concat \".DS L\\n\"
341 \"%s\\n\\n\"
342 \"%s\"
343 \".DE\")
344 full-title contents))"
345 :group 'org-export-groff
346 :type 'function)
348 ;; Src blocks
350 (defcustom org-groff-source-highlight nil
351 "Use GNU source highlight to embellish source blocks "
352 :group 'org-export-groff
353 :type 'boolean)
355 (defcustom org-groff-source-highlight-langs
356 '((emacs-lisp "lisp") (lisp "lisp") (clojure "lisp")
357 (scheme "scheme")
358 (c "c") (cc "cpp") (csharp "csharp") (d "d")
359 (fortran "fortran") (cobol "cobol") (pascal "pascal")
360 (ada "ada") (asm "asm")
361 (perl "perl") (cperl "perl")
362 (python "python") (ruby "ruby") (tcl "tcl") (lua "lua")
363 (java "java") (javascript "javascript")
364 (tex "latex")
365 (shell-script "sh") (awk "awk") (diff "diff") (m4 "m4")
366 (ocaml "caml") (caml "caml")
367 (sql "sql") (sqlite "sql")
368 (html "html") (css "css") (xml "xml")
369 (bat "bat") (bison "bison") (clipper "clipper")
370 (ldap "ldap") (opa "opa")
371 (php "php") (postscript "postscript") (prolog "prolog")
372 (properties "properties") (makefile "makefile")
373 (tml "tml") (vala "vala") (vbscript "vbscript") (xorg "xorg"))
374 "Alist mapping languages to their listing language counterpart.
375 The key is a symbol, the major mode symbol without the \"-mode\".
376 The value is the string that should be inserted as the language
377 parameter for the listings package. If the mode name and the
378 listings name are the same, the language does not need an entry
379 in this list - but it does not hurt if it is present."
380 :group 'org-export-groff
381 :type '(repeat
382 (list
383 (symbol :tag "Major mode ")
384 (string :tag "Listings language"))))
386 (defcustom org-groff-source-highlight-options nil
387 "Association list of options for the groff listings package.
389 These options are supplied as a comma-separated list to the
390 \\lstset command. Each element of the association list should be
391 a list containing two strings: the name of the option, and the
392 value. For example,
394 (setq org-groff-source-highlight-options
395 '((\"basicstyle\" \"\\small\")
396 (\"keywordstyle\" \"\\color{black}\\bfseries\\underbar\")))
398 will typeset the code in a small size font with underlined, bold
399 black keywords.
401 Note that the same options will be applied to blocks of all
402 languages."
403 :group 'org-export-groff
404 :type '(repeat
405 (list
406 (string :tag "Listings option name ")
407 (string :tag "Listings option value"))))
409 (defvar org-groff-custom-lang-environments nil
410 "Alist mapping languages to language-specific Groff environments.
412 It is used during export of src blocks by the listings and
413 groff packages. For example,
415 \(setq org-groff-custom-lang-environments
416 '\(\(python \"pythoncode\"\)\)\)
418 would have the effect that if org encounters begin_src python
419 during groff export it will use pythoncode as the source-highlight
420 language.")
422 ;;; Plain text
424 (defcustom org-groff-special-char
425 '(("(c)" . "\\\\(co")
426 ("(tm)" . "\\\\(tm")
427 ("(rg)" . "\\\\(rg"))
428 "CONS list in which the value of the car
429 is replace on the value of the CDR. "
430 :group 'org-export-groff
431 :type '(list
432 (cons :tag "Character Subtitute"
433 (string :tag "Original Character Group")
434 (string :tag "Replacement Character"))))
436 ;;; Compilation
438 (defcustom org-groff-pdf-process
439 '("pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"
440 "pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"
441 "pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf")
443 "Commands to process a Groff file to a PDF file.
444 This is a list of strings, each of them will be given to the
445 shell as a command. %f in the command will be replaced by the
446 full file name, %b by the file base name \(i.e. without
447 extension) and %o by the base directory of the file."
448 :group 'org-export-pdf
449 :type '(choice
450 (repeat :tag "Shell command sequence"
451 (string :tag "Shell command"))
452 (const :tag "2 runs of pdfgroff"
453 ("pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"
454 "pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"))
455 (const :tag "3 runs of pdfgroff"
456 ("pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"
457 "pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"
458 "pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"))
459 (function)))
461 (defcustom org-groff-logfiles-extensions
462 '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
463 "The list of file extensions to consider as Groff logfiles."
464 :group 'org-export-groff
465 :type '(repeat (string :tag "Extension")))
467 (defcustom org-groff-remove-logfiles t
468 "Non-nil means remove the logfiles produced by PDF production.
469 These are the .aux, .log, .out, and .toc files."
470 :group 'org-export-groff
471 :type 'boolean)
473 (defcustom org-groff-organization "Org User"
474 "Name of the organization used to populate the .AF command."
475 :group 'org-export-groff
476 :type 'string)
478 (defcustom org-groff-raster-to-ps nil
479 "Command used to convert raster to EPS. Nil for no conversion. Make sure that
480 `org-groff-inline-image-rules' is adjusted accordingly if not conversion is being
481 done. In this case, remove the entries for jpg and png in the file and fuzzy lists."
482 :group 'org-export-groff
483 :type '(choice
484 (repeat :tag "Shell Command Sequence" (string :tag "Shell Command"))
485 (const :tag "sam2p" "a=%s;b=%s;sam2p ${a} ${b} ;grep -v BeginData ${b} > b_${b};mv b_${b} ${b}" )
486 (const :tag "NetPNM" "a=%s;b=%s;pngtopnm ${a} | pnmtops -noturn > ${b}" )
487 (const :tag "None" nil)))
489 (defvar org-groff-registered-references nil)
490 (defvar org-groff-special-content nil)
494 ;;; Internal Functions
496 (defun org-groff--caption/label-string (element info)
497 "Return caption and label Groff string for ELEMENT.
499 INFO is a plist holding contextual information. If there's no
500 caption nor label, return the empty string.
502 For non-floats, see `org-groff--wrap-label'."
503 (let ((main (org-export-get-caption element))
504 (short (org-export-get-caption element t))
505 (label (org-element-property :name element)))
506 (cond ((and (not main) (not label)) "")
507 ((not main) (format "\\fI%s\\fP" label))
508 ;; Option caption format with short name.
509 (short (format "%s\n.br\n - %s\n"
510 (org-export-data short info)
511 (org-export-data main info)))
512 ;; Standard caption format.
513 (t (format "\\fR%s\\fP" (org-export-data main info))))))
515 (defun org-groff--wrap-label (element output)
516 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
517 This function shouldn't be used for floats. See
518 `org-groff--caption/label-string'."
519 (let ((label (org-element-property :name element)))
520 (if (or (not output) (not label) (string= output "") (string= label ""))
521 output
522 (concat (format "%s\n.br\n" label) output))))
524 (defun org-groff--text-markup (text markup)
525 "Format TEXT depending on MARKUP text markup.
526 See `org-groff-text-markup-alist' for details."
527 (let ((fmt (cdr (assq markup org-groff-text-markup-alist))))
528 (cond
529 ;; No format string: Return raw text.
530 ((not fmt) text)
531 ((string= "protectedtexttt" fmt)
532 (let ((start 0)
533 (trans '(("\\" . "\\")))
534 (rtn "")
535 char)
536 (while (string-match "[\\{}$%&_#~^]" text)
537 (setq char (match-string 0 text))
538 (if (> (match-beginning 0) 0)
539 (setq rtn (concat rtn (substring text 0 (match-beginning 0)))))
540 (setq text (substring text (1+ (match-beginning 0))))
541 (setq char (or (cdr (assoc char trans)) (concat "\\" char))
542 rtn (concat rtn char)))
543 (setq text (concat rtn text))
544 (format "\\fC%s\\fP" text)))
545 ;; Else use format string.
546 (t (format fmt text)))))
549 (defun org-groff--get-tagged-content (tag info)
550 (cdr (assoc tag org-groff-special-content)))
552 (defun org-groff--mt-head (title contents attr info)
553 (concat
555 ;; 1. Insert Organization
556 (let ((firm-option (plist-get attr :firm)))
557 (cond
558 ((stringp firm-option)
559 (format ".AF \"%s\" \n" firm-option))
560 (t (format ".AF \"%s\" \n" (or org-groff-organization "")))))
562 ;; 2. Title
563 (let ((subtitle1 (plist-get attr :subtitle1))
564 (subtitle2 (plist-get attr :subtitle2)))
566 (cond
567 ((string= "" title)
568 (format ".TL \"%s\" \"%s\" \n%s\n"
569 (or subtitle1 "")
570 (or subtitle2 "") " "))
572 ((not (or subtitle1 subtitle2))
573 (format ".TL\n%s\n"
574 (or title "")))
576 (format ".TL \"%s\" \"%s \" \n%s\n"
577 (or subtitle1 "")
578 (or subtitle2 "") title))))
580 ;; 3. Author.
581 ;; In Groff, .AU *MUST* be placed after .TL
582 ;; If From, populate with data from From else
584 (let ((author (and (plist-get info :with-author)
585 (let ((auth (plist-get info :author)))
586 (and auth (org-export-data auth info)))))
587 (email (and (plist-get info :with-email)
588 (org-export-data (plist-get info :email) info)))
589 (from-data (org-groff--get-tagged-content "FROM" info))
591 (to-data (org-groff--get-tagged-content "TO" info)))
593 (cond
594 ((and author from-data)
595 (let ((au-line
596 (mapconcat
597 (lambda (from-line)
598 (format " \"%s\" " from-line))
599 (split-string
600 (setq from-data
601 (replace-regexp-in-string "\\.P\n" "" from-data)) "\n") "")))
603 (concat
604 (format ".AU \"%s\" " author) au-line "\n")))
606 ((and author email (not (string= "" email)))
607 (format ".AU \"%s\" \"%s\"\n" author email))
609 (author (format ".AU \"%s\"\n" author))
611 (t ".AU \"\" \n")))
614 ;; 4. Author Title, if present
615 (let ((at-item (plist-get attr :author-title)))
616 (if (and at-item (stringp at-item))
617 (format ".AT \"%s\" \n" at-item)
618 ""))
620 ;; 5. Date.
621 (when (plist-get info :with-date)
622 (let ((date (org-export-data (plist-get info :date) info)))
623 (and date (format ".ND \"%s\"\n" date))))
626 ;; If Abstract, then Populate Abstract
629 (let ((abstract-data (org-groff--get-tagged-content "ABSTRACT" info))
630 (to-data (org-groff--get-tagged-content "TO" info)))
631 (cond
632 (abstract-data
633 (format ".AS\n%s\n.AE\n" abstract-data))
634 (to-data
635 (format ".AS\n%s\n.AE\n" to-data))))))
637 (defun org-groff--letter-head (title contents attr info)
638 (let ((author (and (plist-get info :with-author)
639 (let ((auth (plist-get info :author)))
640 (and auth (org-export-data auth info)))))
641 (email (and (plist-get info :with-email)
642 (org-export-data (plist-get info :email) info)))
643 (from-data (org-groff--get-tagged-content "FROM" info))
644 (at-item (plist-get attr :author-title))
645 (to-data (org-groff--get-tagged-content "TO" info)))
648 ;; If FROM then get data from FROM
649 (if from-data
650 (setq from-data
651 (replace-regexp-in-string "\\.P\n" "" from-data))
652 (setq from-data ""))
654 (if to-data
655 (setq to-data
656 (replace-regexp-in-string "\\.P\n" "" to-data))
657 (setq from-data ""))
659 (concat
660 (cond
661 (from-data
662 (format ".WA \"%s\" \"%s\" \n%s\n.WE\n" author (or at-item "") from-data))
663 ((and author email (not (string= "" email)))
664 (format ".WA \"%s\"\n \"%s\"\n.WE\n" author email))
665 (author (format ".WA \"%s\"\n.WE\n" author))
666 (t ".WA \"\" \n.WE\n"))
668 ;; If TO then get data from TO
670 (when to-data
671 (format ".IA \n%s\n.IE\n" to-data)))))
674 ;;; Template
676 (defun org-groff-template (contents info)
677 "Return complete document string after Groff conversion.
678 CONTENTS is the transcoded contents string. INFO is a plist
679 holding export options."
680 (let* ((title (org-export-data (plist-get info :title) info))
681 (attr (read
682 (format "(%s)"
683 (mapconcat
684 #'identity
685 (list (plist-get info :groff-class-options))
686 " "))))
687 (class (plist-get info :groff-class))
688 (class-options (plist-get info :groff-class-options))
689 (classes (assoc class org-groff-classes))
690 (classes-options (car (last classes)))
691 (heading-option (plist-get classes-options :heading))
692 (type-option (plist-get classes-options :type))
693 (last-option (plist-get classes-options :last-section))
694 (hyphenate (plist-get attr :hyphenate))
695 (justify-right (plist-get attr :justify-right))
697 (document-class-string
698 (progn
699 (org-element-normalize-string
700 (let* ((header (nth 1 (assoc class org-groff-classes)))
701 (document-class-item (if (stringp header) header "")))
702 document-class-item)))))
705 (concat
706 (if justify-right
707 (case justify-right
708 ('yes ".SA 1 \n")
709 ('no ".SA 0 \n")
710 (t ""))
713 (if hyphenate
714 (case hyphenate
715 ('yes ".nr Hy 1 \n")
716 ('no ".nr Hy 0 \n")
717 (t ""))
720 (cond
721 ((string= type-option "custom") "")
723 ((and (stringp document-class-string)
724 (string= type-option "cover"))
726 (concat
727 (format ".COVER %s\n" document-class-string)
728 (org-groff--mt-head title contents attr info)
729 ".COVEND\n"))
731 ((string= type-option "memo")
732 (concat
733 (org-groff--mt-head title contents attr info)
734 document-class-string))
735 ((string= type-option "letter")
736 (concat
737 (org-groff--letter-head title contents attr info)
738 (let ((sa-item (plist-get attr :salutation))
739 (cn-item (plist-get attr :confidential))
740 (sj-item (plist-get attr :subject))
741 (rn-item (plist-get attr :reference))
742 (at-item (plist-get attr :attention)))
744 (concat
746 (if (stringp sa-item)
747 (format ".LO SA \"%s\" \n" sa-item)
748 ".LO SA\n")
750 (when cn-item
751 (if (stringp cn-item)
752 (format ".LO CN \"%s\"\n" cn-item)
753 ".LO CN\n"))
755 (when (and at-item (stringp at-item))
756 (format ".LO AT \"%s\" \n" at-item))
757 (when (and title rn-item)
758 (format ".LO RN \"%s\"\n" title))
760 (when (and sj-item (stringp sj-item))
761 (format ".LO SJ \"%s\" \n" sj-item))
764 ".LT " document-class-string "\n"))))
766 (t ""))
768 contents
770 (cond
771 ((string= last-option "toc")
772 ".TC")
773 ((string= last-option "sign")
774 (let ((fc-item (plist-get attr :closing)))
775 (concat (if (stringp fc-item)
776 (format ".FC \"%s\" \n" fc-item)
777 ".FC\n")
778 ".SG\n")))
779 (t ""))
781 (progn
782 (mapconcat
783 (lambda (item)
784 (when (string= (car item) "NS")
785 (replace-regexp-in-string
786 "\\.P\n" "" (cdr item))))
787 (reverse org-groff-special-content) "\n")))))
791 ;;; Transcode Functions
793 ;;; Babel Call
795 ;; Babel Calls are ignored.
798 ;;; Bold
800 (defun org-groff-bold (bold contents info)
801 "Transcode BOLD from Org to Groff.
802 CONTENTS is the text with bold markup. INFO is a plist holding
803 contextual information."
804 (org-groff--text-markup contents 'bold))
806 ;;; Center Block
808 (defun org-groff-center-block (center-block contents info)
809 "Transcode a CENTER-BLOCK element from Org to Groff.
810 CONTENTS holds the contents of the center block. INFO is a plist
811 holding contextual information."
812 (org-groff--wrap-label
813 center-block
814 (format ".DS C \n%s\n.DE" contents)))
816 ;;; Clock
818 (defun org-groff-clock (clock contents info)
819 "Transcode a CLOCK element from Org to Groff.
820 CONTENTS is nil. INFO is a plist holding contextual
821 information."
822 (concat
823 (format "\\fB%s\\fP " org-clock-string)
824 (format org-groff-inactive-timestamp-format
825 (concat (org-translate-time
826 (org-element-property :raw-value
827 (org-element-property :value clock)))
828 (let ((time (org-element-property :duration clock)))
829 (and time (format " (%s)" time)))))))
831 ;;; Code
833 (defun org-groff-code (code contents info)
834 "Transcode a CODE object from Org to Groff.
835 CONTENTS is nil. INFO is a plist used as a communication
836 channel."
837 (org-groff--text-markup (org-element-property :value code) 'code))
839 ;;; Comments and Comment Blocks are ignored.
841 ;;; Drawer
843 (defun org-groff-drawer (drawer contents info)
844 "Transcode a DRAWER element from Org to Groff.
845 CONTENTS holds the contents of the block. INFO is a plist
846 holding contextual information."
847 (let* ((name (org-element-property :drawer-name drawer))
848 (output (if (functionp org-groff-format-drawer-function)
849 (funcall org-groff-format-drawer-function
850 name contents)
851 ;; If there's no user defined function: simply
852 ;; display contents of the drawer.
853 contents)))
854 (org-groff--wrap-label drawer output)))
856 ;;; Dynamic Block
858 (defun org-groff-dynamic-block (dynamic-block contents info)
859 "Transcode a DYNAMIC-BLOCK element from Org to Groff.
860 CONTENTS holds the contents of the block. INFO is a plist
861 holding contextual information. See `org-export-data'."
862 (org-groff--wrap-label dynamic-block contents))
864 ;;; Entity
866 (defun org-groff-entity (entity contents info)
867 "Transcode an ENTITY object from Org to Groff.
868 CONTENTS are the definition itself. INFO is a plist holding
869 contextual information."
870 (org-element-property :utf-8 entity))
872 ;;; Example Block
874 (defun org-groff-example-block (example-block contents info)
875 "Transcode an EXAMPLE-BLOCK element from Org to Groff.
876 CONTENTS is nil. INFO is a plist holding contextual
877 information."
878 (org-groff--wrap-label
879 example-block
880 (format ".DS L\n%s\n.DE"
881 (org-export-format-code-default example-block info))))
883 ;;; Export Block
885 (defun org-groff-export-block (export-block contents info)
886 "Transcode a EXPORT-BLOCK element from Org to Groff.
887 CONTENTS is nil. INFO is a plist holding contextual information."
888 (when (string= (org-element-property :type export-block) "GROFF")
889 (org-remove-indentation (org-element-property :value export-block))))
891 ;;; Export Snippet
893 (defun org-groff-export-snippet (export-snippet contents info)
894 "Transcode a EXPORT-SNIPPET object from Org to Groff.
895 CONTENTS is nil. INFO is a plist holding contextual information."
896 (when (eq (org-export-snippet-backend export-snippet) 'groff)
897 (org-element-property :value export-snippet)))
899 ;;; Fixed Width
901 (defun org-groff-fixed-width (fixed-width contents info)
902 "Transcode a FIXED-WIDTH element from Org to Groff.
903 CONTENTS is nil. INFO is a plist holding contextual information."
904 (org-groff--wrap-label
905 fixed-width
906 (format "\\fC\n%s\\fP"
907 (org-remove-indentation
908 (org-element-property :value fixed-width)))))
910 ;;; Footnote Definition
912 ;; Footnote Definitions are ignored.
914 ;; Footnotes are handled automatically in GROFF. Although manual
915 ;; references can be added, not really required.
917 (defun org-groff-footnote-reference (footnote-reference contents info)
918 ;; Changing from info to footnote-reference
919 (let* ((raw (org-export-get-footnote-definition footnote-reference info))
920 (n (org-export-get-footnote-number footnote-reference info))
921 (data (org-trim (org-export-data raw info)))
922 (ref-id (plist-get (nth 1 footnote-reference) :label)))
923 ;; It is a reference
924 (if (string-match "fn:rl" ref-id)
925 (if (member ref-id org-groff-registered-references)
926 (format "\\*[%s]" ref-id)
927 (progn
928 (push ref-id org-groff-registered-references)
929 (format "\\*(Rf\n.RS \"%s\" \n%s\n.RF\n" ref-id data)))
930 ;; else it is a footnote
931 (format "\\u\\s-2%s\\d\\s+2\n.FS %s\n%s\n.FE\n" n n data))))
933 ;;; Headline
935 (defun org-groff-headline (headline contents info)
936 "Transcode an HEADLINE element from Org to Groff.
937 CONTENTS holds the contents of the headline. INFO is a plist
938 holding contextual information."
939 (let* ((class (plist-get info :groff-class))
940 (level (org-export-get-relative-level headline info))
941 (numberedp (org-export-numbered-headline-p headline info))
942 ;; Section formatting will set two placeholders: one for the
943 ;; title and the other for the contents.
944 (classes (assoc class org-groff-classes))
945 (classes-options (car (last classes)))
946 (heading-option (plist-get classes-options :heading))
947 (section-fmt
948 (progn
949 (cond
950 ((and (symbolp heading-option)
951 (fboundp heading-option))
952 (funcall heading-option level numberedp))
953 ((> level 7) nil)
954 (t (if numberedp
955 (concat ".H " (number-to-string level) " \"%s\"\n%s")
956 ".HU \"%s\"\n%s")))))
957 ;; End of section-fmt
958 (text (org-export-data (org-element-property :title headline) info))
959 (todo
960 (and (plist-get info :with-todo-keywords)
961 (let ((todo (org-element-property :todo-keyword headline)))
962 (and todo (org-export-data todo info)))))
963 (todo-type (and todo (org-element-property :todo-type headline)))
964 (tags (and (plist-get info :with-tags)
965 (org-export-get-tags headline info)))
966 (priority (and (plist-get info :with-priority)
967 (org-element-property :priority headline)))
968 ;; Create the headline text along with a no-tag version. The
969 ;; latter is required to remove tags from table of contents.
970 (full-text (if (functionp org-groff-format-headline-function)
971 ;; User-defined formatting function.
972 (funcall org-groff-format-headline-function
973 todo todo-type priority text tags)
974 ;; Default formatting.
975 (concat
976 (when todo
977 (format "\\fB%s\\fP " todo))
978 (when priority (format " [\\#%c] " priority))
979 text
980 (when tags
981 (format " \\fC:%s:\\fP "
982 (mapconcat 'identity tags ":"))))))
983 (full-text-no-tag
984 (if (functionp org-groff-format-headline-function)
985 ;; User-defined formatting function.
986 (funcall org-groff-format-headline-function
987 todo todo-type priority text nil)
988 ;; Default formatting.
989 (concat
990 (when todo (format "\\fB%s\\fP " todo))
991 (when priority (format " [\\#%c] " priority))
992 text)))
993 ;; Associate some \label to the headline for internal links.
994 ;; (headline-label
995 ;; (format "\\label{sec-%s}\n"
996 ;; (mapconcat 'number-to-string
997 ;; (org-export-get-headline-number headline info)
998 ;; "-")))
999 (headline-label "")
1000 (pre-blanks
1001 (make-string (org-element-property :pre-blank headline) 10)))
1003 (cond
1004 ;; Case 1: Special Tag
1005 ((member (car tags) org-groff-special-tags)
1006 (cond
1007 ((string= (car tags) "BODY") contents)
1009 ((string= (car tags) "NS")
1010 (progn
1011 (push (cons (car tags)
1012 (format ".NS \"%s\" 1 \n%s"
1013 (car (org-element-property :title headline))
1014 (or contents " ")))
1015 org-groff-special-content) nil))
1018 (progn
1019 (push (cons (car tags) contents) org-groff-special-content)
1020 nil))))
1022 ;; Case 2: This is a footnote section: ignore it.
1023 ((org-element-property :footnote-section-p headline) nil)
1025 ;; Case 3: This is a deep sub-tree: export it as a list item.
1026 ;; Also export as items headlines for which no section
1027 ;; format has been found.
1028 ((or (not section-fmt) (org-export-low-level-p headline info))
1029 ;; Build the real contents of the sub-tree.
1030 (let ((low-level-body
1031 (concat
1032 ;; If the headline is the first sibling, start a list.
1033 (when (org-export-first-sibling-p headline info)
1034 (format "%s\n" (if numberedp ".AL 1\n" ".DL \n")))
1035 ;; Itemize headline
1036 ".LI\n" full-text "\n" headline-label pre-blanks contents)))
1037 ;; If headline is not the last sibling simply return
1038 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
1039 ;; blank line.
1040 (if (not (org-export-last-sibling-p headline info)) low-level-body
1041 (replace-regexp-in-string
1042 "[ \t\n]*\\'"
1043 (concat "\n.LE")
1044 low-level-body))))
1046 ;; Case 4. Standard headline. Export it as a section.
1048 (format section-fmt full-text
1049 (concat headline-label pre-blanks contents))))))
1051 ;;; Horizontal Rule
1052 ;; Not supported
1054 ;;; Inline Babel Call
1056 ;; Inline Babel Calls are ignored.
1058 ;;; Inline Src Block
1060 (defun org-groff-inline-src-block (inline-src-block contents info)
1061 "Transcode an INLINE-SRC-BLOCK element from Org to Groff.
1062 CONTENTS holds the contents of the item. INFO is a plist holding
1063 contextual information."
1064 (let* ((code (org-element-property :value inline-src-block)))
1065 (cond
1066 (org-groff-source-highlight
1067 (let* ((tmpdir (if (featurep 'xemacs)
1068 temp-directory
1069 temporary-file-directory))
1070 (in-file (make-temp-name
1071 (expand-file-name "srchilite" tmpdir)))
1072 (out-file (make-temp-name
1073 (expand-file-name "reshilite" tmpdir)))
1074 (org-lang (org-element-property :language inline-src-block))
1075 (lst-lang (cadr (assq (intern org-lang)
1076 org-groff-source-highlight-langs)))
1078 (cmd (concat (expand-file-name "source-highlight")
1079 " -s " lst-lang
1080 " -f groff_mm_color "
1081 " -i " in-file
1082 " -o " out-file)))
1083 (if lst-lang
1084 (let ((code-block ""))
1085 (with-temp-file in-file (insert code))
1086 (shell-command cmd)
1087 (setq code-block (org-file-contents out-file))
1088 (delete-file in-file)
1089 (delete-file out-file)
1090 code-block)
1091 (format ".DS I\n\\fC\\m[black]%s\\m[]\\fP\n.DE\n"
1092 code))))
1094 ;; Do not use a special package: transcode it verbatim.
1096 (concat ".DS I\n" "\\fC" code "\\fP\n.DE\n")))))
1098 ;;; Inlinetask
1100 (defun org-groff-inlinetask (inlinetask contents info)
1101 "Transcode an INLINETASK element from Org to Groff.
1102 CONTENTS holds the contents of the block. INFO is a plist
1103 holding contextual information."
1104 (let ((title (org-export-data (org-element-property :title inlinetask) info))
1105 (todo (and (plist-get info :with-todo-keywords)
1106 (let ((todo (org-element-property :todo-keyword inlinetask)))
1107 (and todo (org-export-data todo info)))))
1108 (todo-type (org-element-property :todo-type inlinetask))
1109 (tags (and (plist-get info :with-tags)
1110 (org-export-get-tags inlinetask info)))
1111 (priority (and (plist-get info :with-priority)
1112 (org-element-property :priority inlinetask))))
1113 ;; If `org-groff-format-inlinetask-function' is provided, call it
1114 ;; with appropriate arguments.
1115 (if (functionp org-groff-format-inlinetask-function)
1116 (funcall org-groff-format-inlinetask-function
1117 todo todo-type priority title tags contents)
1118 ;; Otherwise, use a default template.
1119 (org-groff--wrap-label
1120 inlinetask
1121 (let ((full-title
1122 (concat
1123 (when todo (format "\\fB%s\\fP " todo))
1124 (when priority (format " [\\#%c] " priority))
1125 title
1126 (when tags (format " \\fC:%s:\\fP "
1127 (mapconcat 'identity tags ":"))))))
1128 (format (concat "\n.DS I\n"
1129 "%s\n"
1130 ".sp"
1131 "%s\n"
1132 ".DE")
1133 full-title contents))))))
1135 ;;; Italic
1137 (defun org-groff-italic (italic contents info)
1138 "Transcode ITALIC from Org to Groff.
1139 CONTENTS is the text with italic markup. INFO is a plist holding
1140 contextual information."
1141 (org-groff--text-markup contents 'italic))
1143 ;;; Item
1145 (defun org-groff-item (item contents info)
1146 "Transcode an ITEM element from Org to Groff.
1147 CONTENTS holds the contents of the item. INFO is a plist holding
1148 contextual information."
1149 (let* ((bullet (org-element-property :bullet item))
1150 (type (org-element-property
1151 :type (org-element-property :parent item)))
1152 (checkbox (case (org-element-property :checkbox item)
1153 (on "\\o'\\(sq\\(mu'")
1154 (off "\\(sq")
1155 (trans "\\o'\\(sq\\(mi'")))
1156 (tag (let ((tag (org-element-property :tag item)))
1157 ;; Check-boxes must belong to the tag.
1158 (and tag (format "%s"
1159 (concat checkbox
1160 (org-export-data tag info)))))))
1162 (cond
1163 ((or checkbox tag)
1164 (concat ".LI ""\"" (or tag (concat "\\ " checkbox)) "\""
1165 "\n"
1166 (org-trim (or contents " "))))
1167 ((eq type 'ordered)
1168 (concat ".LI"
1169 "\n"
1170 (org-trim (or contents " "))))
1172 (let* ((bullet (org-trim bullet))
1173 (marker (cond ((string= "-" bullet) "\\(em")
1174 ((string= "*" bullet) "\\(bu")
1175 (t "\\(dg"))))
1176 (concat ".LI " marker "\n"
1177 (org-trim (or contents " "))))))))
1179 ;;; Keyword
1181 (defun org-groff-keyword (keyword contents info)
1182 "Transcode a KEYWORD element from Org to Groff.
1183 CONTENTS is nil. INFO is a plist holding contextual information."
1184 (let ((key (org-element-property :key keyword))
1185 (value (org-element-property :value keyword)))
1186 (cond
1187 ((string= key "GROFF") value)
1188 (t nil))))
1190 ;;; Line Break
1192 (defun org-groff-line-break (line-break contents info)
1193 "Transcode a LINE-BREAK object from Org to Groff.
1194 CONTENTS is nil. INFO is a plist holding contextual information."
1195 ".br\n")
1197 ;;; Link
1198 ;; Inline images just place a call to .PSPIC or .PS/.PE
1199 ;; and load the graph.
1201 (defun org-groff-link--inline-image (link info)
1202 "Return Groff code for an inline image.
1203 LINK is the link pointing to the inline image. INFO is a plist
1204 used as a communication channel."
1205 (let* ((parent (org-export-get-parent-element link))
1206 (path (let ((raw-path (org-element-property :path link)))
1207 (if (not (file-name-absolute-p raw-path)) raw-path
1208 (expand-file-name raw-path))))
1209 (attr (org-export-read-attribute :attr_groff link))
1210 (placement
1211 (case (plist-get attr :position)
1212 ('center "")
1213 ('left "-L")
1214 ('right "-R")
1215 (t "")))
1216 (width (or (plist-get attr :width) ""))
1217 (height (or (plist-get attr :height) ""))
1218 (caption (and (not (plist-get attr :disable-caption))
1219 (org-groff--caption/label-string parent info))))
1220 ;; Now clear ATTR from any special keyword and set a default value
1221 ;; if nothing is left. Return proper string.
1222 (concat
1223 (cond
1224 ((and org-groff-raster-to-ps
1225 (or (string-match ".\.png$" path)
1226 (string-match ".\.jpg$" path)))
1227 (let ((eps-path (concat path ".eps")))
1228 (shell-command (format org-groff-raster-to-ps path eps-path))
1229 (format "\n.DS L F\n.PSPIC %s \"%s\" %s %s\n.DE "
1230 placement eps-path width height)))
1231 ((string-match ".\.pic$" path)
1232 (format "\n.PS\ncopy \"%s\"\n.PE" path))
1233 (t (format "\n.DS L F\n.PSPIC %s \"%s\" %s %s\n.DE "
1234 placement path width height)))
1235 (and caption (format "\n.FG \"%s\"" caption)))))
1237 (defun org-groff-link (link desc info)
1238 "Transcode a LINK object from Org to Groff.
1240 DESC is the description part of the link, or the empty string.
1241 INFO is a plist holding contextual information. See
1242 `org-export-data'."
1244 (let* ((type (org-element-property :type link))
1245 (raw-path (org-element-property :path link))
1246 ;; Ensure DESC really exists, or set it to nil.
1247 (desc (and (not (string= desc "")) desc))
1248 (imagep (org-export-inline-image-p
1249 link org-groff-inline-image-rules))
1250 (path (cond
1251 ((member type '("http" "https" "ftp" "mailto"))
1252 (concat type ":" raw-path))
1253 ((string= type "file")
1254 (when (string-match "\\(.+\\)::.+" raw-path)
1255 (setq raw-path (match-string 1 raw-path)))
1256 (if (file-name-absolute-p raw-path)
1257 (concat "file://" (expand-file-name raw-path))
1258 (concat "file://" raw-path)))
1259 (t raw-path)))
1260 protocol)
1261 (cond
1262 ;; Image file.
1263 (imagep (org-groff-link--inline-image link info))
1264 ;; import groff files
1265 ((and (string= type "file")
1266 (string-match ".\.groff$" raw-path))
1267 (concat ".so " raw-path "\n"))
1268 ;; Radio link: transcode target's contents and use them as link's
1269 ;; description.
1270 ((string= type "radio")
1271 (let ((destination (org-export-resolve-radio-link link info)))
1272 (when destination
1273 (format "\\fI [%s] \\fP"
1274 (org-export-solidify-link-text path)))))
1276 ;; Links pointing to an headline: find destination and build
1277 ;; appropriate referencing command.
1278 ((member type '("custom-id" "fuzzy" "id"))
1279 (let ((destination (if (string= type "fuzzy")
1280 (org-export-resolve-fuzzy-link link info)
1281 (org-export-resolve-id-link link info))))
1282 (case (org-element-type destination)
1283 ;; Id link points to an external file.
1284 (plain-text
1285 (if desc (format "%s \\fBat\\fP \\fIfile://%s\\fP" desc destination)
1286 (format "\\fI file://%s \\fP" destination)))
1287 ;; Fuzzy link points nowhere.
1288 ('nil
1289 (format org-groff-link-with-unknown-path-format
1290 (or desc
1291 (org-export-data
1292 (org-element-property :raw-link link) info))))
1293 ;; Fuzzy link points to an invisible target.
1294 (keyword nil)
1295 ;; LINK points to an headline. If headlines are numbered
1296 ;; and the link has no description, display headline's
1297 ;; number. Otherwise, display description or headline's
1298 ;; title.
1299 (headline
1300 (let ((label ""))
1301 (if (and (plist-get info :section-numbers) (not desc))
1302 (format "\\fI%s\\fP" label)
1303 (format "\\fI%s\\fP"
1304 (or desc
1305 (org-export-data
1306 (org-element-property :title destination) info))))))
1307 ;; Fuzzy link points to a target. Do as above.
1308 (otherwise
1309 (let ((path (org-export-solidify-link-text path)))
1310 (if (not desc) (format "\\fI%s\\fP" path)
1311 (format "%s \\fBat\\fP \\fI%s\\fP" desc path)))))))
1312 ;; External link with a description part.
1313 ((and path desc) (format "%s \\fBat\\fP \\fI%s\\fP" path desc))
1314 ;; External link without a description part.
1315 (path (format "\\fI%s\\fP" path))
1316 ;; No path, only description. Try to do something useful.
1317 (t (format org-groff-link-with-unknown-path-format desc)))))
1319 ;;; Paragraph
1321 (defun org-groff-paragraph (paragraph contents info)
1322 "Transcode a PARAGRAPH element from Org to Groff.
1323 CONTENTS is the contents of the paragraph, as a string. INFO is
1324 the plist used as a communication channel."
1325 (let ((parent (plist-get (nth 1 paragraph) :parent)))
1326 (when parent
1327 (let* ((parent-type (car parent))
1328 (fixed-paragraph "")
1329 (class (plist-get info :groff-class))
1330 (class-options (plist-get info :groff-class-options))
1331 (classes (assoc class org-groff-classes))
1332 (classes-options (car (last classes)))
1333 (paragraph-option (plist-get classes-options :paragraph)))
1334 (cond
1335 ((and (symbolp paragraph-option)
1336 (fboundp paragraph-option))
1337 (funcall paragraph-option parent-type parent contents))
1338 ((and (eq parent-type 'item)
1339 (plist-get (nth 1 parent) :bullet))
1340 (setq fixed-paragraph (concat "" contents)))
1341 ((eq parent-type 'section)
1342 (setq fixed-paragraph (concat ".P\n" contents)))
1343 ((eq parent-type 'footnote-definition)
1344 (setq fixed-paragraph (concat "" contents)))
1345 (t (setq fixed-paragraph (concat "" contents))))
1346 fixed-paragraph))))
1348 ;;; Plain List
1350 (defun org-groff-plain-list (plain-list contents info)
1351 "Transcode a PLAIN-LIST element from Org to Groff.
1352 CONTENTS is the contents of the list. INFO is a plist holding
1353 contextual information."
1354 (let* ((type (org-element-property :type plain-list))
1355 (attr (mapconcat #'identity
1356 (org-element-property :attr_groff plain-list)
1357 " "))
1358 (groff-type (cond
1359 ((eq type 'ordered) ".AL")
1360 ((eq type 'unordered) ".BL")
1361 ((eq type 'descriptive) ".VL 2.0i"))))
1362 (org-groff--wrap-label
1363 plain-list
1364 (format "%s\n%s\n.LE" groff-type contents))))
1366 ;;; Plain Text
1368 (defun org-groff-plain-text (text info)
1369 "Transcode a TEXT string from Org to Groff.
1370 TEXT is the string to transcode. INFO is a plist holding
1371 contextual information."
1372 (let ((output text))
1373 ;; Protect various characters.
1374 (setq output (replace-regexp-in-string
1375 "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
1376 "$\\" output nil t 1))
1377 ;; Activate smart quotes. Be sure to provide original TEXT string
1378 ;; since OUTPUT may have been modified.
1379 (when (plist-get info :with-smart-quotes)
1380 (setq output (org-export-activate-smart-quotes output :utf-8 info text)))
1381 ;; Handle Special Characters
1382 (if org-groff-special-char
1383 (dolist (special-char-list org-groff-special-char)
1384 (setq output
1385 (replace-regexp-in-string (car special-char-list)
1386 (cdr special-char-list) output))))
1387 ;; Handle break preservation if required.
1388 (when (plist-get info :preserve-breaks)
1389 (setq output (replace-regexp-in-string
1390 "\\(\\\\\\\\\\)?[ \t]*\n" ".br\n" output)))
1391 ;; Return value.
1392 output))
1394 ;;; Planning
1396 (defun org-groff-planning (planning contents info)
1397 "Transcode a PLANNING element from Org to Groff.
1398 CONTENTS is nil. INFO is a plist holding contextual
1399 information."
1400 (concat
1401 (mapconcat
1402 'identity
1403 (delq nil
1404 (list
1405 (let ((closed (org-element-property :closed planning)))
1406 (when closed
1407 (concat
1408 (format "\\fR %s \\fP" org-closed-string)
1409 (format org-groff-inactive-timestamp-format
1410 (org-translate-time
1411 (org-element-property :raw-value closed))))))
1412 (let ((deadline (org-element-property :deadline planning)))
1413 (when deadline
1414 (concat
1415 (format "\\fB %s \\fP" org-deadline-string)
1416 (format org-groff-active-timestamp-format
1417 (org-translate-time
1418 (org-element-property :raw-value deadline))))))
1419 (let ((scheduled (org-element-property :scheduled planning)))
1420 (when scheduled
1421 (concat
1422 (format "\\fR %s \\fP" org-scheduled-string)
1423 (format org-groff-active-timestamp-format
1424 (org-translate-time
1425 (org-element-property :raw-value scheduled))))))))
1427 ""))
1429 ;;; Property Drawer
1431 (defun org-groff-property-drawer (property-drawer contents info)
1432 "Transcode a PROPERTY-DRAWER element from Org to Groff.
1433 CONTENTS is nil. INFO is a plist holding contextual
1434 information."
1435 ;; The property drawer isn't exported but we want separating blank
1436 ;; lines nonetheless.
1439 ;;; Quote Block
1441 (defun org-groff-quote-block (quote-block contents info)
1442 "Transcode a QUOTE-BLOCK element from Org to Groff.
1443 CONTENTS holds the contents of the block. INFO is a plist
1444 holding contextual information."
1445 (org-groff--wrap-label
1446 quote-block
1447 (format ".DS I\n.I\n%s\n.R\n.DE" contents)))
1449 ;;; Quote Section
1451 (defun org-groff-quote-section (quote-section contents info)
1452 "Transcode a QUOTE-SECTION element from Org to Groff.
1453 CONTENTS is nil. INFO is a plist holding contextual information."
1454 (let ((value (org-remove-indentation
1455 (org-element-property :value quote-section))))
1456 (when value (format ".DS L\n\\fI%s\\fP\n.DE\n" value))))
1458 ;;; Radio Target
1460 (defun org-groff-radio-target (radio-target text info)
1461 "Transcode a RADIO-TARGET object from Org to Groff.
1462 TEXT is the text of the target. INFO is a plist holding
1463 contextual information."
1464 (format "%s - %s"
1465 (org-export-solidify-link-text
1466 (org-element-property :value radio-target))
1467 text))
1469 ;;; Section
1471 (defun org-groff-section (section contents info)
1472 "Transcode a SECTION element from Org to Groff.
1473 CONTENTS holds the contents of the section. INFO is a plist
1474 holding contextual information."
1475 contents)
1477 ;;; Special Block
1479 (defun org-groff-special-block (special-block contents info)
1480 "Transcode a SPECIAL-BLOCK element from Org to Groff.
1481 CONTENTS holds the contents of the block. INFO is a plist
1482 holding contextual information."
1483 (let ((type (downcase (org-element-property :type special-block))))
1484 (org-groff--wrap-label
1485 special-block
1486 (format "%s\n" contents))))
1488 ;;; Src Block
1490 (defun org-groff-src-block (src-block contents info)
1491 "Transcode a SRC-BLOCK element from Org to Groff.
1492 CONTENTS holds the contents of the item. INFO is a plist holding
1493 contextual information."
1494 (let* ((lang (org-element-property :language src-block))
1495 (label (org-element-property :name src-block))
1496 (code (org-element-property :value src-block))
1497 (custom-env (and lang
1498 (cadr (assq (intern lang)
1499 org-groff-custom-lang-environments))))
1500 (num-start (case (org-element-property :number-lines src-block)
1501 (continued (org-export-get-loc src-block info))
1502 (new 0)))
1503 (retain-labels (org-element-property :retain-labels src-block))
1504 (caption (and (not (org-export-read-attribute
1505 :attr_groff src-block :disable-caption))
1506 (org-groff--caption/label-string src-block info))))
1508 (cond
1509 ;; Case 1. No source fontification.
1510 ((not org-groff-source-highlight)
1511 (concat
1512 (format ".DS I\n\\fC%s\\fP\n.DE\n"
1513 (org-export-format-code-default src-block info))
1514 (and caption (format ".EX \"%s\" " caption))))
1516 ;; Case 2. Source fontification.
1517 (org-groff-source-highlight
1518 (let* ((tmpdir (if (featurep 'xemacs)
1519 temp-directory
1520 temporary-file-directory))
1521 (in-file (make-temp-name
1522 (expand-file-name "srchilite" tmpdir)))
1523 (out-file (make-temp-name
1524 (expand-file-name "reshilite" tmpdir)))
1526 (org-lang (org-element-property :language src-block))
1527 (lst-lang (cadr (assq (intern org-lang)
1528 org-groff-source-highlight-langs)))
1530 (cmd (concat "source-highlight"
1531 " -s " lst-lang
1532 " -f groff_mm_color "
1533 " -i " in-file
1534 " -o " out-file)))
1536 (concat
1537 (if lst-lang
1538 (let ((code-block ""))
1539 (with-temp-file in-file (insert code))
1540 (shell-command cmd)
1541 (setq code-block (org-file-contents out-file))
1542 (delete-file in-file)
1543 (delete-file out-file)
1544 (format "%s\n" code-block))
1545 (format ".DS I\n\\fC\\m[black]%s\\m[]\\fP\n.DE\n"
1546 code))
1547 (and caption (format ".EX \"%s\" " caption))))))))
1550 ;;; Statistics Cookie
1552 (defun org-groff-statistics-cookie (statistics-cookie contents info)
1553 "Transcode a STATISTICS-COOKIE object from Org to Groff.
1554 CONTENTS is nil. INFO is a plist holding contextual information."
1555 (org-element-property :value statistics-cookie))
1558 ;;; Strike-Through
1560 (defun org-groff-strike-through (strike-through contents info)
1561 "Transcode STRIKE-THROUGH from Org to Groff.
1562 CONTENTS is the text with strike-through markup. INFO is a plist
1563 holding contextual information."
1564 (org-groff--text-markup contents 'strike-through))
1566 ;;; Subscript
1568 (defun org-groff-subscript (subscript contents info)
1569 "Transcode a SUBSCRIPT object from Org to Groff.
1570 CONTENTS is the contents of the object. INFO is a plist holding
1571 contextual information."
1572 (format "\\d\\s-2%s\\s+2\\u" contents))
1574 ;;; Superscript "^_%s$
1576 (defun org-groff-superscript (superscript contents info)
1577 "Transcode a SUPERSCRIPT object from Org to Groff.
1578 CONTENTS is the contents of the object. INFO is a plist holding
1579 contextual information."
1580 (format "\\u\\s-2%s\\s+2\\d" contents))
1583 ;;; Table
1585 ;; `org-groff-table' is the entry point for table transcoding. It
1586 ;; takes care of tables with a "verbatim" attribute. Otherwise, it
1587 ;; delegates the job to `org-groff-table--org-table' function,
1588 ;; depending of the type of the table.
1590 ;; `org-groff-table--align-string' is a subroutine used to build
1591 ;; alignment string for Org tables.
1593 (defun org-groff-table (table contents info)
1594 "Transcode a TABLE element from Org to Groff.
1595 CONTENTS is the contents of the table. INFO is a plist holding
1596 contextual information."
1597 (cond
1598 ;; Case 1: verbatim table.
1599 ((or org-groff-tables-verbatim
1600 (let ((attr (read (format "(%s)"
1601 (mapconcat
1602 #'identity
1603 (org-element-property :attr_groff table) " ")))))
1604 (and attr (plist-get attr :verbatim))))
1606 (format ".DS L\n\\fC%s\\fP\n.DE"
1607 ;; Re-create table, without affiliated keywords.
1608 (org-trim
1609 (org-element-interpret-data
1610 `(table nil ,@(org-element-contents table))))))
1612 ;; Case 2: Standard table.
1613 (t (org-groff-table--org-table table contents info))))
1615 (defun org-groff-table--align-string (divider table info)
1616 "Return an appropriate Groff alignment string.
1617 TABLE is the considered table. INFO is a plist used as
1618 a communication channel."
1619 (let (alignment)
1620 ;; Extract column groups and alignment from first (non-rule) row.
1621 (org-element-map
1622 (org-element-map table 'table-row
1623 (lambda (row)
1624 (and (eq (org-element-property :type row) 'standard) row))
1625 info 'first-match)
1626 'table-cell
1627 (lambda (cell)
1628 (let* ((borders (org-export-table-cell-borders cell info))
1629 (raw-width (org-export-table-cell-width cell info))
1630 (width-cm (when raw-width (/ raw-width 5)))
1631 (width (if raw-width (format "w(%dc)"
1632 (if (< width-cm 1) 1 width-cm)) "")))
1633 ;; Check left border for the first cell only.
1634 ;; Alignment is nil on assignment
1636 (when (and (memq 'left borders) (not alignment))
1637 (push "|" alignment))
1638 (push
1639 (case (org-export-table-cell-alignment cell info)
1640 (left (concat "l" width divider))
1641 (right (concat "r" width divider))
1642 (center (concat "c" width divider)))
1643 alignment)
1644 (when (memq 'right borders) (push "|" alignment))))
1645 info)
1646 (apply 'concat (reverse alignment))))
1648 (defun org-groff-table--org-table (table contents info)
1649 "Return appropriate Groff code for an Org table.
1651 TABLE is the table type element to transcode. CONTENTS is its
1652 contents, as a string. INFO is a plist used as a communication
1653 channel.
1655 This function assumes TABLE has `org' as its `:type' attribute."
1656 (let* ((attr (org-export-read-attribute :attr_groff table))
1657 (label (org-element-property :name table))
1658 (caption (and (not (plist-get attr :disable-caption))
1659 (org-groff--caption/label-string table info)))
1660 (divider (if (plist-get attr :divider) "|" " "))
1662 ;; Determine alignment string.
1663 (alignment (org-groff-table--align-string divider table info))
1665 ;; Extract others display options.
1667 (lines (org-split-string contents "\n"))
1669 (attr-list
1670 (let (result-list)
1671 (dolist (attr-item
1672 (list
1673 (if (plist-get attr :expand)
1674 "expand" nil)
1676 (case (plist-get attr :placement)
1677 ('center "center")
1678 ('left nil)
1680 (if org-groff-tables-centered
1681 "center" "")))
1683 (case (plist-get attr :boxtype)
1684 ('box "box")
1685 ('doublebox "doublebox")
1686 ('allbox "allbox")
1687 ('none nil)
1688 (t "box"))))
1690 (if (not (null attr-item))
1691 (add-to-list 'result-list attr-item)))
1692 result-list))
1694 (title-line (plist-get attr :title-line))
1695 (long-cells (plist-get attr :long-cells))
1697 (table-format
1698 (concat
1699 (format "%s"
1700 (or (car attr-list) ""))
1702 (let (output-list)
1703 (when (cdr attr-list)
1704 (dolist (attr-item (cdr attr-list))
1705 (setq output-list (concat output-list
1706 (format ",%s" attr-item)))))
1707 output-list) "")))
1708 (first-line
1709 (when lines (org-split-string (car lines) "\t"))))
1710 ;; Prepare the final format string for the table.
1713 (cond
1714 ;; Others.
1715 (lines
1716 (concat ".TS\n " table-format ";\n"
1717 (format "%s.\n"
1718 (let ((final-line ""))
1719 (when title-line
1720 (dotimes (i (length first-line))
1721 (setq final-line (concat final-line "cb" divider))))
1723 (setq final-line (concat final-line "\n"))
1725 (if alignment
1726 (setq final-line (concat final-line alignment))
1727 (dotimes (i (length first-line))
1728 (setq final-line (concat final-line "c" divider))))
1729 final-line))
1731 (format "%s.TE\n"
1732 (let ((final-line "")
1733 (long-line "")
1734 (lines (org-split-string contents "\n")))
1736 (dolist (line-item lines)
1737 (setq long-line "")
1739 (if long-cells
1740 (progn
1741 (if (string= line-item "_")
1742 (setq long-line (format "%s\n" line-item))
1743 ;; else string =
1744 (let ((cell-item-list (org-split-string line-item "\t")))
1745 (dolist (cell-item cell-item-list)
1747 (cond ((eq cell-item (car (last cell-item-list)))
1748 (setq long-line (concat long-line
1749 (format "T{\n%s\nT}\t\n" cell-item))))
1751 (setq long-line (concat long-line
1752 (format "T{\n%s\nT}\t" cell-item))))))
1753 long-line))
1754 ;; else long cells
1755 (setq final-line (concat final-line long-line)))
1757 (setq final-line (concat final-line line-item "\n"))))
1758 final-line))
1760 (if caption (format ".TB \"%s\"" caption) ""))))))
1762 ;;; Table Cell
1764 (defun org-groff-table-cell (table-cell contents info)
1765 "Transcode a TABLE-CELL element from Org to Groff
1766 CONTENTS is the cell contents. INFO is a plist used as
1767 a communication channel."
1768 (progn
1769 (concat (if (and contents
1770 org-groff-table-scientific-notation
1771 (string-match orgtbl-exp-regexp contents))
1772 ;; Use appropriate format string for scientific
1773 ;; notation.
1774 (format org-groff-table-scientific-notation
1775 (match-string 1 contents)
1776 (match-string 2 contents))
1777 contents)
1778 (when (org-export-get-next-element table-cell info) "\t"))))
1781 ;;; Table Row
1783 (defun org-groff-table-row (table-row contents info)
1784 "Transcode a TABLE-ROW element from Org to Groff
1785 CONTENTS is the contents of the row. INFO is a plist used as
1786 a communication channel."
1787 ;; Rules are ignored since table separators are deduced from
1788 ;; borders of the current row.
1789 (when (eq (org-element-property :type table-row) 'standard)
1790 (let* ((attr (mapconcat 'identity
1791 (org-element-property
1792 :attr_groff (org-export-get-parent table-row))
1793 " "))
1794 ;; TABLE-ROW's borders are extracted from its first cell.
1795 (borders
1796 (org-export-table-cell-borders
1797 (car (org-element-contents table-row)) info)))
1798 (concat
1799 ;; Mark horizontal lines
1800 (cond ((and (memq 'top borders) (memq 'above borders)) "_\n"))
1801 contents
1802 (cond
1803 ;; When BOOKTABS are activated enforce bottom rule even when
1804 ;; no hline was specifically marked.
1805 ((and (memq 'bottom borders) (memq 'below borders)) "\n_")
1806 ((memq 'below borders) "\n_"))))))
1808 ;;; Target
1810 (defun org-groff-target (target contents info)
1811 "Transcode a TARGET object from Org to Groff.
1812 CONTENTS is nil. INFO is a plist holding contextual
1813 information."
1814 (format "\\fI%s\\fP"
1815 (org-export-solidify-link-text (org-element-property :value target))))
1817 ;;; Timestamp
1819 (defun org-groff-timestamp (timestamp contents info)
1820 "Transcode a TIMESTAMP object from Org to Groff.
1821 CONTENTS is nil. INFO is a plist holding contextual
1822 information."
1823 (let ((value (org-groff-plain-text
1824 (org-timestamp-translate timestamp) info)))
1825 (case (org-element-property :type timestamp)
1826 ((active active-range)
1827 (format org-groff-active-timestamp-format value))
1828 ((inactive inactive-range)
1829 (format org-groff-inactive-timestamp-format value))
1830 (t (format org-groff-diary-timestamp-format value)))))
1832 ;;; Underline
1834 (defun org-groff-underline (underline contents info)
1835 "Transcode UNDERLINE from Org to Groff.
1836 CONTENTS is the text with underline markup. INFO is a plist
1837 holding contextual information."
1838 (org-groff--text-markup contents 'underline))
1840 ;;; Verbatim
1842 (defun org-groff-verbatim (verbatim contents info)
1843 "Transcode a VERBATIM object from Org to Groff.
1844 CONTENTS is nil. INFO is a plist used as a communication
1845 channel."
1846 (org-groff--text-markup (org-element-property :value verbatim) 'verbatim))
1848 ;;; Verse Block
1850 (defun org-groff-verse-block (verse-block contents info)
1851 "Transcode a VERSE-BLOCK element from Org to Groff.
1852 CONTENTS is verse block contents. INFO is a plist holding
1853 contextual information."
1854 (format ".DS C\n.ft HI\n%s\n.ft\n.DE" contents))
1857 ;;; Interactive functions
1859 (defun org-groff-export-to-groff
1860 (&optional async subtreep visible-only body-only ext-plist)
1861 "Export current buffer to a Groff file.
1863 If narrowing is active in the current buffer, only export its
1864 narrowed part.
1866 If a region is active, export that region.
1868 A non-nil optional argument ASYNC means the process should happen
1869 asynchronously. The resulting file should be accessible through
1870 the `org-export-stack' interface.
1872 When optional argument SUBTREEP is non-nil, export the sub-tree
1873 at point, extracting information from the headline properties
1874 first.
1876 When optional argument VISIBLE-ONLY is non-nil, don't export
1877 contents of hidden elements.
1879 EXT-PLIST, when provided, is a property list with external
1880 parameters overriding Org default settings, but still inferior to
1881 file-local settings.
1883 Return output file's name."
1884 (interactive)
1885 (let ((outfile (org-export-output-file-name ".groff" subtreep)))
1886 (if async
1887 (org-export-async-start
1888 (lambda (f) (org-export-add-to-stack f 'groff))
1889 (let ((org-groff-registered-references nil)
1890 (org-groff-special-content nil))
1891 `(expand-file-name
1892 (org-export-to-file
1893 'groff ,outfile ,subtreep ,visible-only ,body-only
1894 ',ext-plist))))
1895 (let ((org-groff-registered-references nil)
1896 (org-groff-special-content nil))
1897 (org-export-to-file
1898 'groff outfile subtreep visible-only body-only ext-plist)))))
1900 (defun org-groff-export-to-pdf
1901 (&optional async subtreep visible-only body-only ext-plist)
1902 "Export current buffer to Groff then process through to PDF.
1904 If narrowing is active in the current buffer, only export its
1905 narrowed part.
1907 If a region is active, export that region.
1909 A non-nil optional argument ASYNC means the process should happen
1910 asynchronously. The resulting file should be accessible through
1911 the `org-export-stack' interface.
1913 When optional argument SUBTREEP is non-nil, export the sub-tree
1914 at point, extracting information from the headline properties
1915 first.
1917 When optional argument VISIBLE-ONLY is non-nil, don't export
1918 contents of hidden elements.
1920 EXT-PLIST, when provided, is a property list with external
1921 parameters overriding Org default settings, but still inferior to
1922 file-local settings.
1924 Return PDF file's name."
1925 (interactive)
1926 (if async
1927 (let ((outfile (org-export-output-file-name ".groff" subtreep)))
1928 (org-export-async-start
1929 (lambda (f) (org-export-add-to-stack f 'groff))
1930 `(expand-file-name
1931 (org-groff-compile
1932 (org-export-to-file
1933 'groff ,outfile ,subtreep ,visible-only ,body-only
1934 ',ext-plist)))))
1935 (org-groff-compile
1936 (org-groff-export-to-groff
1937 nil subtreep visible-only body-only ext-plist))))
1939 (defun org-groff-compile (file)
1940 "Compile a Groff file.
1942 FILE is the name of the file being compiled. Processing is done
1943 through the command specified in `org-groff-pdf-process'.
1945 Return PDF file name or an error if it couldn't be produced."
1946 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file)))
1947 (full-name (file-truename file))
1948 (out-dir (file-name-directory file))
1949 ;; Make sure `default-directory' is set to FILE directory,
1950 ;; not to whatever value the current buffer may have.
1951 (default-directory (file-name-directory full-name))
1952 errors)
1953 (message (format "Processing Groff file %s ..." file))
1954 (save-window-excursion
1955 (cond
1956 ;; A function is provided: Apply it.
1957 ((functionp org-groff-pdf-process)
1958 (funcall org-groff-pdf-process (shell-quote-argument file)))
1959 ;; A list is provided: Replace %b, %f and %o with appropriate
1960 ;; values in each command before applying it. Output is
1961 ;; redirected to "*Org PDF Groff Output*" buffer.
1962 ((consp org-groff-pdf-process)
1963 (let ((outbuf (get-buffer-create "*Org PDF Groff Output*")))
1964 (mapc
1965 (lambda (command)
1966 (shell-command
1967 (replace-regexp-in-string
1968 "%b" (shell-quote-argument base-name)
1969 (replace-regexp-in-string
1970 "%f" (shell-quote-argument full-name)
1971 (replace-regexp-in-string
1972 "%o" (shell-quote-argument out-dir) command t t)
1973 t t) t t)
1974 outbuf))
1975 org-groff-pdf-process)
1976 ;; Collect standard errors from output buffer.
1977 (setq errors (org-groff-collect-errors outbuf))))
1978 (t (error "No valid command to process to PDF")))
1979 (let ((pdffile (concat out-dir base-name ".pdf")))
1980 ;; Check for process failure. Provide collected errors if
1981 ;; possible.
1982 (if (not (file-exists-p pdffile))
1983 (error (concat (format "PDF file %s wasn't produced" pdffile)
1984 (when errors (concat ": " errors))))
1985 ;; Else remove log files, when specified, and signal end of
1986 ;; process to user, along with any error encountered.
1987 (when org-groff-remove-logfiles
1988 (dolist (ext org-groff-logfiles-extensions)
1989 (let ((file (concat out-dir base-name "." ext)))
1990 (when (file-exists-p file) (delete-file file)))))
1991 (message (concat "Process completed"
1992 (if (not errors) "."
1993 (concat " with errors: " errors)))))
1994 ;; Return output file name.
1995 pdffile))))
1997 (defun org-groff-collect-errors (buffer)
1998 "Collect some kind of errors from \"groff\" output
1999 BUFFER is the buffer containing output.
2000 Return collected error types as a string, or nil if there was
2001 none."
2002 (with-current-buffer buffer
2003 (save-excursion
2004 (goto-char (point-max))
2005 ;; Find final run
2006 nil)))
2009 (provide 'ox-groff)
2010 ;;; ox-groff.el ends here