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-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 newline
)
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
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. Beyond
374 this depth Texinfo will not recognize the nodes and will cause
375 errors. Left as a constant in case this value ever changes.")
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--find-verb-separator (s)
393 "Return a character not used in string S.
394 This is used to choose a separator for constructs like \\verb."
395 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
396 (loop for c across ll
397 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
398 return
(char-to-string c
))))
400 (defun org-texinfo--make-option-string (options)
401 "Return a comma separated string of keywords and values.
402 OPTIONS is an alist where the key is the options keyword as
403 a string, and the value a list containing the keyword value, or
405 (mapconcat (lambda (pair)
407 (when (> (length (second pair
)) 0)
408 (concat "=" (second pair
)))))
412 (defun org-texinfo--text-markup (text markup info
)
413 "Format TEXT depending on MARKUP text markup.
414 INFO is a plist used as a communication channel. See
415 `org-texinfo-text-markup-alist' for details."
416 (let ((fmt (cdr (assq markup org-texinfo-text-markup-alist
))))
418 ;; No format string: Return raw text.
421 (let ((separator (org-texinfo--find-verb-separator text
)))
422 (concat "@verb{" separator text separator
"}")))
427 (while (string-match "[@{}]" text
)
428 (setq char
(match-string 0 text
))
429 (if (> (match-beginning 0) 0)
430 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
431 (setq text
(substring text
(1+ (match-beginning 0))))
432 (setq char
(concat "@" char
)
433 rtn
(concat rtn char
)))
434 (setq text
(concat rtn text
)
437 ;; Else use format string.
438 (t (format fmt text
)))))
440 (defun org-texinfo--get-node (headline info
)
441 "Return node entry associated to HEADLINE.
442 INFO is a plist used as a communication channel."
443 (let ((menu-title (org-export-get-alt-title headline info
)))
444 (org-texinfo--sanitize-menu
445 (replace-regexp-in-string
447 (if menu-title
(org-export-data menu-title info
)
448 (org-texinfo--sanitize-headline
449 (org-element-property :title headline
) info
))))))
451 ;;;; Headline sanitizing
453 (defun org-texinfo--sanitize-headline (headline info
)
454 "Remove all formatting from the text of a headline for use in
455 node and menu listing."
457 (org-texinfo--sanitize-headline-contents headline info
) " "))
459 (defun org-texinfo--sanitize-headline-contents (headline info
)
460 "Retrieve the content of the headline.
462 Any content that can contain further formatting is checked
463 recursively, to ensure that nested content is also properly
465 (loop for contents in headline append
469 (list (replace-regexp-in-string " $" "" contents
)))
470 ;; Is exported as-is (value)
471 ((org-element-map contents
'(verbatim code
)
472 (lambda (value) (org-element-property :value value
)) info
))
473 ;; Has content and recurse into the content
474 ((org-element-contents contents
)
475 (org-texinfo--sanitize-headline-contents
476 (org-element-contents contents
) info
)))))
480 (defun org-texinfo--sanitize-menu (title)
481 "Remove invalid characters from TITLE for use in menus and
484 Based on Texinfo specifications, the following must be removed:
486 (replace-regexp-in-string "[@{}():,.]" "" title
))
488 ;;;; Content sanitizing
490 (defun org-texinfo--sanitize-content (text)
491 "Ensure characters are properly escaped when used in headlines or blocks.
493 Escape characters are: @ { }"
494 (replace-regexp-in-string "\\\([@{}]\\\)" "@\\1" text
))
498 (defun org-texinfo--build-menu (tree level info
&optional detailed
)
499 "Create the @menu/@end menu information from TREE at headline
502 TREE contains the parse-tree to work with, either of the entire
503 document or of a specific parent headline. LEVEL indicates what
504 level of headlines to look at when generating the menu. INFO is
505 a plist containing contextual information.
507 Detailed determines whether to build a single level of menu, or
508 recurse into all children as well."
509 (let ((menu (org-texinfo--generate-menu-list tree level info
))
513 ;; Looping is done within the menu generation.
514 (setq text-menu
(org-texinfo--generate-detailed menu level info
)))
516 (setq text-menu
(org-texinfo--generate-menu-items menu info
))))
518 (setq output
(org-texinfo--format-menu text-menu info
))
519 (mapconcat 'identity output
"\n"))))
521 (defun org-texinfo--generate-detailed (menu level info
)
522 "Generate a detailed listing of all subheadings within MENU starting at LEVEL.
524 MENU is the parse-tree to work with. LEVEL is the starting level
525 for the menu headlines and from which recursion occurs. INFO is
526 a plist containing contextual information."
528 (let ((max-depth (min org-texinfo-max-toc-depth
529 (plist-get info
:headline-levels
))))
530 (when (> max-depth level
)
531 (loop for headline in menu append
532 (let* ((title (org-texinfo--menu-headlines headline info
))
533 ;; Create list of menu entries for the next level
534 (sublist (org-texinfo--generate-menu-list
535 headline
(1+ level
) info
))
536 ;; Generate the menu items for that level. If
537 ;; there are none omit that heading completely,
538 ;; otherwise join the title to it's related entries.
539 (submenu (if (org-texinfo--generate-menu-items sublist info
)
541 (org-texinfo--generate-menu-items sublist info
))
543 ;; Start the process over the next level down.
544 (recursion (org-texinfo--generate-detailed sublist
(1+ level
) info
)))
545 (setq recursion
(append submenu recursion
))
548 (defun org-texinfo--generate-menu-list (tree level info
)
549 "Generate the list of headlines that are within a given level
550 of the tree for further formatting.
552 TREE is the parse-tree containing the headlines. LEVEL is the
553 headline level to generate a list of. INFO is a plist holding
554 contextual information."
555 (org-element-map tree
'headline
557 (and (= (org-export-get-relative-level head info
) level
)
558 ;; Do not take note of footnotes or copying headlines.
559 (not (org-element-property :COPYING head
))
560 (not (org-element-property :footnote-section-p head
))
565 (defun org-texinfo--generate-menu-items (items info
)
566 "Generate a list of headline information from the listing ITEMS.
568 ITEMS is a list of the headlines to be converted into entries.
569 INFO is a plist containing contextual information.
571 Returns a list containing the following information from each
572 headline: length, title, description. This is used to format the
573 menu using `org-texinfo--format-menu'."
574 (loop for headline in items collect
575 (let* ((menu-title (org-texinfo--sanitize-menu
577 (org-export-get-alt-title headline info
)
579 (title (org-texinfo--sanitize-menu
580 (org-texinfo--sanitize-headline
581 (org-element-property :title headline
) info
)))
582 (descr (org-export-data
583 (org-element-property :DESCRIPTION headline
)
585 (menu-entry (if (string= "" menu-title
) title menu-title
))
586 (len (length menu-entry
))
587 (output (list len menu-entry descr
)))
590 (defun org-texinfo--menu-headlines (headline info
)
591 "Retrieve the title from HEADLINE.
593 INFO is a plist holding contextual information.
595 Return the headline as a list of (length title description) with
596 length of -1 and nil description. This is used in
597 `org-texinfo--format-menu' to identify headlines as opposed to
599 (let ((title (org-export-data
600 (org-element-property :title headline
) info
)))
601 (list -
1 title
'nil
)))
603 (defun org-texinfo--format-menu (text-menu info
)
604 "Format the TEXT-MENU items to be properly printed in the menu.
605 INFO is a plist containing contextual information.
607 Each entry in the menu should be provided as (length title
610 Headlines in the detailed menu are given length -1 to ensure they
611 are never confused with other entries. They also have no
614 Other menu items are output as:
617 With the spacing between :: and description based on the length
618 of the longest menu entry."
621 (let* ((title (nth 1 name
))
623 (length (nth 0 name
))
626 ;; 6 is "* " ":: " for inserted text
627 (- (plist-get info
:texinfo-node-description-column
) 6)))
628 (spacing (- column length
)))
630 (concat "* " title
":: "
631 (make-string spacing ?\s
)
632 (and desc
(concat desc
)))
633 (concat "\n" title
"\n"))))
638 (defun org-texinfo-template (contents info
)
639 "Return complete document string after Texinfo conversion.
640 CONTENTS is the transcoded contents string. INFO is a plist
641 holding export options."
642 (let ((title (org-export-data (plist-get info
:title
) info
))
643 ;; Copying data is the contents of the first headline in
644 ;; parse tree with a non-nil copying property.
645 (copying (org-element-map (plist-get info
:parse-tree
) 'headline
647 (and (org-not-nil (org-element-property :COPYING hl
))
648 (org-element-contents hl
)))
651 "\\input texinfo @c -*- texinfo -*-\n"
652 "@c %**start of header\n"
653 (let ((file (or (plist-get info
:texinfo-filename
)
654 (let ((f (plist-get info
:output-file
)))
655 (and f
(concat (file-name-sans-extension f
) ".info"))))))
656 (and file
(format "@setfilename %s\n" file
)))
657 (format "@settitle %s\n" title
)
658 ;; Insert class-defined header.
659 (org-element-normalize-string
660 (let ((header (nth 1 (assoc (plist-get info
:texinfo-class
)
661 org-texinfo-classes
)))
663 (catch 'coding-system
664 (let ((case-fold-search t
)
665 (name (symbol-name (or org-texinfo-coding-system
666 buffer-file-coding-system
))))
667 (dolist (system org-texinfo-supported-coding-systems
"UTF-8")
668 (when (org-string-match-p (regexp-quote system
) name
)
669 (throw 'coding-system system
))))))
670 (language (plist-get info
:language
))
671 (case-fold-search nil
))
672 ;; Auto coding system.
673 (replace-regexp-in-string
674 "^@documentencoding \\(AUTO\\)$"
676 (replace-regexp-in-string
677 "^@documentlanguage \\(AUTO\\)$" language header nil nil
1)
679 ;; Additional header options set by #+TEXINFO_HEADER.
680 (let ((texinfo-header (plist-get info
:texinfo-header
)))
681 (and texinfo-header
(org-element-normalize-string texinfo-header
)))
682 "@c %**end of header\n\n"
683 ;; Additional options set by #+TEXINFO_POST_HEADER.
684 (let ((texinfo-post-header (plist-get info
:texinfo-post-header
)))
685 (and texinfo-post-header
686 (org-element-normalize-string texinfo-post-header
)))
689 (format "@copying\n%s@end copying\n\n"
690 (org-element-normalize-string
691 (org-export-data copying info
))))
692 ;; Info directory information. Only supply if both title and
693 ;; category are provided.
694 (let ((dircat (plist-get info
:texinfo-dircat
))
696 (let ((title (plist-get info
:texinfo-dirtitle
)))
698 (string-match "^\\(?:\\* \\)?\\(.*?\\)\\(\\.\\)?$" title
)
699 (format "* %s." (match-string 1 title
))))))
700 (when (and dircat dirtitle
)
701 (concat "@dircategory " dircat
"\n"
704 (let ((desc (plist-get info
:texinfo-dirdesc
)))
705 (cond ((not desc
) nil
)
706 ((org-string-match-p "\\.$" desc
) desc
)
707 (t (concat desc
"."))))))
708 (if dirdesc
(format "%-23s %s" dirtitle dirdesc
) dirtitle
))
710 "@end direntry\n\n")))
714 (format "@title %s\n" (or (plist-get info
:texinfo-printed-title
) title
))
715 (let ((subtitle (plist-get info
:subtitle
)))
717 (org-element-normalize-string
718 (replace-regexp-in-string "^" "@subtitle " subtitle
))))
719 (when (plist-get info
:with-author
)
722 (let ((author (org-string-nw-p
723 (org-export-data (plist-get info
:author
) info
)))
724 (email (and (plist-get info
:with-email
)
726 (org-export-data (plist-get info
:email
) info
)))))
727 (cond ((and author email
)
728 (format "@author %s (@email{%s})\n" author email
))
729 (author (format "@author %s\n" author
))
730 (email (format "@author @email{%s}\n" email
))))
732 (let ((subauthor (plist-get info
:subauthor
)))
734 (org-element-normalize-string
735 (replace-regexp-in-string "^" "@author " subauthor
))))))
736 (and copying
"@page\n@vskip 0pt plus 1filll\n@insertcopying\n")
738 ;; Table of contents.
739 (and (plist-get info
:with-toc
) "@contents\n\n")
740 ;; Configure Top Node when not for Tex
743 (format "@top %s\n" title
)
744 (and copying
"@insertcopying\n")
747 (let ((menu (org-texinfo-make-menu info
'main
))
748 (detail-menu (org-texinfo-make-menu info
'detailed
)))
753 (concat "\n@detailmenu\n"
754 " --- The Detailed Node Listing ---\n"
756 "@end detailmenu\n"))
761 (case (plist-get info
:with-creator
)
763 (comment (format "@c %s\n" (plist-get info
:creator
)))
764 (otherwise (concat (plist-get info
:creator
) "\n")))
770 ;;; Transcode Functions
774 (defun org-texinfo-bold (bold contents info
)
775 "Transcode BOLD from Org to Texinfo.
776 CONTENTS is the text with bold markup. INFO is a plist holding
777 contextual information."
778 (org-texinfo--text-markup contents
'bold info
))
782 (defun org-texinfo-center-block (center-block contents info
)
783 "Transcode a CENTER-BLOCK element from Org to Texinfo.
784 CONTENTS holds the contents of the block. INFO is a plist used
785 as a communication channel."
790 (defun org-texinfo-clock (clock contents info
)
791 "Transcode a CLOCK element from Org to Texinfo.
792 CONTENTS is nil. INFO is a plist holding contextual
796 (format "@strong{%s} " org-clock-string
)
797 (format (plist-get info
:texinfo-inactive-timestamp-format
)
798 (concat (org-translate-time
799 (org-element-property :raw-value
800 (org-element-property :value clock
)))
801 (let ((time (org-element-property :duration clock
)))
802 (and time
(format " (%s)" time
)))))
807 (defun org-texinfo-code (code contents info
)
808 "Transcode a CODE object from Org to Texinfo.
809 CONTENTS is nil. INFO is a plist used as a communication
811 (org-texinfo--text-markup (org-element-property :value code
) 'code info
))
815 (defun org-texinfo-drawer (drawer contents info
)
816 "Transcode a DRAWER element from Org to Texinfo.
817 CONTENTS holds the contents of the block. INFO is a plist
818 holding contextual information."
819 (let* ((name (org-element-property :drawer-name drawer
))
820 (output (funcall (plist-get info
:texinfo-format-drawer-function
)
826 (defun org-texinfo-dynamic-block (dynamic-block contents info
)
827 "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
828 CONTENTS holds the contents of the block. INFO is a plist
829 holding contextual information."
834 (defun org-texinfo-entity (entity contents info
)
835 "Transcode an ENTITY object from Org to Texinfo.
836 CONTENTS are the definition itself. INFO is a plist holding
837 contextual information."
838 (let ((ent (org-element-property :latex entity
)))
839 (if (org-element-property :latex-math-p entity
) (format "@math{%s}" ent
) ent
)))
843 (defun org-texinfo-example-block (example-block contents info
)
844 "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
845 CONTENTS is nil. INFO is a plist holding contextual
847 (format "@verbatim\n%s@end verbatim"
848 (org-export-format-code-default example-block info
)))
852 (defun org-texinfo-export-snippet (export-snippet contents info
)
853 "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
854 CONTENTS is nil. INFO is a plist holding contextual information."
855 (when (eq (org-export-snippet-backend export-snippet
) 'texinfo
)
856 (org-element-property :value export-snippet
)))
860 (defun org-texinfo-fixed-width (fixed-width contents info
)
861 "Transcode a FIXED-WIDTH element from Org to Texinfo.
862 CONTENTS is nil. INFO is a plist holding contextual information."
863 (format "@example\n%s\n@end example"
864 (org-remove-indentation
865 (org-texinfo--sanitize-content
866 (org-element-property :value fixed-width
)))))
868 ;;;; Footnote Reference
870 (defun org-texinfo-footnote-reference (footnote contents info
)
871 "Create a footnote reference for FOOTNOTE.
873 FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
874 plist holding contextual information."
875 (let ((def (org-export-get-footnote-definition footnote info
)))
876 (format "@footnote{%s}"
877 (org-trim (org-export-data def info
)))))
881 (defun org-texinfo-headline (headline contents info
)
882 "Transcode a HEADLINE element from Org to Texinfo.
883 CONTENTS holds the contents of the headline. INFO is a plist
884 holding contextual information."
885 (let* ((class (plist-get info
:texinfo-class
))
886 (level (org-export-get-relative-level headline info
))
887 (numberedp (org-export-numbered-headline-p headline info
))
888 (class-sectioning (assoc class
(plist-get info
:texinfo-classes
)))
889 ;; Find the index type, if any
890 (index (org-element-property :INDEX headline
))
891 ;; Retrieve headline text
892 (text (org-texinfo--sanitize-headline
893 (org-element-property :title headline
) info
))
894 ;; Create node info, to insert it before section formatting.
895 ;; Use custom menu title if present
896 (node (format "@node %s\n" (org-texinfo--get-node headline info
)))
897 ;; Menus must be generated with first child, otherwise they
898 ;; will not nest properly
899 (menu (let* ((first (org-export-first-sibling-p headline info
))
900 (parent (org-export-get-parent-headline headline
))
901 (title (org-texinfo--sanitize-headline
902 (org-element-property :title parent
) info
))
904 (tree (plist-get info
:parse-tree
)))
906 (org-element-map (plist-get info
:parse-tree
) 'headline
908 (if (member title
(org-element-property :title ref
))
911 (setq listing
(org-texinfo--build-menu
912 (car heading
) level info
))
914 (setq listing
(replace-regexp-in-string
917 "\n@menu\n%s\n@end menu\n\n" listing
))
919 ;; Section formatting will set two placeholders: one for the
920 ;; title and the other for the contents.
922 (if (org-not-nil (org-element-property :APPENDIX headline
))
923 (concat menu node
"appendix\n%s")
924 (let ((sec (if (and (symbolp (nth 2 class-sectioning
))
925 (fboundp (nth 2 class-sectioning
)))
926 (funcall (nth 2 class-sectioning
) level numberedp
)
927 (nth (1+ level
) class-sectioning
))))
929 ;; No section available for that LEVEL.
931 ;; Section format directly returned by a function.
933 ;; (numbered-section . unnumbered-section)
934 ((not (consp (cdr sec
)))
937 ;; An index is always unnumbered.
938 (if (or index
(not numberedp
)) (cdr sec
) (car sec
))
941 (and (plist-get info
:with-todo-keywords
)
942 (let ((todo (org-element-property :todo-keyword headline
)))
943 (and todo
(org-export-data todo info
)))))
944 (todo-type (and todo
(org-element-property :todo-type headline
)))
945 (tags (and (plist-get info
:with-tags
)
946 (org-export-get-tags headline info
)))
947 (priority (and (plist-get info
:with-priority
)
948 (org-element-property :priority headline
)))
949 ;; Create the headline text along with a no-tag version. The
950 ;; latter is required to remove tags from table of contents.
951 (full-text (org-texinfo--sanitize-content
952 (funcall (plist-get info
:texinfo-format-headline-function
)
953 todo todo-type priority text tags
)))
955 (org-texinfo--sanitize-content
956 (funcall (plist-get info
:texinfo-format-headline-function
)
957 todo todo-type priority text nil
)))
959 (make-string (org-element-property :pre-blank headline
) 10)))
961 ;; Case 1: This is a footnote section: ignore it.
962 ((org-element-property :footnote-section-p headline
) nil
)
963 ;; Case 2: This is the `copying' section: ignore it
964 ;; This is used elsewhere.
965 ((org-element-property :COPYING headline
) nil
)
966 ;; Case 3: An index. If it matches one of the known indexes,
967 ;; print it as such following the contents, otherwise
968 ;; print the contents and leave the index up to the user.
971 section-fmt full-text
972 (concat pre-blanks contents
"\n"
973 (if (member index
'("cp" "fn" "ky" "pg" "tp" "vr"))
974 (concat "@printindex " index
)))))
975 ;; Case 4: This is a deep sub-tree: export it as a list item.
976 ;; Also export as items headlines for which no section
977 ;; format has been found.
978 ((or (not section-fmt
) (org-export-low-level-p headline info
))
979 ;; Build the real contents of the sub-tree.
980 (let ((low-level-body
982 ;; If the headline is the first sibling, start a list.
983 (when (org-export-first-sibling-p headline info
)
984 (format "@%s\n" (if numberedp
'enumerate
'itemize
)))
986 "@item\n" full-text
"\n" pre-blanks contents
)))
987 ;; If headline is not the last sibling simply return
988 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
990 (if (not (org-export-last-sibling-p headline info
)) low-level-body
991 (replace-regexp-in-string
993 (format "\n@end %s" (if numberedp
'enumerate
'itemize
))
995 ;; Case 5: Standard headline. Export it as a section.
998 ((not (and tags
(eq (plist-get info
:with-tags
) 'not-in-toc
)))
999 ;; Regular section. Use specified format string.
1000 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1001 (concat pre-blanks contents
)))
1002 ((string-match "\\`@\\(.*?\\){" section-fmt
)
1003 ;; If tags should be removed from table of contents, insert
1004 ;; title without tags as an alternative heading in sectioning
1006 (format (replace-match (concat (match-string 1 section-fmt
) "[%s]")
1007 nil nil section-fmt
1)
1008 ;; Replace square brackets with parenthesis since
1009 ;; square brackets are not supported in optional
1011 (replace-regexp-in-string
1013 (replace-regexp-in-string
1017 (concat pre-blanks contents
)))
1019 ;; Impossible to add an alternative heading. Fallback to
1020 ;; regular sectioning format string.
1021 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1022 (concat pre-blanks contents
))))))))
1024 (defun org-texinfo-format-headline-default-function
1025 (todo todo-type priority text tags
)
1026 "Default format function for a headline.
1027 See `org-texinfo-format-headline-function' for details."
1028 (concat (when todo
(format "@strong{%s} " todo
))
1029 (when priority
(format "@emph{#%s} " priority
))
1031 (when tags
(format " :%s:" (mapconcat 'identity tags
":")))))
1033 ;;;; Inline Src Block
1035 (defun org-texinfo-inline-src-block (inline-src-block contents info
)
1036 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
1037 CONTENTS holds the contents of the item. INFO is a plist holding
1038 contextual information."
1039 (let* ((code (org-element-property :value inline-src-block
))
1040 (separator (org-texinfo--find-verb-separator code
)))
1041 (concat "@verb{" separator code separator
"}")))
1045 (defun org-texinfo-inlinetask (inlinetask contents info
)
1046 "Transcode an INLINETASK element from Org to Texinfo.
1047 CONTENTS holds the contents of the block. INFO is a plist
1048 holding contextual information."
1049 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
1050 (todo (and (plist-get info
:with-todo-keywords
)
1051 (let ((todo (org-element-property :todo-keyword inlinetask
)))
1052 (and todo
(org-export-data todo info
)))))
1053 (todo-type (org-element-property :todo-type inlinetask
))
1054 (tags (and (plist-get info
:with-tags
)
1055 (org-export-get-tags inlinetask info
)))
1056 (priority (and (plist-get info
:with-priority
)
1057 (org-element-property :priority inlinetask
))))
1058 (funcall (plist-get info
:texinfo-format-inlinetask-function
)
1059 todo todo-type priority title tags contents
)))
1061 (defun org-texinfo-format-inlinetask-default-function
1062 (todo todo-type priority title tags contents
)
1063 "Default format function for a inlinetasks.
1064 See `org-texinfo-format-inlinetask-function' for details."
1066 (concat (when todo
(format "@strong{%s} " todo
))
1067 (when priority
(format "#%c " priority
))
1069 (when tags
(format ":%s:" (mapconcat #'identity tags
":"))))))
1070 (format "@center %s\n\n%s\n" full-title contents
)))
1074 (defun org-texinfo-italic (italic contents info
)
1075 "Transcode ITALIC from Org to Texinfo.
1076 CONTENTS is the text with italic markup. INFO is a plist holding
1077 contextual information."
1078 (org-texinfo--text-markup contents
'italic info
))
1082 (defun org-texinfo-item (item contents info
)
1083 "Transcode an ITEM element from Org to Texinfo.
1084 CONTENTS holds the contents of the item. INFO is a plist holding
1085 contextual information."
1086 (let* ((tag (org-element-property :tag item
))
1087 (desc (org-export-data tag info
)))
1088 (concat "\n@item " (if tag desc
) "\n"
1089 (and contents
(org-trim contents
)) "\n")))
1093 (defun org-texinfo-keyword (keyword contents info
)
1094 "Transcode a KEYWORD element from Org to Texinfo.
1095 CONTENTS is nil. INFO is a plist holding contextual information."
1096 (let ((key (org-element-property :key keyword
))
1097 (value (org-element-property :value keyword
)))
1099 ((string= key
"TEXINFO") value
)
1100 ((string= key
"CINDEX") (format "@cindex %s" value
))
1101 ((string= key
"FINDEX") (format "@findex %s" value
))
1102 ((string= key
"KINDEX") (format "@kindex %s" value
))
1103 ((string= key
"PINDEX") (format "@pindex %s" value
))
1104 ((string= key
"TINDEX") (format "@tindex %s" value
))
1105 ((string= key
"VINDEX") (format "@vindex %s" value
)))))
1109 (defun org-texinfo-line-break (line-break contents info
)
1110 "Transcode a LINE-BREAK object from Org to Texinfo.
1111 CONTENTS is nil. INFO is a plist holding contextual information."
1116 (defun org-texinfo-link (link desc info
)
1117 "Transcode a LINK object from Org to Texinfo.
1119 DESC is the description part of the link, or the empty string.
1120 INFO is a plist holding contextual information. See
1122 (let* ((type (org-element-property :type link
))
1123 (raw-path (org-element-property :path link
))
1124 ;; Ensure DESC really exists, or set it to nil.
1125 (desc (and (not (string= desc
"")) desc
))
1127 ((member type
'("http" "https" "ftp"))
1128 (concat type
":" raw-path
))
1129 ((and (string= type
"file") (file-name-absolute-p raw-path
))
1130 (concat "file:" raw-path
))
1132 (email (if (string= type
"mailto")
1133 (let ((text (replace-regexp-in-string
1134 "@" "@@" raw-path
)))
1135 (concat text
(if desc
(concat "," desc
))))))
1138 ;; Links pointing to a headline: Find destination and build
1139 ;; appropriate referencing command.
1140 ((member type
'("custom-id" "id"))
1141 (let ((destination (org-export-resolve-id-link link info
)))
1142 (case (org-element-type destination
)
1143 ;; Id link points to an external file.
1145 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1146 (format "@uref{file://%s}" destination
)))
1147 ;; LINK points to a headline. Use the headline as the NODE target
1149 (format "@ref{%s,%s}"
1150 (org-texinfo--get-node destination info
)
1153 (let ((path (org-export-solidify-link-text path
)))
1154 (if (not desc
) (format "@ref{%s}" path
)
1155 (format "@ref{%s,,%s}" path desc
)))))))
1156 ((member type
'("info"))
1157 (let* ((info-path (split-string path
"[:#]"))
1158 (info-manual (car info-path
))
1159 (info-node (or (cadr info-path
) "top"))
1160 (title (or desc
"")))
1161 (format "@ref{%s,%s,,%s,}" info-node title info-manual
)))
1162 ((member type
'("fuzzy"))
1163 (let ((destination (org-export-resolve-fuzzy-link link info
)))
1164 (case (org-element-type destination
)
1165 ;; Id link points to an external file.
1167 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1168 (format "@uref{file://%s}" destination
)))
1169 ;; LINK points to a headline. Use the headline as the NODE target
1171 (format "@ref{%s,%s}"
1172 (org-texinfo--get-node destination info
)
1175 (let ((path (org-export-solidify-link-text path
)))
1176 (if (not desc
) (format "@ref{%s}" path
)
1177 (format "@ref{%s,,%s}" path desc
)))))))
1178 ;; Special case for email addresses
1180 (format "@email{%s}" email
))
1181 ;; External link with a description part.
1182 ((and path desc
) (format "@uref{%s,%s}" path desc
))
1183 ;; External link without a description part.
1184 (path (format "@uref{%s}" path
))
1185 ;; No path, only description. Try to do something useful.
1187 (format (plist-get info
:texinfo-link-with-unknown-path-format
) desc
)))))
1192 (defun org-texinfo-make-menu (info level
)
1193 "Create the menu for inclusion in the texifo document.
1195 INFO is the parsed buffer that contains the headlines. LEVEL
1196 determines whether to make the main menu, or the detailed menu.
1198 This is only used for generating the primary menu. In-Node menus
1199 are generated directly."
1200 (let ((parse (plist-get info
:parse-tree
)))
1202 ;; Generate the main menu
1203 ((eq level
'main
) (org-texinfo--build-menu parse
1 info
))
1204 ;; Generate the detailed (recursive) menu
1205 ((eq level
'detailed
)
1206 ;; Requires recursion
1207 ;;(org-texinfo--build-detailed-menu parse top info)
1208 (org-texinfo--build-menu parse
1 info
'detailed
)))))
1212 (defun org-texinfo-node-property (node-property contents info
)
1213 "Transcode a NODE-PROPERTY element from Org to Texinfo.
1214 CONTENTS is nil. INFO is a plist holding contextual
1217 (org-element-property :key node-property
)
1218 (let ((value (org-element-property :value node-property
)))
1219 (if value
(concat " " value
) ""))))
1223 (defun org-texinfo-paragraph (paragraph contents info
)
1224 "Transcode a PARAGRAPH element from Org to Texinfo.
1225 CONTENTS is the contents of the paragraph, as a string. INFO is
1226 the plist used as a communication channel."
1231 (defun org-texinfo-plain-list (plain-list contents info
)
1232 "Transcode a PLAIN-LIST element from Org to Texinfo.
1233 CONTENTS is the contents of the list. INFO is a plist holding
1234 contextual information."
1235 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1236 (indic (or (plist-get attr
:indic
)
1237 (plist-get info
:texinfo-def-table-markup
)))
1238 (table-type (plist-get attr
:table-type
))
1239 (type (org-element-property :type plain-list
))
1241 ((eq type
'ordered
) "enumerate")
1242 ((eq type
'unordered
) "itemize")
1243 ((member table-type
'("ftable" "vtable")) table-type
)
1245 (format "@%s\n%s@end %s"
1246 (if (eq type
'descriptive
) (concat list-type
" " indic
) list-type
)
1252 (defun org-texinfo-plain-text (text info
)
1253 "Transcode a TEXT string from Org to Texinfo.
1254 TEXT is the string to transcode. INFO is a plist holding
1255 contextual information."
1256 ;; First protect @, { and }.
1257 (let ((output (org-texinfo--sanitize-content text
)))
1258 ;; Activate smart quotes. Be sure to provide original TEXT string
1259 ;; since OUTPUT may have been modified.
1260 (when (plist-get info
:with-smart-quotes
)
1262 (org-export-activate-smart-quotes output
:texinfo info text
)))
1263 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1264 (let ((case-fold-search nil
)
1266 (while (string-match "\\(\\(?:La\\)?TeX\\)" output start
)
1267 (setq output
(replace-match
1268 (format "@%s{}" (match-string 1 output
)) nil t output
)
1269 start
(match-end 0))))
1270 ;; Convert special strings.
1271 (when (plist-get info
:with-special-strings
)
1272 (while (string-match (regexp-quote "...") output
)
1273 (setq output
(replace-match "@dots{}" nil t output
))))
1274 ;; Handle break preservation if required.
1275 (when (plist-get info
:preserve-breaks
)
1276 (setq output
(replace-regexp-in-string
1277 "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output
)))
1283 (defun org-texinfo-planning (planning contents info
)
1284 "Transcode a PLANNING element from Org to Texinfo.
1285 CONTENTS is nil. INFO is a plist holding contextual
1293 (let ((closed (org-element-property :closed planning
)))
1296 (format "@strong{%s} " org-closed-string
)
1297 (format (plist-get info
:texinfo-inactive-timestamp-format
)
1299 (org-element-property :raw-value closed
))))))
1300 (let ((deadline (org-element-property :deadline planning
)))
1303 (format "@strong{%s} " org-deadline-string
)
1304 (format (plist-get info
:texinfo-active-timestamp-format
)
1306 (org-element-property :raw-value deadline
))))))
1307 (let ((scheduled (org-element-property :scheduled planning
)))
1310 (format "@strong{%s} " org-scheduled-string
)
1311 (format (plist-get info
:texinfo-active-timestamp-format
)
1313 (org-element-property :raw-value scheduled
))))))))
1317 ;;;; Property Drawer
1319 (defun org-texinfo-property-drawer (property-drawer contents info
)
1320 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1321 CONTENTS holds the contents of the drawer. INFO is a plist
1322 holding contextual information."
1323 (and (org-string-nw-p contents
)
1324 (format "@verbatim\n%s@end verbatim" contents
)))
1328 (defun org-texinfo-quote-block (quote-block contents info
)
1329 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1330 CONTENTS holds the contents of the block. INFO is a plist
1331 holding contextual information."
1332 (let* ((title (org-element-property :name quote-block
))
1333 (start-quote (concat "@quotation"
1335 (format " %s" title
)))))
1336 (format "%s\n%s@end quotation" start-quote contents
)))
1340 (defun org-texinfo-radio-target (radio-target text info
)
1341 "Transcode a RADIO-TARGET object from Org to Texinfo.
1342 TEXT is the text of the target. INFO is a plist holding
1343 contextual information."
1344 (format "@anchor{%s}%s"
1345 (org-export-solidify-link-text
1346 (org-element-property :value radio-target
))
1351 (defun org-texinfo-section (section contents info
)
1352 "Transcode a SECTION element from Org to Texinfo.
1353 CONTENTS holds the contents of the section. INFO is a plist
1354 holding contextual information."
1359 (defun org-texinfo-special-block (special-block contents info
)
1360 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1361 CONTENTS holds the contents of the block. INFO is a plist used
1362 as a communication channel."
1363 (if (org-export-raw-special-block-p special-block info
)
1364 (org-remove-indentation (org-element-property :raw-value special-block
))
1369 (defun org-texinfo-src-block (src-block contents info
)
1370 "Transcode a SRC-BLOCK element from Org to Texinfo.
1371 CONTENTS holds the contents of the item. INFO is a plist holding
1372 contextual information."
1373 (let* ((lang (org-element-property :language src-block
))
1374 (lisp-p (string-match-p "lisp" lang
))
1375 (src-contents (org-texinfo--sanitize-content
1376 (org-export-format-code-default src-block info
))))
1378 ;; Case 1. Lisp Block
1380 (format "@lisp\n%s@end lisp"
1382 ;; Case 2. Other blocks
1384 (format "@example\n%s@end example"
1387 ;;;; Statistics Cookie
1389 (defun org-texinfo-statistics-cookie (statistics-cookie contents info
)
1390 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1391 CONTENTS is nil. INFO is a plist holding contextual information."
1392 (org-element-property :value statistics-cookie
))
1396 (defun org-texinfo-subscript (subscript contents info
)
1397 "Transcode a SUBSCRIPT object from Org to Texinfo.
1398 CONTENTS is the contents of the object. INFO is a plist holding
1399 contextual information."
1400 (format "@math{_%s}" contents
))
1404 (defun org-texinfo-superscript (superscript contents info
)
1405 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1406 CONTENTS is the contents of the object. INFO is a plist holding
1407 contextual information."
1408 (format "@math{^%s}" contents
))
1412 (defun org-texinfo-table (table contents info
)
1413 "Transcode a TABLE element from Org to Texinfo.
1414 CONTENTS is the contents of the table. INFO is a plist holding
1415 contextual information."
1416 (if (eq (org-element-property :type table
) 'table.el
)
1417 (format "@verbatim\n%s@end verbatim"
1418 (org-element-normalize-string
1419 (org-element-property :value table
)))
1420 (let* ((col-width (org-export-read-attribute :attr_texinfo table
:columns
))
1422 (if col-width
(format "@columnfractions %s" col-width
)
1423 (org-texinfo-table-column-widths table info
))))
1424 (format "@multitable %s\n%s@end multitable"
1428 (defun org-texinfo-table-column-widths (table info
)
1429 "Determine the largest table cell in each column to process alignment.
1430 TABLE is the table element to transcode. INFO is a plist used as
1431 a communication channel."
1432 (let ((widths (make-vector (cdr (org-export-table-dimensions table info
)) 0)))
1433 (org-element-map table
'table-row
1436 (org-element-map row
'table-cell
1438 ;; Length of the cell in the original buffer is only an
1439 ;; approximation of the length of the cell in the
1440 ;; output. It can sometimes fail (e.g. it considers
1441 ;; "/a/" being larger than "ab").
1442 (let ((w (- (org-element-property :contents-end cell
)
1443 (org-element-property :contents-begin cell
))))
1444 (aset widths idx
(max w
(aref widths idx
))))
1448 (format "{%s}" (mapconcat (lambda (w) (make-string w ?a
)) widths
"} {"))))
1452 (defun org-texinfo-table-cell (table-cell contents info
)
1453 "Transcode a TABLE-CELL element from Org to Texinfo.
1454 CONTENTS is the cell contents. INFO is a plist used as
1455 a communication channel."
1457 (let ((scientific-notation
1458 (plist-get info
:texinfo-table-scientific-notation
)))
1461 (string-match orgtbl-exp-regexp contents
))
1462 ;; Use appropriate format string for scientific notation.
1463 (format scientific-notation
1464 (match-string 1 contents
)
1465 (match-string 2 contents
))
1467 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1471 (defun org-texinfo-table-row (table-row contents info
)
1472 "Transcode a TABLE-ROW element from Org to Texinfo.
1473 CONTENTS is the contents of the row. INFO is a plist used as
1474 a communication channel."
1475 ;; Rules are ignored since table separators are deduced from
1476 ;; borders of the current row.
1477 (when (eq (org-element-property :type table-row
) 'standard
)
1479 (if (and (= 1 (org-export-table-row-group table-row info
))
1480 (org-export-table-has-header-p
1481 (org-export-get-parent-table table-row
) info
))
1484 (concat rowgroup-tag contents
"\n"))))
1488 (defun org-texinfo-target (target contents info
)
1489 "Transcode a TARGET object from Org to Texinfo.
1490 CONTENTS is nil. INFO is a plist holding contextual
1492 (format "@anchor{%s}"
1493 (org-export-solidify-link-text (org-element-property :value target
))))
1497 (defun org-texinfo-timestamp (timestamp contents info
)
1498 "Transcode a TIMESTAMP object from Org to Texinfo.
1499 CONTENTS is nil. INFO is a plist holding contextual
1501 (let ((value (org-texinfo-plain-text
1502 (org-timestamp-translate timestamp
) info
)))
1503 (case (org-element-property :type timestamp
)
1504 ((active active-range
)
1505 (format (plist-get info
:texinfo-active-timestamp-format
) value
))
1506 ((inactive inactive-range
)
1507 (format (plist-get info
:texinfo-inactive-timestamp-format
) value
))
1508 (t (format (plist-get info
:texinfo-diary-timestamp-format
) value
)))))
1512 (defun org-texinfo-verbatim (verbatim contents info
)
1513 "Transcode a VERBATIM object from Org to Texinfo.
1514 CONTENTS is nil. INFO is a plist used as a communication
1516 (org-texinfo--text-markup
1517 (org-element-property :value verbatim
) 'verbatim info
))
1521 (defun org-texinfo-verse-block (verse-block contents info
)
1522 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1523 CONTENTS is verse block contents. INFO is a plist holding
1524 contextual information."
1525 (format "@display\n%s@end display" contents
))
1528 ;;; Interactive functions
1530 (defun org-texinfo-export-to-texinfo
1531 (&optional async subtreep visible-only body-only ext-plist
)
1532 "Export current buffer to a Texinfo file.
1534 If narrowing is active in the current buffer, only export its
1537 If a region is active, export that region.
1539 A non-nil optional argument ASYNC means the process should happen
1540 asynchronously. The resulting file should be accessible through
1541 the `org-export-stack' interface.
1543 When optional argument SUBTREEP is non-nil, export the sub-tree
1544 at point, extracting information from the headline properties
1547 When optional argument VISIBLE-ONLY is non-nil, don't export
1548 contents of hidden elements.
1550 When optional argument BODY-ONLY is non-nil, only write code
1551 between \"\\begin{document}\" and \"\\end{document}\".
1553 EXT-PLIST, when provided, is a property list with external
1554 parameters overriding Org default settings, but still inferior to
1555 file-local settings.
1557 Return output file's name."
1559 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1560 (org-export-coding-system org-texinfo-coding-system
))
1561 (org-export-to-file 'texinfo outfile
1562 async subtreep visible-only body-only ext-plist
)))
1564 (defun org-texinfo-export-to-info
1565 (&optional async subtreep visible-only body-only ext-plist
)
1566 "Export current buffer to Texinfo then process through to INFO.
1568 If narrowing is active in the current buffer, only export its
1571 If a region is active, export that region.
1573 A non-nil optional argument ASYNC means the process should happen
1574 asynchronously. The resulting file should be accessible through
1575 the `org-export-stack' interface.
1577 When optional argument SUBTREEP is non-nil, export the sub-tree
1578 at point, extracting information from the headline properties
1581 When optional argument VISIBLE-ONLY is non-nil, don't export
1582 contents of hidden elements.
1584 When optional argument BODY-ONLY is non-nil, only write code
1585 between \"\\begin{document}\" and \"\\end{document}\".
1587 EXT-PLIST, when provided, is a property list with external
1588 parameters overriding Org default settings, but still inferior to
1589 file-local settings.
1591 When optional argument PUB-DIR is set, use it as the publishing
1594 Return INFO file's name."
1596 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1597 (org-export-coding-system org-texinfo-coding-system
))
1598 (org-export-to-file 'texinfo outfile
1599 async subtreep visible-only body-only ext-plist
1600 (lambda (file) (org-texinfo-compile file
)))))
1603 (defun org-texinfo-publish-to-texinfo (plist filename pub-dir
)
1604 "Publish an org file to Texinfo.
1606 FILENAME is the filename of the Org file to be published. PLIST
1607 is the property list for the given project. PUB-DIR is the
1608 publishing directory.
1610 Return output file name."
1611 (org-publish-org-to 'texinfo filename
".texi" plist pub-dir
))
1614 (defun org-texinfo-convert-region-to-texinfo ()
1615 "Assume the current region has org-mode syntax, and convert it to Texinfo.
1616 This can be used in any buffer. For example, you can write an
1617 itemized list in org-mode syntax in an Texinfo buffer and use
1618 this command to convert it."
1620 (org-export-replace-region-by 'texinfo
))
1622 (defun org-texinfo-compile (file)
1623 "Compile a texinfo file.
1625 FILE is the name of the file being compiled. Processing is
1626 done through the command specified in `org-texinfo-info-process'.
1628 Return INFO file name or an error if it couldn't be produced."
1629 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file
)))
1630 (full-name (file-truename file
))
1631 (out-dir (file-name-directory file
))
1632 ;; Properly set working directory for compilation.
1633 (default-directory (if (file-name-absolute-p file
)
1634 (file-name-directory full-name
)
1637 (message (format "Processing Texinfo file %s..." file
))
1638 (save-window-excursion
1640 ;; A function is provided: Apply it.
1641 ((functionp org-texinfo-info-process
)
1642 (funcall org-texinfo-info-process
(shell-quote-argument file
)))
1643 ;; A list is provided: Replace %b, %f and %o with appropriate
1644 ;; values in each command before applying it. Output is
1645 ;; redirected to "*Org INFO Texinfo Output*" buffer.
1646 ((consp org-texinfo-info-process
)
1647 (let ((outbuf (get-buffer-create "*Org INFO Texinfo Output*")))
1651 (replace-regexp-in-string
1652 "%b" (shell-quote-argument base-name
)
1653 (replace-regexp-in-string
1654 "%f" (shell-quote-argument full-name
)
1655 (replace-regexp-in-string
1656 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
1658 org-texinfo-info-process
)
1659 ;; Collect standard errors from output buffer.
1660 (setq errors
(org-texinfo-collect-errors outbuf
))))
1661 (t (error "No valid command to process to Info")))
1662 (let ((infofile (concat out-dir base-name
".info")))
1663 ;; Check for process failure. Provide collected errors if
1665 (if (not (file-exists-p infofile
))
1666 (error (concat (format "INFO file %s wasn't produced" infofile
)
1667 (when errors
(concat ": " errors
))))
1668 ;; Else remove log files, when specified, and signal end of
1669 ;; process to user, along with any error encountered.
1670 (when org-texinfo-remove-logfiles
1671 (dolist (ext org-texinfo-logfiles-extensions
)
1672 (let ((file (concat out-dir base-name
"." ext
)))
1673 (when (file-exists-p file
) (delete-file file
)))))
1674 (message (concat "Process completed"
1675 (if (not errors
) "."
1676 (concat " with errors: " errors
)))))
1677 ;; Return output file name.
1680 (defun org-texinfo-collect-errors (buffer)
1681 "Collect some kind of errors from \"makeinfo\" command output.
1683 BUFFER is the buffer containing output.
1685 Return collected error types as a string, or nil if there was
1687 (with-current-buffer buffer
1689 (goto-char (point-min))
1690 ;; Find final "makeinfo" run.
1692 (let ((case-fold-search t
)
1694 (when (save-excursion
1695 (re-search-forward "perhaps incorrect sectioning?" nil t
))
1696 (setq errors
(concat errors
" [incorrect sectioning]")))
1697 (when (save-excursion
1698 (re-search-forward "missing close brace" nil t
))
1699 (setq errors
(concat errors
" [syntax error]")))
1700 (when (save-excursion
1701 (re-search-forward "Unknown command" nil t
))
1702 (setq errors
(concat errors
" [undefined @command]")))
1703 (when (save-excursion
1704 (re-search-forward "No matching @end" nil t
))
1705 (setq errors
(concat errors
" [block incomplete]")))
1706 (when (save-excursion
1707 (re-search-forward "requires a sectioning" nil t
))
1708 (setq errors
(concat errors
" [invalid section command]")))
1709 (when (save-excursion
1710 (re-search-forward "\\[unexpected\]" nil t
))
1711 (setq errors
(concat errors
" [unexpected error]")))
1712 (when (save-excursion
1713 (re-search-forward "misplaced " nil t
))
1714 (setq errors
(concat errors
" [syntax error]")))
1715 (and (org-string-nw-p errors
) (org-trim errors
)))))))
1718 (provide 'ox-texinfo
)
1721 ;; generated-autoload-file: "org-loaddefs.el"
1724 ;;; ox-texinfo.el ends here