1 ;;; ox-texinfo.el --- Texinfo Back-End for Org Export Engine
3 ;; Copyright (C) 2012-2014 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 (comment .
(lambda (&rest args
) ""))
43 (comment-block .
(lambda (&rest args
) ""))
44 (drawer . org-texinfo-drawer
)
45 (dynamic-block . org-texinfo-dynamic-block
)
46 (entity . org-texinfo-entity
)
47 (example-block . org-texinfo-example-block
)
48 (export-snippet . org-texinfo-export-snippet
)
49 (fixed-width . org-texinfo-fixed-width
)
50 (footnote-definition . org-texinfo-footnote-definition
)
51 (footnote-reference . org-texinfo-footnote-reference
)
52 (headline . org-texinfo-headline
)
53 (inline-src-block . org-texinfo-inline-src-block
)
54 (inlinetask . org-texinfo-inlinetask
)
55 (italic . org-texinfo-italic
)
56 (item . org-texinfo-item
)
57 (keyword . org-texinfo-keyword
)
58 (line-break . org-texinfo-line-break
)
59 (link . org-texinfo-link
)
60 (node-property . org-texinfo-node-property
)
61 (paragraph . org-texinfo-paragraph
)
62 (plain-list . org-texinfo-plain-list
)
63 (plain-text . org-texinfo-plain-text
)
64 (planning . org-texinfo-planning
)
65 (property-drawer . org-texinfo-property-drawer
)
66 (quote-block . org-texinfo-quote-block
)
67 (radio-target . org-texinfo-radio-target
)
68 (section . org-texinfo-section
)
69 (special-block . org-texinfo-special-block
)
70 (src-block . org-texinfo-src-block
)
71 (statistics-cookie . org-texinfo-statistics-cookie
)
72 (subscript . org-texinfo-subscript
)
73 (superscript . org-texinfo-superscript
)
74 (table . org-texinfo-table
)
75 (table-cell . org-texinfo-table-cell
)
76 (table-row . org-texinfo-table-row
)
77 (target . org-texinfo-target
)
78 (template . org-texinfo-template
)
79 (timestamp . org-texinfo-timestamp
)
80 (verbatim . org-texinfo-verbatim
)
81 (verse-block . org-texinfo-verse-block
))
82 :export-block
"TEXINFO"
84 '((:filter-headline . org-texinfo-filter-section-blank-lines
)
85 (:filter-parse-tree . org-texinfo--normalize-headlines
)
86 (:filter-section . org-texinfo-filter-section-blank-lines
))
88 '(?i
"Export to Texinfo"
89 ((?t
"As TEXI file" org-texinfo-export-to-texinfo
)
90 (?i
"As INFO file" org-texinfo-export-to-info
)))
92 '((:texinfo-filename
"TEXINFO_FILENAME" nil nil t
)
93 (:texinfo-class
"TEXINFO_CLASS" nil org-texinfo-default-class t
)
94 (:texinfo-header
"TEXINFO_HEADER" nil nil newline
)
95 (:texinfo-post-header
"TEXINFO_POST_HEADER" nil nil newline
)
96 (:subtitle
"SUBTITLE" nil nil newline
)
97 (:subauthor
"SUBAUTHOR" nil nil newline
)
98 (:texinfo-dircat
"TEXINFO_DIR_CATEGORY" nil nil t
)
99 (:texinfo-dirtitle
"TEXINFO_DIR_TITLE" nil nil t
)
100 (:texinfo-dirdesc
"TEXINFO_DIR_DESC" nil nil t
)
101 (:texinfo-printed-title
"TEXINFO_PRINTED_TITLE" nil nil t
)
103 (:texinfo-classes nil nil org-texinfo-classes
)
104 (:texinfo-format-headline-function nil nil org-texinfo-format-headline-function
)
105 (:texinfo-node-description-column nil nil org-texinfo-node-description-column
)
106 (:texinfo-active-timestamp-format nil nil org-texinfo-active-timestamp-format
)
107 (:texinfo-inactive-timestamp-format nil nil org-texinfo-inactive-timestamp-format
)
108 (:texinfo-diary-timestamp-format nil nil org-texinfo-diary-timestamp-format
)
109 (:texinfo-link-with-unknown-path-format nil nil org-texinfo-link-with-unknown-path-format
)
110 (:texinfo-tables-verbatim nil nil org-texinfo-tables-verbatim
)
111 (:texinfo-table-scientific-notation nil nil org-texinfo-table-scientific-notation
)
112 (:texinfo-def-table-markup nil nil org-texinfo-def-table-markup
)
113 (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist
)
114 (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function
)
115 (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function
)))
119 ;;; User Configurable Variables
121 (defgroup org-export-texinfo nil
122 "Options for exporting Org mode files to Texinfo."
123 :tag
"Org Export Texinfo"
125 :package-version
'(Org .
"8.0")
130 (defcustom org-texinfo-coding-system nil
131 "Default document encoding for Texinfo output.
133 If `nil' it will default to `buffer-file-coding-system'."
134 :group
'org-export-texinfo
135 :type
'coding-system
)
137 (defcustom org-texinfo-default-class
"info"
138 "The default Texinfo class."
139 :group
'org-export-texinfo
140 :type
'(string :tag
"Texinfo class"))
142 (defcustom org-texinfo-classes
144 "@documentencoding AUTO\n@documentlanguage AUTO"
145 ("@chapter %s" .
"@unnumbered %s")
146 ("@section %s" .
"@unnumberedsec %s")
147 ("@subsection %s" .
"@unnumberedsubsec %s")
148 ("@subsubsection %s" .
"@unnumberedsubsubsec %s")))
149 "Alist of Texinfo classes and associated header and structure.
150 If #+TEXINFO_CLASS is set in the buffer, use its value and the
151 associated information. Here is the structure of each cell:
155 \(numbered-section . unnumbered-section)
162 The header string is inserted in the header of the generated
163 document, right after \"@setfilename\" and \"@settitle\"
166 If it contains the special string
168 \"@documentencoding AUTO\"
170 \"AUTO\" will be replaced with an appropriate coding system. See
171 `org-texinfo-coding-system' for more information. Likewise, if
172 the string contains the special string
174 \"@documentlanguage AUTO\"
176 \"AUTO\" will be replaced with the language defined in the
177 buffer, through #+LANGUAGE keyword, or globally, with
178 `org-export-default-language', which see.
181 The sectioning structure
182 ------------------------
184 The sectioning structure of the class is given by the elements
185 following the header string. For each sectioning level, a number
186 of strings is specified. A %s formatter is mandatory in each
187 section string and will be replaced by the title of the section.
189 Instead of a list of sectioning commands, you can also specify
190 a function name. That function will be called with two
191 parameters, the reduced) level of the headline, and a predicate
192 non-nil when the headline should be numbered. It must return
193 a format string in which the section title will be added."
194 :group
'org-export-texinfo
196 :package-version
'(Org .
"8.2")
198 (list (string :tag
"Texinfo class")
199 (string :tag
"Texinfo header")
200 (repeat :tag
"Levels" :inline t
203 (string :tag
" numbered")
204 (string :tag
"unnumbered"))
205 (function :tag
"Hook computing sectioning"))))))
209 (defcustom org-texinfo-format-headline-function
210 'org-texinfo-format-headline-default-function
211 "Function to format headline text.
213 This function will be called with 5 arguments:
214 TODO the todo keyword (string or nil).
215 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
216 PRIORITY the priority of the headline (integer or nil)
217 TEXT the main headline text (string).
218 TAGS the tags as a list of strings (list of strings or nil).
220 The function result will be used in the section format string."
221 :group
'org-export-texinfo
224 :package-version
'(Org .
"8.3"))
226 ;;;; Node listing (menu)
228 (defcustom org-texinfo-node-description-column
32
229 "Column at which to start the description in the node listings.
230 If a node title is greater than this length, the description will
231 be placed after the end of the title."
232 :group
'org-export-texinfo
237 (defcustom org-texinfo-active-timestamp-format
"@emph{%s}"
238 "A printf format string to be applied to active timestamps."
239 :group
'org-export-texinfo
242 (defcustom org-texinfo-inactive-timestamp-format
"@emph{%s}"
243 "A printf format string to be applied to inactive timestamps."
244 :group
'org-export-texinfo
247 (defcustom org-texinfo-diary-timestamp-format
"@emph{%s}"
248 "A printf format string to be applied to diary timestamps."
249 :group
'org-export-texinfo
254 (defcustom org-texinfo-link-with-unknown-path-format
"@indicateurl{%s}"
255 "Format string for links with unknown path type."
256 :group
'org-export-texinfo
261 (defcustom org-texinfo-tables-verbatim nil
262 "When non-nil, tables are exported verbatim."
263 :group
'org-export-texinfo
266 (defcustom org-texinfo-table-scientific-notation
"%s\\,(%s)"
267 "Format string to display numbers in scientific notation.
268 The format should have \"%s\" twice, for mantissa and exponent
269 \(i.e. \"%s\\\\times10^{%s}\").
271 When nil, no transformation is made."
272 :group
'org-export-texinfo
274 (string :tag
"Format string")
275 (const :tag
"No formatting" nil
)))
277 (defcustom org-texinfo-def-table-markup
"@samp"
278 "Default setting for @table environments."
279 :group
'org-export-texinfo
284 (defcustom org-texinfo-text-markup-alist
'((bold .
"@strong{%s}")
286 (italic .
"@emph{%s}")
289 "Alist of Texinfo expressions to convert text markup.
291 The key must be a symbol among `bold', `italic' and `comment'.
292 The value is a formatting string to wrap fontified text with.
294 Value can also be set to the following symbols: `verb' and
295 `code'. For the former, Org will use \"@verb\" to
296 create a format string and select a delimiter character that
297 isn't in the string. For the latter, Org will use \"@code\"
298 to typeset and try to protect special characters.
300 If no association can be found for a given markup, text will be
302 :group
'org-export-texinfo
304 :options
'(bold code italic verbatim comment
))
308 (defcustom org-texinfo-format-drawer-function
309 (lambda (name contents
) contents
)
310 "Function called to format a drawer in Texinfo code.
312 The function must accept two parameters:
313 NAME the drawer name, like \"LOGBOOK\"
314 CONTENTS the contents of the drawer.
316 The function should return the string to be exported.
318 The default function simply returns the value of CONTENTS."
319 :group
'org-export-texinfo
321 :package-version
'(Org .
"8.2")
326 (defcustom org-texinfo-format-inlinetask-function
327 'org-texinfo-format-inlinetask-default-function
328 "Function called to format an inlinetask in Texinfo code.
330 The function must accept six parameters:
331 TODO the todo keyword, as a string
332 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
333 PRIORITY the inlinetask priority, as a string
334 NAME the inlinetask name, as a string.
335 TAGS the inlinetask tags, as a list of strings.
336 CONTENTS the contents of the inlinetask, as a string.
338 The function should return the string to be exported."
339 :group
'org-export-texinfo
344 (defcustom org-texinfo-info-process
'("makeinfo %f")
345 "Commands to process a Texinfo file to an INFO file.
346 This is list of strings, each of them will be given to the shell
347 as a command. %f in the command will be replaced by the full
348 file name, %b by the file base name (i.e without extension) and
349 %o by the base directory of the file."
350 :group
'org-export-texinfo
351 :type
'(repeat :tag
"Shell command sequence"
352 (string :tag
"Shell command")))
354 (defcustom org-texinfo-logfiles-extensions
355 '("aux" "toc" "cp" "fn" "ky" "pg" "tp" "vr")
356 "The list of file extensions to consider as Texinfo logfiles.
357 The logfiles will be remove if `org-texinfo-remove-logfiles' is
359 :group
'org-export-texinfo
360 :type
'(repeat (string :tag
"Extension")))
362 (defcustom org-texinfo-remove-logfiles t
363 "Non-nil means remove the logfiles produced by compiling a Texinfo file.
364 By default, logfiles are files with these extensions: .aux, .toc,
365 .cp, .fn, .ky, .pg and .tp. To define the set of logfiles to remove,
366 set `org-texinfo-logfiles-extensions'."
367 :group
'org-export-latex
372 (defconst org-texinfo-max-toc-depth
4
373 "Maximum depth for creation of detailed menu listings.
374 Beyond this depth, Texinfo will not recognize the nodes and will
375 cause errors. Left as a constant in case this value ever
378 (defconst org-texinfo-supported-coding-systems
379 '("US-ASCII" "UTF-8" "ISO-8859-15" "ISO-8859-1" "ISO-8859-2" "koi8-r" "koi8-u")
380 "List of coding systems supported by Texinfo, as strings.
381 Specified coding system will be matched against these strings.
382 If two strings share the same prefix (e.g. \"ISO-8859-1\" and
383 \"ISO-8859-15\"), the most specific one has to be listed first.")
386 ;;; Internal Functions
388 (defun org-texinfo-filter-section-blank-lines (headline back-end info
)
389 "Filter controlling number of blank lines after a section."
390 (let ((blanks (make-string 2 ?
\n)))
391 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline
)))
393 (defun org-texinfo--normalize-headlines (tree back-end info
)
394 "Normalize headlines in TREE.
396 BACK-END is the symbol specifying back-end used for export. INFO
397 is a plist used as a communication channel.
399 Make sure every headline in TREE contains a section, since those
400 are required to install a menu. Also put exactly one blank line
401 at the end of each section.
404 (org-element-map tree
'headline
406 (org-element-put-property hl
:post-blank
1)
407 (let ((contents (org-element-contents hl
)))
409 (let ((first (org-element-map contents
'(headline section
)
411 (unless (eq (org-element-type first
) 'section
)
412 (apply #'org-element-set-contents
414 (cons `(section (:parent
,hl
)) contents
)))))))
418 (defun org-texinfo--find-verb-separator (s)
419 "Return a character not used in string S.
420 This is used to choose a separator for constructs like \\verb."
421 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
422 (loop for c across ll
423 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
424 return
(char-to-string c
))))
426 (defun org-texinfo--text-markup (text markup info
)
427 "Format TEXT depending on MARKUP text markup.
428 INFO is a plist used as a communication channel. See
429 `org-texinfo-text-markup-alist' for details."
430 (let ((fmt (cdr (assq markup org-texinfo-text-markup-alist
))))
432 ;; No format string: Return raw text.
435 (let ((separator (org-texinfo--find-verb-separator text
)))
436 (concat "@verb{" separator text separator
"}")))
441 (while (string-match "[@{}]" text
)
442 (setq char
(match-string 0 text
))
443 (if (> (match-beginning 0) 0)
444 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
445 (setq text
(substring text
(1+ (match-beginning 0))))
446 (setq char
(concat "@" char
)
447 rtn
(concat rtn char
)))
448 (setq text
(concat rtn text
)
451 ;; Else use format string.
452 (t (format fmt text
)))))
454 (defun org-texinfo--get-node (headline info
)
455 "Return node entry associated to HEADLINE.
456 INFO is a plist used as a communication channel. The function
457 guarantees the node name is unique."
458 (let ((cache (plist-get info
:texinfo-node-cache
)))
459 (or (cdr (assq headline cache
))
460 (let ((name (org-texinfo--sanitize-node
462 (org-export-get-alt-title headline info
) info
))))
463 ;; Ensure NAME is unique.
464 (while (rassoc name cache
) (setq name
(concat name
"x")))
465 (plist-put info
:texinfo-node-cache
(cons (cons headline name
) cache
))
470 (defun org-texinfo--sanitize-node (title)
471 "Bend string TITLE to node line requirements.
472 Trim string and collapse multiple whitespace characters as they
473 are not significant. Also remove the following characters: @
475 (replace-regexp-in-string
477 (replace-regexp-in-string
478 "\\`(\\(.*)\\)" "[\\1"
479 (org-trim (replace-regexp-in-string "[ \t]\\{2,\\}" " " title
)))))
481 ;;;; Content sanitizing
483 (defun org-texinfo--sanitize-content (text)
484 "Escape special characters in string TEXT.
485 Special characters are: @ { }"
486 (replace-regexp-in-string "\\\([@{}]\\\)" "@\\1" text
))
490 (defun org-texinfo-template (contents info
)
491 "Return complete document string after Texinfo conversion.
492 CONTENTS is the transcoded contents string. INFO is a plist
493 holding export options."
494 (let ((title (org-export-data (plist-get info
:title
) info
))
495 ;; Copying data is the contents of the first headline in
496 ;; parse tree with a non-nil copying property.
497 (copying (org-element-map (plist-get info
:parse-tree
) 'headline
499 (and (org-not-nil (org-element-property :COPYING hl
))
500 (org-element-contents hl
)))
503 "\\input texinfo @c -*- texinfo -*-\n"
504 "@c %**start of header\n"
505 (let ((file (or (plist-get info
:texinfo-filename
)
506 (let ((f (plist-get info
:output-file
)))
507 (and f
(concat (file-name-sans-extension f
) ".info"))))))
508 (and file
(format "@setfilename %s\n" file
)))
509 (format "@settitle %s\n" title
)
510 ;; Insert class-defined header.
511 (org-element-normalize-string
512 (let ((header (nth 1 (assoc (plist-get info
:texinfo-class
)
513 org-texinfo-classes
)))
515 (catch 'coding-system
516 (let ((case-fold-search t
)
517 (name (symbol-name (or org-texinfo-coding-system
518 buffer-file-coding-system
))))
519 (dolist (system org-texinfo-supported-coding-systems
"UTF-8")
520 (when (org-string-match-p (regexp-quote system
) name
)
521 (throw 'coding-system system
))))))
522 (language (plist-get info
:language
))
523 (case-fold-search nil
))
524 ;; Auto coding system.
525 (replace-regexp-in-string
526 "^@documentencoding \\(AUTO\\)$"
528 (replace-regexp-in-string
529 "^@documentlanguage \\(AUTO\\)$" language header t nil
1) t nil
1)))
530 ;; Additional header options set by #+TEXINFO_HEADER.
531 (let ((texinfo-header (plist-get info
:texinfo-header
)))
532 (and texinfo-header
(org-element-normalize-string texinfo-header
)))
533 "@c %**end of header\n\n"
534 ;; Additional options set by #+TEXINFO_POST_HEADER.
535 (let ((texinfo-post-header (plist-get info
:texinfo-post-header
)))
536 (and texinfo-post-header
537 (org-element-normalize-string texinfo-post-header
)))
540 (format "@copying\n%s@end copying\n\n"
541 (org-element-normalize-string
542 (org-export-data copying info
))))
543 ;; Info directory information. Only supply if both title and
544 ;; category are provided.
545 (let ((dircat (plist-get info
:texinfo-dircat
))
547 (let ((title (plist-get info
:texinfo-dirtitle
)))
549 (string-match "^\\(?:\\* \\)?\\(.*?\\)\\(\\.\\)?$" title
)
550 (format "* %s." (match-string 1 title
))))))
551 (when (and dircat dirtitle
)
552 (concat "@dircategory " dircat
"\n"
555 (let ((desc (plist-get info
:texinfo-dirdesc
)))
556 (cond ((not desc
) nil
)
557 ((org-string-match-p "\\.$" desc
) desc
)
558 (t (concat desc
"."))))))
559 (if dirdesc
(format "%-23s %s" dirtitle dirdesc
) dirtitle
))
561 "@end direntry\n\n")))
565 (format "@title %s\n" (or (plist-get info
:texinfo-printed-title
) title
))
566 (let ((subtitle (plist-get info
:subtitle
)))
568 (org-element-normalize-string
569 (replace-regexp-in-string "^" "@subtitle " subtitle
))))
570 (when (plist-get info
:with-author
)
573 (let ((author (org-string-nw-p
574 (org-export-data (plist-get info
:author
) info
)))
575 (email (and (plist-get info
:with-email
)
577 (org-export-data (plist-get info
:email
) info
)))))
578 (cond ((and author email
)
579 (format "@author %s (@email{%s})\n" author email
))
580 (author (format "@author %s\n" author
))
581 (email (format "@author @email{%s}\n" email
))))
583 (let ((subauthor (plist-get info
:subauthor
)))
585 (org-element-normalize-string
586 (replace-regexp-in-string "^" "@author " subauthor
))))))
587 (and copying
"@page\n@vskip 0pt plus 1filll\n@insertcopying\n")
589 ;; Table of contents.
590 (and (plist-get info
:with-toc
) "@contents\n\n")
591 ;; Configure Top Node when not for Tex
594 (format "@top %s\n" title
)
595 (and copying
"@insertcopying\n")
598 (org-texinfo-make-menu (plist-get info
:parse-tree
) info
'master
)
603 (case (plist-get info
:with-creator
)
605 (comment (format "@c %s\n" (plist-get info
:creator
)))
606 (otherwise (concat (plist-get info
:creator
) "\n")))
612 ;;; Transcode Functions
616 (defun org-texinfo-bold (bold contents info
)
617 "Transcode BOLD from Org to Texinfo.
618 CONTENTS is the text with bold markup. INFO is a plist holding
619 contextual information."
620 (org-texinfo--text-markup contents
'bold info
))
624 (defun org-texinfo-center-block (center-block contents info
)
625 "Transcode a CENTER-BLOCK element from Org to Texinfo.
626 CONTENTS holds the contents of the block. INFO is a plist used
627 as a communication channel."
632 (defun org-texinfo-clock (clock contents info
)
633 "Transcode a CLOCK element from Org to Texinfo.
634 CONTENTS is nil. INFO is a plist holding contextual
638 (format "@strong{%s} " org-clock-string
)
639 (format (plist-get info
:texinfo-inactive-timestamp-format
)
640 (concat (org-translate-time
641 (org-element-property :raw-value
642 (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-snippet (export-snippet contents info
)
695 "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
696 CONTENTS is nil. INFO is a plist holding contextual information."
697 (when (eq (org-export-snippet-backend export-snippet
) 'texinfo
)
698 (org-element-property :value export-snippet
)))
702 (defun org-texinfo-fixed-width (fixed-width contents info
)
703 "Transcode a FIXED-WIDTH element from Org to Texinfo.
704 CONTENTS is nil. INFO is a plist holding contextual information."
705 (format "@example\n%s\n@end example"
706 (org-remove-indentation
707 (org-texinfo--sanitize-content
708 (org-element-property :value fixed-width
)))))
710 ;;;; Footnote Reference
712 (defun org-texinfo-footnote-reference (footnote contents info
)
713 "Create a footnote reference for FOOTNOTE.
715 FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
716 plist holding contextual information."
717 (let ((def (org-export-get-footnote-definition footnote info
)))
718 (format "@footnote{%s}"
719 (org-trim (org-export-data def info
)))))
723 (defun org-texinfo-headline (headline contents info
)
724 "Transcode a HEADLINE element from Org to Texinfo.
725 CONTENTS holds the contents of the headline. INFO is a plist
726 holding contextual information."
727 (let* ((class (plist-get info
:texinfo-class
))
728 (level (org-export-get-relative-level headline info
))
729 (numberedp (org-export-numbered-headline-p headline info
))
730 (class-sectioning (assoc class
(plist-get info
:texinfo-classes
)))
731 ;; Find the index type, if any.
732 (index (org-element-property :INDEX headline
))
733 ;; Create node info, to insert it before section formatting.
734 ;; Use custom menu title if present.
735 (node (format "@node %s\n" (org-texinfo--get-node headline info
)))
736 ;; Section formatting will set two placeholders: one for the
737 ;; title and the other for the contents.
739 (if (org-not-nil (org-element-property :APPENDIX headline
))
741 (let ((sec (if (and (symbolp (nth 2 class-sectioning
))
742 (fboundp (nth 2 class-sectioning
)))
743 (funcall (nth 2 class-sectioning
) level numberedp
)
744 (nth (1+ level
) class-sectioning
))))
746 ;; No section available for that LEVEL.
748 ;; Section format directly returned by a function.
750 ;; (numbered-section . unnumbered-section)
751 ((not (consp (cdr sec
)))
752 (concat (if (or index
(not numberedp
)) (cdr sec
) (car sec
))
755 (and (plist-get info
:with-todo-keywords
)
756 (let ((todo (org-element-property :todo-keyword headline
)))
757 (and todo
(org-export-data todo info
)))))
758 (todo-type (and todo
(org-element-property :todo-type headline
)))
759 (tags (and (plist-get info
:with-tags
)
760 (org-export-get-tags headline info
)))
761 (priority (and (plist-get info
:with-priority
)
762 (org-element-property :priority headline
)))
763 (text (org-export-data (org-element-property :title headline
) info
))
764 (full-text (funcall (plist-get info
:texinfo-format-headline-function
)
765 todo todo-type priority text tags
))
766 (contents (if (org-string-nw-p contents
) (concat "\n" contents
) "")))
768 ;; Case 1: This is a footnote section: ignore it.
769 ((org-element-property :footnote-section-p headline
) nil
)
770 ;; Case 2: This is the `copying' section: ignore it
771 ;; This is used elsewhere.
772 ((org-not-nil (org-element-property :COPYING headline
)) nil
)
773 ;; Case 3: An index. If it matches one of the known indexes,
774 ;; print it as such following the contents, otherwise
775 ;; print the contents and leave the index up to the user.
782 (and (member index
'("cp" "fn" "ky" "pg" "tp" "vr"))
783 (concat "\n@printindex " index
))))))
784 ;; Case 4: This is a deep sub-tree: export it as a list item.
785 ;; Also export as items headlines for which no section
786 ;; format has been found.
787 ((or (not section-fmt
) (org-export-low-level-p headline info
))
788 ;; Build the real contents of the sub-tree.
789 (concat (and (org-export-first-sibling-p headline info
)
790 (format "@%s\n" (if numberedp
'enumerate
'itemize
)))
791 "@item\n" full-text
"\n"
793 (if (org-export-last-sibling-p headline info
)
794 (format "@end %s" (if numberedp
'enumerate
'itemize
))
796 ;; Case 5: Standard headline. Export it as a section.
797 (t (concat node
(format section-fmt full-text contents
))))))
799 (defun org-texinfo-format-headline-default-function
800 (todo todo-type priority text tags
)
801 "Default format function for a headline.
802 See `org-texinfo-format-headline-function' for details."
803 (concat (when todo
(format "@strong{%s} " todo
))
804 (when priority
(format "@emph{#%s} " priority
))
806 (when tags
(format " :%s:" (mapconcat 'identity tags
":")))))
808 ;;;; Inline Src Block
810 (defun org-texinfo-inline-src-block (inline-src-block contents info
)
811 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
812 CONTENTS holds the contents of the item. INFO is a plist holding
813 contextual information."
814 (let* ((code (org-element-property :value inline-src-block
))
815 (separator (org-texinfo--find-verb-separator code
)))
816 (concat "@verb{" separator code separator
"}")))
820 (defun org-texinfo-inlinetask (inlinetask contents info
)
821 "Transcode an INLINETASK element from Org to Texinfo.
822 CONTENTS holds the contents of the block. INFO is a plist
823 holding contextual information."
824 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
825 (todo (and (plist-get info
:with-todo-keywords
)
826 (let ((todo (org-element-property :todo-keyword inlinetask
)))
827 (and todo
(org-export-data todo info
)))))
828 (todo-type (org-element-property :todo-type inlinetask
))
829 (tags (and (plist-get info
:with-tags
)
830 (org-export-get-tags inlinetask info
)))
831 (priority (and (plist-get info
:with-priority
)
832 (org-element-property :priority inlinetask
))))
833 (funcall (plist-get info
:texinfo-format-inlinetask-function
)
834 todo todo-type priority title tags contents
)))
836 (defun org-texinfo-format-inlinetask-default-function
837 (todo todo-type priority title tags contents
)
838 "Default format function for a inlinetasks.
839 See `org-texinfo-format-inlinetask-function' for details."
841 (concat (when todo
(format "@strong{%s} " todo
))
842 (when priority
(format "#%c " priority
))
844 (when tags
(format ":%s:" (mapconcat #'identity tags
":"))))))
845 (format "@center %s\n\n%s\n" full-title contents
)))
849 (defun org-texinfo-italic (italic contents info
)
850 "Transcode ITALIC from Org to Texinfo.
851 CONTENTS is the text with italic markup. INFO is a plist holding
852 contextual information."
853 (org-texinfo--text-markup contents
'italic info
))
857 (defun org-texinfo-item (item contents info
)
858 "Transcode an ITEM element from Org to Texinfo.
859 CONTENTS holds the contents of the item. INFO is a plist holding
860 contextual information."
861 (format "@item%s\n%s"
862 (let ((tag (org-element-property :tag item
)))
863 (if tag
(concat " " (org-export-data tag info
)) ""))
868 (defun org-texinfo-keyword (keyword contents info
)
869 "Transcode a KEYWORD element from Org to Texinfo.
870 CONTENTS is nil. INFO is a plist holding contextual information."
871 (let ((key (org-element-property :key keyword
))
872 (value (org-element-property :value keyword
)))
874 ((string= key
"TEXINFO") value
)
875 ((string= key
"CINDEX") (format "@cindex %s" value
))
876 ((string= key
"FINDEX") (format "@findex %s" value
))
877 ((string= key
"KINDEX") (format "@kindex %s" value
))
878 ((string= key
"PINDEX") (format "@pindex %s" value
))
879 ((string= key
"TINDEX") (format "@tindex %s" value
))
880 ((string= key
"VINDEX") (format "@vindex %s" value
)))))
884 (defun org-texinfo-line-break (line-break contents info
)
885 "Transcode a LINE-BREAK object from Org to Texinfo.
886 CONTENTS is nil. INFO is a plist holding contextual information."
891 (defun org-texinfo-link (link desc info
)
892 "Transcode a LINK object from Org to Texinfo.
894 DESC is the description part of the link, or the empty string.
895 INFO is a plist holding contextual information. See
897 (let* ((type (org-element-property :type link
))
898 (raw-path (org-element-property :path link
))
899 ;; Ensure DESC really exists, or set it to nil.
900 (desc (and (not (string= desc
"")) desc
))
902 ((member type
'("http" "https" "ftp"))
903 (concat type
":" raw-path
))
904 ((and (string= type
"file") (file-name-absolute-p raw-path
))
905 (concat "file:" raw-path
))
907 (email (if (string= type
"mailto")
908 (let ((text (replace-regexp-in-string
910 (concat text
(if desc
(concat "," desc
))))))
913 ;; Links pointing to a headline: Find destination and build
914 ;; appropriate referencing command.
915 ((member type
'("custom-id" "id"))
916 (let ((destination (org-export-resolve-id-link link info
)))
917 (case (org-element-type destination
)
918 ;; Id link points to an external file.
920 (if desc
(format "@uref{file://%s,%s}" destination desc
)
921 (format "@uref{file://%s}" destination
)))
922 ;; LINK points to a headline. Use the headline as the NODE target
924 (format "@ref{%s,%s}"
925 (org-texinfo--get-node destination info
)
928 (let ((path (org-export-solidify-link-text path
)))
929 (if (not desc
) (format "@ref{%s}" path
)
930 (format "@ref{%s,,%s}" path desc
)))))))
931 ((member type
'("info"))
932 (let* ((info-path (split-string path
"[:#]"))
933 (info-manual (car info-path
))
934 (info-node (or (cadr info-path
) "top"))
935 (title (or desc
"")))
936 (format "@ref{%s,%s,,%s,}" info-node title info-manual
)))
937 ((member type
'("fuzzy"))
938 (let ((destination (org-export-resolve-fuzzy-link link info
)))
939 (case (org-element-type destination
)
940 ;; Id link points to an external file.
942 (if desc
(format "@uref{file://%s,%s}" destination desc
)
943 (format "@uref{file://%s}" destination
)))
944 ;; LINK points to a headline. Use the headline as the NODE target
946 (format "@ref{%s,%s}"
947 (org-texinfo--get-node destination info
)
950 (let ((path (org-export-solidify-link-text path
)))
951 (if (not desc
) (format "@ref{%s}" path
)
952 (format "@ref{%s,,%s}" path desc
)))))))
953 ;; Special case for email addresses
955 (format "@email{%s}" email
))
956 ;; External link with a description part.
957 ((and path desc
) (format "@uref{%s,%s}" path desc
))
958 ;; External link without a description part.
959 (path (format "@uref{%s}" path
))
960 ;; No path, only description. Try to do something useful.
962 (format (plist-get info
:texinfo-link-with-unknown-path-format
) desc
)))))
967 (defun org-texinfo-make-menu (scope info
&optional master
)
968 "Create the menu for inclusion in the Texinfo document.
970 SCOPE is a headline or a full parse tree. INFO is the
971 communication channel, as a plist.
973 When optional argument MASTER is non-nil, generate a master menu,
974 including detailed node listing."
975 (let ((menu (org-texinfo--build-menu scope info
)))
976 (when (org-string-nw-p menu
)
977 (org-element-normalize-string
983 (org-texinfo--build-menu
985 (let ((toc-depth (plist-get info
:with-toc
)))
986 (if (wholenump toc-depth
) toc-depth
987 org-texinfo-max-toc-depth
)))))
988 (when (org-string-nw-p detailmenu
)
989 (concat "\n@detailmenu\n"
990 "--- The Detailed Node Listing ---\n\n"
992 "@end detailmenu\n"))))))))))
994 (defun org-texinfo--build-menu (scope info
&optional level
)
995 "Build menu for entries within SCOPE.
996 SCOPE is a headline or a full parse tree. INFO is a plist
997 containing contextual information. When optional argument LEVEL
998 is an integer, build the menu recursively, down to this depth."
1001 (org-texinfo--format-entries (org-texinfo--menu-entries scope info
) info
))
1004 (org-element-normalize-string
1007 (let ((entries (org-texinfo--menu-entries h info
)))
1010 (format "%s\n\n%s\n"
1011 (org-export-data (org-export-get-alt-title h info
) info
)
1012 (org-texinfo--format-entries entries info
))
1013 (org-texinfo--build-menu h info
(1- level
))))))
1014 (org-texinfo--menu-entries scope info
) "")))))
1016 (defun org-texinfo--format-entries (entries info
)
1017 "Format all direct menu entries in SCOPE, as a string.
1018 SCOPE is either a headline or a full Org document. INFO is
1019 a plist containing contextual information."
1020 (org-element-normalize-string
1023 (let* ((title (org-export-data
1024 (org-export-get-alt-title h info
) info
))
1025 (node (org-texinfo--get-node h info
))
1026 (entry (concat "* " title
":"
1027 (if (string= title node
) ":"
1028 (concat " " node
". "))))
1029 (desc (org-element-property :DESCRIPTION h
)))
1030 (if (not desc
) entry
1031 (format (format "%%-%ds %%s" org-texinfo-node-description-column
)
1035 (defun org-texinfo--menu-entries (scope info
)
1036 "List direct children in SCOPE needing a menu entry.
1037 SCOPE is a headline or a full parse tree. INFO is a plist
1038 holding contextual information."
1039 (let* ((cache (or (plist-get info
:texinfo-entries-cache
)
1040 (plist-get (plist-put info
:texinfo-entries-cache
1041 (make-hash-table :test
#'eq
))
1042 :texinfo-entries-cache
)))
1043 (cached-entries (gethash scope cache
'no-cache
)))
1044 (if (not (eq cached-entries
'no-cache
)) cached-entries
1046 (org-element-map (org-element-contents scope
) 'headline
1048 (and (not (org-not-nil (org-element-property :COPYING h
)))
1049 (not (org-element-property :footnote-section-p h
))
1050 (not (org-export-low-level-p h info
))
1057 (defun org-texinfo-node-property (node-property contents info
)
1058 "Transcode a NODE-PROPERTY element from Org to Texinfo.
1059 CONTENTS is nil. INFO is a plist holding contextual
1062 (org-element-property :key node-property
)
1063 (let ((value (org-element-property :value node-property
)))
1064 (if value
(concat " " value
) ""))))
1068 (defun org-texinfo-paragraph (paragraph contents info
)
1069 "Transcode a PARAGRAPH element from Org to Texinfo.
1070 CONTENTS is the contents of the paragraph, as a string. INFO is
1071 the plist used as a communication channel."
1076 (defun org-texinfo-plain-list (plain-list contents info
)
1077 "Transcode a PLAIN-LIST element from Org to Texinfo.
1078 CONTENTS is the contents of the list. INFO is a plist holding
1079 contextual information."
1080 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1081 (indic (or (plist-get attr
:indic
)
1082 (plist-get info
:texinfo-def-table-markup
)))
1083 (table-type (plist-get attr
:table-type
))
1084 (type (org-element-property :type plain-list
))
1086 ((eq type
'ordered
) "enumerate")
1087 ((eq type
'unordered
) "itemize")
1088 ((member table-type
'("ftable" "vtable")) table-type
)
1090 (format "@%s\n%s@end %s"
1091 (if (eq type
'descriptive
) (concat list-type
" " indic
) list-type
)
1097 (defun org-texinfo-plain-text (text info
)
1098 "Transcode a TEXT string from Org to Texinfo.
1099 TEXT is the string to transcode. INFO is a plist holding
1100 contextual information."
1101 ;; First protect @, { and }.
1102 (let ((output (org-texinfo--sanitize-content text
)))
1103 ;; Activate smart quotes. Be sure to provide original TEXT string
1104 ;; since OUTPUT may have been modified.
1105 (when (plist-get info
:with-smart-quotes
)
1107 (org-export-activate-smart-quotes output
:texinfo info text
)))
1108 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1109 (let ((case-fold-search nil
)
1111 (while (string-match "\\(\\(?:La\\)?TeX\\)" output start
)
1112 (setq output
(replace-match
1113 (format "@%s{}" (match-string 1 output
)) nil t output
)
1114 start
(match-end 0))))
1115 ;; Convert special strings.
1116 (when (plist-get info
:with-special-strings
)
1117 (while (string-match (regexp-quote "...") output
)
1118 (setq output
(replace-match "@dots{}" nil t output
))))
1119 ;; Handle break preservation if required.
1120 (when (plist-get info
:preserve-breaks
)
1121 (setq output
(replace-regexp-in-string
1122 "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output
)))
1128 (defun org-texinfo-planning (planning contents info
)
1129 "Transcode a PLANNING element from Org to Texinfo.
1130 CONTENTS is nil. INFO is a plist holding contextual
1138 (let ((closed (org-element-property :closed planning
)))
1141 (format "@strong{%s} " org-closed-string
)
1142 (format (plist-get info
:texinfo-inactive-timestamp-format
)
1144 (org-element-property :raw-value closed
))))))
1145 (let ((deadline (org-element-property :deadline planning
)))
1148 (format "@strong{%s} " org-deadline-string
)
1149 (format (plist-get info
:texinfo-active-timestamp-format
)
1151 (org-element-property :raw-value deadline
))))))
1152 (let ((scheduled (org-element-property :scheduled planning
)))
1155 (format "@strong{%s} " org-scheduled-string
)
1156 (format (plist-get info
:texinfo-active-timestamp-format
)
1158 (org-element-property :raw-value scheduled
))))))))
1162 ;;;; Property Drawer
1164 (defun org-texinfo-property-drawer (property-drawer contents info
)
1165 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1166 CONTENTS holds the contents of the drawer. INFO is a plist
1167 holding contextual information."
1168 (and (org-string-nw-p contents
)
1169 (format "@verbatim\n%s@end verbatim" contents
)))
1173 (defun org-texinfo-quote-block (quote-block contents info
)
1174 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1175 CONTENTS holds the contents of the block. INFO is a plist
1176 holding contextual information."
1177 (let* ((title (org-element-property :name quote-block
))
1178 (start-quote (concat "@quotation"
1180 (format " %s" title
)))))
1181 (format "%s\n%s@end quotation" start-quote contents
)))
1185 (defun org-texinfo-radio-target (radio-target text info
)
1186 "Transcode a RADIO-TARGET object from Org to Texinfo.
1187 TEXT is the text of the target. INFO is a plist holding
1188 contextual information."
1189 (format "@anchor{%s}%s"
1190 (org-export-solidify-link-text
1191 (org-element-property :value radio-target
))
1196 (defun org-texinfo-section (section contents info
)
1197 "Transcode a SECTION element from Org to Texinfo.
1198 CONTENTS holds the contents of the section. INFO is a plist
1199 holding contextual information."
1201 (let ((parent (org-export-get-parent-headline section
)))
1202 (and parent
(org-texinfo-make-menu parent info
)))))
1206 (defun org-texinfo-special-block (special-block contents info
)
1207 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1208 CONTENTS holds the contents of the block. INFO is a plist used
1209 as a communication channel."
1210 (if (org-export-raw-special-block-p special-block info
)
1211 (org-remove-indentation (org-element-property :raw-value special-block
))
1216 (defun org-texinfo-src-block (src-block contents info
)
1217 "Transcode a SRC-BLOCK element from Org to Texinfo.
1218 CONTENTS holds the contents of the item. INFO is a plist holding
1219 contextual information."
1220 (let ((lispp (org-string-match-p "lisp"
1221 (org-element-property :language src-block
)))
1222 (code (org-texinfo--sanitize-content
1223 (org-export-format-code-default src-block info
))))
1224 (format (if lispp
"@lisp\n%s@end lisp" "@example\n%s@end example") code
)))
1226 ;;;; Statistics Cookie
1228 (defun org-texinfo-statistics-cookie (statistics-cookie contents info
)
1229 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1230 CONTENTS is nil. INFO is a plist holding contextual information."
1231 (org-element-property :value statistics-cookie
))
1235 (defun org-texinfo-subscript (subscript contents info
)
1236 "Transcode a SUBSCRIPT object from Org to Texinfo.
1237 CONTENTS is the contents of the object. INFO is a plist holding
1238 contextual information."
1239 (format "@math{_%s}" contents
))
1243 (defun org-texinfo-superscript (superscript contents info
)
1244 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1245 CONTENTS is the contents of the object. INFO is a plist holding
1246 contextual information."
1247 (format "@math{^%s}" contents
))
1251 (defun org-texinfo-table (table contents info
)
1252 "Transcode a TABLE element from Org to Texinfo.
1253 CONTENTS is the contents of the table. INFO is a plist holding
1254 contextual information."
1255 (if (eq (org-element-property :type table
) 'table.el
)
1256 (format "@verbatim\n%s@end verbatim"
1257 (org-element-normalize-string
1258 (org-element-property :value table
)))
1259 (let* ((col-width (org-export-read-attribute :attr_texinfo table
:columns
))
1261 (if col-width
(format "@columnfractions %s" col-width
)
1262 (org-texinfo-table-column-widths table info
))))
1263 (format "@multitable %s\n%s@end multitable"
1267 (defun org-texinfo-table-column-widths (table info
)
1268 "Determine the largest table cell in each column to process alignment.
1269 TABLE is the table element to transcode. INFO is a plist used as
1270 a communication channel."
1271 (let ((widths (make-vector (cdr (org-export-table-dimensions table info
)) 0)))
1272 (org-element-map table
'table-row
1275 (org-element-map row
'table-cell
1277 ;; Length of the cell in the original buffer is only an
1278 ;; approximation of the length of the cell in the
1279 ;; output. It can sometimes fail (e.g. it considers
1280 ;; "/a/" being larger than "ab").
1281 (let ((w (- (org-element-property :contents-end cell
)
1282 (org-element-property :contents-begin cell
))))
1283 (aset widths idx
(max w
(aref widths idx
))))
1287 (format "{%s}" (mapconcat (lambda (w) (make-string w ?a
)) widths
"} {"))))
1291 (defun org-texinfo-table-cell (table-cell contents info
)
1292 "Transcode a TABLE-CELL element from Org to Texinfo.
1293 CONTENTS is the cell contents. INFO is a plist used as
1294 a communication channel."
1296 (let ((scientific-notation
1297 (plist-get info
:texinfo-table-scientific-notation
)))
1300 (string-match orgtbl-exp-regexp contents
))
1301 ;; Use appropriate format string for scientific notation.
1302 (format scientific-notation
1303 (match-string 1 contents
)
1304 (match-string 2 contents
))
1306 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1310 (defun org-texinfo-table-row (table-row contents info
)
1311 "Transcode a TABLE-ROW element from Org to Texinfo.
1312 CONTENTS is the contents of the row. INFO is a plist used as
1313 a communication channel."
1314 ;; Rules are ignored since table separators are deduced from
1315 ;; borders of the current row.
1316 (when (eq (org-element-property :type table-row
) 'standard
)
1318 (if (and (= 1 (org-export-table-row-group table-row info
))
1319 (org-export-table-has-header-p
1320 (org-export-get-parent-table table-row
) info
))
1323 (concat rowgroup-tag contents
"\n"))))
1327 (defun org-texinfo-target (target contents info
)
1328 "Transcode a TARGET object from Org to Texinfo.
1329 CONTENTS is nil. INFO is a plist holding contextual
1331 (format "@anchor{%s}"
1332 (org-export-solidify-link-text (org-element-property :value target
))))
1336 (defun org-texinfo-timestamp (timestamp contents info
)
1337 "Transcode a TIMESTAMP object from Org to Texinfo.
1338 CONTENTS is nil. INFO is a plist holding contextual
1340 (let ((value (org-texinfo-plain-text
1341 (org-timestamp-translate timestamp
) info
)))
1342 (case (org-element-property :type timestamp
)
1343 ((active active-range
)
1344 (format (plist-get info
:texinfo-active-timestamp-format
) value
))
1345 ((inactive inactive-range
)
1346 (format (plist-get info
:texinfo-inactive-timestamp-format
) value
))
1347 (t (format (plist-get info
:texinfo-diary-timestamp-format
) value
)))))
1351 (defun org-texinfo-verbatim (verbatim contents info
)
1352 "Transcode a VERBATIM object from Org to Texinfo.
1353 CONTENTS is nil. INFO is a plist used as a communication
1355 (org-texinfo--text-markup
1356 (org-element-property :value verbatim
) 'verbatim info
))
1360 (defun org-texinfo-verse-block (verse-block contents info
)
1361 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1362 CONTENTS is verse block contents. INFO is a plist holding
1363 contextual information."
1364 (format "@display\n%s@end display" contents
))
1367 ;;; Interactive functions
1369 (defun org-texinfo-export-to-texinfo
1370 (&optional async subtreep visible-only body-only ext-plist
)
1371 "Export current buffer to a Texinfo file.
1373 If narrowing is active in the current buffer, only export its
1376 If a region is active, export that region.
1378 A non-nil optional argument ASYNC means the process should happen
1379 asynchronously. The resulting file should be accessible through
1380 the `org-export-stack' interface.
1382 When optional argument SUBTREEP is non-nil, export the sub-tree
1383 at point, extracting information from the headline properties
1386 When optional argument VISIBLE-ONLY is non-nil, don't export
1387 contents of hidden elements.
1389 When optional argument BODY-ONLY is non-nil, only write code
1390 between \"\\begin{document}\" and \"\\end{document}\".
1392 EXT-PLIST, when provided, is a property list with external
1393 parameters overriding Org default settings, but still inferior to
1394 file-local settings.
1396 Return output file's name."
1398 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1399 (org-export-coding-system org-texinfo-coding-system
))
1400 (org-export-to-file 'texinfo outfile
1401 async subtreep visible-only body-only ext-plist
)))
1403 (defun org-texinfo-export-to-info
1404 (&optional async subtreep visible-only body-only ext-plist
)
1405 "Export current buffer to Texinfo then process through to INFO.
1407 If narrowing is active in the current buffer, only export its
1410 If a region is active, export that region.
1412 A non-nil optional argument ASYNC means the process should happen
1413 asynchronously. The resulting file should be accessible through
1414 the `org-export-stack' interface.
1416 When optional argument SUBTREEP is non-nil, export the sub-tree
1417 at point, extracting information from the headline properties
1420 When optional argument VISIBLE-ONLY is non-nil, don't export
1421 contents of hidden elements.
1423 When optional argument BODY-ONLY is non-nil, only write code
1424 between \"\\begin{document}\" and \"\\end{document}\".
1426 EXT-PLIST, when provided, is a property list with external
1427 parameters overriding Org default settings, but still inferior to
1428 file-local settings.
1430 When optional argument PUB-DIR is set, use it as the publishing
1433 Return INFO file's name."
1435 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1436 (org-export-coding-system org-texinfo-coding-system
))
1437 (org-export-to-file 'texinfo outfile
1438 async subtreep visible-only body-only ext-plist
1439 (lambda (file) (org-texinfo-compile file
)))))
1442 (defun org-texinfo-publish-to-texinfo (plist filename pub-dir
)
1443 "Publish an org file to Texinfo.
1445 FILENAME is the filename of the Org file to be published. PLIST
1446 is the property list for the given project. PUB-DIR is the
1447 publishing directory.
1449 Return output file name."
1450 (org-publish-org-to 'texinfo filename
".texi" plist pub-dir
))
1453 (defun org-texinfo-convert-region-to-texinfo ()
1454 "Assume the current region has org-mode syntax, and convert it to Texinfo.
1455 This can be used in any buffer. For example, you can write an
1456 itemized list in org-mode syntax in an Texinfo buffer and use
1457 this command to convert it."
1459 (org-export-replace-region-by 'texinfo
))
1461 (defun org-texinfo-compile (file)
1462 "Compile a texinfo file.
1464 FILE is the name of the file being compiled. Processing is
1465 done through the command specified in `org-texinfo-info-process'.
1467 Return INFO file name or an error if it couldn't be produced."
1468 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file
)))
1469 (full-name (file-truename file
))
1470 (out-dir (file-name-directory file
))
1471 ;; Properly set working directory for compilation.
1472 (default-directory (if (file-name-absolute-p file
)
1473 (file-name-directory full-name
)
1476 (message (format "Processing Texinfo file %s..." file
))
1477 (save-window-excursion
1478 ;; Replace %b, %f and %o with appropriate values in each command
1479 ;; before applying it. Output is redirected to "*Org INFO
1480 ;; Texinfo Output*" buffer.
1481 (let ((outbuf (get-buffer-create "*Org INFO Texinfo Output*")))
1482 (dolist (command org-texinfo-info-process
)
1484 (replace-regexp-in-string
1485 "%b" (shell-quote-argument base-name
)
1486 (replace-regexp-in-string
1487 "%f" (shell-quote-argument full-name
)
1488 (replace-regexp-in-string
1489 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
1491 ;; Collect standard errors from output buffer.
1492 (setq errors
(org-texinfo-collect-errors outbuf
)))
1493 (let ((infofile (concat out-dir base-name
".info")))
1494 ;; Check for process failure. Provide collected errors if
1496 (if (not (file-exists-p infofile
))
1497 (error (concat (format "INFO file %s wasn't produced" infofile
)
1498 (when errors
(concat ": " errors
))))
1499 ;; Else remove log files, when specified, and signal end of
1500 ;; process to user, along with any error encountered.
1501 (when org-texinfo-remove-logfiles
1502 (dolist (ext org-texinfo-logfiles-extensions
)
1503 (let ((file (concat out-dir base-name
"." ext
)))
1504 (when (file-exists-p file
) (delete-file file
)))))
1505 (message (concat "Process completed"
1506 (if (not errors
) "."
1507 (concat " with errors: " errors
)))))
1508 ;; Return output file name.
1511 (defun org-texinfo-collect-errors (buffer)
1512 "Collect some kind of errors from \"makeinfo\" command output.
1514 BUFFER is the buffer containing output.
1516 Return collected error types as a string, or nil if there was
1518 (with-current-buffer buffer
1520 (goto-char (point-min))
1521 ;; Find final "makeinfo" run.
1523 (let ((case-fold-search t
)
1525 (when (save-excursion
1526 (re-search-forward "perhaps incorrect sectioning?" nil t
))
1527 (setq errors
(concat errors
" [incorrect sectioning]")))
1528 (when (save-excursion
1529 (re-search-forward "missing close brace" nil t
))
1530 (setq errors
(concat errors
" [syntax error]")))
1531 (when (save-excursion
1532 (re-search-forward "Unknown command" nil t
))
1533 (setq errors
(concat errors
" [undefined @command]")))
1534 (when (save-excursion
1535 (re-search-forward "No matching @end" nil t
))
1536 (setq errors
(concat errors
" [block incomplete]")))
1537 (when (save-excursion
1538 (re-search-forward "requires a sectioning" nil t
))
1539 (setq errors
(concat errors
" [invalid section command]")))
1540 (when (save-excursion
1541 (re-search-forward "\\[unexpected\]" nil t
))
1542 (setq errors
(concat errors
" [unexpected error]")))
1543 (when (save-excursion
1544 (re-search-forward "misplaced " nil t
))
1545 (setq errors
(concat errors
" [syntax error]")))
1546 (and (org-string-nw-p errors
) (org-trim errors
)))))))
1549 (provide 'ox-texinfo
)
1552 ;; generated-autoload-file: "org-loaddefs.el"
1555 ;;; ox-texinfo.el ends here