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 ;; This library implements a Texinfo back-end for Org generic
29 ;; M-: (org-export-to-buffer 'texinfo "*Test Texinfo*") RET
31 ;; in an Org mode buffer then switch to the buffer to see the Texinfo
32 ;; export. See ox.el for more details on how this exporter works.
35 ;; It introduces nine new buffer keywords: "TEXINFO_CLASS",
36 ;; "TEXINFO_FILENAME", "TEXINFO_HEADER", "TEXINFO_POST_HEADER",
37 ;; "TEXINFO_DIR_CATEGORY", "TEXINFO_DIR_TITLE", "TEXINFO_DIR_DESC"
38 ;; "SUBTITLE" and "SUBAUTHOR".
41 ;; It introduces 1 new headline property keywords:
42 ;; "TEXINFO_MENU_TITLE" for optional menu titles.
44 ;; To include inline code snippets (for example for generating @kbd{}
45 ;; and @key{} commands), the following export-snippet keys are
51 ;; You can add them for export snippets via any of the below:
53 ;; (add-to-list 'org-export-snippet-translation-alist
54 ;; '("info" . "texinfo"))
59 (eval-when-compile (require 'cl
))
62 (defvar orgtbl-exp-regexp
)
68 (org-export-define-backend 'texinfo
69 '((bold . org-texinfo-bold
)
70 (center-block . org-texinfo-center-block
)
71 (clock . org-texinfo-clock
)
72 (code . org-texinfo-code
)
73 (comment . org-texinfo-comment
)
74 (comment-block . org-texinfo-comment-block
)
75 (drawer . org-texinfo-drawer
)
76 (dynamic-block . org-texinfo-dynamic-block
)
77 (entity . org-texinfo-entity
)
78 (example-block . org-texinfo-example-block
)
79 (export-snippet . org-texinfo-export-snippet
)
80 (fixed-width . org-texinfo-fixed-width
)
81 (footnote-definition . org-texinfo-footnote-definition
)
82 (footnote-reference . org-texinfo-footnote-reference
)
83 (headline . org-texinfo-headline
)
84 (inline-src-block . org-texinfo-inline-src-block
)
85 (inlinetask . org-texinfo-inlinetask
)
86 (italic . org-texinfo-italic
)
87 (item . org-texinfo-item
)
88 (keyword . org-texinfo-keyword
)
89 (line-break . org-texinfo-line-break
)
90 (link . org-texinfo-link
)
91 (node-property . org-texinfo-node-property
)
92 (paragraph . org-texinfo-paragraph
)
93 (plain-list . org-texinfo-plain-list
)
94 (plain-text . org-texinfo-plain-text
)
95 (planning . org-texinfo-planning
)
96 (property-drawer . org-texinfo-property-drawer
)
97 (quote-block . org-texinfo-quote-block
)
98 (radio-target . org-texinfo-radio-target
)
99 (section . org-texinfo-section
)
100 (special-block . org-texinfo-special-block
)
101 (src-block . org-texinfo-src-block
)
102 (statistics-cookie . org-texinfo-statistics-cookie
)
103 (subscript . org-texinfo-subscript
)
104 (superscript . org-texinfo-superscript
)
105 (table . org-texinfo-table
)
106 (table-cell . org-texinfo-table-cell
)
107 (table-row . org-texinfo-table-row
)
108 (target . org-texinfo-target
)
109 (template . org-texinfo-template
)
110 (timestamp . org-texinfo-timestamp
)
111 (verbatim . org-texinfo-verbatim
)
112 (verse-block . org-texinfo-verse-block
))
113 :export-block
"TEXINFO"
115 '((:filter-headline . org-texinfo-filter-section-blank-lines
)
116 (:filter-section . org-texinfo-filter-section-blank-lines
))
118 '(?i
"Export to Texinfo"
119 ((?t
"As TEXI file" org-texinfo-export-to-texinfo
)
120 (?i
"As INFO file" org-texinfo-export-to-info
)))
122 '((:texinfo-filename
"TEXINFO_FILENAME" nil org-texinfo-filename t
)
123 (:texinfo-class
"TEXINFO_CLASS" nil org-texinfo-default-class t
)
124 (:texinfo-header
"TEXINFO_HEADER" nil nil newline
)
125 (:texinfo-post-header
"TEXINFO_POST_HEADER" nil nil newline
)
126 (:subtitle
"SUBTITLE" nil nil newline
)
127 (:subauthor
"SUBAUTHOR" nil nil newline
)
128 (:texinfo-dircat
"TEXINFO_DIR_CATEGORY" nil nil t
)
129 (:texinfo-dirtitle
"TEXINFO_DIR_TITLE" nil nil t
)
130 (:texinfo-dirdesc
"TEXINFO_DIR_DESC" nil nil t
)
132 (:texinfo-classes nil nil org-texinfo-classes
)
133 (:texinfo-format-headline-function nil nil org-texinfo-format-headline-function
)
134 (:texinfo-node-description-column nil nil org-texinfo-node-description-column
)
135 (:texinfo-active-timestamp-format nil nil org-texinfo-active-timestamp-format
)
136 (:texinfo-inactive-timestamp-format nil nil org-texinfo-inactive-timestamp-format
)
137 (:texinfo-diary-timestamp-format nil nil org-texinfo-diary-timestamp-format
)
138 (:texinfo-link-with-unknown-path-format nil nil org-texinfo-link-with-unknown-path-format
)
139 (:texinfo-tables-verbatim nil nil org-texinfo-tables-verbatim
)
140 (:texinfo-table-scientific-notation nil nil org-texinfo-table-scientific-notation
)
141 (:texinfo-def-table-markup nil nil org-texinfo-def-table-markup
)
142 (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist
)
143 (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function
)
144 (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function
)))
148 ;;; User Configurable Variables
150 (defgroup org-export-texinfo nil
151 "Options for exporting Org mode files to Texinfo."
152 :tag
"Org Export Texinfo"
154 :package-version
'(Org .
"8.0")
159 (defcustom org-texinfo-filename
""
160 "Default filename for Texinfo output."
161 :group
'org-export-texinfo
162 :type
'(string :tag
"Export Filename"))
164 (defcustom org-texinfo-coding-system nil
165 "Default document encoding for Texinfo output.
167 If `nil' it will default to `buffer-file-coding-system'."
168 :group
'org-export-texinfo
169 :type
'coding-system
)
171 (defcustom org-texinfo-default-class
"info"
172 "The default Texinfo class."
173 :group
'org-export-texinfo
174 :type
'(string :tag
"Texinfo class"))
176 (defcustom org-texinfo-classes
178 "\\input texinfo @c -*- texinfo -*-"
179 ("@chapter %s" .
"@unnumbered %s")
180 ("@section %s" .
"@unnumberedsec %s")
181 ("@subsection %s" .
"@unnumberedsubsec %s")
182 ("@subsubsection %s" .
"@unnumberedsubsubsec %s")))
183 "Alist of Texinfo classes and associated header and structure.
184 If #+Texinfo_CLASS is set in the buffer, use its value and the
185 associated information. Here is the structure of each cell:
189 \(numbered-section . unnumbered-section\)
192 The sectioning structure
193 ------------------------
195 The sectioning structure of the class is given by the elements
196 following the header string. For each sectioning level, a number
197 of strings is specified. A %s formatter is mandatory in each
198 section string and will be replaced by the title of the section.
200 Instead of a list of sectioning commands, you can also specify
201 a function name. That function will be called with two
202 parameters, the \(reduced) level of the headline, and a predicate
203 non-nil when the headline should be numbered. It must return
204 a format string in which the section title will be added."
205 :group
'org-export-texinfo
207 (list (string :tag
"Texinfo class")
208 (string :tag
"Texinfo header")
209 (repeat :tag
"Levels" :inline t
212 (string :tag
" numbered")
213 (string :tag
"unnumbered"))
214 (function :tag
"Hook computing sectioning"))))))
218 (defcustom org-texinfo-format-headline-function
219 'org-texinfo-format-headline-default-function
220 "Function to format headline text.
222 This function will be called with 5 arguments:
223 TODO the todo keyword (string or nil).
224 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
225 PRIORITY the priority of the headline (integer or nil)
226 TEXT the main headline text (string).
227 TAGS the tags as a list of strings (list of strings or nil).
229 The function result will be used in the section format string."
230 :group
'org-export-texinfo
233 :package-version
'(Org .
"8.3"))
235 ;;; Node listing (menu)
237 (defcustom org-texinfo-node-description-column
32
238 "Column at which to start the description in the node
241 If a node title is greater than this length, the description will
242 be placed after the end of the title."
243 :group
'org-export-texinfo
248 ;; Footnotes are inserted directly
252 (defcustom org-texinfo-active-timestamp-format
"@emph{%s}"
253 "A printf format string to be applied to active timestamps."
254 :group
'org-export-texinfo
257 (defcustom org-texinfo-inactive-timestamp-format
"@emph{%s}"
258 "A printf format string to be applied to inactive timestamps."
259 :group
'org-export-texinfo
262 (defcustom org-texinfo-diary-timestamp-format
"@emph{%s}"
263 "A printf format string to be applied to diary timestamps."
264 :group
'org-export-texinfo
269 (defcustom org-texinfo-link-with-unknown-path-format
"@indicateurl{%s}"
270 "Format string for links with unknown path type."
271 :group
'org-export-texinfo
276 (defcustom org-texinfo-tables-verbatim nil
277 "When non-nil, tables are exported verbatim."
278 :group
'org-export-texinfo
281 (defcustom org-texinfo-table-scientific-notation
"%s\\,(%s)"
282 "Format string to display numbers in scientific notation.
283 The format should have \"%s\" twice, for mantissa and exponent
284 \(i.e. \"%s\\\\times10^{%s}\").
286 When nil, no transformation is made."
287 :group
'org-export-texinfo
289 (string :tag
"Format string")
290 (const :tag
"No formatting")))
292 (defcustom org-texinfo-def-table-markup
"@samp"
293 "Default setting for @table environments."
294 :group
'org-export-texinfo
299 (defcustom org-texinfo-text-markup-alist
'((bold .
"@strong{%s}")
301 (italic .
"@emph{%s}")
304 "Alist of Texinfo expressions to convert text markup.
306 The key must be a symbol among `bold', `italic' and `comment'.
307 The value is a formatting string to wrap fontified text with.
309 Value can also be set to the following symbols: `verb' and
310 `code'. For the former, Org will use \"@verb\" to
311 create a format string and select a delimiter character that
312 isn't in the string. For the latter, Org will use \"@code\"
313 to typeset and try to protect special characters.
315 If no association can be found for a given markup, text will be
317 :group
'org-export-texinfo
319 :options
'(bold code italic verbatim comment
))
323 (defcustom org-texinfo-format-drawer-function
324 (lambda (name contents
) contents
)
325 "Function called to format a drawer in Texinfo code.
327 The function must accept two parameters:
328 NAME the drawer name, like \"LOGBOOK\"
329 CONTENTS the contents of the drawer.
331 The function should return the string to be exported.
333 The default function simply returns the value of CONTENTS."
334 :group
'org-export-texinfo
336 :package-version
'(Org .
"8.3")
341 (defcustom org-texinfo-format-inlinetask-function
342 'org-texinfo-format-inlinetask-default-function
343 "Function called to format an inlinetask in Texinfo code.
345 The function must accept six parameters:
346 TODO the todo keyword, as a string
347 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
348 PRIORITY the inlinetask priority, as a string
349 NAME the inlinetask name, as a string.
350 TAGS the inlinetask tags, as a list of strings.
351 CONTENTS the contents of the inlinetask, as a string.
353 The function should return the string to be exported."
354 :group
'org-export-texinfo
359 ;; Src Blocks are example blocks, except for LISP
363 (defcustom org-texinfo-info-process
365 "Commands to process a Texinfo file to an INFO file.
366 This is list of strings, each of them will be given to the shell
367 as a command. %f in the command will be replaced by the full
368 file name, %b by the file base name \(i.e without extension) and
369 %o by the base directory of the file."
370 :group
'org-export-texinfo
371 :type
'(repeat :tag
"Shell command sequence"
372 (string :tag
"Shell command")))
374 (defcustom org-texinfo-logfiles-extensions
375 '("aux" "toc" "cp" "fn" "ky" "pg" "tp" "vr")
376 "The list of file extensions to consider as Texinfo logfiles.
377 The logfiles will be remove if `org-texinfo-remove-logfiles' is
379 :group
'org-export-texinfo
380 :type
'(repeat (string :tag
"Extension")))
382 (defcustom org-texinfo-remove-logfiles t
383 "Non-nil means remove the logfiles produced by compiling a Texinfo file.
384 By default, logfiles are files with these extensions: .aux, .toc,
385 .cp, .fn, .ky, .pg and .tp. To define the set of logfiles to remove,
386 set `org-texinfo-logfiles-extensions'."
387 :group
'org-export-latex
392 (defconst org-texinfo-max-toc-depth
4
393 "Maximum depth for creation of detailed menu listings. Beyond
394 this depth Texinfo will not recognize the nodes and will cause
395 errors. Left as a constant in case this value ever changes.")
397 (defconst org-texinfo-supported-coding-systems
398 '("US-ASCII" "UTF-8" "ISO-8859-15" "ISO-8859-1" "ISO-8859-2" "koi8-r" "koi8-u")
399 "List of coding systems supported by Texinfo, as strings.
400 Specified coding system will be matched against these strings.
401 If two strings share the same prefix (e.g. \"ISO-8859-1\" and
402 \"ISO-8859-15\"), the most specific one has to be listed first.")
405 ;;; Internal Functions
407 (defun org-texinfo-filter-section-blank-lines (headline back-end info
)
408 "Filter controlling number of blank lines after a section."
409 (let ((blanks (make-string 2 ?
\n)))
410 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline
)))
412 (defun org-texinfo--find-verb-separator (s)
413 "Return a character not used in string S.
414 This is used to choose a separator for constructs like \\verb."
415 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
416 (loop for c across ll
417 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
418 return
(char-to-string c
))))
420 (defun org-texinfo--make-option-string (options)
421 "Return a comma separated string of keywords and values.
422 OPTIONS is an alist where the key is the options keyword as
423 a string, and the value a list containing the keyword value, or
425 (mapconcat (lambda (pair)
427 (when (> (length (second pair
)) 0)
428 (concat "=" (second pair
)))))
432 (defun org-texinfo--text-markup (text markup info
)
433 "Format TEXT depending on MARKUP text markup.
434 INFO is a plist used as a communication channel. See
435 `org-texinfo-text-markup-alist' for details."
436 (let ((fmt (cdr (assq markup org-texinfo-text-markup-alist
))))
438 ;; No format string: Return raw text.
441 (let ((separator (org-texinfo--find-verb-separator text
)))
442 (concat "@verb{" separator text separator
"}")))
447 (while (string-match "[@{}]" text
)
448 (setq char
(match-string 0 text
))
449 (if (> (match-beginning 0) 0)
450 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
451 (setq text
(substring text
(1+ (match-beginning 0))))
452 (setq char
(concat "@" char
)
453 rtn
(concat rtn char
)))
454 (setq text
(concat rtn text
)
457 ;; Else use format string.
458 (t (format fmt text
)))))
460 (defun org-texinfo--get-node (headline info
)
461 "Return node entry associated to HEADLINE.
462 INFO is a plist used as a communication channel."
463 (let ((menu-title (org-export-get-alt-title headline info
)))
464 (org-texinfo--sanitize-menu
465 (replace-regexp-in-string
467 (if menu-title
(org-export-data menu-title info
)
468 (org-texinfo--sanitize-headline
469 (org-element-property :title headline
) info
))))))
471 ;;; Headline sanitizing
473 (defun org-texinfo--sanitize-headline (headline info
)
474 "Remove all formatting from the text of a headline for use in
475 node and menu listing."
477 (org-texinfo--sanitize-headline-contents headline info
) " "))
479 (defun org-texinfo--sanitize-headline-contents (headline info
)
480 "Retrieve the content of the headline.
482 Any content that can contain further formatting is checked
483 recursively, to ensure that nested content is also properly
485 (loop for contents in headline append
489 (list (replace-regexp-in-string " $" "" contents
)))
490 ;; Is exported as-is (value)
491 ((org-element-map contents
'(verbatim code
)
492 (lambda (value) (org-element-property :value value
)) info
))
493 ;; Has content and recurse into the content
494 ((org-element-contents contents
)
495 (org-texinfo--sanitize-headline-contents
496 (org-element-contents contents
) info
)))))
500 (defun org-texinfo--sanitize-menu (title)
501 "Remove invalid characters from TITLE for use in menus and
504 Based on Texinfo specifications, the following must be removed:
506 (replace-regexp-in-string "[@{}():,.]" "" title
))
508 ;;; Content sanitizing
510 (defun org-texinfo--sanitize-content (text)
511 "Ensure characters are properly escaped when used in headlines or blocks.
513 Escape characters are: @ { }"
514 (replace-regexp-in-string "\\\([@{}]\\\)" "@\\1" text
))
518 (defun org-texinfo--build-menu (tree level info
&optional detailed
)
519 "Create the @menu/@end menu information from TREE at headline
522 TREE contains the parse-tree to work with, either of the entire
523 document or of a specific parent headline. LEVEL indicates what
524 level of headlines to look at when generating the menu. INFO is
525 a plist containing contextual information.
527 Detailed determines whether to build a single level of menu, or
528 recurse into all children as well."
529 (let ((menu (org-texinfo--generate-menu-list tree level info
))
533 ;; Looping is done within the menu generation.
534 (setq text-menu
(org-texinfo--generate-detailed menu level info
)))
536 (setq text-menu
(org-texinfo--generate-menu-items menu info
))))
538 (setq output
(org-texinfo--format-menu text-menu info
))
539 (mapconcat 'identity output
"\n"))))
541 (defun org-texinfo--generate-detailed (menu level info
)
542 "Generate a detailed listing of all subheadings within MENU starting at LEVEL.
544 MENU is the parse-tree to work with. LEVEL is the starting level
545 for the menu headlines and from which recursion occurs. INFO is
546 a plist containing contextual information."
548 (let ((max-depth (min org-texinfo-max-toc-depth
549 (plist-get info
:headline-levels
))))
550 (when (> max-depth level
)
551 (loop for headline in menu append
552 (let* ((title (org-texinfo--menu-headlines headline info
))
553 ;; Create list of menu entries for the next level
554 (sublist (org-texinfo--generate-menu-list
555 headline
(1+ level
) info
))
556 ;; Generate the menu items for that level. If
557 ;; there are none omit that heading completely,
558 ;; otherwise join the title to it's related entries.
559 (submenu (if (org-texinfo--generate-menu-items sublist info
)
561 (org-texinfo--generate-menu-items sublist info
))
563 ;; Start the process over the next level down.
564 (recursion (org-texinfo--generate-detailed sublist
(1+ level
) info
)))
565 (setq recursion
(append submenu recursion
))
568 (defun org-texinfo--generate-menu-list (tree level info
)
569 "Generate the list of headlines that are within a given level
570 of the tree for further formatting.
572 TREE is the parse-tree containing the headlines. LEVEL is the
573 headline level to generate a list of. INFO is a plist holding
574 contextual information."
575 (org-element-map tree
'headline
577 (and (= (org-export-get-relative-level head info
) level
)
578 ;; Do not take note of footnotes or copying headlines.
579 (not (org-element-property :COPYING head
))
580 (not (org-element-property :footnote-section-p head
))
585 (defun org-texinfo--generate-menu-items (items info
)
586 "Generate a list of headline information from the listing ITEMS.
588 ITEMS is a list of the headlines to be converted into entries.
589 INFO is a plist containing contextual information.
591 Returns a list containing the following information from each
592 headline: length, title, description. This is used to format the
593 menu using `org-texinfo--format-menu'."
594 (loop for headline in items collect
595 (let* ((menu-title (org-texinfo--sanitize-menu
597 (org-export-get-alt-title headline info
)
599 (title (org-texinfo--sanitize-menu
600 (org-texinfo--sanitize-headline
601 (org-element-property :title headline
) info
)))
602 (descr (org-export-data
603 (org-element-property :DESCRIPTION headline
)
605 (menu-entry (if (string= "" menu-title
) title menu-title
))
606 (len (length menu-entry
))
607 (output (list len menu-entry descr
)))
610 (defun org-texinfo--menu-headlines (headline info
)
611 "Retrieve the title from HEADLINE.
613 INFO is a plist holding contextual information.
615 Return the headline as a list of (length title description) with
616 length of -1 and nil description. This is used in
617 `org-texinfo--format-menu' to identify headlines as opposed to
619 (let ((title (org-export-data
620 (org-element-property :title headline
) info
)))
621 (list -
1 title
'nil
)))
623 (defun org-texinfo--format-menu (text-menu info
)
624 "Format the TEXT-MENU items to be properly printed in the menu.
625 INFO is a plist containing contextual information.
627 Each entry in the menu should be provided as (length title
630 Headlines in the detailed menu are given length -1 to ensure they
631 are never confused with other entries. They also have no
634 Other menu items are output as:
637 With the spacing between :: and description based on the length
638 of the longest menu entry."
641 (let* ((title (nth 1 name
))
643 (length (nth 0 name
))
646 ;; 6 is "* " ":: " for inserted text
647 (- (plist-get info
:texinfo-node-description-column
) 6)))
648 (spacing (- column length
)))
650 (concat "* " title
":: "
651 (make-string spacing ?\s
)
652 (and desc
(concat desc
)))
653 (concat "\n" title
"\n"))))
658 (defun org-texinfo-template (contents info
)
659 "Return complete document string after Texinfo conversion.
660 CONTENTS is the transcoded contents string. INFO is a plist
661 holding export options."
662 (let* ((title (org-export-data (plist-get info
:title
) info
))
663 (info-filename (or (plist-get info
:texinfo-filename
)
664 (file-name-nondirectory
665 (org-export-output-file-name ".info"))))
666 (author (org-export-data (plist-get info
:author
) info
))
667 (lang (org-export-data (plist-get info
:language
) info
))
668 (texinfo-header (plist-get info
:texinfo-header
))
669 (texinfo-post-header (plist-get info
:texinfo-post-header
))
670 (subtitle (plist-get info
:subtitle
))
671 (subauthor (plist-get info
:subauthor
))
672 (class (plist-get info
:texinfo-class
))
673 (header (nth 1 (assoc class
(plist-get info
:texinfo-classes
))))
675 (org-element-map (plist-get info
:parse-tree
) 'headline
676 (lambda (hl) (and (org-element-property :COPYING hl
) hl
)) info t
))
677 (dircat (plist-get info
:texinfo-dircat
))
678 (dirtitle (plist-get info
:texinfo-dirtitle
))
679 (dirdesc (plist-get info
:texinfo-dirdesc
))
680 ;; Spacing to align description (column 32 - 3 for `* ' and
682 (dirspacing (- 29 (length dirtitle
)))
683 (menu (org-texinfo-make-menu info
'main
))
684 (detail-menu (org-texinfo-make-menu info
'detailed
)))
688 "@c %**start of header\n"
689 ;; Filename and Title
690 "@setfilename " info-filename
"\n"
691 "@settitle " title
"\n"
694 "@documentencoding %s\n"
695 (catch 'coding-system
696 (let ((case-fold-search t
)
697 (name (symbol-name (or org-texinfo-coding-system
698 buffer-file-coding-system
))))
699 (dolist (system org-texinfo-supported-coding-systems
"UTF-8")
700 (when (org-string-match-p (regexp-quote system
) name
)
701 (throw 'coding-system system
))))))
703 (format "@documentlanguage %s\n" lang
)
705 "@c Version and Contact Info\n"
706 "@set AUTHOR " author
"\n"
708 ;; Additional Header Options set by `#+TEXINFO_HEADER
714 "@c %**end of header\n"
718 ;; Additional Header Options set by #+TEXINFO_POST_HEADER
719 (if texinfo-post-header
726 ;; Only export the content of the headline, do not need the
728 (org-export-data (nth 2 copying
) info
)
732 ;; Info directory information
733 ;; Only supply if both title and category are provided
734 (if (and dircat dirtitle
)
735 (concat "@dircategory " dircat
"\n"
738 (make-string dirspacing ?\s
)
745 "@title " title
"\n\n"
747 (concat "@subtitle " subtitle
"\n"))
748 "@author " author
"\n"
750 (concat subauthor
"\n"))
752 "@c The following two commands start the copyright page.\n"
754 "@vskip 0pt plus 1filll\n"
757 "@c Output the table of contents at the beginning.\n"
760 ;; Configure Top Node when not for Tex
763 "@top " title
" Manual\n"
767 ;; Do not output menus if they are empty
775 (concat "@detailmenu\n"
776 " --- The Detailed Node Listing ---\n"
779 "@end detailmenu\n"))
787 (let ((creator-info (plist-get info
:with-creator
)))
789 ((not creator-info
) "")
790 ((eq creator-info
'comment
)
791 (format "@c %s\n" (plist-get info
:creator
)))
792 (t (concat (plist-get info
:creator
) "\n"))))
798 ;;; Transcode Functions
802 (defun org-texinfo-bold (bold contents info
)
803 "Transcode BOLD from Org to Texinfo.
804 CONTENTS is the text with bold markup. INFO is a plist holding
805 contextual information."
806 (org-texinfo--text-markup contents
'bold info
))
810 (defun org-texinfo-center-block (center-block contents info
)
811 "Transcode a CENTER-BLOCK element from Org to Texinfo.
812 CONTENTS holds the contents of the block. INFO is a plist used
813 as a communication channel."
818 (defun org-texinfo-clock (clock contents info
)
819 "Transcode a CLOCK element from Org to Texinfo.
820 CONTENTS is nil. INFO is a plist holding contextual
824 (format "@strong{%s} " org-clock-string
)
825 (format (plist-get info
:texinfo-inactive-timestamp-format
)
826 (concat (org-translate-time
827 (org-element-property :raw-value
828 (org-element-property :value clock
)))
829 (let ((time (org-element-property :duration clock
)))
830 (and time
(format " (%s)" time
)))))
835 (defun org-texinfo-code (code contents info
)
836 "Transcode a CODE object from Org to Texinfo.
837 CONTENTS is nil. INFO is a plist used as a communication
839 (org-texinfo--text-markup (org-element-property :value code
) 'code info
))
843 (defun org-texinfo-comment (comment contents info
)
844 "Transcode a COMMENT object from Org to Texinfo.
845 CONTENTS is the text in the comment. INFO is a plist holding
846 contextual information."
847 (org-texinfo--text-markup
848 (org-element-property :value comment
) 'comment info
))
852 (defun org-texinfo-comment-block (comment-block contents info
)
853 "Transcode a COMMENT-BLOCK object from Org to Texinfo.
854 CONTENTS is the text within the block. INFO is a plist holding
855 contextual information."
856 (format "@ignore\n%s@end ignore" (org-element-property :value comment-block
)))
860 (defun org-texinfo-drawer (drawer contents info
)
861 "Transcode a DRAWER element from Org to Texinfo.
862 CONTENTS holds the contents of the block. INFO is a plist
863 holding contextual information."
864 (let* ((name (org-element-property :drawer-name drawer
))
865 (output (funcall (plist-get info
:texinfo-format-drawer-function
)
871 (defun org-texinfo-dynamic-block (dynamic-block contents info
)
872 "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
873 CONTENTS holds the contents of the block. INFO is a plist
874 holding contextual information. See `org-export-data'."
879 (defun org-texinfo-entity (entity contents info
)
880 "Transcode an ENTITY object from Org to Texinfo.
881 CONTENTS are the definition itself. INFO is a plist holding
882 contextual information."
883 (let ((ent (org-element-property :latex entity
)))
884 (if (org-element-property :latex-math-p entity
) (format "@math{%s}" ent
) ent
)))
888 (defun org-texinfo-example-block (example-block contents info
)
889 "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
890 CONTENTS is nil. INFO is a plist holding contextual
892 (format "@verbatim\n%s@end verbatim"
893 (org-export-format-code-default example-block info
)))
897 (defun org-texinfo-export-snippet (export-snippet contents info
)
898 "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
899 CONTENTS is nil. INFO is a plist holding contextual information."
900 (when (eq (org-export-snippet-backend export-snippet
) 'texinfo
)
901 (org-element-property :value export-snippet
)))
905 (defun org-texinfo-fixed-width (fixed-width contents info
)
906 "Transcode a FIXED-WIDTH element from Org to Texinfo.
907 CONTENTS is nil. INFO is a plist holding contextual information."
908 (format "@example\n%s\n@end example"
909 (org-remove-indentation
910 (org-texinfo--sanitize-content
911 (org-element-property :value fixed-width
)))))
913 ;;; Footnote Reference
916 (defun org-texinfo-footnote-reference (footnote contents info
)
917 "Create a footnote reference for FOOTNOTE.
919 FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
920 plist holding contextual information."
921 (let ((def (org-export-get-footnote-definition footnote info
)))
922 (format "@footnote{%s}"
923 (org-trim (org-export-data def info
)))))
927 (defun org-texinfo-headline (headline contents info
)
928 "Transcode a HEADLINE element from Org to Texinfo.
929 CONTENTS holds the contents of the headline. INFO is a plist
930 holding contextual information."
931 (let* ((class (plist-get info
:texinfo-class
))
932 (level (org-export-get-relative-level headline info
))
933 (numberedp (org-export-numbered-headline-p headline info
))
934 (class-sectioning (assoc class
(plist-get info
:texinfo-classes
)))
935 ;; Find the index type, if any
936 (index (org-element-property :INDEX headline
))
937 ;; Check if it is an appendix
938 (appendix (org-element-property :APPENDIX headline
))
939 ;; Retrieve headline text
940 (text (org-texinfo--sanitize-headline
941 (org-element-property :title headline
) info
))
942 ;; Create node info, to insert it before section formatting.
943 ;; Use custom menu title if present
944 (node (format "@node %s\n" (org-texinfo--get-node headline info
)))
945 ;; Menus must be generated with first child, otherwise they
946 ;; will not nest properly
947 (menu (let* ((first (org-export-first-sibling-p headline info
))
948 (parent (org-export-get-parent-headline headline
))
949 (title (org-texinfo--sanitize-headline
950 (org-element-property :title parent
) info
))
952 (tree (plist-get info
:parse-tree
)))
954 (org-element-map (plist-get info
:parse-tree
) 'headline
956 (if (member title
(org-element-property :title ref
))
959 (setq listing
(org-texinfo--build-menu
960 (car heading
) level info
))
962 (setq listing
(replace-regexp-in-string
965 "\n@menu\n%s\n@end menu\n\n" listing
))
967 ;; Section formatting will set two placeholders: one for the
968 ;; title and the other for the contents.
970 (let ((sec (if (and (symbolp (nth 2 class-sectioning
))
971 (fboundp (nth 2 class-sectioning
)))
972 (funcall (nth 2 class-sectioning
) level numberedp
)
973 (nth (1+ level
) class-sectioning
))))
975 ;; No section available for that LEVEL.
977 ;; Section format directly returned by a function.
979 ;; (numbered-section . unnumbered-section)
980 ((not (consp (cdr sec
)))
982 ;;If an index, always unnumbered
984 (concat menu node
(cdr sec
) "\n%s"))
986 (concat menu node
(replace-regexp-in-string
990 ;; Otherwise number as needed.
994 (if numberedp
#'car
#'cdr
) sec
) "\n%s")))))))
996 (and (plist-get info
:with-todo-keywords
)
997 (let ((todo (org-element-property :todo-keyword headline
)))
998 (and todo
(org-export-data todo info
)))))
999 (todo-type (and todo
(org-element-property :todo-type headline
)))
1000 (tags (and (plist-get info
:with-tags
)
1001 (org-export-get-tags headline info
)))
1002 (priority (and (plist-get info
:with-priority
)
1003 (org-element-property :priority headline
)))
1004 ;; Create the headline text along with a no-tag version. The
1005 ;; latter is required to remove tags from table of contents.
1006 (full-text (org-texinfo--sanitize-content
1007 (funcall (plist-get info
:texinfo-format-headline-function
)
1008 todo todo-type priority text tags
)))
1010 (org-texinfo--sanitize-content
1011 (funcall (plist-get info
:texinfo-format-headline-function
)
1012 todo todo-type priority text nil
)))
1014 (make-string (org-element-property :pre-blank headline
) 10)))
1016 ;; Case 1: This is a footnote section: ignore it.
1017 ((org-element-property :footnote-section-p headline
) nil
)
1018 ;; Case 2: This is the `copying' section: ignore it
1019 ;; This is used elsewhere.
1020 ((org-element-property :COPYING headline
) nil
)
1021 ;; Case 3: An index. If it matches one of the known indexes,
1022 ;; print it as such following the contents, otherwise
1023 ;; print the contents and leave the index up to the user.
1026 section-fmt full-text
1027 (concat pre-blanks contents
"\n"
1028 (if (member index
'("cp" "fn" "ky" "pg" "tp" "vr"))
1029 (concat "@printindex " index
)))))
1030 ;; Case 4: This is a deep sub-tree: export it as a list item.
1031 ;; Also export as items headlines for which no section
1032 ;; format has been found.
1033 ((or (not section-fmt
) (org-export-low-level-p headline info
))
1034 ;; Build the real contents of the sub-tree.
1035 (let ((low-level-body
1037 ;; If the headline is the first sibling, start a list.
1038 (when (org-export-first-sibling-p headline info
)
1039 (format "@%s\n" (if numberedp
'enumerate
'itemize
)))
1041 "@item\n" full-text
"\n" pre-blanks contents
)))
1042 ;; If headline is not the last sibling simply return
1043 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
1045 (if (not (org-export-last-sibling-p headline info
)) low-level-body
1046 (replace-regexp-in-string
1048 (format "\n@end %s" (if numberedp
'enumerate
'itemize
))
1050 ;; Case 5: Standard headline. Export it as a section.
1053 ((not (and tags
(eq (plist-get info
:with-tags
) 'not-in-toc
)))
1054 ;; Regular section. Use specified format string.
1055 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1056 (concat pre-blanks contents
)))
1057 ((string-match "\\`@\\(.*?\\){" section-fmt
)
1058 ;; If tags should be removed from table of contents, insert
1059 ;; title without tags as an alternative heading in sectioning
1061 (format (replace-match (concat (match-string 1 section-fmt
) "[%s]")
1062 nil nil section-fmt
1)
1063 ;; Replace square brackets with parenthesis since
1064 ;; square brackets are not supported in optional
1066 (replace-regexp-in-string
1068 (replace-regexp-in-string
1072 (concat pre-blanks contents
)))
1074 ;; Impossible to add an alternative heading. Fallback to
1075 ;; regular sectioning format string.
1076 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1077 (concat pre-blanks contents
))))))))
1079 (defun org-texinfo-format-headline-default-function
1080 (todo todo-type priority text tags
)
1081 "Default format function for a headline.
1082 See `org-texinfo-format-headline-function' for details."
1083 (concat (when todo
(format "@strong{%s} " todo
))
1084 (when priority
(format "@emph{#%s} " priority
))
1086 (when tags
(format " :%s:" (mapconcat 'identity tags
":")))))
1088 ;;; Inline Src Block
1090 (defun org-texinfo-inline-src-block (inline-src-block contents info
)
1091 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
1092 CONTENTS holds the contents of the item. INFO is a plist holding
1093 contextual information."
1094 (let* ((code (org-element-property :value inline-src-block
))
1095 (separator (org-texinfo--find-verb-separator code
)))
1096 (concat "@verb{" separator code separator
"}")))
1100 (defun org-texinfo-inlinetask (inlinetask contents info
)
1101 "Transcode an INLINETASK element from Org to Texinfo.
1102 CONTENTS holds the contents of the block. INFO is a plist
1103 holding contextual information."
1104 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
1105 (todo (and (plist-get info
:with-todo-keywords
)
1106 (let ((todo (org-element-property :todo-keyword inlinetask
)))
1107 (and todo
(org-export-data todo info
)))))
1108 (todo-type (org-element-property :todo-type inlinetask
))
1109 (tags (and (plist-get info
:with-tags
)
1110 (org-export-get-tags inlinetask info
)))
1111 (priority (and (plist-get info
:with-priority
)
1112 (org-element-property :priority inlinetask
))))
1113 (funcall (plist-get info
:texinfo-format-inlinetask-function
)
1114 todo todo-type priority title tags contents
)))
1116 (defun org-texinfo-format-inlinetask-default-function
1117 (todo todo-type priority title tags contents
)
1118 "Default format function for a inlinetasks.
1119 See `org-texinfo-format-inlinetask-function' for details."
1121 (concat (when todo
(format "@strong{%s} " todo
))
1122 (when priority
(format "#%c " priority
))
1124 (when tags
(format ":%s:" (mapconcat #'identity tags
":"))))))
1125 (format "@center %s\n\n%s\n" full-title contents
)))
1129 (defun org-texinfo-italic (italic contents info
)
1130 "Transcode ITALIC from Org to Texinfo.
1131 CONTENTS is the text with italic markup. INFO is a plist holding
1132 contextual information."
1133 (org-texinfo--text-markup contents
'italic info
))
1137 (defun org-texinfo-item (item contents info
)
1138 "Transcode an ITEM element from Org to Texinfo.
1139 CONTENTS holds the contents of the item. INFO is a plist holding
1140 contextual information."
1141 (let* ((tag (org-element-property :tag item
))
1142 (desc (org-export-data tag info
)))
1143 (concat "\n@item " (if tag desc
) "\n"
1144 (and contents
(org-trim contents
)) "\n")))
1148 (defun org-texinfo-keyword (keyword contents info
)
1149 "Transcode a KEYWORD element from Org to Texinfo.
1150 CONTENTS is nil. INFO is a plist holding contextual information."
1151 (let ((key (org-element-property :key keyword
))
1152 (value (org-element-property :value keyword
)))
1154 ((string= key
"TEXINFO") value
)
1155 ((string= key
"CINDEX") (format "@cindex %s" value
))
1156 ((string= key
"FINDEX") (format "@findex %s" value
))
1157 ((string= key
"KINDEX") (format "@kindex %s" value
))
1158 ((string= key
"PINDEX") (format "@pindex %s" value
))
1159 ((string= key
"TINDEX") (format "@tindex %s" value
))
1160 ((string= key
"VINDEX") (format "@vindex %s" value
)))))
1164 (defun org-texinfo-line-break (line-break contents info
)
1165 "Transcode a LINE-BREAK object from Org to Texinfo.
1166 CONTENTS is nil. INFO is a plist holding contextual information."
1171 (defun org-texinfo-link (link desc info
)
1172 "Transcode a LINK object from Org to Texinfo.
1174 DESC is the description part of the link, or the empty string.
1175 INFO is a plist holding contextual information. See
1177 (let* ((type (org-element-property :type link
))
1178 (raw-path (org-element-property :path link
))
1179 ;; Ensure DESC really exists, or set it to nil.
1180 (desc (and (not (string= desc
"")) desc
))
1182 ((member type
'("http" "https" "ftp"))
1183 (concat type
":" raw-path
))
1184 ((and (string= type
"file") (file-name-absolute-p raw-path
))
1185 (concat "file:" raw-path
))
1187 (email (if (string= type
"mailto")
1188 (let ((text (replace-regexp-in-string
1189 "@" "@@" raw-path
)))
1190 (concat text
(if desc
(concat "," desc
))))))
1193 ;; Links pointing to a headline: Find destination and build
1194 ;; appropriate referencing command.
1195 ((member type
'("custom-id" "id"))
1196 (let ((destination (org-export-resolve-id-link link info
)))
1197 (case (org-element-type destination
)
1198 ;; Id link points to an external file.
1200 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1201 (format "@uref{file://%s}" destination
)))
1202 ;; LINK points to a headline. Use the headline as the NODE target
1204 (format "@ref{%s,%s}"
1205 (org-texinfo--get-node destination info
)
1208 (let ((path (org-export-solidify-link-text path
)))
1209 (if (not desc
) (format "@ref{%s}" path
)
1210 (format "@ref{%s,,%s}" path desc
)))))))
1211 ((member type
'("info"))
1212 (let* ((info-path (split-string path
"[:#]"))
1213 (info-manual (car info-path
))
1214 (info-node (or (cadr info-path
) "top"))
1215 (title (or desc
"")))
1216 (format "@ref{%s,%s,,%s,}" info-node title info-manual
)))
1217 ((member type
'("fuzzy"))
1218 (let ((destination (org-export-resolve-fuzzy-link link info
)))
1219 (case (org-element-type destination
)
1220 ;; Id link points to an external file.
1222 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1223 (format "@uref{file://%s}" destination
)))
1224 ;; LINK points to a headline. Use the headline as the NODE target
1226 (format "@ref{%s,%s}"
1227 (org-texinfo--get-node destination info
)
1230 (let ((path (org-export-solidify-link-text path
)))
1231 (if (not desc
) (format "@ref{%s}" path
)
1232 (format "@ref{%s,,%s}" path desc
)))))))
1233 ;; Special case for email addresses
1235 (format "@email{%s}" email
))
1236 ;; External link with a description part.
1237 ((and path desc
) (format "@uref{%s,%s}" path desc
))
1238 ;; External link without a description part.
1239 (path (format "@uref{%s}" path
))
1240 ;; No path, only description. Try to do something useful.
1242 (format (plist-get info
:texinfo-link-with-unknown-path-format
) desc
)))))
1247 (defun org-texinfo-make-menu (info level
)
1248 "Create the menu for inclusion in the texifo document.
1250 INFO is the parsed buffer that contains the headlines. LEVEL
1251 determines whether to make the main menu, or the detailed menu.
1253 This is only used for generating the primary menu. In-Node menus
1254 are generated directly."
1255 (let ((parse (plist-get info
:parse-tree
)))
1257 ;; Generate the main menu
1258 ((eq level
'main
) (org-texinfo--build-menu parse
1 info
))
1259 ;; Generate the detailed (recursive) menu
1260 ((eq level
'detailed
)
1261 ;; Requires recursion
1262 ;;(org-texinfo--build-detailed-menu parse top info)
1263 (org-texinfo--build-menu parse
1 info
'detailed
)))))
1267 (defun org-texinfo-node-property (node-property contents info
)
1268 "Transcode a NODE-PROPERTY element from Org to Texinfo.
1269 CONTENTS is nil. INFO is a plist holding contextual
1272 (org-element-property :key node-property
)
1273 (let ((value (org-element-property :value node-property
)))
1274 (if value
(concat " " value
) ""))))
1278 (defun org-texinfo-paragraph (paragraph contents info
)
1279 "Transcode a PARAGRAPH element from Org to Texinfo.
1280 CONTENTS is the contents of the paragraph, as a string. INFO is
1281 the plist used as a communication channel."
1286 (defun org-texinfo-plain-list (plain-list contents info
)
1287 "Transcode a PLAIN-LIST element from Org to Texinfo.
1288 CONTENTS is the contents of the list. INFO is a plist holding
1289 contextual information."
1290 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1291 (indic (or (plist-get attr
:indic
)
1292 (plist-get info
:texinfo-def-table-markup
)))
1293 (type (org-element-property :type plain-list
))
1294 (table-type (plist-get attr
:table-type
))
1295 ;; Ensure valid texinfo table type.
1296 (table-type (if (member table-type
'("ftable" "vtable")) table-type
1299 ((eq type
'ordered
) "enumerate")
1300 ((eq type
'unordered
) "itemize")
1301 ((eq type
'descriptive
) table-type
))))
1302 (format "@%s%s\n@end %s"
1303 (if (eq type
'descriptive
)
1304 (concat list-type
" " indic
)
1311 (defun org-texinfo-plain-text (text info
)
1312 "Transcode a TEXT string from Org to Texinfo.
1313 TEXT is the string to transcode. INFO is a plist holding
1314 contextual information."
1315 ;; First protect @, { and }.
1316 (let ((output (org-texinfo--sanitize-content text
)))
1317 ;; Activate smart quotes. Be sure to provide original TEXT string
1318 ;; since OUTPUT may have been modified.
1319 (when (plist-get info
:with-smart-quotes
)
1321 (org-export-activate-smart-quotes output
:texinfo info text
)))
1322 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1323 (let ((case-fold-search nil
)
1325 (while (string-match "\\(\\(?:La\\)?TeX\\)" output start
)
1326 (setq output
(replace-match
1327 (format "@%s{}" (match-string 1 output
)) nil t output
)
1328 start
(match-end 0))))
1329 ;; Convert special strings.
1330 (when (plist-get info
:with-special-strings
)
1331 (while (string-match (regexp-quote "...") output
)
1332 (setq output
(replace-match "@dots{}" nil t output
))))
1333 ;; Handle break preservation if required.
1334 (when (plist-get info
:preserve-breaks
)
1335 (setq output
(replace-regexp-in-string
1336 "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output
)))
1342 (defun org-texinfo-planning (planning contents info
)
1343 "Transcode a PLANNING element from Org to Texinfo.
1344 CONTENTS is nil. INFO is a plist holding contextual
1352 (let ((closed (org-element-property :closed planning
)))
1355 (format "@strong{%s} " org-closed-string
)
1356 (format (plist-get info
:texinfo-inactive-timestamp-format
)
1358 (org-element-property :raw-value closed
))))))
1359 (let ((deadline (org-element-property :deadline planning
)))
1362 (format "@strong{%s} " org-deadline-string
)
1363 (format (plist-get info
:texinfo-active-timestamp-format
)
1365 (org-element-property :raw-value deadline
))))))
1366 (let ((scheduled (org-element-property :scheduled planning
)))
1369 (format "@strong{%s} " org-scheduled-string
)
1370 (format (plist-get info
:texinfo-active-timestamp-format
)
1372 (org-element-property :raw-value scheduled
))))))))
1378 (defun org-texinfo-property-drawer (property-drawer contents info
)
1379 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1380 CONTENTS holds the contents of the drawer. INFO is a plist
1381 holding contextual information."
1382 (and (org-string-nw-p contents
)
1383 (format "@verbatim\n%s@end verbatim" contents
)))
1387 (defun org-texinfo-quote-block (quote-block contents info
)
1388 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1389 CONTENTS holds the contents of the block. INFO is a plist
1390 holding contextual information."
1391 (let* ((title (org-element-property :name quote-block
))
1392 (start-quote (concat "@quotation"
1394 (format " %s" title
)))))
1395 (format "%s\n%s@end quotation" start-quote contents
)))
1399 (defun org-texinfo-radio-target (radio-target text info
)
1400 "Transcode a RADIO-TARGET object from Org to Texinfo.
1401 TEXT is the text of the target. INFO is a plist holding
1402 contextual information."
1403 (format "@anchor{%s}%s"
1404 (org-export-solidify-link-text
1405 (org-element-property :value radio-target
))
1410 (defun org-texinfo-section (section contents info
)
1411 "Transcode a SECTION element from Org to Texinfo.
1412 CONTENTS holds the contents of the section. INFO is a plist
1413 holding contextual information."
1418 (defun org-texinfo-special-block (special-block contents info
)
1419 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1420 CONTENTS holds the contents of the block. INFO is a plist used
1421 as a communication channel."
1422 (if (org-export-raw-special-block-p special-block info
)
1423 (org-remove-indentation (org-element-property :raw-value special-block
))
1428 (defun org-texinfo-src-block (src-block contents info
)
1429 "Transcode a SRC-BLOCK element from Org to Texinfo.
1430 CONTENTS holds the contents of the item. INFO is a plist holding
1431 contextual information."
1432 (let* ((lang (org-element-property :language src-block
))
1433 (lisp-p (string-match-p "lisp" lang
))
1434 (src-contents (org-texinfo--sanitize-content
1435 (org-export-format-code-default src-block info
))))
1437 ;; Case 1. Lisp Block
1439 (format "@lisp\n%s@end lisp"
1441 ;; Case 2. Other blocks
1443 (format "@example\n%s@end example"
1446 ;;; Statistics Cookie
1448 (defun org-texinfo-statistics-cookie (statistics-cookie contents info
)
1449 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1450 CONTENTS is nil. INFO is a plist holding contextual information."
1451 (org-element-property :value statistics-cookie
))
1455 (defun org-texinfo-subscript (subscript contents info
)
1456 "Transcode a SUBSCRIPT object from Org to Texinfo.
1457 CONTENTS is the contents of the object. INFO is a plist holding
1458 contextual information."
1459 (format "@math{_%s}" contents
))
1463 (defun org-texinfo-superscript (superscript contents info
)
1464 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1465 CONTENTS is the contents of the object. INFO is a plist holding
1466 contextual information."
1467 (format "@math{^%s}" contents
))
1471 ;; `org-texinfo-table' is the entry point for table transcoding. It
1472 ;; takes care of tables with a "verbatim" attribute. Otherwise, it
1473 ;; delegates the job to either `org-texinfo-table--table.el-table' or
1474 ;; `org-texinfo-table--org-table' functions, depending of the type of
1477 ;; `org-texinfo-table--align-string' is a subroutine used to build
1478 ;; alignment string for Org tables.
1480 (defun org-texinfo-table (table contents info
)
1481 "Transcode a TABLE element from Org to Texinfo.
1482 CONTENTS is the contents of the table. INFO is a plist holding
1483 contextual information."
1485 ;; Case 1: verbatim table.
1486 ((or (plist-get info
:texinfo-tables-verbatim
)
1487 (let ((attr (mapconcat 'identity
1488 (org-element-property :attr_latex table
)
1490 (and attr
(string-match "\\<verbatim\\>" attr
))))
1491 (format "@verbatim \n%s\n@end verbatim"
1492 ;; Re-create table, without affiliated keywords.
1494 (org-element-interpret-data
1495 `(table nil
,@(org-element-contents table
))))))
1496 ;; Case 2: table.el table. Convert it using appropriate tools.
1497 ((eq (org-element-property :type table
) 'table.el
)
1498 (org-texinfo-table--table.el-table table contents info
))
1499 ;; Case 3: Standard table.
1500 (t (org-texinfo-table--org-table table contents info
))))
1502 (defun org-texinfo-table-column-widths (table info
)
1503 "Determine the largest table cell in each column to process alignment.
1505 TABLE is the table element to transcode. INFO is a plist used as
1506 a communication channel."
1507 (let* ((rows (org-element-map table
'table-row
'identity info
))
1508 (collected (loop for row in rows collect
1509 (org-element-map row
'table-cell
'identity info
)))
1510 (number-cells (length (car collected
)))
1512 (loop for row in collected do
1513 (push (mapcar (lambda (ref)
1514 (let* ((start (org-element-property :contents-begin ref
))
1515 (end (org-element-property :contents-end ref
))
1516 (length (- end start
)))
1517 length
)) row
) cells
))
1518 (setq cells
(org-remove-if 'null cells
))
1519 (push (loop for count from
0 to
(- number-cells
1) collect
1520 (loop for item in cells collect
1521 (nth count item
))) counts
)
1522 (mapconcat (lambda (size)
1523 (make-string size ?a
)) (mapcar (lambda (ref)
1524 (apply 'max
`(,@ref
))) (car counts
))
1527 (defun org-texinfo-table--org-table (table contents info
)
1528 "Return appropriate Texinfo code for an Org table.
1530 TABLE is the table type element to transcode. CONTENTS is its
1531 contents, as a string. INFO is a plist used as a communication
1534 This function assumes TABLE has `org' as its `:type' attribute."
1535 (let* ((attr (org-export-read-attribute :attr_texinfo table
))
1536 (col-width (plist-get attr
:columns
))
1537 (columns (if col-width
1538 (format "@columnfractions %s"
1541 (org-texinfo-table-column-widths
1543 ;; Prepare the final format string for the table.
1548 (format "@multitable %s\n%s@end multitable"
1552 (defun org-texinfo-table--table.el-table
(table contents info
)
1555 Rather than return an invalid table, nothing is returned."
1560 (defun org-texinfo-table-cell (table-cell contents info
)
1561 "Transcode a TABLE-CELL element from Org to Texinfo.
1562 CONTENTS is the cell contents. INFO is a plist used as
1563 a communication channel."
1565 (let ((scientific-notation
1566 (plist-get info
:texinfo-table-scientific-notation
)))
1569 (string-match orgtbl-exp-regexp contents
))
1570 ;; Use appropriate format string for scientific notation.
1571 (format scientific-notation
1572 (match-string 1 contents
)
1573 (match-string 2 contents
))
1575 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1579 (defun org-texinfo-table-row (table-row contents info
)
1580 "Transcode a TABLE-ROW element from Org to Texinfo.
1581 CONTENTS is the contents of the row. INFO is a plist used as
1582 a communication channel."
1583 ;; Rules are ignored since table separators are deduced from
1584 ;; borders of the current row.
1585 (when (eq (org-element-property :type table-row
) 'standard
)
1588 ;; Case 1: Belongs to second or subsequent rowgroup.
1589 ((not (= 1 (org-export-table-row-group table-row info
)))
1591 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
1592 ((org-export-table-has-header-p
1593 (org-export-get-parent-table table-row
) info
)
1595 ;; Case 3: Row is from first and only row group.
1597 (when (eq (org-element-property :type table-row
) 'standard
)
1598 (concat rowgroup-tag contents
"\n")))))
1602 (defun org-texinfo-target (target contents info
)
1603 "Transcode a TARGET object from Org to Texinfo.
1604 CONTENTS is nil. INFO is a plist holding contextual
1606 (format "@anchor{%s}"
1607 (org-export-solidify-link-text (org-element-property :value target
))))
1611 (defun org-texinfo-timestamp (timestamp contents info
)
1612 "Transcode a TIMESTAMP object from Org to Texinfo.
1613 CONTENTS is nil. INFO is a plist holding contextual
1615 (let ((value (org-texinfo-plain-text
1616 (org-timestamp-translate timestamp
) info
)))
1617 (case (org-element-property :type timestamp
)
1618 ((active active-range
)
1619 (format (plist-get info
:texinfo-active-timestamp-format
) value
))
1620 ((inactive inactive-range
)
1621 (format (plist-get info
:texinfo-inactive-timestamp-format
) value
))
1622 (t (format (plist-get info
:texinfo-diary-timestamp-format
) value
)))))
1626 (defun org-texinfo-verbatim (verbatim contents info
)
1627 "Transcode a VERBATIM object from Org to Texinfo.
1628 CONTENTS is nil. INFO is a plist used as a communication
1630 (org-texinfo--text-markup
1631 (org-element-property :value verbatim
) 'verbatim info
))
1635 (defun org-texinfo-verse-block (verse-block contents info
)
1636 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1637 CONTENTS is verse block contents. INFO is a plist holding
1638 contextual information."
1639 ;; In a verse environment, add a line break to each newline
1640 ;; character and change each white space at beginning of a line
1641 ;; into a space of 1 em. Also change each blank line with
1642 ;; a vertical space of 1 em.
1644 (setq contents
(replace-regexp-in-string
1645 "^ *\\\\\\\\$" "\\\\vspace*{1em}"
1646 (replace-regexp-in-string
1647 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" contents
)))
1648 (while (string-match "^[ \t]+" contents
)
1649 (let ((new-str (format "\\hspace*{%dem}"
1650 (length (match-string 0 contents
)))))
1651 (setq contents
(replace-match new-str nil t contents
))))
1652 (format "\\begin{verse}\n%s\\end{verse}" contents
)))
1655 ;;; Interactive functions
1657 (defun org-texinfo-export-to-texinfo
1658 (&optional async subtreep visible-only body-only ext-plist
)
1659 "Export current buffer to a Texinfo file.
1661 If narrowing is active in the current buffer, only export its
1664 If a region is active, export that region.
1666 A non-nil optional argument ASYNC means the process should happen
1667 asynchronously. The resulting file should be accessible through
1668 the `org-export-stack' interface.
1670 When optional argument SUBTREEP is non-nil, export the sub-tree
1671 at point, extracting information from the headline properties
1674 When optional argument VISIBLE-ONLY is non-nil, don't export
1675 contents of hidden elements.
1677 When optional argument BODY-ONLY is non-nil, only write code
1678 between \"\\begin{document}\" and \"\\end{document}\".
1680 EXT-PLIST, when provided, is a property list with external
1681 parameters overriding Org default settings, but still inferior to
1682 file-local settings.
1684 Return output file's name."
1686 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1687 (org-export-coding-system org-texinfo-coding-system
))
1688 (org-export-to-file 'texinfo outfile
1689 async subtreep visible-only body-only ext-plist
)))
1691 (defun org-texinfo-export-to-info
1692 (&optional async subtreep visible-only body-only ext-plist
)
1693 "Export current buffer to Texinfo then process through to INFO.
1695 If narrowing is active in the current buffer, only export its
1698 If a region is active, export that region.
1700 A non-nil optional argument ASYNC means the process should happen
1701 asynchronously. The resulting file should be accessible through
1702 the `org-export-stack' interface.
1704 When optional argument SUBTREEP is non-nil, export the sub-tree
1705 at point, extracting information from the headline properties
1708 When optional argument VISIBLE-ONLY is non-nil, don't export
1709 contents of hidden elements.
1711 When optional argument BODY-ONLY is non-nil, only write code
1712 between \"\\begin{document}\" and \"\\end{document}\".
1714 EXT-PLIST, when provided, is a property list with external
1715 parameters overriding Org default settings, but still inferior to
1716 file-local settings.
1718 When optional argument PUB-DIR is set, use it as the publishing
1721 Return INFO file's name."
1723 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1724 (org-export-coding-system org-texinfo-coding-system
))
1725 (org-export-to-file 'texinfo outfile
1726 async subtreep visible-only body-only ext-plist
1727 (lambda (file) (org-texinfo-compile file
)))))
1730 (defun org-texinfo-publish-to-texinfo (plist filename pub-dir
)
1731 "Publish an org file to Texinfo.
1733 FILENAME is the filename of the Org file to be published. PLIST
1734 is the property list for the given project. PUB-DIR is the
1735 publishing directory.
1737 Return output file name."
1738 (org-publish-org-to 'texinfo filename
".texi" plist pub-dir
))
1741 (defun org-texinfo-convert-region-to-texinfo ()
1742 "Assume the current region has org-mode syntax, and convert it to Texinfo.
1743 This can be used in any buffer. For example, you can write an
1744 itemized list in org-mode syntax in an Texinfo buffer and use
1745 this command to convert it."
1747 (org-export-replace-region-by 'texinfo
))
1749 (defun org-texinfo-compile (file)
1750 "Compile a texinfo file.
1752 FILE is the name of the file being compiled. Processing is
1753 done through the command specified in `org-texinfo-info-process'.
1755 Return INFO file name or an error if it couldn't be produced."
1756 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file
)))
1757 (full-name (file-truename file
))
1758 (out-dir (file-name-directory file
))
1759 ;; Properly set working directory for compilation.
1760 (default-directory (if (file-name-absolute-p file
)
1761 (file-name-directory full-name
)
1764 (message (format "Processing Texinfo file %s..." file
))
1765 (save-window-excursion
1767 ;; A function is provided: Apply it.
1768 ((functionp org-texinfo-info-process
)
1769 (funcall org-texinfo-info-process
(shell-quote-argument file
)))
1770 ;; A list is provided: Replace %b, %f and %o with appropriate
1771 ;; values in each command before applying it. Output is
1772 ;; redirected to "*Org INFO Texinfo Output*" buffer.
1773 ((consp org-texinfo-info-process
)
1774 (let ((outbuf (get-buffer-create "*Org INFO Texinfo Output*")))
1778 (replace-regexp-in-string
1779 "%b" (shell-quote-argument base-name
)
1780 (replace-regexp-in-string
1781 "%f" (shell-quote-argument full-name
)
1782 (replace-regexp-in-string
1783 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
1785 org-texinfo-info-process
)
1786 ;; Collect standard errors from output buffer.
1787 (setq errors
(org-texinfo-collect-errors outbuf
))))
1788 (t (error "No valid command to process to Info")))
1789 (let ((infofile (concat out-dir base-name
".info")))
1790 ;; Check for process failure. Provide collected errors if
1792 (if (not (file-exists-p infofile
))
1793 (error (concat (format "INFO file %s wasn't produced" infofile
)
1794 (when errors
(concat ": " errors
))))
1795 ;; Else remove log files, when specified, and signal end of
1796 ;; process to user, along with any error encountered.
1797 (when org-texinfo-remove-logfiles
1798 (dolist (ext org-texinfo-logfiles-extensions
)
1799 (let ((file (concat out-dir base-name
"." ext
)))
1800 (when (file-exists-p file
) (delete-file file
)))))
1801 (message (concat "Process completed"
1802 (if (not errors
) "."
1803 (concat " with errors: " errors
)))))
1804 ;; Return output file name.
1807 (defun org-texinfo-collect-errors (buffer)
1808 "Collect some kind of errors from \"makeinfo\" command output.
1810 BUFFER is the buffer containing output.
1812 Return collected error types as a string, or nil if there was
1814 (with-current-buffer buffer
1816 (goto-char (point-min))
1817 ;; Find final "makeinfo" run.
1819 (let ((case-fold-search t
)
1821 (when (save-excursion
1822 (re-search-forward "perhaps incorrect sectioning?" nil t
))
1823 (setq errors
(concat errors
" [incorrect sectioning]")))
1824 (when (save-excursion
1825 (re-search-forward "missing close brace" nil t
))
1826 (setq errors
(concat errors
" [syntax error]")))
1827 (when (save-excursion
1828 (re-search-forward "Unknown command" nil t
))
1829 (setq errors
(concat errors
" [undefined @command]")))
1830 (when (save-excursion
1831 (re-search-forward "No matching @end" nil t
))
1832 (setq errors
(concat errors
" [block incomplete]")))
1833 (when (save-excursion
1834 (re-search-forward "requires a sectioning" nil t
))
1835 (setq errors
(concat errors
" [invalid section command]")))
1836 (when (save-excursion
1837 (re-search-forward "\\[unexpected\]" nil t
))
1838 (setq errors
(concat errors
" [unexpected error]")))
1839 (when (save-excursion
1840 (re-search-forward "misplaced " nil t
))
1841 (setq errors
(concat errors
" [syntax error]")))
1842 (and (org-string-nw-p errors
) (org-trim errors
)))))))
1845 (provide 'ox-texinfo
)
1848 ;; generated-autoload-file: "org-loaddefs.el"
1851 ;;; ox-texinfo.el ends here