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 (case (org-element-type blob
)
464 (org-export-data (org-export-get-alt-title blob info
) info
))
465 ((radio-target target
) (org-element-property :value blob
))
466 (otherwise (or (org-element-property :name blob
) ""))))))
467 ;; Ensure NAME is unique.
468 (while (rassoc name cache
) (setq name
(concat name
"x")))
469 (plist-put info
:texinfo-node-cache
(cons (cons blob name
) cache
))
474 (defun org-texinfo--sanitize-node (title)
475 "Bend string TITLE to node line requirements.
476 Trim string and collapse multiple whitespace characters as they
477 are not significant. Also remove the following characters: @
479 (replace-regexp-in-string
481 (replace-regexp-in-string
482 "\\`(\\(.*)\\)" "[\\1"
483 (org-trim (replace-regexp-in-string "[ \t]\\{2,\\}" " " title
)))))
485 ;;;; Content sanitizing
487 (defun org-texinfo--sanitize-content (text)
488 "Escape special characters in string TEXT.
489 Special characters are: @ { }"
490 (replace-regexp-in-string "[@{}]" "@\\&" text
))
494 (defun org-texinfo-template (contents info
)
495 "Return complete document string after Texinfo conversion.
496 CONTENTS is the transcoded contents string. INFO is a plist
497 holding export options."
498 (let ((title (org-export-data (plist-get info
:title
) info
))
499 ;; Copying data is the contents of the first headline in
500 ;; parse tree with a non-nil copying property.
501 (copying (org-element-map (plist-get info
:parse-tree
) 'headline
503 (and (org-not-nil (org-element-property :COPYING hl
))
504 (org-element-contents hl
)))
507 "\\input texinfo @c -*- texinfo -*-\n"
508 "@c %**start of header\n"
509 (let ((file (or (plist-get info
:texinfo-filename
)
510 (let ((f (plist-get info
:output-file
)))
511 (and f
(concat (file-name-sans-extension f
) ".info"))))))
512 (and file
(format "@setfilename %s\n" file
)))
513 (format "@settitle %s\n" title
)
514 ;; Insert class-defined header.
515 (org-element-normalize-string
516 (let ((header (nth 1 (assoc (plist-get info
:texinfo-class
)
517 org-texinfo-classes
)))
519 (catch 'coding-system
520 (let ((case-fold-search t
)
521 (name (symbol-name (or org-texinfo-coding-system
522 buffer-file-coding-system
))))
523 (dolist (system org-texinfo-supported-coding-systems
"UTF-8")
524 (when (org-string-match-p (regexp-quote system
) name
)
525 (throw 'coding-system system
))))))
526 (language (plist-get info
:language
))
527 (case-fold-search nil
))
528 ;; Auto coding system.
529 (replace-regexp-in-string
530 "^@documentencoding \\(AUTO\\)$"
532 (replace-regexp-in-string
533 "^@documentlanguage \\(AUTO\\)$" language header t nil
1) t nil
1)))
534 ;; Additional header options set by #+TEXINFO_HEADER.
535 (let ((texinfo-header (plist-get info
:texinfo-header
)))
536 (and texinfo-header
(org-element-normalize-string texinfo-header
)))
537 "@c %**end of header\n\n"
538 ;; Additional options set by #+TEXINFO_POST_HEADER.
539 (let ((texinfo-post-header (plist-get info
:texinfo-post-header
)))
540 (and texinfo-post-header
541 (org-element-normalize-string texinfo-post-header
)))
544 (format "@copying\n%s@end copying\n\n"
545 (org-element-normalize-string
546 (org-export-data copying info
))))
547 ;; Info directory information. Only supply if both title and
548 ;; category are provided.
549 (let ((dircat (plist-get info
:texinfo-dircat
))
551 (let ((title (plist-get info
:texinfo-dirtitle
)))
553 (string-match "^\\(?:\\* \\)?\\(.*?\\)\\(\\.\\)?$" title
)
554 (format "* %s." (match-string 1 title
))))))
555 (when (and dircat dirtitle
)
556 (concat "@dircategory " dircat
"\n"
559 (let ((desc (plist-get info
:texinfo-dirdesc
)))
560 (cond ((not desc
) nil
)
561 ((org-string-match-p "\\.$" desc
) desc
)
562 (t (concat desc
"."))))))
563 (if dirdesc
(format "%-23s %s" dirtitle dirdesc
) dirtitle
))
565 "@end direntry\n\n")))
569 (when (plist-get info
:with-title
)
571 (format "@title %s\n" (or (plist-get info
:texinfo-printed-title
) title
""))
572 (let ((subtitle (plist-get info
:subtitle
)))
574 (format "@subtitle %s\n"
575 (org-export-data subtitle info
))))))
576 (when (plist-get info
:with-author
)
579 (let ((author (org-string-nw-p
580 (org-export-data (plist-get info
:author
) info
)))
581 (email (and (plist-get info
:with-email
)
583 (org-export-data (plist-get info
:email
) info
)))))
584 (cond ((and author email
)
585 (format "@author %s (@email{%s})\n" author email
))
586 (author (format "@author %s\n" author
))
587 (email (format "@author @email{%s}\n" email
))))
589 (let ((subauthor (plist-get info
:subauthor
)))
591 (org-element-normalize-string
592 (replace-regexp-in-string "^" "@author " subauthor
))))))
593 (and copying
"@page\n@vskip 0pt plus 1filll\n@insertcopying\n")
595 ;; Table of contents.
596 (and (plist-get info
:with-toc
) "@contents\n\n")
597 ;; Configure Top Node when not for Tex
600 (format "@top %s\n" title
)
601 (and copying
"@insertcopying\n")
604 (org-texinfo-make-menu (plist-get info
:parse-tree
) info
'master
)
609 (and (plist-get info
:with-creator
)
610 (concat (plist-get info
:creator
) "\n"))
616 ;;; Transcode Functions
620 (defun org-texinfo-bold (bold contents info
)
621 "Transcode BOLD from Org to Texinfo.
622 CONTENTS is the text with bold markup. INFO is a plist holding
623 contextual information."
624 (org-texinfo--text-markup contents
'bold info
))
628 (defun org-texinfo-center-block (center-block contents info
)
629 "Transcode a CENTER-BLOCK element from Org to Texinfo.
630 CONTENTS holds the contents of the block. INFO is a plist used
631 as a communication channel."
636 (defun org-texinfo-clock (clock contents info
)
637 "Transcode a CLOCK element from Org to Texinfo.
638 CONTENTS is nil. INFO is a plist holding contextual
642 (format "@strong{%s} " org-clock-string
)
643 (format (plist-get info
:texinfo-inactive-timestamp-format
)
644 (concat (org-timestamp-translate (org-element-property :value clock
))
645 (let ((time (org-element-property :duration clock
)))
646 (and time
(format " (%s)" time
)))))
651 (defun org-texinfo-code (code contents info
)
652 "Transcode a CODE object from Org to Texinfo.
653 CONTENTS is nil. INFO is a plist used as a communication
655 (org-texinfo--text-markup (org-element-property :value code
) 'code info
))
659 (defun org-texinfo-drawer (drawer contents info
)
660 "Transcode a DRAWER element from Org to Texinfo.
661 CONTENTS holds the contents of the block. INFO is a plist
662 holding contextual information."
663 (let* ((name (org-element-property :drawer-name drawer
))
664 (output (funcall (plist-get info
:texinfo-format-drawer-function
)
670 (defun org-texinfo-dynamic-block (dynamic-block contents info
)
671 "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
672 CONTENTS holds the contents of the block. INFO is a plist
673 holding contextual information."
678 (defun org-texinfo-entity (entity contents info
)
679 "Transcode an ENTITY object from Org to Texinfo.
680 CONTENTS are the definition itself. INFO is a plist holding
681 contextual information."
682 (let ((ent (org-element-property :latex entity
)))
683 (if (org-element-property :latex-math-p entity
) (format "@math{%s}" ent
) ent
)))
687 (defun org-texinfo-example-block (example-block contents info
)
688 "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
689 CONTENTS is nil. INFO is a plist holding contextual
691 (format "@verbatim\n%s@end verbatim"
692 (org-export-format-code-default example-block info
)))
696 (defun org-texinfo-export-block (export-block contents info
)
697 "Transcode a EXPORT-BLOCK element from Org to Texinfo.
698 CONTENTS is nil. INFO is a plist holding contextual information."
699 (when (string= (org-element-property :type export-block
) "TEXINFO")
700 (org-remove-indentation (org-element-property :value export-block
))))
704 (defun org-texinfo-export-snippet (export-snippet contents info
)
705 "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
706 CONTENTS is nil. INFO is a plist holding contextual information."
707 (when (eq (org-export-snippet-backend export-snippet
) 'texinfo
)
708 (org-element-property :value export-snippet
)))
712 (defun org-texinfo-fixed-width (fixed-width contents info
)
713 "Transcode a FIXED-WIDTH element from Org to Texinfo.
714 CONTENTS is nil. INFO is a plist holding contextual information."
715 (format "@example\n%s\n@end example"
716 (org-remove-indentation
717 (org-texinfo--sanitize-content
718 (org-element-property :value fixed-width
)))))
720 ;;;; Footnote Reference
722 (defun org-texinfo-footnote-reference (footnote contents info
)
723 "Create a footnote reference for FOOTNOTE.
725 FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
726 plist holding contextual information."
727 (let ((def (org-export-get-footnote-definition footnote info
)))
728 (format "@footnote{%s}"
729 (org-trim (org-export-data def info
)))))
733 (defun org-texinfo-headline (headline contents info
)
734 "Transcode a HEADLINE element from Org to Texinfo.
735 CONTENTS holds the contents of the headline. INFO is a plist
736 holding contextual information."
737 (let* ((class (plist-get info
:texinfo-class
))
738 (level (org-export-get-relative-level headline info
))
739 (numberedp (org-export-numbered-headline-p headline info
))
740 (class-sectioning (assoc class
(plist-get info
:texinfo-classes
)))
741 ;; Find the index type, if any.
742 (index (org-element-property :INDEX headline
))
743 ;; Create node info, to insert it before section formatting.
744 ;; Use custom menu title if present.
745 (node (format "@node %s\n" (org-texinfo--get-node headline info
)))
746 ;; Section formatting will set two placeholders: one for the
747 ;; title and the other for the contents.
749 (if (org-not-nil (org-element-property :APPENDIX headline
))
751 (let ((sec (if (and (symbolp (nth 2 class-sectioning
))
752 (fboundp (nth 2 class-sectioning
)))
753 (funcall (nth 2 class-sectioning
) level numberedp
)
754 (nth (1+ level
) class-sectioning
))))
756 ;; No section available for that LEVEL.
758 ;; Section format directly returned by a function.
760 ;; (numbered-section . unnumbered-section)
761 ((not (consp (cdr sec
)))
762 (concat (if (or index
(not numberedp
)) (cdr sec
) (car sec
))
765 (and (plist-get info
:with-todo-keywords
)
766 (let ((todo (org-element-property :todo-keyword headline
)))
767 (and todo
(org-export-data todo info
)))))
768 (todo-type (and todo
(org-element-property :todo-type headline
)))
769 (tags (and (plist-get info
:with-tags
)
770 (org-export-get-tags headline info
)))
771 (priority (and (plist-get info
:with-priority
)
772 (org-element-property :priority headline
)))
773 (text (org-export-data (org-element-property :title headline
) info
))
774 (full-text (funcall (plist-get info
:texinfo-format-headline-function
)
775 todo todo-type priority text tags
))
776 (contents (if (org-string-nw-p contents
) (concat "\n" contents
) "")))
778 ;; Case 1: This is a footnote section: ignore it.
779 ((org-element-property :footnote-section-p headline
) nil
)
780 ;; Case 2: This is the `copying' section: ignore it
781 ;; This is used elsewhere.
782 ((org-not-nil (org-element-property :COPYING headline
)) nil
)
783 ;; Case 3: An index. If it matches one of the known indexes,
784 ;; print it as such following the contents, otherwise
785 ;; print the contents and leave the index up to the user.
792 (and (member index
'("cp" "fn" "ky" "pg" "tp" "vr"))
793 (concat "\n@printindex " index
))))))
794 ;; Case 4: This is a deep sub-tree: export it as a list item.
795 ;; Also export as items headlines for which no section
796 ;; format has been found.
797 ((or (not section-fmt
) (org-export-low-level-p headline info
))
798 ;; Build the real contents of the sub-tree.
799 (concat (and (org-export-first-sibling-p headline info
)
800 (format "@%s\n" (if numberedp
'enumerate
'itemize
)))
801 "@item\n" full-text
"\n"
803 (if (org-export-last-sibling-p headline info
)
804 (format "@end %s" (if numberedp
'enumerate
'itemize
))
806 ;; Case 5: Standard headline. Export it as a section.
807 (t (concat node
(format section-fmt full-text contents
))))))
809 (defun org-texinfo-format-headline-default-function
810 (todo todo-type priority text tags
)
811 "Default format function for a headline.
812 See `org-texinfo-format-headline-function' for details."
813 (concat (when todo
(format "@strong{%s} " todo
))
814 (when priority
(format "@emph{#%s} " priority
))
816 (when tags
(format " :%s:" (mapconcat 'identity tags
":")))))
818 ;;;; Inline Src Block
820 (defun org-texinfo-inline-src-block (inline-src-block contents info
)
821 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
822 CONTENTS holds the contents of the item. INFO is a plist holding
823 contextual information."
824 (let* ((code (org-element-property :value inline-src-block
))
825 (separator (org-texinfo--find-verb-separator code
)))
826 (concat "@verb{" separator code separator
"}")))
830 (defun org-texinfo-inlinetask (inlinetask contents info
)
831 "Transcode an INLINETASK element from Org to Texinfo.
832 CONTENTS holds the contents of the block. INFO is a plist
833 holding contextual information."
834 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
835 (todo (and (plist-get info
:with-todo-keywords
)
836 (let ((todo (org-element-property :todo-keyword inlinetask
)))
837 (and todo
(org-export-data todo info
)))))
838 (todo-type (org-element-property :todo-type inlinetask
))
839 (tags (and (plist-get info
:with-tags
)
840 (org-export-get-tags inlinetask info
)))
841 (priority (and (plist-get info
:with-priority
)
842 (org-element-property :priority inlinetask
))))
843 (funcall (plist-get info
:texinfo-format-inlinetask-function
)
844 todo todo-type priority title tags contents
)))
846 (defun org-texinfo-format-inlinetask-default-function
847 (todo todo-type priority title tags contents
)
848 "Default format function for a inlinetasks.
849 See `org-texinfo-format-inlinetask-function' for details."
851 (concat (when todo
(format "@strong{%s} " todo
))
852 (when priority
(format "#%c " priority
))
854 (when tags
(format ":%s:" (mapconcat #'identity tags
":"))))))
855 (format "@center %s\n\n%s\n" full-title contents
)))
859 (defun org-texinfo-italic (italic contents info
)
860 "Transcode ITALIC from Org to Texinfo.
861 CONTENTS is the text with italic markup. INFO is a plist holding
862 contextual information."
863 (org-texinfo--text-markup contents
'italic info
))
867 (defun org-texinfo-item (item contents info
)
868 "Transcode an ITEM element from Org to Texinfo.
869 CONTENTS holds the contents of the item. INFO is a plist holding
870 contextual information."
871 (format "@item%s\n%s"
872 (let ((tag (org-element-property :tag item
)))
873 (if tag
(concat " " (org-export-data tag info
)) ""))
878 (defun org-texinfo-keyword (keyword contents info
)
879 "Transcode a KEYWORD element from Org to Texinfo.
880 CONTENTS is nil. INFO is a plist holding contextual information."
881 (let ((key (org-element-property :key keyword
))
882 (value (org-element-property :value keyword
)))
884 ((string= key
"TEXINFO") value
)
885 ((string= key
"CINDEX") (format "@cindex %s" value
))
886 ((string= key
"FINDEX") (format "@findex %s" value
))
887 ((string= key
"KINDEX") (format "@kindex %s" value
))
888 ((string= key
"PINDEX") (format "@pindex %s" value
))
889 ((string= key
"TINDEX") (format "@tindex %s" value
))
890 ((string= key
"VINDEX") (format "@vindex %s" value
)))))
894 (defun org-texinfo-line-break (line-break contents info
)
895 "Transcode a LINE-BREAK object from Org to Texinfo.
896 CONTENTS is nil. INFO is a plist holding contextual information."
901 (defun org-texinfo-link (link desc info
)
902 "Transcode a LINK object from Org to Texinfo.
904 DESC is the description part of the link, or the empty string.
905 INFO is a plist holding contextual information. See
907 (let* ((type (org-element-property :type link
))
908 (raw-path (org-element-property :path link
))
909 ;; Ensure DESC really exists, or set it to nil.
910 (desc (and (not (string= desc
"")) desc
))
912 ((member type
'("http" "https" "ftp"))
913 (concat type
":" raw-path
))
914 ((and (string= type
"file") (file-name-absolute-p raw-path
))
915 (concat "file:" raw-path
))
918 ((org-export-custom-protocol-maybe link desc
'texinfo
))
919 ((equal type
"radio")
920 (let ((destination (org-export-resolve-radio-link link info
)))
921 (if (not destination
) desc
922 (format "@ref{%s,,%s}"
923 (org-texinfo--get-node destination info
)
925 ((member type
'("custom-id" "id" "fuzzy"))
927 (if (equal type
"fuzzy")
928 (org-export-resolve-fuzzy-link link info
)
929 (org-export-resolve-id-link link info
))))
930 (case (org-element-type destination
)
932 (format org-texinfo-link-with-unknown-path-format
933 (org-texinfo--sanitize-content path
)))
934 ;; Id link points to an external file.
936 (if desc
(format "@uref{file://%s,%s}" destination desc
)
937 (format "@uref{file://%s}" destination
)))
939 (format "@ref{%s,%s}"
940 (org-texinfo--get-node destination info
)
943 ((org-export-numbered-headline-p destination info
)
945 (org-element-property :title destination
) info
))
949 (org-export-get-headline-number destination info
) ".")))))
953 (if (and (eq (org-element-type destination
) 'headline
)
954 (not (org-export-numbered-headline-p
957 (org-element-property :title destination
) info
))
958 (let ((n (org-export-get-ordinal destination info
)))
962 (t (mapconcat #'number-to-string n
".")))))))
964 (format "@ref{%s,,%s}"
965 (org-texinfo--get-node destination info
)
968 (let* ((info-path (split-string path
"[:#]"))
969 (info-manual (car info-path
))
970 (info-node (or (cadr info-path
) "top"))
971 (title (or desc
"")))
972 (format "@ref{%s,%s,,%s,}" info-node title info-manual
)))
973 ((string= type
"mailto")
975 (concat (org-texinfo--sanitize-content path
)
976 (and desc
(concat "," desc
)))))
977 ;; External link with a description part.
978 ((and path desc
) (format "@uref{%s,%s}" path desc
))
979 ;; External link without a description part.
980 (path (format "@uref{%s}" path
))
981 ;; No path, only description. Try to do something useful.
983 (format (plist-get info
:texinfo-link-with-unknown-path-format
) desc
)))))
988 (defun org-texinfo-make-menu (scope info
&optional master
)
989 "Create the menu for inclusion in the Texinfo document.
991 SCOPE is a headline or a full parse tree. INFO is the
992 communication channel, as a plist.
994 When optional argument MASTER is non-nil, generate a master menu,
995 including detailed node listing."
996 (let ((menu (org-texinfo--build-menu scope info
)))
997 (when (org-string-nw-p menu
)
998 (org-element-normalize-string
1000 "@menu\n%s@end menu"
1004 (org-texinfo--build-menu
1006 (let ((toc-depth (plist-get info
:with-toc
)))
1007 (if (wholenump toc-depth
) toc-depth
1008 org-texinfo-max-toc-depth
)))))
1009 (when (org-string-nw-p detailmenu
)
1010 (concat "\n@detailmenu\n"
1011 "--- The Detailed Node Listing ---\n\n"
1013 "@end detailmenu\n"))))))))))
1015 (defun org-texinfo--build-menu (scope info
&optional level
)
1016 "Build menu for entries within SCOPE.
1017 SCOPE is a headline or a full parse tree. INFO is a plist
1018 containing contextual information. When optional argument LEVEL
1019 is an integer, build the menu recursively, down to this depth."
1022 (org-texinfo--format-entries (org-texinfo--menu-entries scope info
) info
))
1025 (org-element-normalize-string
1028 (let ((entries (org-texinfo--menu-entries h info
)))
1031 (format "%s\n\n%s\n"
1032 (org-export-data (org-export-get-alt-title h info
) info
)
1033 (org-texinfo--format-entries entries info
))
1034 (org-texinfo--build-menu h info
(1- level
))))))
1035 (org-texinfo--menu-entries scope info
) "")))))
1037 (defun org-texinfo--format-entries (entries info
)
1038 "Format all direct menu entries in SCOPE, as a string.
1039 SCOPE is either a headline or a full Org document. INFO is
1040 a plist containing contextual information."
1041 (org-element-normalize-string
1044 (let* ((title (org-export-data
1045 (org-export-get-alt-title h info
) info
))
1046 (node (org-texinfo--get-node h info
))
1047 (entry (concat "* " title
":"
1048 (if (string= title node
) ":"
1049 (concat " " node
". "))))
1050 (desc (org-element-property :DESCRIPTION h
)))
1051 (if (not desc
) entry
1052 (format (format "%%-%ds %%s" org-texinfo-node-description-column
)
1056 (defun org-texinfo--menu-entries (scope info
)
1057 "List direct children in SCOPE needing a menu entry.
1058 SCOPE is a headline or a full parse tree. INFO is a plist
1059 holding contextual information."
1060 (let* ((cache (or (plist-get info
:texinfo-entries-cache
)
1061 (plist-get (plist-put info
:texinfo-entries-cache
1062 (make-hash-table :test
#'eq
))
1063 :texinfo-entries-cache
)))
1064 (cached-entries (gethash scope cache
'no-cache
)))
1065 (if (not (eq cached-entries
'no-cache
)) cached-entries
1067 (org-element-map (org-element-contents scope
) 'headline
1069 (and (not (org-not-nil (org-element-property :COPYING h
)))
1070 (not (org-element-property :footnote-section-p h
))
1071 (not (org-export-low-level-p h info
))
1078 (defun org-texinfo-node-property (node-property contents info
)
1079 "Transcode a NODE-PROPERTY element from Org to Texinfo.
1080 CONTENTS is nil. INFO is a plist holding contextual
1083 (org-element-property :key node-property
)
1084 (let ((value (org-element-property :value node-property
)))
1085 (if value
(concat " " value
) ""))))
1089 (defun org-texinfo-paragraph (paragraph contents info
)
1090 "Transcode a PARAGRAPH element from Org to Texinfo.
1091 CONTENTS is the contents of the paragraph, as a string. INFO is
1092 the plist used as a communication channel."
1097 (defun org-texinfo-plain-list (plain-list contents info
)
1098 "Transcode a PLAIN-LIST element from Org to Texinfo.
1099 CONTENTS is the contents of the list. INFO is a plist holding
1100 contextual information."
1101 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1102 (indic (or (plist-get attr
:indic
)
1103 (plist-get info
:texinfo-def-table-markup
)))
1104 (table-type (plist-get attr
:table-type
))
1105 (type (org-element-property :type plain-list
))
1107 ((eq type
'ordered
) "enumerate")
1108 ((eq type
'unordered
) "itemize")
1109 ((member table-type
'("ftable" "vtable")) table-type
)
1111 (format "@%s\n%s@end %s"
1112 (if (eq type
'descriptive
) (concat list-type
" " indic
) list-type
)
1118 (defun org-texinfo-plain-text (text info
)
1119 "Transcode a TEXT string from Org to Texinfo.
1120 TEXT is the string to transcode. INFO is a plist holding
1121 contextual information."
1122 ;; First protect @, { and }.
1123 (let ((output (org-texinfo--sanitize-content text
)))
1124 ;; Activate smart quotes. Be sure to provide original TEXT string
1125 ;; since OUTPUT may have been modified.
1126 (when (plist-get info
:with-smart-quotes
)
1128 (org-export-activate-smart-quotes output
:texinfo info text
)))
1129 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1130 (let ((case-fold-search nil
)
1132 (while (string-match "\\(\\(?:La\\)?TeX\\)" output start
)
1133 (setq output
(replace-match
1134 (format "@%s{}" (match-string 1 output
)) nil t output
)
1135 start
(match-end 0))))
1136 ;; Convert special strings.
1137 (when (plist-get info
:with-special-strings
)
1138 (while (string-match (regexp-quote "...") output
)
1139 (setq output
(replace-match "@dots{}" nil t output
))))
1140 ;; Handle break preservation if required.
1141 (when (plist-get info
:preserve-breaks
)
1142 (setq output
(replace-regexp-in-string
1143 "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output
)))
1149 (defun org-texinfo-planning (planning contents info
)
1150 "Transcode a PLANNING element from Org to Texinfo.
1151 CONTENTS is nil. INFO is a plist holding contextual
1159 (let ((closed (org-element-property :closed planning
)))
1162 (format "@strong{%s} " org-closed-string
)
1163 (format (plist-get info
:texinfo-inactive-timestamp-format
)
1164 (org-timestamp-translate closed
)))))
1165 (let ((deadline (org-element-property :deadline planning
)))
1168 (format "@strong{%s} " org-deadline-string
)
1169 (format (plist-get info
:texinfo-active-timestamp-format
)
1170 (org-timestamp-translate deadline
)))))
1171 (let ((scheduled (org-element-property :scheduled planning
)))
1174 (format "@strong{%s} " org-scheduled-string
)
1175 (format (plist-get info
:texinfo-active-timestamp-format
)
1176 (org-timestamp-translate scheduled
)))))))
1180 ;;;; Property Drawer
1182 (defun org-texinfo-property-drawer (property-drawer contents info
)
1183 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1184 CONTENTS holds the contents of the drawer. INFO is a plist
1185 holding contextual information."
1186 (and (org-string-nw-p contents
)
1187 (format "@verbatim\n%s@end verbatim" contents
)))
1191 (defun org-texinfo-quote-block (quote-block contents info
)
1192 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1193 CONTENTS holds the contents of the block. INFO is a plist
1194 holding contextual information."
1195 (let* ((title (org-element-property :name quote-block
))
1196 (start-quote (concat "@quotation"
1198 (format " %s" title
)))))
1199 (format "%s\n%s@end quotation" start-quote contents
)))
1203 (defun org-texinfo-radio-target (radio-target text info
)
1204 "Transcode a RADIO-TARGET object from Org to Texinfo.
1205 TEXT is the text of the target. INFO is a plist holding
1206 contextual information."
1207 (format "@anchor{%s}%s"
1208 (org-export-solidify-link-text
1209 (org-element-property :value radio-target
))
1214 (defun org-texinfo-section (section contents info
)
1215 "Transcode a SECTION element from Org to Texinfo.
1216 CONTENTS holds the contents of the section. INFO is a plist
1217 holding contextual information."
1219 (let ((parent (org-export-get-parent-headline section
)))
1220 (and parent
(org-texinfo-make-menu parent info
)))))
1224 (defun org-texinfo-special-block (special-block contents info
)
1225 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1226 CONTENTS holds the contents of the block. INFO is a plist used
1227 as a communication channel."
1228 (let ((type (org-element-property :type special-block
)))
1229 (format "@%s\n%s@end %s" type contents type
)))
1233 (defun org-texinfo-src-block (src-block contents info
)
1234 "Transcode a SRC-BLOCK element from Org to Texinfo.
1235 CONTENTS holds the contents of the item. INFO is a plist holding
1236 contextual information."
1237 (let ((lispp (org-string-match-p "lisp"
1238 (org-element-property :language src-block
)))
1239 (code (org-texinfo--sanitize-content
1240 (org-export-format-code-default src-block info
))))
1241 (format (if lispp
"@lisp\n%s@end lisp" "@example\n%s@end example") code
)))
1243 ;;;; Statistics Cookie
1245 (defun org-texinfo-statistics-cookie (statistics-cookie contents info
)
1246 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1247 CONTENTS is nil. INFO is a plist holding contextual information."
1248 (org-element-property :value statistics-cookie
))
1252 (defun org-texinfo-subscript (subscript contents info
)
1253 "Transcode a SUBSCRIPT object from Org to Texinfo.
1254 CONTENTS is the contents of the object. INFO is a plist holding
1255 contextual information."
1256 (format "@math{_%s}" contents
))
1260 (defun org-texinfo-superscript (superscript contents info
)
1261 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1262 CONTENTS is the contents of the object. INFO is a plist holding
1263 contextual information."
1264 (format "@math{^%s}" contents
))
1268 (defun org-texinfo-table (table contents info
)
1269 "Transcode a TABLE element from Org to Texinfo.
1270 CONTENTS is the contents of the table. INFO is a plist holding
1271 contextual information."
1272 (if (eq (org-element-property :type table
) 'table.el
)
1273 (format "@verbatim\n%s@end verbatim"
1274 (org-element-normalize-string
1275 (org-element-property :value table
)))
1276 (let* ((col-width (org-export-read-attribute :attr_texinfo table
:columns
))
1278 (if col-width
(format "@columnfractions %s" col-width
)
1279 (org-texinfo-table-column-widths table info
))))
1280 (format "@multitable %s\n%s@end multitable"
1284 (defun org-texinfo-table-column-widths (table info
)
1285 "Determine the largest table cell in each column to process alignment.
1286 TABLE is the table element to transcode. INFO is a plist used as
1287 a communication channel."
1288 (let ((widths (make-vector (cdr (org-export-table-dimensions table info
)) 0)))
1289 (org-element-map table
'table-row
1292 (org-element-map row
'table-cell
1294 ;; Length of the cell in the original buffer is only an
1295 ;; approximation of the length of the cell in the
1296 ;; output. It can sometimes fail (e.g. it considers
1297 ;; "/a/" being larger than "ab").
1298 (let ((w (- (org-element-property :contents-end cell
)
1299 (org-element-property :contents-begin cell
))))
1300 (aset widths idx
(max w
(aref widths idx
))))
1304 (format "{%s}" (mapconcat (lambda (w) (make-string w ?a
)) widths
"} {"))))
1308 (defun org-texinfo-table-cell (table-cell contents info
)
1309 "Transcode a TABLE-CELL element from Org to Texinfo.
1310 CONTENTS is the cell contents. INFO is a plist used as
1311 a communication channel."
1313 (let ((scientific-notation
1314 (plist-get info
:texinfo-table-scientific-notation
)))
1317 (string-match orgtbl-exp-regexp contents
))
1318 ;; Use appropriate format string for scientific notation.
1319 (format scientific-notation
1320 (match-string 1 contents
)
1321 (match-string 2 contents
))
1323 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1327 (defun org-texinfo-table-row (table-row contents info
)
1328 "Transcode a TABLE-ROW element from Org to Texinfo.
1329 CONTENTS is the contents of the row. INFO is a plist used as
1330 a communication channel."
1331 ;; Rules are ignored since table separators are deduced from
1332 ;; borders of the current row.
1333 (when (eq (org-element-property :type table-row
) 'standard
)
1335 (if (and (= 1 (org-export-table-row-group table-row info
))
1336 (org-export-table-has-header-p
1337 (org-export-get-parent-table table-row
) info
))
1340 (concat rowgroup-tag contents
"\n"))))
1344 (defun org-texinfo-target (target contents info
)
1345 "Transcode a TARGET object from Org to Texinfo.
1346 CONTENTS is nil. INFO is a plist holding contextual
1348 (format "@anchor{%s}"
1349 (org-export-solidify-link-text (org-element-property :value target
))))
1353 (defun org-texinfo-timestamp (timestamp contents info
)
1354 "Transcode a TIMESTAMP object from Org to Texinfo.
1355 CONTENTS is nil. INFO is a plist holding contextual
1357 (let ((value (org-texinfo-plain-text
1358 (org-timestamp-translate timestamp
) info
)))
1359 (case (org-element-property :type timestamp
)
1360 ((active active-range
)
1361 (format (plist-get info
:texinfo-active-timestamp-format
) value
))
1362 ((inactive inactive-range
)
1363 (format (plist-get info
:texinfo-inactive-timestamp-format
) value
))
1364 (t (format (plist-get info
:texinfo-diary-timestamp-format
) value
)))))
1368 (defun org-texinfo-verbatim (verbatim contents info
)
1369 "Transcode a VERBATIM object from Org to Texinfo.
1370 CONTENTS is nil. INFO is a plist used as a communication
1372 (org-texinfo--text-markup
1373 (org-element-property :value verbatim
) 'verbatim info
))
1377 (defun org-texinfo-verse-block (verse-block contents info
)
1378 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1379 CONTENTS is verse block contents. INFO is a plist holding
1380 contextual information."
1381 (format "@display\n%s@end display" contents
))
1384 ;;; Interactive functions
1386 (defun org-texinfo-export-to-texinfo
1387 (&optional async subtreep visible-only body-only ext-plist
)
1388 "Export current buffer to a Texinfo file.
1390 If narrowing is active in the current buffer, only export its
1393 If a region is active, export that region.
1395 A non-nil optional argument ASYNC means the process should happen
1396 asynchronously. The resulting file should be accessible through
1397 the `org-export-stack' interface.
1399 When optional argument SUBTREEP is non-nil, export the sub-tree
1400 at point, extracting information from the headline properties
1403 When optional argument VISIBLE-ONLY is non-nil, don't export
1404 contents of hidden elements.
1406 When optional argument BODY-ONLY is non-nil, only write code
1407 between \"\\begin{document}\" and \"\\end{document}\".
1409 EXT-PLIST, when provided, is a property list with external
1410 parameters overriding Org default settings, but still inferior to
1411 file-local settings.
1413 Return output file's name."
1415 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1416 (org-export-coding-system org-texinfo-coding-system
))
1417 (org-export-to-file 'texinfo outfile
1418 async subtreep visible-only body-only ext-plist
)))
1420 (defun org-texinfo-export-to-info
1421 (&optional async subtreep visible-only body-only ext-plist
)
1422 "Export current buffer to Texinfo then process through to INFO.
1424 If narrowing is active in the current buffer, only export its
1427 If a region is active, export that region.
1429 A non-nil optional argument ASYNC means the process should happen
1430 asynchronously. The resulting file should be accessible through
1431 the `org-export-stack' interface.
1433 When optional argument SUBTREEP is non-nil, export the sub-tree
1434 at point, extracting information from the headline properties
1437 When optional argument VISIBLE-ONLY is non-nil, don't export
1438 contents of hidden elements.
1440 When optional argument BODY-ONLY is non-nil, only write code
1441 between \"\\begin{document}\" and \"\\end{document}\".
1443 EXT-PLIST, when provided, is a property list with external
1444 parameters overriding Org default settings, but still inferior to
1445 file-local settings.
1447 When optional argument PUB-DIR is set, use it as the publishing
1450 Return INFO file's name."
1452 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1453 (org-export-coding-system org-texinfo-coding-system
))
1454 (org-export-to-file 'texinfo outfile
1455 async subtreep visible-only body-only ext-plist
1456 (lambda (file) (org-texinfo-compile file
)))))
1459 (defun org-texinfo-publish-to-texinfo (plist filename pub-dir
)
1460 "Publish an org file to Texinfo.
1462 FILENAME is the filename of the Org file to be published. PLIST
1463 is the property list for the given project. PUB-DIR is the
1464 publishing directory.
1466 Return output file name."
1467 (org-publish-org-to 'texinfo filename
".texi" plist pub-dir
))
1470 (defun org-texinfo-convert-region-to-texinfo ()
1471 "Assume the current region has org-mode syntax, and convert it to Texinfo.
1472 This can be used in any buffer. For example, you can write an
1473 itemized list in org-mode syntax in an Texinfo buffer and use
1474 this command to convert it."
1476 (org-export-replace-region-by 'texinfo
))
1478 (defun org-texinfo-compile (file)
1479 "Compile a texinfo file.
1481 FILE is the name of the file being compiled. Processing is
1482 done through the command specified in `org-texinfo-info-process'.
1484 Return INFO file name or an error if it couldn't be produced."
1485 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file
)))
1486 (full-name (file-truename file
))
1487 (out-dir (file-name-directory file
))
1488 ;; Properly set working directory for compilation.
1489 (default-directory (if (file-name-absolute-p file
)
1490 (file-name-directory full-name
)
1493 (message (format "Processing Texinfo file %s..." file
))
1494 (save-window-excursion
1495 ;; Replace %b, %f and %o with appropriate values in each command
1496 ;; before applying it. Output is redirected to "*Org INFO
1497 ;; Texinfo Output*" buffer.
1498 (let ((outbuf (get-buffer-create "*Org INFO Texinfo Output*")))
1499 (dolist (command org-texinfo-info-process
)
1501 (replace-regexp-in-string
1502 "%b" (shell-quote-argument base-name
)
1503 (replace-regexp-in-string
1504 "%f" (shell-quote-argument full-name
)
1505 (replace-regexp-in-string
1506 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
1508 ;; Collect standard errors from output buffer.
1509 (setq errors
(org-texinfo-collect-errors outbuf
)))
1510 (let ((infofile (concat out-dir base-name
".info")))
1511 ;; Check for process failure. Provide collected errors if
1513 (if (not (file-exists-p infofile
))
1514 (error (concat (format "INFO file %s wasn't produced" infofile
)
1515 (when errors
(concat ": " errors
))))
1516 ;; Else remove log files, when specified, and signal end of
1517 ;; process to user, along with any error encountered.
1518 (when org-texinfo-remove-logfiles
1519 (dolist (ext org-texinfo-logfiles-extensions
)
1520 (let ((file (concat out-dir base-name
"." ext
)))
1521 (when (file-exists-p file
) (delete-file file
)))))
1522 (message (concat "Process completed"
1523 (if (not errors
) "."
1524 (concat " with errors: " errors
)))))
1525 ;; Return output file name.
1528 (defun org-texinfo-collect-errors (buffer)
1529 "Collect some kind of errors from \"makeinfo\" command output.
1531 BUFFER is the buffer containing output.
1533 Return collected error types as a string, or nil if there was
1535 (with-current-buffer buffer
1537 (goto-char (point-min))
1538 ;; Find final "makeinfo" run.
1540 (let ((case-fold-search t
)
1542 (when (save-excursion
1543 (re-search-forward "perhaps incorrect sectioning?" nil t
))
1544 (setq errors
(concat errors
" [incorrect sectioning]")))
1545 (when (save-excursion
1546 (re-search-forward "missing close brace" nil t
))
1547 (setq errors
(concat errors
" [syntax error]")))
1548 (when (save-excursion
1549 (re-search-forward "Unknown command" nil t
))
1550 (setq errors
(concat errors
" [undefined @command]")))
1551 (when (save-excursion
1552 (re-search-forward "No matching @end" nil t
))
1553 (setq errors
(concat errors
" [block incomplete]")))
1554 (when (save-excursion
1555 (re-search-forward "requires a sectioning" nil t
))
1556 (setq errors
(concat errors
" [invalid section command]")))
1557 (when (save-excursion
1558 (re-search-forward "\\[unexpected\]" nil t
))
1559 (setq errors
(concat errors
" [unexpected error]")))
1560 (when (save-excursion
1561 (re-search-forward "misplaced " nil t
))
1562 (setq errors
(concat errors
" [syntax error]")))
1563 (and (org-string-nw-p errors
) (org-trim errors
)))))))
1566 (provide 'ox-texinfo
)
1569 ;; generated-autoload-file: "org-loaddefs.el"
1572 ;;; ox-texinfo.el ends here