1 ;; org-e-groff.el --- Groff Back-End For Org Export Engine
3 ;; Copyright (C) 2011-2012 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
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/>.
24 ;; This library implements a Groff Memorandum Macro back-end for
25 ;; Org generic exporter.
29 ;; M-: (org-export-to-buffer 'e-groff "*Test e-Groff*") RET
31 ;; in an org-mode buffer then switch to the buffer to see the Groff
32 ;; export. See contrib/lisp/org-export.el for more details on how
33 ;; this exporter works.
35 ;; It introduces two new buffer keywords: "GROFF_CLASS" and
36 ;; "GROFF_CLASS_OPTIONS".
40 (eval-when-compile (require 'cl
))
43 (defvar orgtbl-exp-regexp
)
48 (org-export-define-backend e-groff
49 ((bold . org-e-groff-bold
)
50 (center-block . org-e-groff-center-block
)
51 (clock . org-e-groff-clock
)
52 (code . org-e-groff-code
)
53 (drawer . org-e-groff-drawer
)
54 (dynamic-block . org-e-groff-dynamic-block
)
55 (entity . org-e-groff-entity
)
56 (example-block . org-e-groff-example-block
)
57 (export-block . org-e-groff-export-block
)
58 (export-snippet . org-e-groff-export-snippet
)
59 (fixed-width . org-e-groff-fixed-width
)
60 (footnote-definition . org-e-groff-footnote-definition
)
61 (footnote-reference . org-e-groff-footnote-reference
)
62 (headline . org-e-groff-headline
)
63 (horizontal-rule . org-e-groff-horizontal-rule
)
64 (inline-src-block . org-e-groff-inline-src-block
)
65 (inlinetask . org-e-groff-inlinetask
)
66 (italic . org-e-groff-italic
)
67 (item . org-e-groff-item
)
68 (keyword . org-e-groff-keyword
)
69 ;; (latex-environment . org-e-groff-latex-environment)
70 ;; (latex-fragment . org-e-groff-latex-fragment)
71 (line-break . org-e-groff-line-break
)
72 (link . org-e-groff-link
)
73 (paragraph . org-e-groff-paragraph
)
74 (plain-list . org-e-groff-plain-list
)
75 (plain-text . org-e-groff-plain-text
)
76 (planning . org-e-groff-planning
)
77 (property-drawer . org-e-groff-property-drawer
)
78 (quote-block . org-e-groff-quote-block
)
79 (quote-section . org-e-groff-quote-section
)
80 (radio-target . org-e-groff-radio-target
)
81 (section . org-e-groff-section
)
82 (special-block . org-e-groff-special-block
)
83 (src-block . org-e-groff-src-block
)
84 (statistics-cookie . org-e-groff-statistics-cookie
)
85 (strike-through . org-e-groff-strike-through
)
86 (subscript . org-e-groff-subscript
)
87 (superscript . org-e-groff-superscript
)
88 (table . org-e-groff-table
)
89 (table-cell . org-e-groff-table-cell
)
90 (table-row . org-e-groff-table-row
)
91 (target . org-e-groff-target
)
92 (template . org-e-groff-template
)
93 (timestamp . org-e-groff-timestamp
)
94 (underline . org-e-groff-underline
)
95 (verbatim . org-e-groff-verbatim
)
96 (verse-block . org-e-groff-verse-block
))
100 ((?g
"As GROFF file" org-e-groff-export-to-groff
)
101 (?p
"As PDF file" org-e-groff-export-to-pdf
)
102 (?o
"As PDF file and open"
103 (lambda (s v b
) (org-open-file (org-e-groff-export-to-pdf s v b
))))))
105 ((:groff-class
"GROFF_CLASS" nil org-e-groff-default-class t
)
106 (:groff-class-options
"GROFF_CLASS_OPTIONS" nil nil t
)
107 (:groff-header-extra
"GROFF_HEADER" nil nil newline
)))
111 ;;; User Configurable Variables
113 (defgroup org-export-e-groff nil
114 "Options for exporting Org mode files to Groff."
115 :tag
"Org Export Groff"
120 (defcustom org-e-groff-default-class
"internal"
121 "The default Groff class."
122 :group
'org-export-e-groff
123 :type
'(string :tag
"Groff class"))
125 (defcustom org-e-groff-classes
127 (:heading
'default
:type
"memo" :last-section
"toc"))
129 (:heading
'default
:type
"memo" :last-section
"toc"))
130 ("programmer" ".MT 2"
131 (:heading
'default
:type
"memo" :last-section
"toc"))
133 (:heading
'default
:type
"memo" :last-section
"toc"))
135 (:heading
'default
:type
"memo" :last-section
"toc"))
137 (:heading
'default
:type
"memo" :last-section
"sign"))
139 (:heading custom-function
:type
"custom" :last-section
"toc"))
141 (:heading
'default
:type
"memo"))
143 (:heading
'default
:type
"cover" :last-section
"toc"))
145 (:heading
'default
:type
"cover" :last-section
"toc"))
147 (:heading
'default
:type
"letter" :last-section
"sign"))
149 (:heading
'default
:type
"letter" :last-section
"sign"))
151 (:heading
'default
:type
"letter" :last-section
"sign"))
153 (:heading
'default
:type
"letter" :last-section
"sign"))
154 ("none" "" (:heading
'default
:type
"custom")))
156 ;; none means, no Cover or Memorandum Type and no calls to AU, AT, ND and TL
157 ;; This is to facilitate the creation of custom pages.
159 ;; dummy means, no Cover or Memorandum Type but calls to AU, AT, ND and TL
160 ;; are made. This is to facilitate Abstract Insertion.
162 "This list describes the attributes for the documents being created.
163 It allows for the creation of new "
164 :group
'org-export-e-groff
166 (list (string :tag
"Document Type")
167 (string :tag
"Header")
168 (repeat :tag
"Options" :inline t
170 (list :tag
"Heading")
171 (function :tag
"Hook computing sectioning"))))))
175 (defconst org-e-groff-special-tags
176 '("FROM" "TO" "ABSTRACT" "APPENDIX" "BODY" "NS"))
178 (defcustom org-e-groff-format-headline-function nil
179 "Function to format headline text.
181 This function will be called with 5 arguments:
182 TODO the todo keyword (string or nil).
183 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
184 PRIORITY the priority of the headline (integer or nil)
185 TEXT the main headline text (string).
186 TAGS the tags as a list of strings (list of strings or nil).
188 The function result will be used in the section format string.
190 As an example, one could set the variable to the following, in
191 order to reproduce the default set-up:
193 \(defun org-e-groff-format-headline (todo todo-type priority text tags)
194 \"Default format function for an headline.\"
196 \(format \"\\fB%s\\fP \" todo))
198 \(format \"[\\#%c] \" priority))
202 \(mapconcat 'identity tags \":\"))))"
203 :group
'org-export-e-groff
208 (defcustom org-e-groff-active-timestamp-format
"\\fI%s\\fP"
209 "A printf format string to be applied to active timestamps."
210 :group
'org-export-e-groff
213 (defcustom org-e-groff-inactive-timestamp-format
"\\fI%s\\fP"
214 "A printf format string to be applied to inactive timestamps."
215 :group
'org-export-e-groff
218 (defcustom org-e-groff-diary-timestamp-format
"\\fI%s\\fP"
219 "A printf format string to be applied to diary timestamps."
220 :group
'org-export-e-groff
225 (defcustom org-e-groff-inline-image-rules
226 '(("file" .
"\\.\\(jpg\\|png\\|pdf\\|ps\\|eps\\|pic\\)\\'")
227 ("fuzzy" .
"\\.\\(jpg\\|png\\|pdf\\|ps\\|eps\\|pic\\)\\'"))
228 "Rules characterizing image files that can be inlined into Groff.
230 A rule consists in an association whose key is the type of link
231 to consider, and value is a regexp that will be matched against
234 Note that, by default, the image extensions actually allowed
235 depend on the way the Groff file is processed. When used with
236 pdfgroff, pdf, jpg and png images are OK. When processing
237 through dvi to Postscript, only ps and eps are allowed. The
238 default we use here encompasses both."
239 :group
'org-export-e-groff
240 :type
'(alist :key-type
(string :tag
"Type")
241 :value-type
(regexp :tag
"Path")))
243 (defcustom org-e-groff-link-with-unknown-path-format
"\\fI%s\\fP"
244 "Format string for links with unknown path type."
245 :group
'org-export-groff
250 (defcustom org-e-groff-tables-centered t
251 "When non-nil, tables are exported in a center environment."
252 :group
'org-export-e-groff
255 (defcustom org-e-groff-tables-verbatim nil
256 "When non-nil, tables are exported verbatim."
257 :group
'org-export-e-groff
260 (defcustom org-e-groff-table-scientific-notation
"%sE%s"
261 "Format string to display numbers in scientific notation.
262 The format should have \"%s\" twice, for mantissa and exponent
263 \(i.e. \"%s\\\\times10^{%s}\").
265 When nil, no transformation is made."
266 :group
'org-export-e-groff
268 (string :tag
"Format string")
269 (const :tag
"No formatting")))
273 (defcustom org-e-groff-text-markup-alist
274 '((bold .
"\\fB%s\\fP")
275 (code .
"\\fC%s\\fP")
276 (italic .
"\\fI%s\\fP")
277 (strike-through .
"\\fC%s\\fP") ; Strike through and underline
278 (underline .
"\\fI%s\\fP") ; need to be revised.
279 (verbatim .
"protectedtexttt"))
280 "Alist of Groff expressions to convert text markup.
282 The key must be a symbol among `bold', `code', `italic',
283 `strike-through', `underline' and `verbatim'. The value is
284 a formatting string to wrap fontified text with it.
286 If no association can be found for a given markup, text will be
288 :group
'org-export-e-groff
290 :options
'(bold code italic strike-through underline verbatim
))
294 (defcustom org-e-groff-format-drawer-function nil
295 "Function called to format a drawer in Groff code.
297 The function must accept two parameters:
298 NAME the drawer name, like \"LOGBOOK\"
299 CONTENTS the contents of the drawer.
301 The function should return the string to be exported.
303 For example, the variable could be set to the following function
304 in order to mimic default behaviour:
306 \(defun org-e-groff-format-drawer-default \(name contents\)
307 \"Format a drawer element for Groff export.\"
309 :group
'org-export-e-groff
314 (defcustom org-e-groff-format-inlinetask-function nil
315 "Function called to format an inlinetask in Groff code.
317 The function must accept six parameters:
318 TODO the todo keyword, as a string
319 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
320 PRIORITY the inlinetask priority, as a string
321 NAME the inlinetask name, as a string.
322 TAGS the inlinetask tags, as a list of strings.
323 CONTENTS the contents of the inlinetask, as a string.
325 The function should return the string to be exported.
327 For example, the variable could be set to the following function
328 in order to mimic default behaviour:
330 \(defun org-e-groff-format-inlinetask \(todo type priority name tags contents\)
331 \"Format an inline task element for Groff export.\"
335 \(format \"\\fB%s\\fP \" todo))
336 \(when priority (format \"[\\#%c] \" priority))
340 \(mapconcat 'identity tags \":\")))))
341 \(format (concat \".DS L\\n\"
345 full-title contents))"
346 :group
'org-export-e-groff
351 (defcustom org-e-groff-source-highlight nil
352 "Use GNU source highlight to embellish source blocks "
353 :group
'org-export-e-groff
356 (defcustom org-e-groff-source-highlight-langs
357 '((emacs-lisp "lisp") (lisp "lisp") (clojure "lisp")
359 (c "c") (cc "cpp") (csharp "csharp") (d "d")
360 (fortran "fortran") (cobol "cobol") (pascal "pascal")
361 (ada "ada") (asm "asm")
362 (perl "perl") (cperl "perl")
363 (python "python") (ruby "ruby") (tcl "tcl") (lua "lua")
364 (java "java") (javascript "javascript")
366 (shell-script "sh") (awk "awk") (diff "diff") (m4 "m4")
367 (ocaml "caml") (caml "caml")
368 (sql "sql") (sqlite "sql")
369 (html "html") (css "css") (xml "xml")
370 (bat "bat") (bison "bison") (clipper "clipper")
371 (ldap "ldap") (opa "opa")
372 (php "php") (postscript "postscript") (prolog "prolog")
373 (properties "properties") (makefile "makefile")
374 (tml "tml") (vala "vala") (vbscript "vbscript") (xorg "xorg"))
375 "Alist mapping languages to their listing language counterpart.
376 The key is a symbol, the major mode symbol without the \"-mode\".
377 The value is the string that should be inserted as the language
378 parameter for the listings package. If the mode name and the
379 listings name are the same, the language does not need an entry
380 in this list - but it does not hurt if it is present."
381 :group
'org-export-e-groff
384 (symbol :tag
"Major mode ")
385 (string :tag
"Listings language"))))
387 (defcustom org-e-groff-source-highlight-options nil
388 "Association list of options for the groff listings package.
390 These options are supplied as a comma-separated list to the
391 \\lstset command. Each element of the association list should be
392 a list containing two strings: the name of the option, and the
395 (setq org-e-groff-source-highlight-options
396 '((\"basicstyle\" \"\\small\")
397 (\"keywordstyle\" \"\\color{black}\\bfseries\\underbar\")))
399 will typeset the code in a small size font with underlined, bold
402 Note that the same options will be applied to blocks of all
404 :group
'org-export-e-groff
407 (string :tag
"Listings option name ")
408 (string :tag
"Listings option value"))))
410 (defvar org-e-groff-custom-lang-environments nil
411 "Alist mapping languages to language-specific Groff environments.
413 It is used during export of src blocks by the listings and
414 groff packages. For example,
416 \(setq org-e-groff-custom-lang-environments
417 '\(\(python \"pythoncode\"\)\)\)
419 would have the effect that if org encounters begin_src python
420 during groff export it will use pythoncode as the source-highlight
425 (defcustom org-e-groff-special-char
426 '(("(c)" .
"\\\\(co")
428 ("(rg)" .
"\\\\(rg"))
429 "CONS list in which the value of the car
430 is replace on the value of the CDR. "
431 :group
'org-export-e-groff
433 (cons :tag
"Character Subtitute"
434 (string :tag
"Original Character Group")
435 (string :tag
"Replacement Character"))))
439 (defcustom org-e-groff-pdf-process
440 '("pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"
441 "pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"
442 "pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf")
444 "Commands to process a Groff file to a PDF file.
445 This is a list of strings, each of them will be given to the
446 shell as a command. %f in the command will be replaced by the
447 full file name, %b by the file base name \(i.e. without
448 extension) and %o by the base directory of the file."
449 :group
'org-export-pdf
451 (repeat :tag
"Shell command sequence"
452 (string :tag
"Shell command"))
453 (const :tag
"2 runs of pdfgroff"
454 ("pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"
455 "pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"))
456 (const :tag
"3 runs of pdfgroff"
457 ("pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"
458 "pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"
459 "pic %f | tbl | eqn | groff -mm | ps2pdf - > %b.pdf"))
462 (defcustom org-e-groff-logfiles-extensions
463 '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
464 "The list of file extensions to consider as Groff logfiles."
465 :group
'org-export-e-groff
466 :type
'(repeat (string :tag
"Extension")))
468 (defcustom org-e-groff-remove-logfiles t
469 "Non-nil means remove the logfiles produced by PDF production.
470 These are the .aux, .log, .out, and .toc files."
471 :group
'org-export-e-groff
474 (defcustom org-e-groff-organization
"Org User"
475 "Name of the organization used to populate the .AF command."
476 :group
'org-export-e-groff
479 (defcustom org-e-groff-raster-to-ps nil
480 "Command used to convert raster to EPS. Nil for no conversion. Make sure that
481 `org-e-groff-inline-image-rules' is adjusted accordingly if not conversion is being
482 done. In this case, remove the entries for jpg and png in the file and fuzzy lists."
483 :group
'org-export-e-groff
485 (repeat :tag
"Shell Command Sequence" (string :tag
"Shell Command"))
486 (const :tag
"sam2p" "a=%s;b=%s;sam2p ${a} ${b} ;grep -v BeginData ${b} > b_${b};mv b_${b} ${b}" )
487 (const :tag
"NetPNM" "a=%s;b=%s;pngtopnm ${a} | pnmtops -noturn > ${b}" )
488 (const :tag
"None" nil
)))
490 (defvar org-e-groff-registered-references nil
)
491 (defvar org-e-groff-special-content nil
)
495 ;;; Internal Functions
497 (defun org-e-groff--caption/label-string
(element info
)
498 "Return caption and label Groff string for ELEMENT.
500 INFO is a plist holding contextual information. If there's no
501 caption nor label, return the empty string.
503 For non-floats, see `org-e-groff--wrap-label'."
504 (let ((main (org-export-get-caption element
))
505 (short (org-export-get-caption element t
))
506 (label (org-element-property :name element
)))
507 (cond ((and (not main
) (not label
)) "")
508 ((not main
) (format "\\fI%s\\fP" label
))
509 ;; Option caption format with short name.
510 (short (format "%s\n.br\n - %s\n"
511 (org-export-data short info
)
512 (org-export-data main info
)))
513 ;; Standard caption format.
514 (t (format "\\fR%s\\fP" (org-export-data main info
))))))
516 (defun org-e-groff--wrap-label (element output
)
517 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
518 This function shouldn't be used for floats. See
519 `org-e-groff--caption/label-string'."
520 (let ((label (org-element-property :name element
)))
521 (if (or (not output
) (not label
) (string= output
"") (string= label
""))
523 (concat (format "%s\n.br\n" label
) output
))))
525 (defun org-e-groff--text-markup (text markup
)
526 "Format TEXT depending on MARKUP text markup.
527 See `org-e-groff-text-markup-alist' for details."
528 (let ((fmt (cdr (assq markup org-e-groff-text-markup-alist
))))
530 ;; No format string: Return raw text.
532 ((string= "protectedtexttt" fmt
)
534 (trans '(("\\" .
"\\")))
537 (while (string-match "[\\{}$%&_#~^]" text
)
538 (setq char
(match-string 0 text
))
539 (if (> (match-beginning 0) 0)
540 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
541 (setq text
(substring text
(1+ (match-beginning 0))))
542 (setq char
(or (cdr (assoc char trans
)) (concat "\\" char
))
543 rtn
(concat rtn char
)))
544 (setq text
(concat rtn text
))
545 (format "\\fC%s\\fP" text
)))
546 ;; Else use format string.
547 (t (format fmt text
)))))
550 (defun org-e-groff--get-tagged-content (tag info
)
551 (cdr (assoc tag org-e-groff-special-content
)))
553 (defun org-e-groff--mt-head (title contents attr info
)
556 ;; 1. Insert Organization
557 (let ((firm-option (plist-get attr
:firm
)))
559 ((stringp firm-option
)
560 (format ".AF \"%s\" \n" firm-option
))
561 (t (format ".AF \"%s\" \n" (or org-e-groff-organization
"")))))
564 (let ((subtitle1 (plist-get attr
:subtitle1
))
565 (subtitle2 (plist-get attr
:subtitle2
)))
569 (format ".TL \"%s\" \"%s\" \n%s\n"
571 (or subtitle2
"") " "))
573 ((not (or subtitle1 subtitle2
))
577 (format ".TL \"%s\" \"%s \" \n%s\n"
579 (or subtitle2
"") title
))))
582 ;; In Groff, .AU *MUST* be placed after .TL
583 ;; If From, populate with data from From else
585 (let ((author (and (plist-get info
:with-author
)
586 (let ((auth (plist-get info
:author
)))
587 (and auth
(org-export-data auth info
)))))
588 (email (and (plist-get info
:with-email
)
589 (org-export-data (plist-get info
:email
) info
)))
590 (from-data (org-e-groff--get-tagged-content "FROM" info
))
592 (to-data (org-e-groff--get-tagged-content "TO" info
)))
595 ((and author from-data
)
599 (format " \"%s\" " from-line
))
602 (replace-regexp-in-string "\\.P\n" "" from-data
)) "\n") "")))
605 (format ".AU \"%s\" " author
) au-line
"\n")))
607 ((and author email
(not (string= "" email
)))
608 (format ".AU \"%s\" \"%s\"\n" author email
))
610 (author (format ".AU \"%s\"\n" author
))
615 ;; 4. Author Title, if present
616 (let ((at-item (plist-get attr
:author-title
)))
617 (if (and at-item
(stringp at-item
))
618 (format ".AT \"%s\" \n" at-item
)
622 (when (plist-get info
:with-date
)
623 (let ((date (org-export-data (plist-get info
:date
) info
)))
624 (and date
(format ".ND \"%s\"\n" date
))))
627 ;; If Abstract, then Populate Abstract
630 (let ((abstract-data (org-e-groff--get-tagged-content "ABSTRACT" info
))
631 (to-data (org-e-groff--get-tagged-content "TO" info
)))
634 (format ".AS\n%s\n.AE\n" abstract-data
))
636 (format ".AS\n%s\n.AE\n" to-data
))))))
638 (defun org-e-groff--letter-head (title contents attr info
)
639 (let ((author (and (plist-get info
:with-author
)
640 (let ((auth (plist-get info
:author
)))
641 (and auth
(org-export-data auth info
)))))
642 (email (and (plist-get info
:with-email
)
643 (org-export-data (plist-get info
:email
) info
)))
644 (from-data (org-e-groff--get-tagged-content "FROM" info
))
645 (at-item (plist-get attr
:author-title
))
646 (to-data (org-e-groff--get-tagged-content "TO" info
)))
649 ;; If FROM then get data from FROM
652 (replace-regexp-in-string "\\.P\n" "" from-data
))
657 (replace-regexp-in-string "\\.P\n" "" to-data
))
663 (format ".WA \"%s\" \"%s\" \n%s\n.WE\n" author
(or at-item
"") from-data
))
664 ((and author email
(not (string= "" email
)))
665 (format ".WA \"%s\"\n \"%s\"\n.WE\n" author email
))
666 (author (format ".WA \"%s\"\n.WE\n" author
))
667 (t ".WA \"\" \n.WE\n"))
669 ;; If TO then get data from TO
672 (format ".IA \n%s\n.IE\n" to-data
)))))
677 (defun org-e-groff-template (contents info
)
678 "Return complete document string after Groff conversion.
679 CONTENTS is the transcoded contents string. INFO is a plist
680 holding export options."
681 (let* ((title (org-export-data (plist-get info
:title
) info
))
686 (list (plist-get info
:groff-class-options
))
688 (class (plist-get info
:groff-class
))
689 (class-options (plist-get info
:groff-class-options
))
690 (classes (assoc class org-e-groff-classes
))
691 (classes-options (car (last classes
)))
692 (heading-option (plist-get classes-options
:heading
))
693 (type-option (plist-get classes-options
:type
))
694 (last-option (plist-get classes-options
:last-section
))
695 (hyphenate (plist-get attr
:hyphenate
))
696 (justify-right (plist-get attr
:justify-right
))
698 (document-class-string
700 (org-element-normalize-string
701 (let* ((header (nth 1 (assoc class org-e-groff-classes
)))
702 (document-class-item (if (stringp header
) header
"")))
703 document-class-item
)))))
722 ((string= type-option
"custom") "")
724 ((and (stringp document-class-string
)
725 (string= type-option
"cover"))
728 (format ".COVER %s\n" document-class-string
)
729 (org-e-groff--mt-head title contents attr info
)
732 ((string= type-option
"memo")
734 (org-e-groff--mt-head title contents attr info
)
735 document-class-string
))
736 ((string= type-option
"letter")
738 (org-e-groff--letter-head title contents attr info
)
739 (let ((sa-item (plist-get attr
:salutation
))
740 (cn-item (plist-get attr
:confidential
))
741 (sj-item (plist-get attr
:subject
))
742 (rn-item (plist-get attr
:reference
))
743 (at-item (plist-get attr
:attention
)))
747 (if (stringp sa-item
)
748 (format ".LO SA \"%s\" \n" sa-item
)
752 (if (stringp cn-item
)
753 (format ".LO CN \"%s\"\n" cn-item
)
756 (when (and at-item
(stringp at-item
))
757 (format ".LO AT \"%s\" \n" at-item
))
758 (when (and title rn-item
)
759 (format ".LO RN \"%s\"\n" title
))
761 (when (and sj-item
(stringp sj-item
))
762 (format ".LO SJ \"%s\" \n" sj-item
))
765 ".LT " document-class-string
"\n"))))
772 ((string= last-option
"toc")
774 ((string= last-option
"sign")
775 (let ((fc-item (plist-get attr
:closing
)))
776 (concat (if (stringp fc-item
)
777 (format ".FC \"%s\" \n" fc-item
)
785 (when (string= (car item
) "NS")
786 (replace-regexp-in-string
787 "\\.P\n" "" (cdr item
))))
788 (reverse org-e-groff-special-content
) "\n")))))
792 ;;; Transcode Functions
796 ;; Babel Calls are ignored.
801 (defun org-e-groff-bold (bold contents info
)
802 "Transcode BOLD from Org to Groff.
803 CONTENTS is the text with bold markup. INFO is a plist holding
804 contextual information."
805 (org-e-groff--text-markup contents
'bold
))
809 (defun org-e-groff-center-block (center-block contents info
)
810 "Transcode a CENTER-BLOCK element from Org to Groff.
811 CONTENTS holds the contents of the center block. INFO is a plist
812 holding contextual information."
813 (org-e-groff--wrap-label
815 (format ".DS C \n%s\n.DE" contents
)))
819 (defun org-e-groff-clock (clock contents info
)
820 "Transcode a CLOCK element from Org to Groff.
821 CONTENTS is nil. INFO is a plist holding contextual
824 (format "\\fB%s\\fP " org-clock-string
)
825 (format org-e-groff-inactive-timestamp-format
826 (concat (org-translate-time
827 (org-element-property :raw-value
828 (org-element-property :value clock
)))
829 (let ((time (org-element-property :duration clock
)))
830 (and time
(format " (%s)" time
)))))))
834 (defun org-e-groff-code (code contents info
)
835 "Transcode a CODE object from Org to Groff.
836 CONTENTS is nil. INFO is a plist used as a communication
838 (org-e-groff--text-markup (org-element-property :value code
) 'code
))
840 ;;; Comments and Comment Blocks are ignored.
844 (defun org-e-groff-drawer (drawer contents info
)
845 "Transcode a DRAWER element from Org to Groff.
846 CONTENTS holds the contents of the block. INFO is a plist
847 holding contextual information."
848 (let* ((name (org-element-property :drawer-name drawer
))
849 (output (if (functionp org-e-groff-format-drawer-function
)
850 (funcall org-e-groff-format-drawer-function
852 ;; If there's no user defined function: simply
853 ;; display contents of the drawer.
855 (org-e-groff--wrap-label drawer output
)))
859 (defun org-e-groff-dynamic-block (dynamic-block contents info
)
860 "Transcode a DYNAMIC-BLOCK element from Org to Groff.
861 CONTENTS holds the contents of the block. INFO is a plist
862 holding contextual information. See `org-export-data'."
863 (org-e-groff--wrap-label dynamic-block contents
))
867 (defun org-e-groff-entity (entity contents info
)
868 "Transcode an ENTITY object from Org to Groff.
869 CONTENTS are the definition itself. INFO is a plist holding
870 contextual information."
871 (org-element-property :utf-8 entity
))
875 (defun org-e-groff-example-block (example-block contents info
)
876 "Transcode an EXAMPLE-BLOCK element from Org to Groff.
877 CONTENTS is nil. INFO is a plist holding contextual
879 (org-e-groff--wrap-label
881 (format ".DS L\n%s\n.DE"
882 (org-export-format-code-default example-block info
))))
886 (defun org-e-groff-export-block (export-block contents info
)
887 "Transcode a EXPORT-BLOCK element from Org to Groff.
888 CONTENTS is nil. INFO is a plist holding contextual information."
889 (when (string= (org-element-property :type export-block
) "GROFF")
890 (org-remove-indentation (org-element-property :value export-block
))))
894 (defun org-e-groff-export-snippet (export-snippet contents info
)
895 "Transcode a EXPORT-SNIPPET object from Org to Groff.
896 CONTENTS is nil. INFO is a plist holding contextual information."
897 (when (eq (org-export-snippet-backend export-snippet
) 'e-groff
)
898 (org-element-property :value export-snippet
)))
902 (defun org-e-groff-fixed-width (fixed-width contents info
)
903 "Transcode a FIXED-WIDTH element from Org to Groff.
904 CONTENTS is nil. INFO is a plist holding contextual information."
905 (org-e-groff--wrap-label
907 (format "\\fC\n%s\\fP"
908 (org-remove-indentation
909 (org-element-property :value fixed-width
)))))
911 ;;; Footnote Definition
913 ;; Footnote Definitions are ignored.
915 ;; Footnotes are handled automatically in GROFF. Although manual
916 ;; references can be added, not really required.
918 (defun org-e-groff-footnote-reference (footnote-reference contents info
)
919 ;; Changing from info to footnote-reference
920 (let* ((raw (org-export-get-footnote-definition footnote-reference info
))
921 (n (org-export-get-footnote-number footnote-reference info
))
922 (data (org-trim (org-export-data raw info
)))
923 (ref-id (plist-get (nth 1 footnote-reference
) :label
)))
925 (if (string-match "fn:rl" ref-id
)
926 (if (member ref-id org-e-groff-registered-references
)
927 (format "\\*[%s]" ref-id
)
929 (push ref-id org-e-groff-registered-references
)
930 (format "\\*(Rf\n.RS \"%s\" \n%s\n.RF\n" ref-id data
)))
931 ;; else it is a footnote
932 (format "\\u\\s-2%s\\d\\s+2\n.FS %s\n%s\n.FE\n" n n data
))))
936 (defun org-e-groff-headline (headline contents info
)
937 "Transcode an HEADLINE element from Org to Groff.
938 CONTENTS holds the contents of the headline. INFO is a plist
939 holding contextual information."
940 (let* ((class (plist-get info
:groff-class
))
941 (level (org-export-get-relative-level headline info
))
942 (numberedp (org-export-numbered-headline-p headline info
))
943 ;; Section formatting will set two placeholders: one for the
944 ;; title and the other for the contents.
945 (classes (assoc class org-e-groff-classes
))
946 (classes-options (car (last classes
)))
947 (heading-option (plist-get classes-options
:heading
))
951 ((and (symbolp heading-option
)
952 (fboundp heading-option
))
953 (funcall heading-option level numberedp
))
956 (concat ".H " (number-to-string level
) " \"%s\"\n%s")
957 ".HU \"%s\"\n%s")))))
958 ;; End of section-fmt
959 (text (org-export-data (org-element-property :title headline
) info
))
961 (and (plist-get info
:with-todo-keywords
)
962 (let ((todo (org-element-property :todo-keyword headline
)))
963 (and todo
(org-export-data todo info
)))))
964 (todo-type (and todo
(org-element-property :todo-type headline
)))
965 (tags (and (plist-get info
:with-tags
)
966 (org-export-get-tags headline info
)))
967 (priority (and (plist-get info
:with-priority
)
968 (org-element-property :priority headline
)))
969 ;; Create the headline text along with a no-tag version. The
970 ;; latter is required to remove tags from table of contents.
971 (full-text (if (functionp org-e-groff-format-headline-function
)
972 ;; User-defined formatting function.
973 (funcall org-e-groff-format-headline-function
974 todo todo-type priority text tags
)
975 ;; Default formatting.
978 (format "\\fB%s\\fP " todo
))
979 (when priority
(format " [\\#%c] " priority
))
982 (format " \\fC:%s:\\fP "
983 (mapconcat 'identity tags
":"))))))
985 (if (functionp org-e-groff-format-headline-function
)
986 ;; User-defined formatting function.
987 (funcall org-e-groff-format-headline-function
988 todo todo-type priority text nil
)
989 ;; Default formatting.
991 (when todo
(format "\\fB%s\\fP " todo
))
992 (when priority
(format " [\\#%c] " priority
))
994 ;; Associate some \label to the headline for internal links.
996 ;; (format "\\label{sec-%s}\n"
997 ;; (mapconcat 'number-to-string
998 ;; (org-export-get-headline-number headline info)
1002 (make-string (org-element-property :pre-blank headline
) 10)))
1005 ;; Case 1: Special Tag
1006 ((member (car tags
) org-e-groff-special-tags
)
1008 ((string= (car tags
) "BODY") contents
)
1010 ((string= (car tags
) "NS")
1012 (push (cons (car tags
)
1013 (format ".NS \"%s\" 1 \n%s"
1014 (car (org-element-property :title headline
))
1016 org-e-groff-special-content
) nil
))
1020 (push (cons (car tags
) contents
) org-e-groff-special-content
)
1023 ;; Case 2: This is a footnote section: ignore it.
1024 ((org-element-property :footnote-section-p headline
) nil
)
1026 ;; Case 3: This is a deep sub-tree: export it as a list item.
1027 ;; Also export as items headlines for which no section
1028 ;; format has been found.
1029 ((or (not section-fmt
) (org-export-low-level-p headline info
))
1030 ;; Build the real contents of the sub-tree.
1031 (let ((low-level-body
1033 ;; If the headline is the first sibling, start a list.
1034 (when (org-export-first-sibling-p headline info
)
1035 (format "%s\n" (if numberedp
".AL 1\n" ".DL \n")))
1037 ".LI\n" full-text
"\n" headline-label pre-blanks contents
)))
1038 ;; If headline is not the last sibling simply return
1039 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
1041 (if (not (org-export-last-sibling-p headline info
)) low-level-body
1042 (replace-regexp-in-string
1047 ;; Case 4. Standard headline. Export it as a section.
1049 (format section-fmt full-text
1050 (concat headline-label pre-blanks contents
))))))
1055 ;;; Inline Babel Call
1057 ;; Inline Babel Calls are ignored.
1059 ;;; Inline Src Block
1061 (defun org-e-groff-inline-src-block (inline-src-block contents info
)
1062 "Transcode an INLINE-SRC-BLOCK element from Org to Groff.
1063 CONTENTS holds the contents of the item. INFO is a plist holding
1064 contextual information."
1065 (let* ((code (org-element-property :value inline-src-block
)))
1067 (org-e-groff-source-highlight
1068 (let* ((tmpdir (if (featurep 'xemacs
)
1070 temporary-file-directory
))
1071 (in-file (make-temp-name
1072 (expand-file-name "srchilite" tmpdir
)))
1073 (out-file (make-temp-name
1074 (expand-file-name "reshilite" tmpdir
)))
1075 (org-lang (org-element-property :language inline-src-block
))
1076 (lst-lang (cadr (assq (intern org-lang
)
1077 org-e-groff-source-highlight-langs
)))
1079 (cmd (concat (expand-file-name "source-highlight")
1081 " -f groff_mm_color "
1085 (let ((code-block ""))
1086 (with-temp-file in-file
(insert code
))
1088 (setq code-block
(org-file-contents out-file
))
1089 (delete-file in-file
)
1090 (delete-file out-file
)
1092 (format ".DS I\n\\fC\\m[black]%s\\m[]\\fP\n.DE\n"
1095 ;; Do not use a special package: transcode it verbatim.
1097 (concat ".DS I\n" "\\fC" code
"\\fP\n.DE\n")))))
1101 (defun org-e-groff-inlinetask (inlinetask contents info
)
1102 "Transcode an INLINETASK element from Org to Groff.
1103 CONTENTS holds the contents of the block. INFO is a plist
1104 holding contextual information."
1105 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
1106 (todo (and (plist-get info
:with-todo-keywords
)
1107 (let ((todo (org-element-property :todo-keyword inlinetask
)))
1108 (and todo
(org-export-data todo info
)))))
1109 (todo-type (org-element-property :todo-type inlinetask
))
1110 (tags (and (plist-get info
:with-tags
)
1111 (org-export-get-tags inlinetask info
)))
1112 (priority (and (plist-get info
:with-priority
)
1113 (org-element-property :priority inlinetask
))))
1114 ;; If `org-e-groff-format-inlinetask-function' is provided, call it
1115 ;; with appropriate arguments.
1116 (if (functionp org-e-groff-format-inlinetask-function
)
1117 (funcall org-e-groff-format-inlinetask-function
1118 todo todo-type priority title tags contents
)
1119 ;; Otherwise, use a default template.
1120 (org-e-groff--wrap-label
1124 (when todo
(format "\\fB%s\\fP " todo
))
1125 (when priority
(format " [\\#%c] " priority
))
1127 (when tags
(format " \\fC:%s:\\fP "
1128 (mapconcat 'identity tags
":"))))))
1129 (format (concat "\n.DS I\n"
1134 full-title contents
))))))
1138 (defun org-e-groff-italic (italic contents info
)
1139 "Transcode ITALIC from Org to Groff.
1140 CONTENTS is the text with italic markup. INFO is a plist holding
1141 contextual information."
1142 (org-e-groff--text-markup contents
'italic
))
1146 (defun org-e-groff-item (item contents info
)
1147 "Transcode an ITEM element from Org to Groff.
1148 CONTENTS holds the contents of the item. INFO is a plist holding
1149 contextual information."
1150 (let* ((bullet (org-element-property :bullet item
))
1151 (type (org-element-property
1152 :type
(org-element-property :parent item
)))
1153 (checkbox (case (org-element-property :checkbox item
)
1154 (on "\\o'\\(sq\\(mu'")
1156 (trans "\\o'\\(sq\\(mi'")))
1157 (tag (let ((tag (org-element-property :tag item
)))
1158 ;; Check-boxes must belong to the tag.
1159 (and tag
(format "%s"
1161 (org-export-data tag info
)))))))
1165 (concat ".LI ""\"" (or tag
(concat "\\ " checkbox
)) "\""
1167 (org-trim (or contents
" "))))
1171 (org-trim (or contents
" "))))
1173 (let* ((bullet (org-trim bullet
))
1174 (marker (cond ((string= "-" bullet
) "\\(em")
1175 ((string= "*" bullet
) "\\(bu")
1177 (concat ".LI " marker
"\n"
1178 (org-trim (or contents
" "))))))))
1182 (defun org-e-groff-keyword (keyword contents info
)
1183 "Transcode a KEYWORD element from Org to Groff.
1184 CONTENTS is nil. INFO is a plist holding contextual information."
1185 (let ((key (org-element-property :key keyword
))
1186 (value (org-element-property :value keyword
)))
1188 ((string= key
"GROFF") value
)
1191 ;;; LaTeX Environment
1193 (defun org-e-groff-latex-environment (latex-environment contents info
)
1194 "Transcode a LATEX-ENVIRONMENT element from Org to Groff.
1195 CONTENTS is nil. INFO is a plist holding contextual information."
1196 (let ((label (org-element-property :name latex-environment
))
1197 (value (org-remove-indentation
1198 (org-element-property :value latex-environment
))))
1199 (if (not (org-string-nw-p label
)) value
1200 ;; Environment is labelled: label must be within the environment
1201 ;; (otherwise, a reference pointing to that element will count
1202 ;; the section instead).
1205 (goto-char (point-min))
1207 (insert (format "%s\n" label
))
1212 (defun org-e-groff-latex-fragment (latex-fragment contents info
)
1213 "Transcode a LATEX-FRAGMENT object from Org to Groff.
1214 CONTENTS is nil. INFO is a plist holding contextual information."
1215 (org-element-property :value latex-fragment
))
1219 (defun org-e-groff-line-break (line-break contents info
)
1220 "Transcode a LINE-BREAK object from Org to Groff.
1221 CONTENTS is nil. INFO is a plist holding contextual information."
1225 ;; Inline images just place a call to .PSPIC or .PS/.PE
1226 ;; and load the graph.
1228 (defun org-e-groff-link--inline-image (link info
)
1229 "Return Groff code for an inline image.
1230 LINK is the link pointing to the inline image. INFO is a plist
1231 used as a communication channel."
1232 (let* ((parent (org-export-get-parent-element link
))
1233 (path (let ((raw-path (org-element-property :path link
)))
1234 (if (not (file-name-absolute-p raw-path
)) raw-path
1235 (expand-file-name raw-path
))))
1236 (attr (org-export-read-attribute :attr_groff link
))
1238 (case (plist-get attr
:position
)
1243 (width (or (plist-get attr
:width
) ""))
1244 (height (or (plist-get attr
:height
) ""))
1245 (caption (and (not (plist-get attr
:disable-caption
))
1246 (org-e-groff--caption/label-string parent info
))))
1247 ;; Now clear ATTR from any special keyword and set a default value
1248 ;; if nothing is left. Return proper string.
1251 ((and org-e-groff-raster-to-ps
1252 (or (string-match ".\.png$" path
)
1253 (string-match ".\.jpg$" path
)))
1254 (let ((eps-path (concat path
".eps")))
1255 (shell-command (format org-e-groff-raster-to-ps path eps-path
))
1256 (format "\n.DS L F\n.PSPIC %s \"%s\" %s %s\n.DE "
1257 placement eps-path width height
)))
1258 ((string-match ".\.pic$" path
)
1259 (format "\n.PS\ncopy \"%s\"\n.PE" path
))
1260 (t (format "\n.DS L F\n.PSPIC %s \"%s\" %s %s\n.DE "
1261 placement path width height
)))
1262 (and caption
(format "\n.FG \"%s\"" caption
)))))
1264 (defun org-e-groff-link (link desc info
)
1265 "Transcode a LINK object from Org to Groff.
1267 DESC is the description part of the link, or the empty string.
1268 INFO is a plist holding contextual information. See
1271 (let* ((type (org-element-property :type link
))
1272 (raw-path (org-element-property :path link
))
1273 ;; Ensure DESC really exists, or set it to nil.
1274 (desc (and (not (string= desc
"")) desc
))
1275 (imagep (org-export-inline-image-p
1276 link org-e-groff-inline-image-rules
))
1278 ((member type
'("http" "https" "ftp" "mailto"))
1279 (concat type
":" raw-path
))
1280 ((string= type
"file")
1281 (when (string-match "\\(.+\\)::.+" raw-path
)
1282 (setq raw-path
(match-string 1 raw-path
)))
1283 (if (file-name-absolute-p raw-path
)
1284 (concat "file://" (expand-file-name raw-path
))
1285 (concat "file://" raw-path
)))
1290 (imagep (org-e-groff-link--inline-image link info
))
1291 ;; import groff files
1292 ((and (string= type
"file")
1293 (string-match ".\.groff$" raw-path
))
1294 (concat ".so " raw-path
"\n"))
1295 ;; Radio link: transcode target's contents and use them as link's
1297 ((string= type
"radio")
1298 (let ((destination (org-export-resolve-radio-link link info
)))
1300 (format "\\fI [%s] \\fP"
1301 (org-export-solidify-link-text path
)))))
1303 ;; Links pointing to an headline: find destination and build
1304 ;; appropriate referencing command.
1305 ((member type
'("custom-id" "fuzzy" "id"))
1306 (let ((destination (if (string= type
"fuzzy")
1307 (org-export-resolve-fuzzy-link link info
)
1308 (org-export-resolve-id-link link info
))))
1309 (case (org-element-type destination
)
1310 ;; Id link points to an external file.
1312 (if desc
(format "%s \\fBat\\fP \\fIfile://%s\\fP" desc destination
)
1313 (format "\\fI file://%s \\fP" destination
)))
1314 ;; Fuzzy link points nowhere.
1316 (format org-e-groff-link-with-unknown-path-format
1319 (org-element-property :raw-link link
) info
))))
1320 ;; Fuzzy link points to an invisible target.
1322 ;; LINK points to an headline. If headlines are numbered
1323 ;; and the link has no description, display headline's
1324 ;; number. Otherwise, display description or headline's
1328 (if (and (plist-get info
:section-numbers
) (not desc
))
1329 (format "\\fI%s\\fP" label
)
1330 (format "\\fI%s\\fP"
1333 (org-element-property :title destination
) info
))))))
1334 ;; Fuzzy link points to a target. Do as above.
1336 (let ((path (org-export-solidify-link-text path
)))
1337 (if (not desc
) (format "\\fI%s\\fP" path
)
1338 (format "%s \\fBat\\fP \\fI%s\\fP" desc path
)))))))
1339 ;; External link with a description part.
1340 ((and path desc
) (format "%s \\fBat\\fP \\fI%s\\fP" path desc
))
1341 ;; External link without a description part.
1342 (path (format "\\fI%s\\fP" path
))
1343 ;; No path, only description. Try to do something useful.
1344 (t (format org-e-groff-link-with-unknown-path-format desc
)))))
1348 (defun org-e-groff-paragraph (paragraph contents info
)
1349 "Transcode a PARAGRAPH element from Org to Groff.
1350 CONTENTS is the contents of the paragraph, as a string. INFO is
1351 the plist used as a communication channel."
1352 (let ((parent (plist-get (nth 1 paragraph
) :parent
)))
1354 (let* ((parent-type (car parent
))
1355 (fixed-paragraph "")
1356 (class (plist-get info
:groff-class
))
1357 (class-options (plist-get info
:groff-class-options
))
1358 (classes (assoc class org-e-groff-classes
))
1359 (classes-options (car (last classes
)))
1360 (paragraph-option (plist-get classes-options
:paragraph
)))
1362 ((and (symbolp paragraph-option
)
1363 (fboundp paragraph-option
))
1364 (funcall paragraph-option parent-type parent contents
))
1365 ((and (eq parent-type
'item
)
1366 (plist-get (nth 1 parent
) :bullet
))
1367 (setq fixed-paragraph
(concat "" contents
)))
1368 ((eq parent-type
'section
)
1369 (setq fixed-paragraph
(concat ".P\n" contents
)))
1370 ((eq parent-type
'footnote-definition
)
1371 (setq fixed-paragraph
(concat "" contents
)))
1372 (t (setq fixed-paragraph
(concat "" contents
))))
1377 (defun org-e-groff-plain-list (plain-list contents info
)
1378 "Transcode a PLAIN-LIST element from Org to Groff.
1379 CONTENTS is the contents of the list. INFO is a plist holding
1380 contextual information."
1381 (let* ((type (org-element-property :type plain-list
))
1382 (attr (mapconcat #'identity
1383 (org-element-property :attr_groff plain-list
)
1386 ((eq type
'ordered
) ".AL")
1387 ((eq type
'unordered
) ".BL")
1388 ((eq type
'descriptive
) ".VL 2.0i"))))
1389 (org-e-groff--wrap-label
1391 (format "%s\n%s\n.LE" groff-type contents
))))
1395 (defun org-e-groff-plain-text (text info
)
1396 "Transcode a TEXT string from Org to Groff.
1397 TEXT is the string to transcode. INFO is a plist holding
1398 contextual information."
1399 (let ((output text
))
1400 ;; Protect various characters.
1401 (setq output
(replace-regexp-in-string
1402 "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
1403 "$\\" output nil t
1))
1404 ;; Activate smart quotes. Be sure to provide original TEXT string
1405 ;; since OUTPUT may have been modified.
1406 (when (plist-get info
:with-smart-quotes
)
1407 (setq output
(org-export-activate-smart-quotes output
:utf-8 info text
)))
1408 ;; Handle Special Characters
1409 (if org-e-groff-special-char
1410 (dolist (special-char-list org-e-groff-special-char
)
1412 (replace-regexp-in-string (car special-char-list
)
1413 (cdr special-char-list
) output
))))
1414 ;; Handle break preservation if required.
1415 (when (plist-get info
:preserve-breaks
)
1416 (setq output
(replace-regexp-in-string
1417 "\\(\\\\\\\\\\)?[ \t]*\n" ".br\n" output
)))
1423 (defun org-e-groff-planning (planning contents info
)
1424 "Transcode a PLANNING element from Org to Groff.
1425 CONTENTS is nil. INFO is a plist holding contextual
1432 (let ((closed (org-element-property :closed planning
)))
1435 (format "\\fR %s \\fP" org-closed-string
)
1436 (format org-e-groff-inactive-timestamp-format
1438 (org-element-property :raw-value closed
))))))
1439 (let ((deadline (org-element-property :deadline planning
)))
1442 (format "\\fB %s \\fP" org-deadline-string
)
1443 (format org-e-groff-active-timestamp-format
1445 (org-element-property :raw-value deadline
))))))
1446 (let ((scheduled (org-element-property :scheduled planning
)))
1449 (format "\\fR %s \\fP" org-scheduled-string
)
1450 (format org-e-groff-active-timestamp-format
1452 (org-element-property :raw-value scheduled
))))))))
1458 (defun org-e-groff-property-drawer (property-drawer contents info
)
1459 "Transcode a PROPERTY-DRAWER element from Org to Groff.
1460 CONTENTS is nil. INFO is a plist holding contextual
1462 ;; The property drawer isn't exported but we want separating blank
1463 ;; lines nonetheless.
1468 (defun org-e-groff-quote-block (quote-block contents info
)
1469 "Transcode a QUOTE-BLOCK element from Org to Groff.
1470 CONTENTS holds the contents of the block. INFO is a plist
1471 holding contextual information."
1472 (org-e-groff--wrap-label
1474 (format ".DS I\n.I\n%s\n.R\n.DE" contents
)))
1478 (defun org-e-groff-quote-section (quote-section contents info
)
1479 "Transcode a QUOTE-SECTION element from Org to Groff.
1480 CONTENTS is nil. INFO is a plist holding contextual information."
1481 (let ((value (org-remove-indentation
1482 (org-element-property :value quote-section
))))
1483 (when value
(format ".DS L\n\\fI%s\\fP\n.DE\n" value
))))
1487 (defun org-e-groff-radio-target (radio-target text info
)
1488 "Transcode a RADIO-TARGET object from Org to Groff.
1489 TEXT is the text of the target. INFO is a plist holding
1490 contextual information."
1492 (org-export-solidify-link-text
1493 (org-element-property :value radio-target
))
1498 (defun org-e-groff-section (section contents info
)
1499 "Transcode a SECTION element from Org to Groff.
1500 CONTENTS holds the contents of the section. INFO is a plist
1501 holding contextual information."
1506 (defun org-e-groff-special-block (special-block contents info
)
1507 "Transcode a SPECIAL-BLOCK element from Org to Groff.
1508 CONTENTS holds the contents of the block. INFO is a plist
1509 holding contextual information."
1510 (let ((type (downcase (org-element-property :type special-block
))))
1511 (org-e-groff--wrap-label
1513 (format "%s\n" contents
))))
1517 (defun org-e-groff-src-block (src-block contents info
)
1518 "Transcode a SRC-BLOCK element from Org to Groff.
1519 CONTENTS holds the contents of the item. INFO is a plist holding
1520 contextual information."
1521 (let* ((lang (org-element-property :language src-block
))
1522 (label (org-element-property :name src-block
))
1523 (code (org-element-property :value src-block
))
1524 (custom-env (and lang
1525 (cadr (assq (intern lang
)
1526 org-e-groff-custom-lang-environments
))))
1527 (num-start (case (org-element-property :number-lines src-block
)
1528 (continued (org-export-get-loc src-block info
))
1530 (retain-labels (org-element-property :retain-labels src-block
))
1531 (caption (and (not (org-export-read-attribute
1532 :attr_groff src-block
:disable-caption
))
1533 (org-e-groff--caption/label-string src-block info
))))
1536 ;; Case 1. No source fontification.
1537 ((not org-e-groff-source-highlight
)
1539 (format ".DS I\n\\fC%s\\fP\n.DE\n"
1540 (org-export-format-code-default src-block info
))
1541 (and caption
(format ".EX \"%s\" " caption
))))
1543 ;; Case 2. Source fontification.
1544 (org-e-groff-source-highlight
1545 (let* ((tmpdir (if (featurep 'xemacs
)
1547 temporary-file-directory
))
1548 (in-file (make-temp-name
1549 (expand-file-name "srchilite" tmpdir
)))
1550 (out-file (make-temp-name
1551 (expand-file-name "reshilite" tmpdir
)))
1553 (org-lang (org-element-property :language src-block
))
1554 (lst-lang (cadr (assq (intern org-lang
)
1555 org-e-groff-source-highlight-langs
)))
1557 (cmd (concat "source-highlight"
1559 " -f groff_mm_color "
1565 (let ((code-block ""))
1566 (with-temp-file in-file
(insert code
))
1568 (setq code-block
(org-file-contents out-file
))
1569 (delete-file in-file
)
1570 (delete-file out-file
)
1571 (format "%s\n" code-block
))
1572 (format ".DS I\n\\fC\\m[black]%s\\m[]\\fP\n.DE\n"
1574 (and caption
(format ".EX \"%s\" " caption
))))))))
1577 ;;; Statistics Cookie
1579 (defun org-e-groff-statistics-cookie (statistics-cookie contents info
)
1580 "Transcode a STATISTICS-COOKIE object from Org to Groff.
1581 CONTENTS is nil. INFO is a plist holding contextual information."
1582 (org-element-property :value statistics-cookie
))
1587 (defun org-e-groff-strike-through (strike-through contents info
)
1588 "Transcode STRIKE-THROUGH from Org to Groff.
1589 CONTENTS is the text with strike-through markup. INFO is a plist
1590 holding contextual information."
1591 (org-e-groff--text-markup contents
'strike-through
))
1595 (defun org-e-groff-subscript (subscript contents info
)
1596 "Transcode a SUBSCRIPT object from Org to Groff.
1597 CONTENTS is the contents of the object. INFO is a plist holding
1598 contextual information."
1599 (format "\\d\\s-2%s\\s+2\\u" contents
))
1601 ;;; Superscript "^_%s$
1603 (defun org-e-groff-superscript (superscript contents info
)
1604 "Transcode a SUPERSCRIPT object from Org to Groff.
1605 CONTENTS is the contents of the object. INFO is a plist holding
1606 contextual information."
1607 (format "\\u\\s-2%s\\s+2\\d" contents
))
1612 ;; `org-e-groff-table' is the entry point for table transcoding. It
1613 ;; takes care of tables with a "verbatim" attribute. Otherwise, it
1614 ;; delegates the job to `org-e-groff-table--org-table' function,
1615 ;; depending of the type of the table.
1617 ;; `org-e-groff-table--align-string' is a subroutine used to build
1618 ;; alignment string for Org tables.
1620 (defun org-e-groff-table (table contents info
)
1621 "Transcode a TABLE element from Org to Groff.
1622 CONTENTS is the contents of the table. INFO is a plist holding
1623 contextual information."
1625 ;; Case 1: verbatim table.
1626 ((or org-e-groff-tables-verbatim
1627 (let ((attr (read (format "(%s)"
1630 (org-element-property :attr_groff table
) " ")))))
1631 (and attr
(plist-get attr
:verbatim
))))
1633 (format ".DS L\n\\fC%s\\fP\n.DE"
1634 ;; Re-create table, without affiliated keywords.
1636 (org-element-interpret-data
1637 `(table nil
,@(org-element-contents table
))))))
1639 ;; Case 2: Standard table.
1640 (t (org-e-groff-table--org-table table contents info
))))
1642 (defun org-e-groff-table--align-string (divider table info
)
1643 "Return an appropriate Groff alignment string.
1644 TABLE is the considered table. INFO is a plist used as
1645 a communication channel."
1647 ;; Extract column groups and alignment from first (non-rule)
1653 (and (eq (org-element-property :type row
) 'standard
) row
))
1657 (let* ((borders (org-export-table-cell-borders cell info
))
1658 (raw-width (org-export-table-cell-width cell info
))
1659 (width-cm (when raw-width
(/ raw-width
5)))
1660 (width (if raw-width
(format "w(%dc)"
1661 (if (< width-cm
1) 1 width-cm
)) "")))
1662 ;; Check left border for the first cell only.
1663 ;; Alignment is nil on assignment
1665 (when (and (memq 'left borders
) (not alignment
))
1666 (push "|" alignment
))
1668 (case (org-export-table-cell-alignment cell info
)
1669 (left (concat "l" width divider
))
1670 (right (concat "r" width divider
))
1671 (center (concat "c" width divider
)))
1673 (when (memq 'right borders
) (push "|" alignment
))))
1675 (apply 'concat
(reverse alignment
))))
1677 (defun org-e-groff-table--org-table (table contents info
)
1678 "Return appropriate Groff code for an Org table.
1680 TABLE is the table type element to transcode. CONTENTS is its
1681 contents, as a string. INFO is a plist used as a communication
1684 This function assumes TABLE has `org' as its `:type' attribute."
1685 (let* ((attr (org-export-read-attribute :attr_groff table
))
1686 (label (org-element-property :name table
))
1687 (caption (and (not (plist-get attr
:disable-caption
))
1688 (org-e-groff--caption/label-string table info
)))
1689 (divider (if (plist-get attr
:divider
) "|" " "))
1691 ;; Determine alignment string.
1692 (alignment (org-e-groff-table--align-string divider table info
))
1694 ;; Extract others display options.
1696 (lines (org-split-string contents
"\n"))
1702 (if (plist-get attr
:expand
)
1705 (case (plist-get attr
:placement
)
1709 (if org-e-groff-tables-centered
1712 (case (plist-get attr
:boxtype
)
1714 ('doublebox
"doublebox")
1719 (if (not (null attr-item
))
1720 (add-to-list 'result-list attr-item
)))
1723 (title-line (plist-get attr
:title-line
))
1724 (long-cells (plist-get attr
:long-cells
))
1729 (or (car attr-list
) ""))
1732 (when (cdr attr-list
)
1733 (dolist (attr-item (cdr attr-list
))
1734 (setq output-list
(concat output-list
1735 (format ",%s" attr-item
)))))
1738 (when lines
(org-split-string (car lines
) "\t"))))
1739 ;; Prepare the final format string for the table.
1745 (concat ".TS\n " table-format
";\n"
1747 (let ((final-line ""))
1749 (dotimes (i (length first-line
))
1750 (setq final-line
(concat final-line
"cb" divider
))))
1752 (setq final-line
(concat final-line
"\n"))
1755 (setq final-line
(concat final-line alignment
))
1756 (dotimes (i (length first-line
))
1757 (setq final-line
(concat final-line
"c" divider
))))
1761 (let ((final-line "")
1763 (lines (org-split-string contents
"\n")))
1765 (dolist (line-item lines
)
1770 (if (string= line-item
"_")
1771 (setq long-line
(format "%s\n" line-item
))
1773 (let ((cell-item-list (org-split-string line-item
"\t")))
1774 (dolist (cell-item cell-item-list
)
1776 (cond ((eq cell-item
(car (last cell-item-list
)))
1777 (setq long-line
(concat long-line
1778 (format "T{\n%s\nT}\t\n" cell-item
))))
1780 (setq long-line
(concat long-line
1781 (format "T{\n%s\nT}\t" cell-item
))))))
1784 (setq final-line
(concat final-line long-line
)))
1786 (setq final-line
(concat final-line line-item
"\n"))))
1789 (if caption
(format ".TB \"%s\"" caption
) ""))))))
1793 (defun org-e-groff-table-cell (table-cell contents info
)
1794 "Transcode a TABLE-CELL element from Org to Groff
1795 CONTENTS is the cell contents. INFO is a plist used as
1796 a communication channel."
1798 (concat (if (and contents
1799 org-e-groff-table-scientific-notation
1800 (string-match orgtbl-exp-regexp contents
))
1801 ;; Use appropriate format string for scientific
1803 (format org-e-groff-table-scientific-notation
1804 (match-string 1 contents
)
1805 (match-string 2 contents
))
1807 (when (org-export-get-next-element table-cell info
) "\t"))))
1812 (defun org-e-groff-table-row (table-row contents info
)
1813 "Transcode a TABLE-ROW element from Org to Groff
1814 CONTENTS is the contents of the row. INFO is a plist used as
1815 a communication channel."
1816 ;; Rules are ignored since table separators are deduced from
1817 ;; borders of the current row.
1818 (when (eq (org-element-property :type table-row
) 'standard
)
1819 (let* ((attr (mapconcat 'identity
1820 (org-element-property
1821 :attr_groff
(org-export-get-parent table-row
))
1823 ;; TABLE-ROW's borders are extracted from its first cell.
1825 (org-export-table-cell-borders
1826 (car (org-element-contents table-row
)) info
)))
1828 ;; Mark horizontal lines
1829 (cond ((and (memq 'top borders
) (memq 'above borders
)) "_\n"))
1832 ;; When BOOKTABS are activated enforce bottom rule even when
1833 ;; no hline was specifically marked.
1834 ((and (memq 'bottom borders
) (memq 'below borders
)) "\n_")
1835 ((memq 'below borders
) "\n_"))))))
1839 (defun org-e-groff-target (target contents info
)
1840 "Transcode a TARGET object from Org to Groff.
1841 CONTENTS is nil. INFO is a plist holding contextual
1843 (format "\\fI%s\\fP"
1844 (org-export-solidify-link-text (org-element-property :value target
))))
1848 (defun org-e-groff-timestamp (timestamp contents info
)
1849 "Transcode a TIMESTAMP object from Org to Groff.
1850 CONTENTS is nil. INFO is a plist holding contextual
1852 (let ((value (org-e-groff-plain-text
1853 (org-export-translate-timestamp timestamp
) info
)))
1854 (case (org-element-property :type timestamp
)
1855 ((active active-range
)
1856 (format org-e-groff-active-timestamp-format value
))
1857 ((inactive inactive-range
)
1858 (format org-e-groff-inactive-timestamp-format value
))
1859 (t (format org-e-groff-diary-timestamp-format value
)))))
1863 (defun org-e-groff-underline (underline contents info
)
1864 "Transcode UNDERLINE from Org to Groff.
1865 CONTENTS is the text with underline markup. INFO is a plist
1866 holding contextual information."
1867 (org-e-groff--text-markup contents
'underline
))
1871 (defun org-e-groff-verbatim (verbatim contents info
)
1872 "Transcode a VERBATIM object from Org to Groff.
1873 CONTENTS is nil. INFO is a plist used as a communication
1875 (org-e-groff--text-markup (org-element-property :value verbatim
) 'verbatim
))
1879 (defun org-e-groff-verse-block (verse-block contents info
)
1880 "Transcode a VERSE-BLOCK element from Org to Groff.
1881 CONTENTS is verse block contents. INFO is a plist holding
1882 contextual information."
1883 (format ".DS C\n.ft HI\n%s\n.ft\n.DE" contents
))
1886 ;;; Interactive functions
1888 (defun org-e-groff-export-to-groff
1889 (&optional subtreep visible-only body-only ext-plist
)
1890 "Export current buffer to a Groff file.
1892 If narrowing is active in the current buffer, only export its
1895 If a region is active, export that region.
1897 When optional argument SUBTREEP is non-nil, export the sub-tree
1898 at point, extracting information from the headline properties
1901 When optional argument VISIBLE-ONLY is non-nil, don't export
1902 contents of hidden elements.
1904 EXT-PLIST, when provided, is a property list with external
1905 parameters overriding Org default settings, but still inferior to
1906 file-local settings.
1908 Return output file's name."
1910 (setq org-e-groff-registered-references nil
)
1911 (setq org-e-groff-special-content nil
)
1912 (let ((outfile (org-export-output-file-name ".groff" subtreep
)))
1914 'e-groff outfile subtreep visible-only body-only ext-plist
)))
1916 (defun org-e-groff-export-to-pdf
1917 (&optional subtreep visible-only body-only ext-plist
)
1918 "Export current buffer to Groff then process through to PDF.
1920 If narrowing is active in the current buffer, only export its
1923 If a region is active, export that region.
1925 When optional argument SUBTREEP is non-nil, export the sub-tree
1926 at point, extracting information from the headline properties
1929 When optional argument VISIBLE-ONLY is non-nil, don't export
1930 contents of hidden elements.
1932 EXT-PLIST, when provided, is a property list with external
1933 parameters overriding Org default settings, but still inferior to
1934 file-local settings.
1936 Return PDF file's name."
1938 (org-e-groff-compile
1939 (org-e-groff-export-to-groff subtreep visible-only body-only ext-plist
)))
1941 (defun org-e-groff-compile (file)
1942 "Compile a Groff file.
1944 FILE is the name of the file being compiled. Processing is done
1945 through the command specified in `org-e-groff-pdf-process'.
1947 Return PDF file name or an error if it couldn't be produced."
1948 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file
)))
1949 (full-name (file-truename file
))
1950 (out-dir (file-name-directory file
))
1951 ;; Make sure `default-directory' is set to FILE directory,
1952 ;; not to whatever value the current buffer may have.
1953 (default-directory (file-name-directory full-name
))
1955 (message (format "Processing Groff file %s ..." file
))
1956 (save-window-excursion
1958 ;; A function is provided: Apply it.
1959 ((functionp org-e-groff-pdf-process
)
1960 (funcall org-e-groff-pdf-process
(shell-quote-argument file
)))
1961 ;; A list is provided: Replace %b, %f and %o with appropriate
1962 ;; values in each command before applying it. Output is
1963 ;; redirected to "*Org PDF Groff Output*" buffer.
1964 ((consp org-e-groff-pdf-process
)
1965 (let ((outbuf (get-buffer-create "*Org PDF Groff Output*")))
1969 (replace-regexp-in-string
1970 "%b" (shell-quote-argument base-name
)
1971 (replace-regexp-in-string
1972 "%f" (shell-quote-argument full-name
)
1973 (replace-regexp-in-string
1974 "%o" (shell-quote-argument out-dir
) command t t
)
1977 org-e-groff-pdf-process
)
1978 ;; Collect standard errors from output buffer.
1979 (setq errors
(org-e-groff-collect-errors outbuf
))))
1980 (t (error "No valid command to process to PDF")))
1981 (let ((pdffile (concat out-dir base-name
".pdf")))
1982 ;; Check for process failure. Provide collected errors if
1984 (if (not (file-exists-p pdffile
))
1985 (error (concat (format "PDF file %s wasn't produced" pdffile
)
1986 (when errors
(concat ": " errors
))))
1987 ;; Else remove log files, when specified, and signal end of
1988 ;; process to user, along with any error encountered.
1989 (when org-e-groff-remove-logfiles
1990 (dolist (ext org-e-groff-logfiles-extensions
)
1991 (let ((file (concat out-dir base-name
"." ext
)))
1992 (when (file-exists-p file
) (delete-file file
)))))
1993 (message (concat "Process completed"
1994 (if (not errors
) "."
1995 (concat " with errors: " errors
)))))
1996 ;; Return output file name.
1999 (defun org-e-groff-collect-errors (buffer)
2000 "Collect some kind of errors from \"groff\" output
2001 BUFFER is the buffer containing output.
2002 Return collected error types as a string, or nil if there was
2004 (with-current-buffer buffer
2006 (goto-char (point-max))
2011 (provide 'org-e-groff
)
2012 ;;; org-e-groff.el ends here