1 ;;; ox-texinfo.el --- Texinfo Back-End for Org Export Engine
3 ;; Copyright (C) 2012-2015 Free Software Foundation, Inc.
4 ;; Author: Jonathan Leech-Pepin <jonathan.leechpepin at gmail dot com>
5 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; See Org manual for details.
28 (eval-when-compile (require 'cl
))
31 (defvar orgtbl-exp-regexp
)
37 (org-export-define-backend 'texinfo
38 '((bold . org-texinfo-bold
)
39 (center-block . org-texinfo-center-block
)
40 (clock . org-texinfo-clock
)
41 (code . org-texinfo-code
)
42 (drawer . org-texinfo-drawer
)
43 (dynamic-block . org-texinfo-dynamic-block
)
44 (entity . org-texinfo-entity
)
45 (example-block . org-texinfo-example-block
)
46 (export-block . org-texinfo-export-block
)
47 (export-snippet . org-texinfo-export-snippet
)
48 (fixed-width . org-texinfo-fixed-width
)
49 (footnote-definition . org-texinfo-footnote-definition
)
50 (footnote-reference . org-texinfo-footnote-reference
)
51 (headline . org-texinfo-headline
)
52 (inline-src-block . org-texinfo-inline-src-block
)
53 (inlinetask . org-texinfo-inlinetask
)
54 (italic . org-texinfo-italic
)
55 (item . org-texinfo-item
)
56 (keyword . org-texinfo-keyword
)
57 (line-break . org-texinfo-line-break
)
58 (link . org-texinfo-link
)
59 (node-property . org-texinfo-node-property
)
60 (paragraph . org-texinfo-paragraph
)
61 (plain-list . org-texinfo-plain-list
)
62 (plain-text . org-texinfo-plain-text
)
63 (planning . org-texinfo-planning
)
64 (property-drawer . org-texinfo-property-drawer
)
65 (quote-block . org-texinfo-quote-block
)
66 (radio-target . org-texinfo-radio-target
)
67 (section . org-texinfo-section
)
68 (special-block . org-texinfo-special-block
)
69 (src-block . org-texinfo-src-block
)
70 (statistics-cookie . org-texinfo-statistics-cookie
)
71 (subscript . org-texinfo-subscript
)
72 (superscript . org-texinfo-superscript
)
73 (table . org-texinfo-table
)
74 (table-cell . org-texinfo-table-cell
)
75 (table-row . org-texinfo-table-row
)
76 (target . org-texinfo-target
)
77 (template . org-texinfo-template
)
78 (timestamp . org-texinfo-timestamp
)
79 (verbatim . org-texinfo-verbatim
)
80 (verse-block . org-texinfo-verse-block
))
81 :export-block
"TEXINFO"
83 '((:filter-headline . org-texinfo-filter-section-blank-lines
)
84 (:filter-parse-tree . org-texinfo--normalize-headlines
)
85 (:filter-section . org-texinfo-filter-section-blank-lines
))
87 '(?i
"Export to Texinfo"
88 ((?t
"As TEXI file" org-texinfo-export-to-texinfo
)
89 (?i
"As INFO file" org-texinfo-export-to-info
)))
91 '((:texinfo-filename
"TEXINFO_FILENAME" nil nil t
)
92 (:texinfo-class
"TEXINFO_CLASS" nil org-texinfo-default-class t
)
93 (:texinfo-header
"TEXINFO_HEADER" nil nil newline
)
94 (:texinfo-post-header
"TEXINFO_POST_HEADER" nil nil newline
)
95 (:subtitle
"SUBTITLE" nil nil parse
)
96 (:subauthor
"SUBAUTHOR" nil nil newline
)
97 (:texinfo-dircat
"TEXINFO_DIR_CATEGORY" nil nil t
)
98 (:texinfo-dirtitle
"TEXINFO_DIR_TITLE" nil nil t
)
99 (:texinfo-dirdesc
"TEXINFO_DIR_DESC" nil nil t
)
100 (:texinfo-printed-title
"TEXINFO_PRINTED_TITLE" nil nil t
)
102 (:texinfo-classes nil nil org-texinfo-classes
)
103 (:texinfo-format-headline-function nil nil org-texinfo-format-headline-function
)
104 (:texinfo-node-description-column nil nil org-texinfo-node-description-column
)
105 (:texinfo-active-timestamp-format nil nil org-texinfo-active-timestamp-format
)
106 (:texinfo-inactive-timestamp-format nil nil org-texinfo-inactive-timestamp-format
)
107 (:texinfo-diary-timestamp-format nil nil org-texinfo-diary-timestamp-format
)
108 (:texinfo-link-with-unknown-path-format nil nil org-texinfo-link-with-unknown-path-format
)
109 (:texinfo-tables-verbatim nil nil org-texinfo-tables-verbatim
)
110 (:texinfo-table-scientific-notation nil nil org-texinfo-table-scientific-notation
)
111 (:texinfo-def-table-markup nil nil org-texinfo-def-table-markup
)
112 (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist
)
113 (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function
)
114 (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function
)))
118 ;;; User Configurable Variables
120 (defgroup org-export-texinfo nil
121 "Options for exporting Org mode files to Texinfo."
122 :tag
"Org Export Texinfo"
124 :package-version
'(Org .
"8.0")
129 (defcustom org-texinfo-coding-system nil
130 "Default document encoding for Texinfo output.
132 If `nil' it will default to `buffer-file-coding-system'."
133 :group
'org-export-texinfo
134 :type
'coding-system
)
136 (defcustom org-texinfo-default-class
"info"
137 "The default Texinfo class."
138 :group
'org-export-texinfo
139 :type
'(string :tag
"Texinfo class"))
141 (defcustom org-texinfo-classes
143 "@documentencoding AUTO\n@documentlanguage AUTO"
144 ("@chapter %s" .
"@unnumbered %s")
145 ("@section %s" .
"@unnumberedsec %s")
146 ("@subsection %s" .
"@unnumberedsubsec %s")
147 ("@subsubsection %s" .
"@unnumberedsubsubsec %s")))
148 "Alist of Texinfo classes and associated header and structure.
149 If #+TEXINFO_CLASS is set in the buffer, use its value and the
150 associated information. Here is the structure of each cell:
154 \(numbered-section . unnumbered-section)
161 The header string is inserted in the header of the generated
162 document, right after \"@setfilename\" and \"@settitle\"
165 If it contains the special string
167 \"@documentencoding AUTO\"
169 \"AUTO\" will be replaced with an appropriate coding system. See
170 `org-texinfo-coding-system' for more information. Likewise, if
171 the string contains the special string
173 \"@documentlanguage AUTO\"
175 \"AUTO\" will be replaced with the language defined in the
176 buffer, through #+LANGUAGE keyword, or globally, with
177 `org-export-default-language', which see.
180 The sectioning structure
181 ------------------------
183 The sectioning structure of the class is given by the elements
184 following the header string. For each sectioning level, a number
185 of strings is specified. A %s formatter is mandatory in each
186 section string and will be replaced by the title of the section.
188 Instead of a list of sectioning commands, you can also specify
189 a function name. That function will be called with two
190 parameters, the reduced) level of the headline, and a predicate
191 non-nil when the headline should be numbered. It must return
192 a format string in which the section title will be added."
193 :group
'org-export-texinfo
195 :package-version
'(Org .
"8.2")
197 (list (string :tag
"Texinfo class")
198 (string :tag
"Texinfo header")
199 (repeat :tag
"Levels" :inline t
202 (string :tag
" numbered")
203 (string :tag
"unnumbered"))
204 (function :tag
"Hook computing sectioning"))))))
208 (defcustom org-texinfo-format-headline-function
209 'org-texinfo-format-headline-default-function
210 "Function to format headline text.
212 This function will be called with 5 arguments:
213 TODO the todo keyword (string or nil).
214 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
215 PRIORITY the priority of the headline (integer or nil)
216 TEXT the main headline text (string).
217 TAGS the tags as a list of strings (list of strings or nil).
219 The function result will be used in the section format string."
220 :group
'org-export-texinfo
223 :package-version
'(Org .
"8.3"))
225 ;;;; Node listing (menu)
227 (defcustom org-texinfo-node-description-column
32
228 "Column at which to start the description in the node listings.
229 If a node title is greater than this length, the description will
230 be placed after the end of the title."
231 :group
'org-export-texinfo
236 (defcustom org-texinfo-active-timestamp-format
"@emph{%s}"
237 "A printf format string to be applied to active timestamps."
238 :group
'org-export-texinfo
241 (defcustom org-texinfo-inactive-timestamp-format
"@emph{%s}"
242 "A printf format string to be applied to inactive timestamps."
243 :group
'org-export-texinfo
246 (defcustom org-texinfo-diary-timestamp-format
"@emph{%s}"
247 "A printf format string to be applied to diary timestamps."
248 :group
'org-export-texinfo
253 (defcustom org-texinfo-link-with-unknown-path-format
"@indicateurl{%s}"
254 "Format string for links with unknown path type."
255 :group
'org-export-texinfo
260 (defcustom org-texinfo-tables-verbatim nil
261 "When non-nil, tables are exported verbatim."
262 :group
'org-export-texinfo
265 (defcustom org-texinfo-table-scientific-notation
"%s\\,(%s)"
266 "Format string to display numbers in scientific notation.
267 The format should have \"%s\" twice, for mantissa and exponent
268 \(i.e. \"%s\\\\times10^{%s}\").
270 When nil, no transformation is made."
271 :group
'org-export-texinfo
273 (string :tag
"Format string")
274 (const :tag
"No formatting" nil
)))
276 (defcustom org-texinfo-def-table-markup
"@samp"
277 "Default setting for @table environments."
278 :group
'org-export-texinfo
283 (defcustom org-texinfo-text-markup-alist
'((bold .
"@strong{%s}")
285 (italic .
"@emph{%s}")
288 "Alist of Texinfo expressions to convert text markup.
290 The key must be a symbol among `bold', `italic' and `comment'.
291 The value is a formatting string to wrap fontified text with.
293 Value can also be set to the following symbols: `verb' and
294 `code'. For the former, Org will use \"@verb\" to
295 create a format string and select a delimiter character that
296 isn't in the string. For the latter, Org will use \"@code\"
297 to typeset and try to protect special characters.
299 If no association can be found for a given markup, text will be
301 :group
'org-export-texinfo
303 :options
'(bold code italic verbatim comment
))
307 (defcustom org-texinfo-format-drawer-function
308 (lambda (name contents
) contents
)
309 "Function called to format a drawer in Texinfo code.
311 The function must accept two parameters:
312 NAME the drawer name, like \"LOGBOOK\"
313 CONTENTS the contents of the drawer.
315 The function should return the string to be exported.
317 The default function simply returns the value of CONTENTS."
318 :group
'org-export-texinfo
320 :package-version
'(Org .
"8.2")
325 (defcustom org-texinfo-format-inlinetask-function
326 'org-texinfo-format-inlinetask-default-function
327 "Function called to format an inlinetask in Texinfo code.
329 The function must accept six parameters:
330 TODO the todo keyword, as a string
331 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
332 PRIORITY the inlinetask priority, as a string
333 NAME the inlinetask name, as a string.
334 TAGS the inlinetask tags, as a list of strings.
335 CONTENTS the contents of the inlinetask, as a string.
337 The function should return the string to be exported."
338 :group
'org-export-texinfo
343 (defcustom org-texinfo-info-process
'("makeinfo %f")
344 "Commands to process a Texinfo file to an INFO file.
345 This is list of strings, each of them will be given to the shell
346 as a command. %f in the command will be replaced by the full
347 file name, %b by the file base name (i.e without extension) and
348 %o by the base directory of the file."
349 :group
'org-export-texinfo
350 :type
'(repeat :tag
"Shell command sequence"
351 (string :tag
"Shell command")))
353 (defcustom org-texinfo-logfiles-extensions
354 '("aux" "toc" "cp" "fn" "ky" "pg" "tp" "vr")
355 "The list of file extensions to consider as Texinfo logfiles.
356 The logfiles will be remove if `org-texinfo-remove-logfiles' is
358 :group
'org-export-texinfo
359 :type
'(repeat (string :tag
"Extension")))
361 (defcustom org-texinfo-remove-logfiles t
362 "Non-nil means remove the logfiles produced by compiling a Texinfo file.
363 By default, logfiles are files with these extensions: .aux, .toc,
364 .cp, .fn, .ky, .pg and .tp. To define the set of logfiles to remove,
365 set `org-texinfo-logfiles-extensions'."
366 :group
'org-export-latex
371 (defconst org-texinfo-max-toc-depth
4
372 "Maximum depth for creation of detailed menu listings.
373 Beyond this depth, Texinfo will not recognize the nodes and will
374 cause errors. Left as a constant in case this value ever
377 (defconst org-texinfo-supported-coding-systems
378 '("US-ASCII" "UTF-8" "ISO-8859-15" "ISO-8859-1" "ISO-8859-2" "koi8-r" "koi8-u")
379 "List of coding systems supported by Texinfo, as strings.
380 Specified coding system will be matched against these strings.
381 If two strings share the same prefix (e.g. \"ISO-8859-1\" and
382 \"ISO-8859-15\"), the most specific one has to be listed first.")
385 ;;; Internal Functions
387 (defun org-texinfo-filter-section-blank-lines (headline back-end info
)
388 "Filter controlling number of blank lines after a section."
389 (let ((blanks (make-string 2 ?
\n)))
390 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline
)))
392 (defun org-texinfo--normalize-headlines (tree back-end info
)
393 "Normalize headlines in TREE.
395 BACK-END is the symbol specifying back-end used for export. INFO
396 is a plist used as a communication channel.
398 Make sure every headline in TREE contains a section, since those
399 are required to install a menu. Also put exactly one blank line
400 at the end of each section.
403 (org-element-map tree
'headline
405 (org-element-put-property hl
:post-blank
1)
406 (let ((contents (org-element-contents hl
)))
408 (let ((first (org-element-map contents
'(headline section
)
410 (unless (eq (org-element-type first
) 'section
)
411 (apply #'org-element-set-contents
413 (cons `(section (:parent
,hl
)) contents
)))))))
417 (defun org-texinfo--find-verb-separator (s)
418 "Return a character not used in string S.
419 This is used to choose a separator for constructs like \\verb."
420 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
421 (loop for c across ll
422 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
423 return
(char-to-string c
))))
425 (defun org-texinfo--text-markup (text markup info
)
426 "Format TEXT depending on MARKUP text markup.
427 INFO is a plist used as a communication channel. See
428 `org-texinfo-text-markup-alist' for details."
429 (let ((fmt (cdr (assq markup org-texinfo-text-markup-alist
))))
431 ;; No format string: Return raw text.
434 (let ((separator (org-texinfo--find-verb-separator text
)))
435 (concat "@verb{" separator text separator
"}")))
440 (while (string-match "[@{}]" text
)
441 (setq char
(match-string 0 text
))
442 (if (> (match-beginning 0) 0)
443 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
444 (setq text
(substring text
(1+ (match-beginning 0))))
445 (setq char
(concat "@" char
)
446 rtn
(concat rtn char
)))
447 (setq text
(concat rtn text
)
450 ;; Else use format string.
451 (t (format fmt text
)))))
453 (defun org-texinfo--get-node (blob info
)
454 "Return node or anchor associated to BLOB.
455 BLOB is an element or object. INFO is a plist used as
456 a communication channel. The function guarantees the node or
457 anchor name is unique."
458 (let ((cache (plist-get info
:texinfo-node-cache
)))
459 (or (cdr (assq blob cache
))
461 (org-texinfo--sanitize-node
462 (if (eq (org-element-type blob
) 'headline
)
463 (org-export-data (org-export-get-alt-title blob info
) info
)
464 (org-export-get-reference blob info
)))))
465 ;; Ensure NAME is unique.
466 (while (rassoc name cache
) (setq name
(concat name
"x")))
467 (plist-put info
:texinfo-node-cache
(cons (cons blob name
) cache
))
472 (defun org-texinfo--sanitize-node (title)
473 "Bend string TITLE to node line requirements.
474 Trim string and collapse multiple whitespace characters as they
475 are not significant. Also remove the following characters: @
477 (replace-regexp-in-string
479 (replace-regexp-in-string
480 "\\`(\\(.*)\\)" "[\\1"
481 (org-trim (replace-regexp-in-string "[ \t]\\{2,\\}" " " title
)))))
483 ;;;; Content sanitizing
485 (defun org-texinfo--sanitize-content (text)
486 "Escape special characters in string TEXT.
487 Special characters are: @ { }"
488 (replace-regexp-in-string "[@{}]" "@\\&" text
))
492 (defun org-texinfo-template (contents info
)
493 "Return complete document string after Texinfo conversion.
494 CONTENTS is the transcoded contents string. INFO is a plist
495 holding export options."
496 (let ((title (org-export-data (plist-get info
:title
) info
))
497 ;; Copying data is the contents of the first headline in
498 ;; parse tree with a non-nil copying property.
499 (copying (org-element-map (plist-get info
:parse-tree
) 'headline
501 (and (org-not-nil (org-element-property :COPYING hl
))
502 (org-element-contents hl
)))
505 "\\input texinfo @c -*- texinfo -*-\n"
506 "@c %**start of header\n"
507 (let ((file (or (plist-get info
:texinfo-filename
)
508 (let ((f (plist-get info
:output-file
)))
509 (and f
(concat (file-name-sans-extension f
) ".info"))))))
510 (and file
(format "@setfilename %s\n" file
)))
511 (format "@settitle %s\n" title
)
512 ;; Insert class-defined header.
513 (org-element-normalize-string
514 (let ((header (nth 1 (assoc (plist-get info
:texinfo-class
)
515 org-texinfo-classes
)))
517 (catch 'coding-system
518 (let ((case-fold-search t
)
519 (name (symbol-name (or org-texinfo-coding-system
520 buffer-file-coding-system
))))
521 (dolist (system org-texinfo-supported-coding-systems
"UTF-8")
522 (when (org-string-match-p (regexp-quote system
) name
)
523 (throw 'coding-system system
))))))
524 (language (plist-get info
:language
))
525 (case-fold-search nil
))
526 ;; Auto coding system.
527 (replace-regexp-in-string
528 "^@documentencoding \\(AUTO\\)$"
530 (replace-regexp-in-string
531 "^@documentlanguage \\(AUTO\\)$" language header t nil
1) t nil
1)))
532 ;; Additional header options set by #+TEXINFO_HEADER.
533 (let ((texinfo-header (plist-get info
:texinfo-header
)))
534 (and texinfo-header
(org-element-normalize-string texinfo-header
)))
535 "@c %**end of header\n\n"
536 ;; Additional options set by #+TEXINFO_POST_HEADER.
537 (let ((texinfo-post-header (plist-get info
:texinfo-post-header
)))
538 (and texinfo-post-header
539 (org-element-normalize-string texinfo-post-header
)))
542 (format "@copying\n%s@end copying\n\n"
543 (org-element-normalize-string
544 (org-export-data copying info
))))
545 ;; Info directory information. Only supply if both title and
546 ;; category are provided.
547 (let ((dircat (plist-get info
:texinfo-dircat
))
549 (let ((title (plist-get info
:texinfo-dirtitle
)))
551 (string-match "^\\(?:\\* \\)?\\(.*?\\)\\(\\.\\)?$" title
)
552 (format "* %s." (match-string 1 title
))))))
553 (when (and dircat dirtitle
)
554 (concat "@dircategory " dircat
"\n"
557 (let ((desc (plist-get info
:texinfo-dirdesc
)))
558 (cond ((not desc
) nil
)
559 ((org-string-match-p "\\.$" desc
) desc
)
560 (t (concat desc
"."))))))
561 (if dirdesc
(format "%-23s %s" dirtitle dirdesc
) dirtitle
))
563 "@end direntry\n\n")))
567 (when (plist-get info
:with-title
)
569 (format "@title %s\n" (or (plist-get info
:texinfo-printed-title
) title
""))
570 (let ((subtitle (plist-get info
:subtitle
)))
572 (format "@subtitle %s\n"
573 (org-export-data subtitle info
))))))
574 (when (plist-get info
:with-author
)
577 (let ((author (org-string-nw-p
578 (org-export-data (plist-get info
:author
) info
)))
579 (email (and (plist-get info
:with-email
)
581 (org-export-data (plist-get info
:email
) info
)))))
582 (cond ((and author email
)
583 (format "@author %s (@email{%s})\n" author email
))
584 (author (format "@author %s\n" author
))
585 (email (format "@author @email{%s}\n" email
))))
587 (let ((subauthor (plist-get info
:subauthor
)))
589 (org-element-normalize-string
590 (replace-regexp-in-string "^" "@author " subauthor
))))))
591 (and copying
"@page\n@vskip 0pt plus 1filll\n@insertcopying\n")
593 ;; Table of contents.
594 (and (plist-get info
:with-toc
) "@contents\n\n")
595 ;; Configure Top Node when not for Tex
598 (format "@top %s\n" title
)
599 (and copying
"@insertcopying\n")
602 (org-texinfo-make-menu (plist-get info
:parse-tree
) info
'master
)
607 (and (plist-get info
:with-creator
)
608 (concat (plist-get info
:creator
) "\n"))
614 ;;; Transcode Functions
618 (defun org-texinfo-bold (bold contents info
)
619 "Transcode BOLD from Org to Texinfo.
620 CONTENTS is the text with bold markup. INFO is a plist holding
621 contextual information."
622 (org-texinfo--text-markup contents
'bold info
))
626 (defun org-texinfo-center-block (center-block contents info
)
627 "Transcode a CENTER-BLOCK element from Org to Texinfo.
628 CONTENTS holds the contents of the block. INFO is a plist used
629 as a communication channel."
634 (defun org-texinfo-clock (clock contents info
)
635 "Transcode a CLOCK element from Org to Texinfo.
636 CONTENTS is nil. INFO is a plist holding contextual
640 (format "@strong{%s} " org-clock-string
)
641 (format (plist-get info
:texinfo-inactive-timestamp-format
)
642 (concat (org-timestamp-translate (org-element-property :value clock
))
643 (let ((time (org-element-property :duration clock
)))
644 (and time
(format " (%s)" time
)))))
649 (defun org-texinfo-code (code contents info
)
650 "Transcode a CODE object from Org to Texinfo.
651 CONTENTS is nil. INFO is a plist used as a communication
653 (org-texinfo--text-markup (org-element-property :value code
) 'code info
))
657 (defun org-texinfo-drawer (drawer contents info
)
658 "Transcode a DRAWER element from Org to Texinfo.
659 CONTENTS holds the contents of the block. INFO is a plist
660 holding contextual information."
661 (let* ((name (org-element-property :drawer-name drawer
))
662 (output (funcall (plist-get info
:texinfo-format-drawer-function
)
668 (defun org-texinfo-dynamic-block (dynamic-block contents info
)
669 "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
670 CONTENTS holds the contents of the block. INFO is a plist
671 holding contextual information."
676 (defun org-texinfo-entity (entity contents info
)
677 "Transcode an ENTITY object from Org to Texinfo.
678 CONTENTS are the definition itself. INFO is a plist holding
679 contextual information."
680 (let ((ent (org-element-property :latex entity
)))
681 (if (org-element-property :latex-math-p entity
) (format "@math{%s}" ent
) ent
)))
685 (defun org-texinfo-example-block (example-block contents info
)
686 "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
687 CONTENTS is nil. INFO is a plist holding contextual
689 (format "@verbatim\n%s@end verbatim"
690 (org-export-format-code-default example-block info
)))
694 (defun org-texinfo-export-block (export-block contents info
)
695 "Transcode a EXPORT-BLOCK element from Org to Texinfo.
696 CONTENTS is nil. INFO is a plist holding contextual information."
697 (when (string= (org-element-property :type export-block
) "TEXINFO")
698 (org-remove-indentation (org-element-property :value export-block
))))
702 (defun org-texinfo-export-snippet (export-snippet contents info
)
703 "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
704 CONTENTS is nil. INFO is a plist holding contextual information."
705 (when (eq (org-export-snippet-backend export-snippet
) 'texinfo
)
706 (org-element-property :value export-snippet
)))
710 (defun org-texinfo-fixed-width (fixed-width contents info
)
711 "Transcode a FIXED-WIDTH element from Org to Texinfo.
712 CONTENTS is nil. INFO is a plist holding contextual information."
713 (format "@example\n%s\n@end example"
714 (org-remove-indentation
715 (org-texinfo--sanitize-content
716 (org-element-property :value fixed-width
)))))
718 ;;;; Footnote Reference
720 (defun org-texinfo-footnote-reference (footnote contents info
)
721 "Create a footnote reference for FOOTNOTE.
723 FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
724 plist holding contextual information."
725 (let ((def (org-export-get-footnote-definition footnote info
)))
726 (format "@footnote{%s}"
727 (org-trim (org-export-data def info
)))))
731 (defun org-texinfo-headline (headline contents info
)
732 "Transcode a HEADLINE element from Org to Texinfo.
733 CONTENTS holds the contents of the headline. INFO is a plist
734 holding contextual information."
735 (let* ((class (plist-get info
:texinfo-class
))
736 (level (org-export-get-relative-level headline info
))
737 (numberedp (org-export-numbered-headline-p headline info
))
738 (class-sectioning (assoc class
(plist-get info
:texinfo-classes
)))
739 ;; Find the index type, if any.
740 (index (org-element-property :INDEX headline
))
741 ;; Create node info, to insert it before section formatting.
742 ;; Use custom menu title if present.
743 (node (format "@node %s\n" (org-texinfo--get-node headline info
)))
744 ;; Section formatting will set two placeholders: one for the
745 ;; title and the other for the contents.
747 (if (org-not-nil (org-element-property :APPENDIX headline
))
749 (let ((sec (if (and (symbolp (nth 2 class-sectioning
))
750 (fboundp (nth 2 class-sectioning
)))
751 (funcall (nth 2 class-sectioning
) level numberedp
)
752 (nth (1+ level
) class-sectioning
))))
754 ;; No section available for that LEVEL.
756 ;; Section format directly returned by a function.
758 ;; (numbered-section . unnumbered-section)
759 ((not (consp (cdr sec
)))
760 (concat (if (or index
(not numberedp
)) (cdr sec
) (car sec
))
763 (and (plist-get info
:with-todo-keywords
)
764 (let ((todo (org-element-property :todo-keyword headline
)))
765 (and todo
(org-export-data todo info
)))))
766 (todo-type (and todo
(org-element-property :todo-type headline
)))
767 (tags (and (plist-get info
:with-tags
)
768 (org-export-get-tags headline info
)))
769 (priority (and (plist-get info
:with-priority
)
770 (org-element-property :priority headline
)))
771 (text (org-export-data (org-element-property :title headline
) info
))
772 (full-text (funcall (plist-get info
:texinfo-format-headline-function
)
773 todo todo-type priority text tags
))
774 (contents (if (org-string-nw-p contents
) (concat "\n" contents
) "")))
776 ;; Case 1: This is a footnote section: ignore it.
777 ((org-element-property :footnote-section-p headline
) nil
)
778 ;; Case 2: This is the `copying' section: ignore it
779 ;; This is used elsewhere.
780 ((org-not-nil (org-element-property :COPYING headline
)) nil
)
781 ;; Case 3: An index. If it matches one of the known indexes,
782 ;; print it as such following the contents, otherwise
783 ;; print the contents and leave the index up to the user.
790 (and (member index
'("cp" "fn" "ky" "pg" "tp" "vr"))
791 (concat "\n@printindex " index
))))))
792 ;; Case 4: This is a deep sub-tree: export it as a list item.
793 ;; Also export as items headlines for which no section
794 ;; format has been found.
795 ((or (not section-fmt
) (org-export-low-level-p headline info
))
796 ;; Build the real contents of the sub-tree.
797 (concat (and (org-export-first-sibling-p headline info
)
798 (format "@%s\n" (if numberedp
'enumerate
'itemize
)))
799 "@item\n" full-text
"\n"
801 (if (org-export-last-sibling-p headline info
)
802 (format "@end %s" (if numberedp
'enumerate
'itemize
))
804 ;; Case 5: Standard headline. Export it as a section.
805 (t (concat node
(format section-fmt full-text contents
))))))
807 (defun org-texinfo-format-headline-default-function
808 (todo todo-type priority text tags
)
809 "Default format function for a headline.
810 See `org-texinfo-format-headline-function' for details."
811 (concat (when todo
(format "@strong{%s} " todo
))
812 (when priority
(format "@emph{#%s} " priority
))
814 (when tags
(format " :%s:" (mapconcat 'identity tags
":")))))
816 ;;;; Inline Src Block
818 (defun org-texinfo-inline-src-block (inline-src-block contents info
)
819 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
820 CONTENTS holds the contents of the item. INFO is a plist holding
821 contextual information."
822 (let* ((code (org-element-property :value inline-src-block
))
823 (separator (org-texinfo--find-verb-separator code
)))
824 (concat "@verb{" separator code separator
"}")))
828 (defun org-texinfo-inlinetask (inlinetask contents info
)
829 "Transcode an INLINETASK element from Org to Texinfo.
830 CONTENTS holds the contents of the block. INFO is a plist
831 holding contextual information."
832 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
833 (todo (and (plist-get info
:with-todo-keywords
)
834 (let ((todo (org-element-property :todo-keyword inlinetask
)))
835 (and todo
(org-export-data todo info
)))))
836 (todo-type (org-element-property :todo-type inlinetask
))
837 (tags (and (plist-get info
:with-tags
)
838 (org-export-get-tags inlinetask info
)))
839 (priority (and (plist-get info
:with-priority
)
840 (org-element-property :priority inlinetask
))))
841 (funcall (plist-get info
:texinfo-format-inlinetask-function
)
842 todo todo-type priority title tags contents
)))
844 (defun org-texinfo-format-inlinetask-default-function
845 (todo todo-type priority title tags contents
)
846 "Default format function for a inlinetasks.
847 See `org-texinfo-format-inlinetask-function' for details."
849 (concat (when todo
(format "@strong{%s} " todo
))
850 (when priority
(format "#%c " priority
))
852 (when tags
(format ":%s:" (mapconcat #'identity tags
":"))))))
853 (format "@center %s\n\n%s\n" full-title contents
)))
857 (defun org-texinfo-italic (italic contents info
)
858 "Transcode ITALIC from Org to Texinfo.
859 CONTENTS is the text with italic markup. INFO is a plist holding
860 contextual information."
861 (org-texinfo--text-markup contents
'italic info
))
865 (defun org-texinfo-item (item contents info
)
866 "Transcode an ITEM element from Org to Texinfo.
867 CONTENTS holds the contents of the item. INFO is a plist holding
868 contextual information."
869 (format "@item%s\n%s"
870 (let ((tag (org-element-property :tag item
)))
871 (if tag
(concat " " (org-export-data tag info
)) ""))
876 (defun org-texinfo-keyword (keyword contents info
)
877 "Transcode a KEYWORD element from Org to Texinfo.
878 CONTENTS is nil. INFO is a plist holding contextual information."
879 (let ((key (org-element-property :key keyword
))
880 (value (org-element-property :value keyword
)))
882 ((string= key
"TEXINFO") value
)
883 ((string= key
"CINDEX") (format "@cindex %s" value
))
884 ((string= key
"FINDEX") (format "@findex %s" value
))
885 ((string= key
"KINDEX") (format "@kindex %s" value
))
886 ((string= key
"PINDEX") (format "@pindex %s" value
))
887 ((string= key
"TINDEX") (format "@tindex %s" value
))
888 ((string= key
"VINDEX") (format "@vindex %s" value
)))))
892 (defun org-texinfo-line-break (line-break contents info
)
893 "Transcode a LINE-BREAK object from Org to Texinfo.
894 CONTENTS is nil. INFO is a plist holding contextual information."
899 (defun org-texinfo-link (link desc info
)
900 "Transcode a LINK object from Org to Texinfo.
902 DESC is the description part of the link, or the empty string.
903 INFO is a plist holding contextual information. See
905 (let* ((type (org-element-property :type link
))
906 (raw-path (org-element-property :path link
))
907 ;; Ensure DESC really exists, or set it to nil.
908 (desc (and (not (string= desc
"")) desc
))
910 ((member type
'("http" "https" "ftp"))
911 (concat type
":" raw-path
))
912 ((string= type
"file") (org-export-file-uri raw-path
))
915 ((org-export-custom-protocol-maybe link desc
'texinfo
))
916 ((equal type
"radio")
917 (let ((destination (org-export-resolve-radio-link link info
)))
918 (if (not destination
) desc
919 (format "@ref{%s,,%s}"
920 (org-texinfo--get-node destination info
)
922 ((member type
'("custom-id" "id" "fuzzy"))
924 (if (equal type
"fuzzy")
925 (org-export-resolve-fuzzy-link link info
)
926 (org-export-resolve-id-link link info
))))
927 (case (org-element-type destination
)
929 (format org-texinfo-link-with-unknown-path-format
930 (org-texinfo--sanitize-content path
)))
931 ;; Id link points to an external file.
933 (if desc
(format "@uref{file://%s,%s}" destination desc
)
934 (format "@uref{file://%s}" destination
)))
936 (format "@ref{%s,%s}"
937 (org-texinfo--get-node destination info
)
940 ((org-export-numbered-headline-p destination info
)
942 (org-element-property :title destination
) info
))
946 (org-export-get-headline-number destination info
) ".")))))
950 (if (and (eq (org-element-type destination
) 'headline
)
951 (not (org-export-numbered-headline-p
954 (org-element-property :title destination
) info
))
955 (let ((n (org-export-get-ordinal destination info
)))
959 (t (mapconcat #'number-to-string n
".")))))))
961 (format "@ref{%s,,%s}"
962 (org-texinfo--get-node destination info
)
965 (let* ((info-path (split-string path
"[:#]"))
966 (info-manual (car info-path
))
967 (info-node (or (cadr info-path
) "top"))
968 (title (or desc
"")))
969 (format "@ref{%s,%s,,%s,}" info-node title info-manual
)))
970 ((string= type
"mailto")
972 (concat (org-texinfo--sanitize-content path
)
973 (and desc
(concat "," desc
)))))
974 ;; External link with a description part.
975 ((and path desc
) (format "@uref{%s,%s}" path desc
))
976 ;; External link without a description part.
977 (path (format "@uref{%s}" path
))
978 ;; No path, only description. Try to do something useful.
980 (format (plist-get info
:texinfo-link-with-unknown-path-format
) desc
)))))
985 (defun org-texinfo-make-menu (scope info
&optional master
)
986 "Create the menu for inclusion in the Texinfo document.
988 SCOPE is a headline or a full parse tree. INFO is the
989 communication channel, as a plist.
991 When optional argument MASTER is non-nil, generate a master menu,
992 including detailed node listing."
993 (let ((menu (org-texinfo--build-menu scope info
)))
994 (when (org-string-nw-p menu
)
995 (org-element-normalize-string
1001 (org-texinfo--build-menu
1003 (let ((toc-depth (plist-get info
:with-toc
)))
1004 (if (wholenump toc-depth
) toc-depth
1005 org-texinfo-max-toc-depth
)))))
1006 (when (org-string-nw-p detailmenu
)
1007 (concat "\n@detailmenu\n"
1008 "--- The Detailed Node Listing ---\n\n"
1010 "@end detailmenu\n"))))))))))
1012 (defun org-texinfo--build-menu (scope info
&optional level
)
1013 "Build menu for entries within SCOPE.
1014 SCOPE is a headline or a full parse tree. INFO is a plist
1015 containing contextual information. When optional argument LEVEL
1016 is an integer, build the menu recursively, down to this depth."
1019 (org-texinfo--format-entries (org-texinfo--menu-entries scope info
) info
))
1022 (org-element-normalize-string
1025 (let ((entries (org-texinfo--menu-entries h info
)))
1028 (format "%s\n\n%s\n"
1029 (org-export-data (org-export-get-alt-title h info
) info
)
1030 (org-texinfo--format-entries entries info
))
1031 (org-texinfo--build-menu h info
(1- level
))))))
1032 (org-texinfo--menu-entries scope info
) "")))))
1034 (defun org-texinfo--format-entries (entries info
)
1035 "Format all direct menu entries in SCOPE, as a string.
1036 SCOPE is either a headline or a full Org document. INFO is
1037 a plist containing contextual information."
1038 (org-element-normalize-string
1041 (let* ((title (org-export-data
1042 (org-export-get-alt-title h info
) info
))
1043 (node (org-texinfo--get-node h info
))
1044 (entry (concat "* " title
":"
1045 (if (string= title node
) ":"
1046 (concat " " node
". "))))
1047 (desc (org-element-property :DESCRIPTION h
)))
1048 (if (not desc
) entry
1049 (format (format "%%-%ds %%s" org-texinfo-node-description-column
)
1053 (defun org-texinfo--menu-entries (scope info
)
1054 "List direct children in SCOPE needing a menu entry.
1055 SCOPE is a headline or a full parse tree. INFO is a plist
1056 holding contextual information."
1057 (let* ((cache (or (plist-get info
:texinfo-entries-cache
)
1058 (plist-get (plist-put info
:texinfo-entries-cache
1059 (make-hash-table :test
#'eq
))
1060 :texinfo-entries-cache
)))
1061 (cached-entries (gethash scope cache
'no-cache
)))
1062 (if (not (eq cached-entries
'no-cache
)) cached-entries
1064 (org-element-map (org-element-contents scope
) 'headline
1066 (and (not (org-not-nil (org-element-property :COPYING h
)))
1067 (not (org-element-property :footnote-section-p h
))
1068 (not (org-export-low-level-p h info
))
1075 (defun org-texinfo-node-property (node-property contents info
)
1076 "Transcode a NODE-PROPERTY element from Org to Texinfo.
1077 CONTENTS is nil. INFO is a plist holding contextual
1080 (org-element-property :key node-property
)
1081 (let ((value (org-element-property :value node-property
)))
1082 (if value
(concat " " value
) ""))))
1086 (defun org-texinfo-paragraph (paragraph contents info
)
1087 "Transcode a PARAGRAPH element from Org to Texinfo.
1088 CONTENTS is the contents of the paragraph, as a string. INFO is
1089 the plist used as a communication channel."
1094 (defun org-texinfo-plain-list (plain-list contents info
)
1095 "Transcode a PLAIN-LIST element from Org to Texinfo.
1096 CONTENTS is the contents of the list. INFO is a plist holding
1097 contextual information."
1098 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1099 (indic (or (plist-get attr
:indic
)
1100 (plist-get info
:texinfo-def-table-markup
)))
1101 (table-type (plist-get attr
:table-type
))
1102 (type (org-element-property :type plain-list
))
1104 ((eq type
'ordered
) "enumerate")
1105 ((eq type
'unordered
) "itemize")
1106 ((member table-type
'("ftable" "vtable")) table-type
)
1108 (format "@%s\n%s@end %s"
1109 (if (eq type
'descriptive
) (concat list-type
" " indic
) list-type
)
1115 (defun org-texinfo-plain-text (text info
)
1116 "Transcode a TEXT string from Org to Texinfo.
1117 TEXT is the string to transcode. INFO is a plist holding
1118 contextual information."
1119 ;; First protect @, { and }.
1120 (let ((output (org-texinfo--sanitize-content text
)))
1121 ;; Activate smart quotes. Be sure to provide original TEXT string
1122 ;; since OUTPUT may have been modified.
1123 (when (plist-get info
:with-smart-quotes
)
1125 (org-export-activate-smart-quotes output
:texinfo info text
)))
1126 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1127 (let ((case-fold-search nil
)
1129 (while (string-match "\\(\\(?:La\\)?TeX\\)" output start
)
1130 (setq output
(replace-match
1131 (format "@%s{}" (match-string 1 output
)) nil t output
)
1132 start
(match-end 0))))
1133 ;; Convert special strings.
1134 (when (plist-get info
:with-special-strings
)
1135 (while (string-match (regexp-quote "...") output
)
1136 (setq output
(replace-match "@dots{}" nil t output
))))
1137 ;; Handle break preservation if required.
1138 (when (plist-get info
:preserve-breaks
)
1139 (setq output
(replace-regexp-in-string
1140 "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output
)))
1146 (defun org-texinfo-planning (planning contents info
)
1147 "Transcode a PLANNING element from Org to Texinfo.
1148 CONTENTS is nil. INFO is a plist holding contextual
1156 (let ((closed (org-element-property :closed planning
)))
1159 (format "@strong{%s} " org-closed-string
)
1160 (format (plist-get info
:texinfo-inactive-timestamp-format
)
1161 (org-timestamp-translate closed
)))))
1162 (let ((deadline (org-element-property :deadline planning
)))
1165 (format "@strong{%s} " org-deadline-string
)
1166 (format (plist-get info
:texinfo-active-timestamp-format
)
1167 (org-timestamp-translate deadline
)))))
1168 (let ((scheduled (org-element-property :scheduled planning
)))
1171 (format "@strong{%s} " org-scheduled-string
)
1172 (format (plist-get info
:texinfo-active-timestamp-format
)
1173 (org-timestamp-translate scheduled
)))))))
1177 ;;;; Property Drawer
1179 (defun org-texinfo-property-drawer (property-drawer contents info
)
1180 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1181 CONTENTS holds the contents of the drawer. INFO is a plist
1182 holding contextual information."
1183 (and (org-string-nw-p contents
)
1184 (format "@verbatim\n%s@end verbatim" contents
)))
1188 (defun org-texinfo-quote-block (quote-block contents info
)
1189 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1190 CONTENTS holds the contents of the block. INFO is a plist
1191 holding contextual information."
1192 (let* ((title (org-element-property :name quote-block
))
1193 (start-quote (concat "@quotation"
1195 (format " %s" title
)))))
1196 (format "%s\n%s@end quotation" start-quote contents
)))
1200 (defun org-texinfo-radio-target (radio-target text info
)
1201 "Transcode a RADIO-TARGET object from Org to Texinfo.
1202 TEXT is the text of the target. INFO is a plist holding
1203 contextual information."
1204 (format "@anchor{%s}%s"
1205 (org-export-get-reference radio-target info
)
1210 (defun org-texinfo-section (section contents info
)
1211 "Transcode a SECTION element from Org to Texinfo.
1212 CONTENTS holds the contents of the section. INFO is a plist
1213 holding contextual information."
1215 (let ((parent (org-export-get-parent-headline section
)))
1216 (and parent
(org-texinfo-make-menu parent info
)))))
1220 (defun org-texinfo-special-block (special-block contents info
)
1221 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1222 CONTENTS holds the contents of the block. INFO is a plist used
1223 as a communication channel."
1224 (let ((type (org-element-property :type special-block
)))
1225 (format "@%s\n%s@end %s" type contents type
)))
1229 (defun org-texinfo-src-block (src-block contents info
)
1230 "Transcode a SRC-BLOCK element from Org to Texinfo.
1231 CONTENTS holds the contents of the item. INFO is a plist holding
1232 contextual information."
1233 (let ((lispp (org-string-match-p "lisp"
1234 (org-element-property :language src-block
)))
1235 (code (org-texinfo--sanitize-content
1236 (org-export-format-code-default src-block info
))))
1237 (format (if lispp
"@lisp\n%s@end lisp" "@example\n%s@end example") code
)))
1239 ;;;; Statistics Cookie
1241 (defun org-texinfo-statistics-cookie (statistics-cookie contents info
)
1242 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1243 CONTENTS is nil. INFO is a plist holding contextual information."
1244 (org-element-property :value statistics-cookie
))
1248 (defun org-texinfo-subscript (subscript contents info
)
1249 "Transcode a SUBSCRIPT object from Org to Texinfo.
1250 CONTENTS is the contents of the object. INFO is a plist holding
1251 contextual information."
1252 (format "@math{_%s}" contents
))
1256 (defun org-texinfo-superscript (superscript contents info
)
1257 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1258 CONTENTS is the contents of the object. INFO is a plist holding
1259 contextual information."
1260 (format "@math{^%s}" contents
))
1264 (defun org-texinfo-table (table contents info
)
1265 "Transcode a TABLE element from Org to Texinfo.
1266 CONTENTS is the contents of the table. INFO is a plist holding
1267 contextual information."
1268 (if (eq (org-element-property :type table
) 'table.el
)
1269 (format "@verbatim\n%s@end verbatim"
1270 (org-element-normalize-string
1271 (org-element-property :value table
)))
1272 (let* ((col-width (org-export-read-attribute :attr_texinfo table
:columns
))
1274 (if col-width
(format "@columnfractions %s" col-width
)
1275 (org-texinfo-table-column-widths table info
))))
1276 (format "@multitable %s\n%s@end multitable"
1280 (defun org-texinfo-table-column-widths (table info
)
1281 "Determine the largest table cell in each column to process alignment.
1282 TABLE is the table element to transcode. INFO is a plist used as
1283 a communication channel."
1284 (let ((widths (make-vector (cdr (org-export-table-dimensions table info
)) 0)))
1285 (org-element-map table
'table-row
1288 (org-element-map row
'table-cell
1290 ;; Length of the cell in the original buffer is only an
1291 ;; approximation of the length of the cell in the
1292 ;; output. It can sometimes fail (e.g. it considers
1293 ;; "/a/" being larger than "ab").
1294 (let ((w (- (org-element-property :contents-end cell
)
1295 (org-element-property :contents-begin cell
))))
1296 (aset widths idx
(max w
(aref widths idx
))))
1300 (format "{%s}" (mapconcat (lambda (w) (make-string w ?a
)) widths
"} {"))))
1304 (defun org-texinfo-table-cell (table-cell contents info
)
1305 "Transcode a TABLE-CELL element from Org to Texinfo.
1306 CONTENTS is the cell contents. INFO is a plist used as
1307 a communication channel."
1309 (let ((scientific-notation
1310 (plist-get info
:texinfo-table-scientific-notation
)))
1313 (string-match orgtbl-exp-regexp contents
))
1314 ;; Use appropriate format string for scientific notation.
1315 (format scientific-notation
1316 (match-string 1 contents
)
1317 (match-string 2 contents
))
1319 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1323 (defun org-texinfo-table-row (table-row contents info
)
1324 "Transcode a TABLE-ROW element from Org to Texinfo.
1325 CONTENTS is the contents of the row. INFO is a plist used as
1326 a communication channel."
1327 ;; Rules are ignored since table separators are deduced from
1328 ;; borders of the current row.
1329 (when (eq (org-element-property :type table-row
) 'standard
)
1331 (if (and (= 1 (org-export-table-row-group table-row info
))
1332 (org-export-table-has-header-p
1333 (org-export-get-parent-table table-row
) info
))
1336 (concat rowgroup-tag contents
"\n"))))
1340 (defun org-texinfo-target (target contents info
)
1341 "Transcode a TARGET object from Org to Texinfo.
1342 CONTENTS is nil. INFO is a plist holding contextual
1344 (format "@anchor{%s}" (org-export-get-reference target info
)))
1348 (defun org-texinfo-timestamp (timestamp contents info
)
1349 "Transcode a TIMESTAMP object from Org to Texinfo.
1350 CONTENTS is nil. INFO is a plist holding contextual
1352 (let ((value (org-texinfo-plain-text
1353 (org-timestamp-translate timestamp
) info
)))
1354 (case (org-element-property :type timestamp
)
1355 ((active active-range
)
1356 (format (plist-get info
:texinfo-active-timestamp-format
) value
))
1357 ((inactive inactive-range
)
1358 (format (plist-get info
:texinfo-inactive-timestamp-format
) value
))
1359 (t (format (plist-get info
:texinfo-diary-timestamp-format
) value
)))))
1363 (defun org-texinfo-verbatim (verbatim contents info
)
1364 "Transcode a VERBATIM object from Org to Texinfo.
1365 CONTENTS is nil. INFO is a plist used as a communication
1367 (org-texinfo--text-markup
1368 (org-element-property :value verbatim
) 'verbatim info
))
1372 (defun org-texinfo-verse-block (verse-block contents info
)
1373 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1374 CONTENTS is verse block contents. INFO is a plist holding
1375 contextual information."
1376 (format "@display\n%s@end display" contents
))
1379 ;;; Interactive functions
1381 (defun org-texinfo-export-to-texinfo
1382 (&optional async subtreep visible-only body-only ext-plist
)
1383 "Export current buffer to a Texinfo file.
1385 If narrowing is active in the current buffer, only export its
1388 If a region is active, export that region.
1390 A non-nil optional argument ASYNC means the process should happen
1391 asynchronously. The resulting file should be accessible through
1392 the `org-export-stack' interface.
1394 When optional argument SUBTREEP is non-nil, export the sub-tree
1395 at point, extracting information from the headline properties
1398 When optional argument VISIBLE-ONLY is non-nil, don't export
1399 contents of hidden elements.
1401 When optional argument BODY-ONLY is non-nil, only write code
1402 between \"\\begin{document}\" and \"\\end{document}\".
1404 EXT-PLIST, when provided, is a property list with external
1405 parameters overriding Org default settings, but still inferior to
1406 file-local settings.
1408 Return output file's name."
1410 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1411 (org-export-coding-system org-texinfo-coding-system
))
1412 (org-export-to-file 'texinfo outfile
1413 async subtreep visible-only body-only ext-plist
)))
1415 (defun org-texinfo-export-to-info
1416 (&optional async subtreep visible-only body-only ext-plist
)
1417 "Export current buffer to Texinfo then process through to INFO.
1419 If narrowing is active in the current buffer, only export its
1422 If a region is active, export that region.
1424 A non-nil optional argument ASYNC means the process should happen
1425 asynchronously. The resulting file should be accessible through
1426 the `org-export-stack' interface.
1428 When optional argument SUBTREEP is non-nil, export the sub-tree
1429 at point, extracting information from the headline properties
1432 When optional argument VISIBLE-ONLY is non-nil, don't export
1433 contents of hidden elements.
1435 When optional argument BODY-ONLY is non-nil, only write code
1436 between \"\\begin{document}\" and \"\\end{document}\".
1438 EXT-PLIST, when provided, is a property list with external
1439 parameters overriding Org default settings, but still inferior to
1440 file-local settings.
1442 When optional argument PUB-DIR is set, use it as the publishing
1445 Return INFO file's name."
1447 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1448 (org-export-coding-system org-texinfo-coding-system
))
1449 (org-export-to-file 'texinfo outfile
1450 async subtreep visible-only body-only ext-plist
1451 (lambda (file) (org-texinfo-compile file
)))))
1454 (defun org-texinfo-publish-to-texinfo (plist filename pub-dir
)
1455 "Publish an org file to Texinfo.
1457 FILENAME is the filename of the Org file to be published. PLIST
1458 is the property list for the given project. PUB-DIR is the
1459 publishing directory.
1461 Return output file name."
1462 (org-publish-org-to 'texinfo filename
".texi" plist pub-dir
))
1465 (defun org-texinfo-convert-region-to-texinfo ()
1466 "Assume the current region has org-mode syntax, and convert it to Texinfo.
1467 This can be used in any buffer. For example, you can write an
1468 itemized list in org-mode syntax in an Texinfo buffer and use
1469 this command to convert it."
1471 (org-export-replace-region-by 'texinfo
))
1473 (defun org-texinfo-compile (file)
1474 "Compile a texinfo file.
1476 FILE is the name of the file being compiled. Processing is
1477 done through the command specified in `org-texinfo-info-process'.
1479 Return INFO file name or an error if it couldn't be produced."
1480 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file
)))
1481 (full-name (file-truename file
))
1482 (out-dir (file-name-directory file
))
1483 ;; Properly set working directory for compilation.
1484 (default-directory (if (file-name-absolute-p file
)
1485 (file-name-directory full-name
)
1488 (message (format "Processing Texinfo file %s..." file
))
1489 (save-window-excursion
1490 ;; Replace %b, %f and %o with appropriate values in each command
1491 ;; before applying it. Output is redirected to "*Org INFO
1492 ;; Texinfo Output*" buffer.
1493 (let ((outbuf (get-buffer-create "*Org INFO Texinfo Output*")))
1494 (dolist (command org-texinfo-info-process
)
1496 (replace-regexp-in-string
1497 "%b" (shell-quote-argument base-name
)
1498 (replace-regexp-in-string
1499 "%f" (shell-quote-argument full-name
)
1500 (replace-regexp-in-string
1501 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
1503 ;; Collect standard errors from output buffer.
1504 (setq errors
(org-texinfo-collect-errors outbuf
)))
1505 (let ((infofile (concat out-dir base-name
".info")))
1506 ;; Check for process failure. Provide collected errors if
1508 (if (not (file-exists-p infofile
))
1509 (error (concat (format "INFO file %s wasn't produced" infofile
)
1510 (when errors
(concat ": " errors
))))
1511 ;; Else remove log files, when specified, and signal end of
1512 ;; process to user, along with any error encountered.
1513 (when org-texinfo-remove-logfiles
1514 (dolist (ext org-texinfo-logfiles-extensions
)
1515 (let ((file (concat out-dir base-name
"." ext
)))
1516 (when (file-exists-p file
) (delete-file file
)))))
1517 (message (concat "Process completed"
1518 (if (not errors
) "."
1519 (concat " with errors: " errors
)))))
1520 ;; Return output file name.
1523 (defun org-texinfo-collect-errors (buffer)
1524 "Collect some kind of errors from \"makeinfo\" command output.
1526 BUFFER is the buffer containing output.
1528 Return collected error types as a string, or nil if there was
1530 (with-current-buffer buffer
1532 (goto-char (point-min))
1533 ;; Find final "makeinfo" run.
1535 (let ((case-fold-search t
)
1537 (when (save-excursion
1538 (re-search-forward "perhaps incorrect sectioning?" nil t
))
1539 (setq errors
(concat errors
" [incorrect sectioning]")))
1540 (when (save-excursion
1541 (re-search-forward "missing close brace" nil t
))
1542 (setq errors
(concat errors
" [syntax error]")))
1543 (when (save-excursion
1544 (re-search-forward "Unknown command" nil t
))
1545 (setq errors
(concat errors
" [undefined @command]")))
1546 (when (save-excursion
1547 (re-search-forward "No matching @end" nil t
))
1548 (setq errors
(concat errors
" [block incomplete]")))
1549 (when (save-excursion
1550 (re-search-forward "requires a sectioning" nil t
))
1551 (setq errors
(concat errors
" [invalid section command]")))
1552 (when (save-excursion
1553 (re-search-forward "\\[unexpected\]" nil t
))
1554 (setq errors
(concat errors
" [unexpected error]")))
1555 (when (save-excursion
1556 (re-search-forward "misplaced " nil t
))
1557 (setq errors
(concat errors
" [syntax error]")))
1558 (and (org-string-nw-p errors
) (org-trim errors
)))))))
1561 (provide 'ox-texinfo
)
1564 ;; generated-autoload-file: "org-loaddefs.el"
1567 ;;; ox-texinfo.el ends here