1 ;;; ox-texinfo.el --- Texinfo Back-End for Org Export Engine
3 ;; Copyright (C) 2012, 2013 Jonathan Leech-Pepin
4 ;; Author: Jonathan Leech-Pepin <jonathan.leechpepin at gmail dot com>
5 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; This file is not part of GNU Emacs.
9 ;; This program 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 ;; This program 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 this program. 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-block . org-texinfo-export-block
)
80 (export-snippet . org-texinfo-export-snippet
)
81 (fixed-width . org-texinfo-fixed-width
)
82 (footnote-definition . org-texinfo-footnote-definition
)
83 (footnote-reference . org-texinfo-footnote-reference
)
84 (headline . org-texinfo-headline
)
85 (inline-src-block . org-texinfo-inline-src-block
)
86 (inlinetask . org-texinfo-inlinetask
)
87 (italic . org-texinfo-italic
)
88 (item . org-texinfo-item
)
89 (keyword . org-texinfo-keyword
)
90 (line-break . org-texinfo-line-break
)
91 (link . org-texinfo-link
)
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 (quote-section . org-texinfo-quote-section
)
99 (radio-target . org-texinfo-radio-target
)
100 (section . org-texinfo-section
)
101 (special-block . org-texinfo-special-block
)
102 (src-block . org-texinfo-src-block
)
103 (statistics-cookie . org-texinfo-statistics-cookie
)
104 (subscript . org-texinfo-subscript
)
105 (superscript . org-texinfo-superscript
)
106 (table . org-texinfo-table
)
107 (table-cell . org-texinfo-table-cell
)
108 (table-row . org-texinfo-table-row
)
109 (target . org-texinfo-target
)
110 (template . org-texinfo-template
)
111 (timestamp . org-texinfo-timestamp
)
112 (verbatim . org-texinfo-verbatim
)
113 (verse-block . org-texinfo-verse-block
))
114 :export-block
"TEXINFO"
116 ((:filter-headline . org-texinfo-filter-section-blank-lines
)
117 (:filter-section . org-texinfo-filter-section-blank-lines
))
119 (?i
"Export to Texinfo"
120 ((?t
"As TEXI file" org-texinfo-export-to-texinfo
)
121 (?i
"As INFO file" org-texinfo-export-to-info
)))
123 ((:texinfo-filename
"TEXINFO_FILENAME" nil org-texinfo-filename t
)
124 (:texinfo-class
"TEXINFO_CLASS" nil org-texinfo-default-class t
)
125 (:texinfo-header
"TEXINFO_HEADER" nil nil newline
)
126 (:texinfo-post-header
"TEXINFO_POST_HEADER" nil nil newline
)
127 (:subtitle
"SUBTITLE" nil nil newline
)
128 (:subauthor
"SUBAUTHOR" nil nil newline
)
129 (:texinfo-dircat
"TEXINFO_DIR_CATEGORY" nil nil t
)
130 (:texinfo-dirtitle
"TEXINFO_DIR_TITLE" nil nil t
)
131 (:texinfo-dirdesc
"TEXINFO_DIR_DESC" nil nil t
)
132 (:texinfo-menu-title
"TEXINFO_MENU_TITLE" nil nil newline
)))
136 ;;; User Configurable Variables
138 (defgroup org-export-texinfo nil
139 "Options for exporting Org mode files to Texinfo."
140 :tag
"Org Export Texinfo"
145 (defcustom org-texinfo-filename nil
146 "Default filename for texinfo output."
147 :group
'org-export-texinfo
148 :type
'(string :tag
"Export Filename"))
150 (defcustom org-texinfo-default-class
"info"
151 "The default Texinfo class."
152 :group
'org-export-texinfo
153 :type
'(string :tag
"Texinfo class"))
155 (defcustom org-texinfo-classes
157 "\\input texinfo @c -*- texinfo -*-"
158 ("@chapter %s" .
"@unnumbered %s")
159 ("@section %s" .
"@unnumberedsec %s")
160 ("@subsection %s" .
"@unnumberedsubsec %s")
161 ("@subsubsection %s" .
"@unnumberedsubsubsec %s")))
162 "Alist of Texinfo classes and associated header and structure.
163 If #+Texinfo_CLASS is set in the buffer, use its value and the
164 associated information. Here is the structure of each cell:
168 \(numbered-section . unnumbered-section\)
171 The sectioning structure
172 ------------------------
174 The sectioning structure of the class is given by the elements
175 following the header string. For each sectioning level, a number
176 of strings is specified. A %s formatter is mandatory in each
177 section string and will be replaced by the title of the section.
179 Instead of a list of sectioning commands, you can also specify
180 a function name. That function will be called with two
181 parameters, the \(reduced) level of the headline, and a predicate
182 non-nil when the headline should be numbered. It must return
183 a format string in which the section title will be added."
184 :group
'org-export-texinfo
186 (list (string :tag
"Texinfo class")
187 (string :tag
"Texinfo header")
188 (repeat :tag
"Levels" :inline t
191 (string :tag
" numbered")
192 (string :tag
"unnumbered"))
193 (function :tag
"Hook computing sectioning"))))))
197 (defcustom org-texinfo-format-headline-function nil
198 "Function to format headline text.
200 This function will be called with 5 arguments:
201 TODO the todo keyword (string or nil).
202 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
203 PRIORITY the priority of the headline (integer or nil)
204 TEXT the main headline text (string).
205 TAGS the tags as a list of strings (list of strings or nil).
207 The function result will be used in the section format string.
209 As an example, one could set the variable to the following, in
210 order to reproduce the default set-up:
212 \(defun org-texinfo-format-headline (todo todo-type priority text tags)
213 \"Default format function for an headline.\"
215 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
217 \(format \"\\\\framebox{\\\\#%c} \" priority))
220 \(format \"\\\\hfill{}\\\\textsc{%s}\"
221 \(mapconcat 'identity tags \":\"))))"
222 :group
'org-export-texinfo
228 ;; Footnotes are inserted directly
232 (defcustom org-texinfo-active-timestamp-format
"@emph{%s}"
233 "A printf format string to be applied to active timestamps."
234 :group
'org-export-texinfo
237 (defcustom org-texinfo-inactive-timestamp-format
"@emph{%s}"
238 "A printf format string to be applied to inactive timestamps."
239 :group
'org-export-texinfo
242 (defcustom org-texinfo-diary-timestamp-format
"@emph{%s}"
243 "A printf format string to be applied to diary timestamps."
244 :group
'org-export-texinfo
249 (defcustom org-texinfo-link-with-unknown-path-format
"@indicateurl{%s}"
250 "Format string for links with unknown path type."
251 :group
'org-export-texinfo
256 (defcustom org-texinfo-tables-verbatim nil
257 "When non-nil, tables are exported verbatim."
258 :group
'org-export-texinfo
261 (defcustom org-texinfo-table-scientific-notation
"%s\\,(%s)"
262 "Format string to display numbers in scientific notation.
263 The format should have \"%s\" twice, for mantissa and exponent
264 \(i.e. \"%s\\\\times10^{%s}\").
266 When nil, no transformation is made."
267 :group
'org-export-texinfo
269 (string :tag
"Format string")
270 (const :tag
"No formatting")))
272 (defcustom org-texinfo-def-table-markup
"@samp"
273 "Default setting for @table environments.")
277 (defcustom org-texinfo-text-markup-alist
'((bold .
"@strong{%s}")
279 (italic .
"@emph{%s}")
282 "Alist of Texinfo expressions to convert text markup.
284 The key must be a symbol among `bold', `italic' and `comment'.
285 The value is a formatting string to wrap fontified text with.
287 Value can also be set to the following symbols: `verb' and
288 `code'. For the former, Org will use \"@verb\" to
289 create a format string and select a delimiter character that
290 isn't in the string. For the latter, Org will use \"@code\"
291 to typeset and try to protect special characters.
293 If no association can be found for a given markup, text will be
295 :group
'org-export-texinfo
297 :options
'(bold code italic verbatim comment
))
301 (defcustom org-texinfo-format-drawer-function nil
302 "Function called to format a drawer in Texinfo code.
304 The function must accept two parameters:
305 NAME the drawer name, like \"LOGBOOK\"
306 CONTENTS the contents of the drawer.
308 The function should return the string to be exported.
310 For example, the variable could be set to the following function
311 in order to mimic default behaviour:
313 \(defun org-texinfo-format-drawer-default \(name contents\)
314 \"Format a drawer element for Texinfo export.\"
316 :group
'org-export-texinfo
321 (defcustom org-texinfo-format-inlinetask-function nil
322 "Function called to format an inlinetask in Texinfo code.
324 The function must accept six parameters:
325 TODO the todo keyword, as a string
326 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
327 PRIORITY the inlinetask priority, as a string
328 NAME the inlinetask name, as a string.
329 TAGS the inlinetask tags, as a list of strings.
330 CONTENTS the contents of the inlinetask, as a string.
332 The function should return the string to be exported.
334 For example, the variable could be set to the following function
335 in order to mimic default behaviour:
337 \(defun org-texinfo-format-inlinetask \(todo type priority name tags contents\)
338 \"Format an inline task element for Texinfo export.\"
342 \(format \"@strong{%s} \" todo))
343 \(when priority (format \"#%c \" priority))
347 \(mapconcat 'identity tags \":\")))))
348 \(format (concat \"@center %s\n\n\"
351 full-title contents))"
352 :group
'org-export-texinfo
357 ;; Src Blocks are example blocks, except for LISP
361 (defcustom org-texinfo-info-process
363 "Commands to process a texinfo file to an INFO file.
364 This is list of strings, each of them will be given to the shell
365 as a command. %f in the command will be replaced by the full
366 file name, %b by the file base name \(i.e without extension) and
367 %o by the base directory of the file."
368 :group
'org-export-texinfo
369 :type
'(repeat :tag
"Shell command sequence"
370 (string :tag
"Shell command")))
373 ;;; Internal Functions
375 (defun org-texinfo-filter-section-blank-lines (headline back-end info
)
376 "Filter controlling number of blank lines after a section."
377 (let ((blanks (make-string 2 ?
\n)))
378 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline
)))
380 (defun org-texinfo--find-verb-separator (s)
381 "Return a character not used in string S.
382 This is used to choose a separator for constructs like \\verb."
383 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
384 (loop for c across ll
385 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
386 return
(char-to-string c
))))
388 (defun org-texinfo--make-option-string (options)
389 "Return a comma separated string of keywords and values.
390 OPTIONS is an alist where the key is the options keyword as
391 a string, and the value a list containing the keyword value, or
393 (mapconcat (lambda (pair)
395 (when (> (length (second pair
)) 0)
396 (concat "=" (second pair
)))))
400 (defun org-texinfo--text-markup (text markup
)
401 "Format TEXT depending on MARKUP text markup.
402 See `org-texinfo-text-markup-alist' for details."
403 (let ((fmt (cdr (assq markup org-texinfo-text-markup-alist
))))
405 ;; No format string: Return raw text.
408 (let ((separator (org-texinfo--find-verb-separator text
)))
409 (concat "@verb{" separator text separator
"}")))
414 (while (string-match "[@{}]" text
)
415 (setq char
(match-string 0 text
))
416 (if (> (match-beginning 0) 0)
417 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
418 (setq text
(substring text
(1+ (match-beginning 0))))
419 (setq char
(concat "@" char
)
420 rtn
(concat rtn char
)))
421 (setq text
(concat rtn text
)
424 ;; Else use format string.
425 (t (format fmt text
)))))
427 ;;; Headline sanitizing
429 (defun org-texinfo--sanitize-headline (headline info
)
430 "Remove all formatting from the text of a headline for use in
431 node and menu listing."
433 (org-texinfo--sanitize-headline-contents headline info
) " "))
435 (defun org-texinfo--sanitize-headline-contents (headline info
)
436 "Retrieve the content of the headline.
438 Any content that can contain further formatting is checked
439 recursively, to ensure that nested content is also properly
441 (loop for contents in headline append
445 (list (replace-regexp-in-string " $" "" contents
)))
446 ;; Is exported as-is (value)
447 ((org-element-map contents
'(verbatim code
)
448 (lambda (value) (org-element-property :value value
)) info
))
449 ;; Has content and recurse into the content
450 ((org-element-contents contents
)
451 (org-texinfo--sanitize-headline-contents
452 (org-element-contents contents
) info
)))))
456 (defun org-texinfo--sanitize-menu (title)
457 "Remove invalid characters from TITLE for use in menus and
460 Based on TEXINFO specifications, the following must be removed:
462 (replace-regexp-in-string "[@{}():,.]" "" title
))
464 ;;; Content sanitizing
466 (defun org-texinfo--sanitize-content (text)
467 "Ensure characters are properly escaped when used in headlines or blocks.
469 Escape characters are: @ { }"
470 (replace-regexp-in-string "\\\([@{}]\\\)" "@\\1" text
))
474 (defun org-texinfo--build-menu (tree level info
&optional detailed
)
475 "Create the @menu/@end menu information from TREE at headline
478 TREE contains the parse-tree to work with, either of the entire
479 document or of a specific parent headline. LEVEL indicates what
480 level of headlines to look at when generating the menu. INFO is
481 a plist containing contextual information.
483 Detailed determines whether to build a single level of menu, or
484 recurse into all children as well."
485 (let ((menu (org-texinfo--generate-menu-list tree level info
))
489 ;; Looping is done within the menu generation.
490 (setq text-menu
(org-texinfo--generate-detailed menu level info
)))
492 (setq text-menu
(org-texinfo--generate-menu-items menu info
))))
494 (setq output
(org-texinfo--format-menu text-menu
))
495 (mapconcat 'identity output
"\n"))))
497 (defun org-texinfo--generate-detailed (menu level info
)
498 "Generate a detailed listing of all subheadings within MENU starting at LEVEL.
500 MENU is the parse-tree to work with. LEVEL is the starting level
501 for the menu headlines and from which recursion occurs. INFO is
502 a plist containing contextual information."
504 (let ((max-depth (plist-get info
:headline-levels
)))
505 (when (> max-depth level
)
506 (loop for headline in menu append
507 (let* ((title (org-texinfo--menu-headlines headline info
))
508 ;; Create list of menu entries for the next level
509 (sublist (org-texinfo--generate-menu-list
510 headline
(1+ level
) info
))
511 ;; Generate the menu items for that level. If
512 ;; there are none omit that heading completely,
513 ;; otherwise join the title to it's related entries.
514 (submenu (if (org-texinfo--generate-menu-items sublist info
)
516 (org-texinfo--generate-menu-items sublist info
))
518 ;; Start the process over the next level down.
519 (recursion (org-texinfo--generate-detailed sublist
(1+ level
) info
)))
520 (setq recursion
(append submenu recursion
))
523 (defun org-texinfo--generate-menu-list (tree level info
)
524 "Generate the list of headlines that are within a given level
525 of the tree for further formatting.
527 TREE is the parse-tree containing the headlines. LEVEL is the
528 headline level to generate a list of. INFO is a plist holding
529 contextual information."
530 (org-element-map tree
'headline
532 (and (= (org-export-get-relative-level head info
) level
)
533 ;; Do not take note of footnotes or copying headlines.
534 (not (org-element-property :copying head
))
535 (not (org-element-property :footnote-section-p head
))
540 (defun org-texinfo--generate-menu-items (items info
)
541 "Generate a list of headline information from the listing ITEMS.
543 ITEMS is a list of the headlines to be converted into entries.
544 INFO is a plist containing contextual information.
546 Returns a list containing the following information from each
547 headline: length, title, description. This is used to format the
548 menu using `org-texinfo--format-menu'."
549 (loop for headline in items collect
550 (let* ((menu-title (org-texinfo--sanitize-menu
552 (org-element-property :texinfo-menu-title headline
)
554 (title (org-texinfo--sanitize-menu
555 (org-texinfo--sanitize-headline
556 (org-element-property :title headline
) info
)))
557 (descr (org-export-data
558 (org-element-property :description headline
)
560 (menu-entry (if (string= "" menu-title
) title menu-title
))
561 (len (length menu-entry
))
562 (output (list len menu-entry descr
)))
565 (defun org-texinfo--menu-headlines (headline info
)
566 "Retrieve the title from HEADLINE.
568 INFO is a plist holding contextual information.
570 Return the headline as a list of (length title description) with
571 length of -1 and nil description. This is used in
572 `org-texinfo--format-menu' to identify headlines as opposed to
574 (let ((title (org-export-data
575 (org-element-property :title headline
) info
)))
576 (list -
1 title
'nil
)))
578 (defun org-texinfo--format-menu (text-menu)
579 "Format the TEXT-MENU items to be properly printed in the menu.
581 Each entry in the menu should be provided as (length title
584 Headlines in the detailed menu are given length -1 to ensure they
585 are never confused with other entries. They also have no
588 Other menu items are output as:
591 With the spacing between :: and description based on the length
592 of the longest menu entry."
594 (let* ((lengths (mapcar 'car text-menu
))
595 (max-length (apply 'max lengths
))
598 (mapcar (lambda (name)
599 (let* ((title (nth 1 name
))
601 (length (nth 0 name
)))
603 (concat "* " title
":: "
605 (- (+ 3 max-length
) length
)
609 (concat "\n" title
"\n"))))
615 (defun org-texinfo-template (contents info
)
616 "Return complete document string after Texinfo conversion.
617 CONTENTS is the transcoded contents string. INFO is a plist
618 holding export options."
619 (let* ((title (org-export-data (plist-get info
:title
) info
))
620 (info-filename (or (plist-get info
:texinfo-filename
)
621 (file-name-nondirectory
622 (org-export-output-file-name ".info"))))
623 (author (org-export-data (plist-get info
:author
) info
))
624 (texinfo-header (plist-get info
:texinfo-header
))
625 (texinfo-post-header (plist-get info
:texinfo-post-header
))
626 (subtitle (plist-get info
:subtitle
))
627 (subauthor (plist-get info
:subauthor
))
628 (class (plist-get info
:texinfo-class
))
629 (header (nth 1 (assoc class org-texinfo-classes
)))
631 (org-element-map (plist-get info
:parse-tree
) 'headline
632 (lambda (hl) (and (org-element-property :copying hl
) hl
)) info t
))
633 (dircat (plist-get info
:texinfo-dircat
))
634 (dirtitle (plist-get info
:texinfo-dirtitle
))
635 (dirdesc (plist-get info
:texinfo-dirdesc
))
636 ;; Spacing to align description (column 32 - 3 for `* ' and
638 (dirspacing (- 29 (length dirtitle
)))
639 (menu (org-texinfo-make-menu info
'main
))
640 (detail-menu (org-texinfo-make-menu info
'detailed
)))
644 "@c %**start of header\n"
645 ;; Filename and Title
646 "@setfilename " info-filename
"\n"
647 "@settitle " title
"\n"
649 "@c Version and Contact Info\n"
650 "@set AUTHOR " author
"\n"
652 ;; Additional Header Options set by `#+TEXINFO_HEADER
658 "@c %**end of header\n"
662 ;; Additional Header Options set by #+TEXINFO_POST_HEADER
663 (if texinfo-post-header
670 ;; Only export the content of the headline, do not need the
672 (org-export-data (nth 2 copying
) info
)
676 ;; Info directory information
677 ;; Only supply if both title and category are provided
678 (if (and dircat dirtitle
)
679 (concat "@dircategory " dircat
"\n"
682 (make-string dirspacing ?\s
)
689 "@title " title
"\n\n"
691 (concat "@subtitle " subtitle
"\n"))
692 "@author " author
"\n"
694 (concat subauthor
"\n"))
696 "@c The following two commands start the copyright page.\n"
698 "@vskip 0pt plus 1filll\n"
701 "@c Output the table of contents at the beginning.\n"
704 ;; Configure Top Node when not for Tex
707 "@top " title
" Manual\n"
711 ;; Do not output menus if they are empty
719 (concat "@detailmenu\n"
720 " --- The Detailed Node Listing ---\n"
723 "@end detailmenu\n"))
731 (let ((creator-info (plist-get info
:with-creator
)))
733 ((not creator-info
) "")
734 ((eq creator-info
'comment
)
735 (format "@c %s\n" (plist-get info
:creator
)))
736 (t (concat (plist-get info
:creator
) "\n"))))
742 ;;; Transcode Functions
746 (defun org-texinfo-bold (bold contents info
)
747 "Transcode BOLD from Org to Texinfo.
748 CONTENTS is the text with bold markup. INFO is a plist holding
749 contextual information."
750 (org-texinfo--text-markup contents
'bold
))
754 (defun org-texinfo-center-block (center-block contents info
)
755 "Transcode a CENTER-BLOCK element from Org to Texinfo.
756 CONTENTS holds the contents of the block. INFO is a plist used
757 as a communication channel."
762 (defun org-texinfo-clock (clock contents info
)
763 "Transcode a CLOCK element from Org to Texinfo.
764 CONTENTS is nil. INFO is a plist holding contextual
768 (format "@strong{%s} " org-clock-string
)
769 (format org-texinfo-inactive-timestamp-format
770 (concat (org-translate-time
771 (org-element-property :raw-value
772 (org-element-property :value clock
)))
773 (let ((time (org-element-property :duration clock
)))
774 (and time
(format " (%s)" time
)))))
779 (defun org-texinfo-code (code contents info
)
780 "Transcode a CODE object from Org to Texinfo.
781 CONTENTS is nil. INFO is a plist used as a communication
783 (org-texinfo--text-markup (org-element-property :value code
) 'code
))
787 (defun org-texinfo-comment (comment contents info
)
788 "Transcode a COMMENT object from Org to Texinfo.
789 CONTENTS is the text in the comment. INFO is a plist holding
790 contextual information."
791 (org-texinfo--text-markup (org-element-property :value comment
) 'comment
))
795 (defun org-texinfo-comment-block (comment-block contents info
)
796 "Transcode a COMMENT-BLOCK object from Org to Texinfo.
797 CONTENTS is the text within the block. INFO is a plist holding
798 contextual information."
799 (format "@ignore\n%s@end ignore" (org-element-property :value comment-block
)))
803 (defun org-texinfo-drawer (drawer contents info
)
804 "Transcode a DRAWER element from Org to Texinfo.
805 CONTENTS holds the contents of the block. INFO is a plist
806 holding contextual information."
807 (let* ((name (org-element-property :drawer-name drawer
))
808 (output (if (functionp org-texinfo-format-drawer-function
)
809 (funcall org-texinfo-format-drawer-function
811 ;; If there's no user defined function: simply
812 ;; display contents of the drawer.
818 (defun org-texinfo-dynamic-block (dynamic-block contents info
)
819 "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
820 CONTENTS holds the contents of the block. INFO is a plist
821 holding contextual information. See `org-export-data'."
826 (defun org-texinfo-entity (entity contents info
)
827 "Transcode an ENTITY object from Org to Texinfo.
828 CONTENTS are the definition itself. INFO is a plist holding
829 contextual information."
830 (let ((ent (org-element-property :latex entity
)))
831 (if (org-element-property :latex-math-p entity
) (format "@math{%s}" ent
) ent
)))
835 (defun org-texinfo-example-block (example-block contents info
)
836 "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
837 CONTENTS is nil. INFO is a plist holding contextual
839 (format "@verbatim\n%s@end verbatim"
840 (org-export-format-code-default example-block info
)))
844 (defun org-texinfo-export-block (export-block contents info
)
845 "Transcode a EXPORT-BLOCK element from Org to Texinfo.
846 CONTENTS is nil. INFO is a plist holding contextual information."
847 (when (string= (org-element-property :type export-block
) "TEXINFO")
848 (org-remove-indentation (org-element-property :value export-block
))))
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
871 (defun org-texinfo-footnote-reference (footnote contents info
)
872 "Create a footnote reference for FOOTNOTE.
874 FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
875 plist holding contextual information."
876 (let ((def (org-export-get-footnote-definition footnote info
)))
877 (format "@footnote{%s}"
878 (org-trim (org-export-data def info
)))))
882 (defun org-texinfo-headline (headline contents info
)
883 "Transcode an HEADLINE element from Org to Texinfo.
884 CONTENTS holds the contents of the headline. INFO is a plist
885 holding contextual information."
886 (let* ((class (plist-get info
:texinfo-class
))
887 (level (org-export-get-relative-level headline info
))
888 (numberedp (org-export-numbered-headline-p headline info
))
889 (class-sectionning (assoc class org-texinfo-classes
))
890 ;; Find the index type, if any
891 (index (org-element-property :index headline
))
892 ;; Retrieve custom menu title (if any)
893 (menu-title (org-texinfo--sanitize-menu
895 (org-element-property :texinfo-menu-title headline
)
897 ;; Retrieve headline text
898 (text (org-texinfo--sanitize-headline
899 (org-element-property :title headline
) info
))
900 ;; Create node info, to insert it before section formatting.
901 ;; Use custom menu title if present
902 (node (format "@node %s\n"
903 (org-texinfo--sanitize-menu
904 (replace-regexp-in-string "%" "%%"
905 (if (not (string= "" menu-title
))
908 ;; Menus must be generated with first child, otherwise they
909 ;; will not nest properly
910 (menu (let* ((first (org-export-first-sibling-p headline info
))
911 (parent (org-export-get-parent-headline headline
))
912 (title (org-texinfo--sanitize-headline
913 (org-element-property :title parent
) info
))
915 (tree (plist-get info
:parse-tree
)))
917 (org-element-map (plist-get info
:parse-tree
) 'headline
919 (if (member title
(org-element-property :title ref
))
922 (setq listing
(org-texinfo--build-menu
923 (car heading
) level info
))
925 (setq listing
(replace-regexp-in-string
928 "\n@menu\n%s\n@end menu\n\n" listing
))
930 ;; Section formatting will set two placeholders: one for the
931 ;; title and the other for the contents.
933 (let ((sec (if (and (symbolp (nth 2 class-sectionning
))
934 (fboundp (nth 2 class-sectionning
)))
935 (funcall (nth 2 class-sectionning
) level numberedp
)
936 (nth (1+ level
) class-sectionning
))))
938 ;; No section available for that LEVEL.
940 ;; Section format directly returned by a function.
942 ;; (numbered-section . unnumbered-section)
943 ((not (consp (cdr sec
)))
944 ;; If an index, always unnumbered
946 (concat menu node
(cdr sec
) "\n%s")
947 ;; Otherwise number as needed.
950 (if numberedp
#'car
#'cdr
) sec
) "\n%s"))))))
952 (and (plist-get info
:with-todo-keywords
)
953 (let ((todo (org-element-property :todo-keyword headline
)))
954 (and todo
(org-export-data todo info
)))))
955 (todo-type (and todo
(org-element-property :todo-type headline
)))
956 (tags (and (plist-get info
:with-tags
)
957 (org-export-get-tags headline info
)))
958 (priority (and (plist-get info
:with-priority
)
959 (org-element-property :priority headline
)))
960 ;; Create the headline text along with a no-tag version. The
961 ;; latter is required to remove tags from table of contents.
962 (full-text (org-texinfo--sanitize-content
963 (if (functionp org-texinfo-format-headline-function
)
964 ;; User-defined formatting function.
965 (funcall org-texinfo-format-headline-function
966 todo todo-type priority text tags
)
967 ;; Default formatting.
970 (format "@strong{%s} " todo
))
971 (when priority
(format "@emph{#%s} " priority
))
975 (mapconcat 'identity tags
":")))))))
977 (org-texinfo--sanitize-content
978 (if (functionp org-texinfo-format-headline-function
)
979 ;; User-defined formatting function.
980 (funcall org-texinfo-format-headline-function
981 todo todo-type priority text nil
)
982 ;; Default formatting.
984 (when todo
(format "@strong{%s} " todo
))
985 (when priority
(format "@emph{#%c} " priority
))
988 (make-string (org-element-property :pre-blank headline
) 10)))
990 ;; Case 1: This is a footnote section: ignore it.
991 ((org-element-property :footnote-section-p headline
) nil
)
992 ;; Case 2: This is the `copying' section: ignore it
993 ;; This is used elsewhere.
994 ((org-element-property :copying headline
) nil
)
995 ;; Case 3: An index. If it matches one of the known indexes,
996 ;; print it as such following the contents, otherwise
997 ;; print the contents and leave the index up to the user.
1000 section-fmt full-text
1001 (concat pre-blanks contents
"\n"
1002 (if (member index
'("cp" "fn" "ky" "pg" "tp" "vr"))
1003 (concat "@printindex " index
)))))
1004 ;; Case 4: This is a deep sub-tree: export it as a list item.
1005 ;; Also export as items headlines for which no section
1006 ;; format has been found.
1007 ((or (not section-fmt
) (org-export-low-level-p headline info
))
1008 ;; Build the real contents of the sub-tree.
1009 (let ((low-level-body
1011 ;; If the headline is the first sibling, start a list.
1012 (when (org-export-first-sibling-p headline info
)
1013 (format "@%s\n" (if numberedp
'enumerate
'itemize
)))
1015 "@item\n" full-text
"\n" pre-blanks contents
)))
1016 ;; If headline is not the last sibling simply return
1017 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
1019 (if (not (org-export-last-sibling-p headline info
)) low-level-body
1020 (replace-regexp-in-string
1022 (format "\n@end %s" (if numberedp
'enumerate
'itemize
))
1024 ;; Case 5: Standard headline. Export it as a section.
1027 ((not (and tags
(eq (plist-get info
:with-tags
) 'not-in-toc
)))
1028 ;; Regular section. Use specified format string.
1029 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1030 (concat pre-blanks contents
)))
1031 ((string-match "\\`@\\(.*?\\){" section-fmt
)
1032 ;; If tags should be removed from table of contents, insert
1033 ;; title without tags as an alternative heading in sectioning
1035 (format (replace-match (concat (match-string 1 section-fmt
) "[%s]")
1036 nil nil section-fmt
1)
1037 ;; Replace square brackets with parenthesis since
1038 ;; square brackets are not supported in optional
1040 (replace-regexp-in-string
1042 (replace-regexp-in-string
1046 (concat pre-blanks contents
)))
1048 ;; Impossible to add an alternative heading. Fallback to
1049 ;; regular sectioning format string.
1050 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1051 (concat pre-blanks contents
))))))))
1053 ;;; Inline Src Block
1055 (defun org-texinfo-inline-src-block (inline-src-block contents info
)
1056 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
1057 CONTENTS holds the contents of the item. INFO is a plist holding
1058 contextual information."
1059 (let* ((code (org-element-property :value inline-src-block
))
1060 (separator (org-texinfo--find-verb-separator code
)))
1061 (concat "@verb{" separator code separator
"}")))
1065 (defun org-texinfo-inlinetask (inlinetask contents info
)
1066 "Transcode an INLINETASK element from Org to Texinfo.
1067 CONTENTS holds the contents of the block. INFO is a plist
1068 holding contextual information."
1069 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
1070 (todo (and (plist-get info
:with-todo-keywords
)
1071 (let ((todo (org-element-property :todo-keyword inlinetask
)))
1072 (and todo
(org-export-data todo info
)))))
1073 (todo-type (org-element-property :todo-type inlinetask
))
1074 (tags (and (plist-get info
:with-tags
)
1075 (org-export-get-tags inlinetask info
)))
1076 (priority (and (plist-get info
:with-priority
)
1077 (org-element-property :priority inlinetask
))))
1078 ;; If `org-texinfo-format-inlinetask-function' is provided, call it
1079 ;; with appropriate arguments.
1080 (if (functionp org-texinfo-format-inlinetask-function
)
1081 (funcall org-texinfo-format-inlinetask-function
1082 todo todo-type priority title tags contents
)
1083 ;; Otherwise, use a default template.
1086 (when todo
(format "@strong{%s} " todo
))
1087 (when priority
(format "#%c " priority
))
1089 (when tags
(format ":%s:"
1090 (mapconcat 'identity tags
":"))))))
1091 (format (concat "@center %s\n\n"
1094 full-title contents
)))))
1098 (defun org-texinfo-italic (italic contents info
)
1099 "Transcode ITALIC from Org to Texinfo.
1100 CONTENTS is the text with italic markup. INFO is a plist holding
1101 contextual information."
1102 (org-texinfo--text-markup contents
'italic
))
1106 (defun org-texinfo-item (item contents info
)
1107 "Transcode an ITEM element from Org to Texinfo.
1108 CONTENTS holds the contents of the item. INFO is a plist holding
1109 contextual information."
1110 (let* ((tag (org-element-property :tag item
))
1111 (desc (org-export-data tag info
)))
1112 (concat "\n@item " (if tag desc
) "\n"
1113 (org-trim contents
) "\n")))
1117 (defun org-texinfo-keyword (keyword contents info
)
1118 "Transcode a KEYWORD element from Org to Texinfo.
1119 CONTENTS is nil. INFO is a plist holding contextual information."
1120 (let ((key (org-element-property :key keyword
))
1121 (value (org-element-property :value keyword
)))
1123 ((string= key
"TEXINFO") value
)
1124 ((string= key
"CINDEX") (format "@cindex %s" value
))
1125 ((string= key
"FINDEX") (format "@findex %s" value
))
1126 ((string= key
"KINDEX") (format "@kindex %s" value
))
1127 ((string= key
"PINDEX") (format "@pindex %s" value
))
1128 ((string= key
"TINDEX") (format "@tindex %s" value
))
1129 ((string= key
"VINDEX") (format "@vindex %s" value
)))))
1133 (defun org-texinfo-line-break (line-break contents info
)
1134 "Transcode a LINE-BREAK object from Org to Texinfo.
1135 CONTENTS is nil. INFO is a plist holding contextual information."
1140 (defun org-texinfo-link (link desc info
)
1141 "Transcode a LINK object from Org to Texinfo.
1143 DESC is the description part of the link, or the empty string.
1144 INFO is a plist holding contextual information. See
1146 (let* ((type (org-element-property :type link
))
1147 (raw-path (org-element-property :path link
))
1148 ;; Ensure DESC really exists, or set it to nil.
1149 (desc (and (not (string= desc
"")) desc
))
1151 ((member type
'("http" "https" "ftp"))
1152 (concat type
":" raw-path
))
1153 ((string= type
"file")
1154 (if (file-name-absolute-p raw-path
)
1155 (concat "file://" (expand-file-name raw-path
))
1156 (concat "file://" raw-path
)))
1158 (email (if (string= type
"mailto")
1159 (let ((text (replace-regexp-in-string
1160 "@" "@@" raw-path
)))
1161 (concat text
(if desc
(concat "," desc
))))))
1164 ;; Links pointing to an headline: Find destination and build
1165 ;; appropriate referencing command.
1166 ((member type
'("custom-id" "id"))
1167 (let ((destination (org-export-resolve-id-link link info
)))
1168 (case (org-element-type destination
)
1169 ;; Id link points to an external file.
1171 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1172 (format "@uref{file://%s}" destination
)))
1173 ;; LINK points to an headline. Use the headline as the NODE target
1175 (format "@ref{%s,%s}"
1178 (org-element-property :texinfo-menu-title destination
)
1179 (org-element-property :title destination
)) info
)
1182 (let ((path (org-export-solidify-link-text path
)))
1183 (if (not desc
) (format "@ref{%s}" path
)
1184 (format "@ref{%s,,%s}" path desc
)))))))
1185 ((member type
'("info"))
1186 (let* ((info-path (split-string path
":"))
1187 (info-manual (car info-path
))
1188 (info-node (or (cadr info-path
) "top"))
1189 (title (or desc
"")))
1190 (format "@ref{%s,%s,,%s,}" info-node title info-manual
)))
1191 ((member type
'("fuzzy"))
1192 (let ((destination (org-export-resolve-fuzzy-link link info
)))
1193 (case (org-element-type destination
)
1194 ;; Id link points to an external file.
1196 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1197 (format "@uref{file://%s}" destination
)))
1198 ;; LINK points to an headline. Use the headline as the NODE target
1200 (format "@ref{%s,%s}"
1203 (org-element-property :texinfo-menu-title destination
)
1204 (org-element-property :title destination
)) info
)
1207 (let ((path (org-export-solidify-link-text path
)))
1208 (if (not desc
) (format "@ref{%s}" path
)
1209 (format "@ref{%s,,%s}" path desc
)))))))
1210 ;; Special case for email addresses
1212 (format "@email{%s}" email
))
1213 ;; External link with a description part.
1214 ((and path desc
) (format "@uref{%s,%s}" path desc
))
1215 ;; External link without a description part.
1216 (path (format "@uref{%s}" path
))
1217 ;; No path, only description. Try to do something useful.
1218 (t (format org-texinfo-link-with-unknown-path-format desc
)))))
1223 (defun org-texinfo-make-menu (info level
)
1224 "Create the menu for inclusion in the texifo document.
1226 INFO is the parsed buffer that contains the headlines. LEVEL
1227 determines whether to make the main menu, or the detailed menu.
1229 This is only used for generating the primary menu. In-Node menus
1230 are generated directly."
1231 (let ((parse (plist-get info
:parse-tree
)))
1233 ;; Generate the main menu
1234 ((eq level
'main
) (org-texinfo--build-menu parse
1 info
))
1235 ;; Generate the detailed (recursive) menu
1236 ((eq level
'detailed
)
1237 ;; Requires recursion
1238 ;;(org-texinfo--build-detailed-menu parse top info)
1239 (org-texinfo--build-menu parse
1 info
'detailed
)))))
1243 (defun org-texinfo-paragraph (paragraph contents info
)
1244 "Transcode a PARAGRAPH element from Org to Texinfo.
1245 CONTENTS is the contents of the paragraph, as a string. INFO is
1246 the plist used as a communication channel."
1251 (defun org-texinfo-plain-list (plain-list contents info
)
1252 "Transcode a PLAIN-LIST element from Org to Texinfo.
1253 CONTENTS is the contents of the list. INFO is a plist holding
1254 contextual information."
1255 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1256 (indic (or (plist-get attr
:indic
)
1257 org-texinfo-def-table-markup
))
1258 (type (org-element-property :type plain-list
))
1259 (table-type (or (plist-get attr
:table-type
)
1261 ;; Ensure valid texinfo table type.
1262 (table-type (if (memq table-type
'("table" "ftable" "vtable"))
1266 ((eq type
'ordered
) "enumerate")
1267 ((eq type
'unordered
) "itemize")
1268 ((eq type
'descriptive
) table-type
))))
1269 (format "@%s%s\n@end %s"
1270 (if (eq type
'descriptive
)
1271 (concat list-type
" " indic
)
1278 (defun org-texinfo-plain-text (text info
)
1279 "Transcode a TEXT string from Org to Texinfo.
1280 TEXT is the string to transcode. INFO is a plist holding
1281 contextual information."
1282 ;; First protect @, { and }.
1283 (let ((output (org-texinfo--sanitize-content text
)))
1284 ;; Activate smart quotes. Be sure to provide original TEXT string
1285 ;; since OUTPUT may have been modified.
1286 (when (plist-get info
:with-smart-quotes
)
1288 (org-export-activate-smart-quotes output
:texinfo info text
)))
1289 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1290 (let ((case-fold-search nil
)
1292 (while (string-match "\\(\\(?:La\\)?TeX\\)" output start
)
1293 (setq output
(replace-match
1294 (format "@%s{}" (match-string 1 output
)) nil t output
)
1295 start
(match-end 0))))
1296 ;; Convert special strings.
1297 (when (plist-get info
:with-special-strings
)
1298 (while (string-match (regexp-quote "...") output
)
1299 (setq output
(replace-match "@dots{}" nil t output
))))
1300 ;; Handle break preservation if required.
1301 (when (plist-get info
:preserve-breaks
)
1302 (setq output
(replace-regexp-in-string
1303 "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output
)))
1309 (defun org-texinfo-planning (planning contents info
)
1310 "Transcode a PLANNING element from Org to Texinfo.
1311 CONTENTS is nil. INFO is a plist holding contextual
1319 (let ((closed (org-element-property :closed planning
)))
1322 (format "@strong{%s} " org-closed-string
)
1323 (format org-texinfo-inactive-timestamp-format
1325 (org-element-property :raw-value closed
))))))
1326 (let ((deadline (org-element-property :deadline planning
)))
1329 (format "@strong{%s} " org-deadline-string
)
1330 (format org-texinfo-active-timestamp-format
1332 (org-element-property :raw-value deadline
))))))
1333 (let ((scheduled (org-element-property :scheduled planning
)))
1336 (format "@strong{%s} " org-scheduled-string
)
1337 (format org-texinfo-active-timestamp-format
1339 (org-element-property :raw-value scheduled
))))))))
1345 (defun org-texinfo-property-drawer (property-drawer contents info
)
1346 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1347 CONTENTS is nil. INFO is a plist holding contextual
1349 ;; The property drawer isn't exported but we want separating blank
1350 ;; lines nonetheless.
1355 (defun org-texinfo-quote-block (quote-block contents info
)
1356 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1357 CONTENTS holds the contents of the block. INFO is a plist
1358 holding contextual information."
1359 (let* ((title (org-element-property :name quote-block
))
1360 (start-quote (concat "@quotation"
1362 (format " %s" title
)))))
1363 (format "%s\n%s@end quotation" start-quote contents
)))
1367 (defun org-texinfo-quote-section (quote-section contents info
)
1368 "Transcode a QUOTE-SECTION element from Org to Texinfo.
1369 CONTENTS is nil. INFO is a plist holding contextual information."
1370 (let ((value (org-remove-indentation
1371 (org-element-property :value quote-section
))))
1372 (when value
(format "@verbatim\n%s@end verbatim" value
))))
1376 (defun org-texinfo-radio-target (radio-target text info
)
1377 "Transcode a RADIO-TARGET object from Org to Texinfo.
1378 TEXT is the text of the target. INFO is a plist holding
1379 contextual information."
1380 (format "@anchor{%s}%s"
1381 (org-export-solidify-link-text
1382 (org-element-property :value radio-target
))
1387 (defun org-texinfo-section (section contents info
)
1388 "Transcode a SECTION element from Org to Texinfo.
1389 CONTENTS holds the contents of the section. INFO is a plist
1390 holding contextual information."
1395 (defun org-texinfo-special-block (special-block contents info
)
1396 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1397 CONTENTS holds the contents of the block. INFO is a plist used
1398 as a communication channel."
1403 (defun org-texinfo-src-block (src-block contents info
)
1404 "Transcode a SRC-BLOCK element from Org to Texinfo.
1405 CONTENTS holds the contents of the item. INFO is a plist holding
1406 contextual information."
1407 (let* ((lang (org-element-property :language src-block
))
1408 (lisp-p (string-match-p "lisp" lang
)))
1410 ;; Case 1. Lisp Block
1412 (format "@lisp\n%s\n@end lisp"
1413 (org-export-format-code-default src-block info
)))
1414 ;; Case 2. Other blocks
1416 (format "@example\n%s\n@end example"
1417 (org-export-format-code-default src-block info
))))))
1419 ;;; Statistics Cookie
1421 (defun org-texinfo-statistics-cookie (statistics-cookie contents info
)
1422 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1423 CONTENTS is nil. INFO is a plist holding contextual information."
1424 (org-element-property :value statistics-cookie
))
1428 (defun org-texinfo-subscript (subscript contents info
)
1429 "Transcode a SUBSCRIPT object from Org to Texinfo.
1430 CONTENTS is the contents of the object. INFO is a plist holding
1431 contextual information."
1432 (format "@math{_%s}" contents
))
1436 (defun org-texinfo-superscript (superscript contents info
)
1437 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1438 CONTENTS is the contents of the object. INFO is a plist holding
1439 contextual information."
1440 (format "@math{^%s}" contents
))
1444 ;; `org-texinfo-table' is the entry point for table transcoding. It
1445 ;; takes care of tables with a "verbatim" attribute. Otherwise, it
1446 ;; delegates the job to either `org-texinfo-table--table.el-table' or
1447 ;; `org-texinfo-table--org-table' functions, depending of the type of
1450 ;; `org-texinfo-table--align-string' is a subroutine used to build
1451 ;; alignment string for Org tables.
1453 (defun org-texinfo-table (table contents info
)
1454 "Transcode a TABLE element from Org to Texinfo.
1455 CONTENTS is the contents of the table. INFO is a plist holding
1456 contextual information."
1458 ;; Case 1: verbatim table.
1459 ((or org-texinfo-tables-verbatim
1460 (let ((attr (mapconcat 'identity
1461 (org-element-property :attr_latex table
)
1463 (and attr
(string-match "\\<verbatim\\>" attr
))))
1464 (format "@verbatim \n%s\n@end verbatim"
1465 ;; Re-create table, without affiliated keywords.
1467 (org-element-interpret-data
1468 `(table nil
,@(org-element-contents table
))))))
1469 ;; Case 2: table.el table. Convert it using appropriate tools.
1470 ((eq (org-element-property :type table
) 'table.el
)
1471 (org-texinfo-table--table.el-table table contents info
))
1472 ;; Case 3: Standard table.
1473 (t (org-texinfo-table--org-table table contents info
))))
1475 (defun org-texinfo-table-column-widths (table info
)
1476 "Determine the largest table cell in each column to process alignment.
1478 TABLE is the table element to transcode. INFO is a plist used as
1479 a communication channel."
1480 (let* ((rows (org-element-map table
'table-row
'identity info
))
1481 (collected (loop for row in rows collect
1482 (org-element-map row
'table-cell
'identity info
)))
1483 (number-cells (length (car collected
)))
1485 (loop for row in collected do
1486 (push (mapcar (lambda (ref)
1487 (let* ((start (org-element-property :contents-begin ref
))
1488 (end (org-element-property :contents-end ref
))
1489 (length (- end start
)))
1490 length
)) row
) cells
))
1491 (setq cells
(org-remove-if 'null cells
))
1492 (push (loop for count from
0 to
(- number-cells
1) collect
1493 (loop for item in cells collect
1494 (nth count item
))) counts
)
1495 (mapconcat (lambda (size)
1496 (make-string size ?a
)) (mapcar (lambda (ref)
1497 (apply 'max
`,@ref
)) (car counts
))
1500 (defun org-texinfo-table--org-table (table contents info
)
1501 "Return appropriate Texinfo code for an Org table.
1503 TABLE is the table type element to transcode. CONTENTS is its
1504 contents, as a string. INFO is a plist used as a communication
1507 This function assumes TABLE has `org' as its `:type' attribute."
1508 (let* ((attr (org-export-read-attribute :attr_texinfo table
))
1509 (col-width (plist-get attr
:columns
))
1510 (columns (if col-width
1511 (format "@columnfractions %s"
1514 (org-texinfo-table-column-widths
1516 ;; Prepare the final format string for the table.
1521 (format "@multitable %s\n%s@end multitable"
1525 (defun org-texinfo-table--table.el-table
(table contents info
)
1528 Rather than return an invalid table, nothing is returned."
1533 (defun org-texinfo-table-cell (table-cell contents info
)
1534 "Transcode a TABLE-CELL element from Org to Texinfo.
1535 CONTENTS is the cell contents. INFO is a plist used as
1536 a communication channel."
1537 (concat (if (and contents
1538 org-texinfo-table-scientific-notation
1539 (string-match orgtbl-exp-regexp contents
))
1540 ;; Use appropriate format string for scientific
1542 (format org-texinfo-table-scientific-notation
1543 (match-string 1 contents
)
1544 (match-string 2 contents
))
1546 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1550 (defun org-texinfo-table-row (table-row contents info
)
1551 "Transcode a TABLE-ROW element from Org to Texinfo.
1552 CONTENTS is the contents of the row. INFO is a plist used as
1553 a communication channel."
1554 ;; Rules are ignored since table separators are deduced from
1555 ;; borders of the current row.
1556 (when (eq (org-element-property :type table-row
) 'standard
)
1559 ;; Case 1: Belongs to second or subsequent rowgroup.
1560 ((not (= 1 (org-export-table-row-group table-row info
)))
1562 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
1563 ((org-export-table-has-header-p
1564 (org-export-get-parent-table table-row
) info
)
1566 ;; Case 3: Row is from first and only row group.
1568 (when (eq (org-element-property :type table-row
) 'standard
)
1569 (concat rowgroup-tag contents
"\n")))))
1573 (defun org-texinfo-target (target contents info
)
1574 "Transcode a TARGET object from Org to Texinfo.
1575 CONTENTS is nil. INFO is a plist holding contextual
1577 (format "@anchor{%s}"
1578 (org-export-solidify-link-text (org-element-property :value target
))))
1582 (defun org-texinfo-timestamp (timestamp contents info
)
1583 "Transcode a TIMESTAMP object from Org to Texinfo.
1584 CONTENTS is nil. INFO is a plist holding contextual
1586 (let ((value (org-texinfo-plain-text
1587 (org-timestamp-translate timestamp
) info
)))
1588 (case (org-element-property :type timestamp
)
1589 ((active active-range
)
1590 (format org-texinfo-active-timestamp-format value
))
1591 ((inactive inactive-range
)
1592 (format org-texinfo-inactive-timestamp-format value
))
1593 (t (format org-texinfo-diary-timestamp-format value
)))))
1597 (defun org-texinfo-verbatim (verbatim contents info
)
1598 "Transcode a VERBATIM object from Org to Texinfo.
1599 CONTENTS is nil. INFO is a plist used as a communication
1601 (org-texinfo--text-markup (org-element-property :value verbatim
) 'verbatim
))
1605 (defun org-texinfo-verse-block (verse-block contents info
)
1606 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1607 CONTENTS is verse block contents. INFO is a plist holding
1608 contextual information."
1609 ;; In a verse environment, add a line break to each newline
1610 ;; character and change each white space at beginning of a line
1611 ;; into a space of 1 em. Also change each blank line with
1612 ;; a vertical space of 1 em.
1614 (setq contents
(replace-regexp-in-string
1615 "^ *\\\\\\\\$" "\\\\vspace*{1em}"
1616 (replace-regexp-in-string
1617 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" contents
)))
1618 (while (string-match "^[ \t]+" contents
)
1619 (let ((new-str (format "\\hspace*{%dem}"
1620 (length (match-string 0 contents
)))))
1621 (setq contents
(replace-match new-str nil t contents
))))
1622 (format "\\begin{verse}\n%s\\end{verse}" contents
)))
1625 ;;; Interactive functions
1627 (defun org-texinfo-export-to-texinfo
1628 (&optional async subtreep visible-only body-only ext-plist
)
1629 "Export current buffer to a Texinfo file.
1631 If narrowing is active in the current buffer, only export its
1634 If a region is active, export that region.
1636 A non-nil optional argument ASYNC means the process should happen
1637 asynchronously. The resulting file should be accessible through
1638 the `org-export-stack' interface.
1640 When optional argument SUBTREEP is non-nil, export the sub-tree
1641 at point, extracting information from the headline properties
1644 When optional argument VISIBLE-ONLY is non-nil, don't export
1645 contents of hidden elements.
1647 When optional argument BODY-ONLY is non-nil, only write code
1648 between \"\\begin{document}\" and \"\\end{document}\".
1650 EXT-PLIST, when provided, is a property list with external
1651 parameters overriding Org default settings, but still inferior to
1652 file-local settings.
1654 Return output file's name."
1656 (let ((outfile (org-export-output-file-name ".texi" subtreep
)))
1658 (org-export-async-start
1659 (lambda (f) (org-export-add-to-stack f
'texinfo
))
1662 'texinfo
,outfile
,subtreep
,visible-only
,body-only
1665 'texinfo outfile subtreep visible-only body-only ext-plist
))))
1667 (defun org-texinfo-export-to-info
1668 (&optional async subtreep visible-only body-only ext-plist
)
1669 "Export current buffer to Texinfo then process through to INFO.
1671 If narrowing is active in the current buffer, only export its
1674 If a region is active, export that region.
1676 A non-nil optional argument ASYNC means the process should happen
1677 asynchronously. The resulting file should be accessible through
1678 the `org-export-stack' interface.
1680 When optional argument SUBTREEP is non-nil, export the sub-tree
1681 at point, extracting information from the headline properties
1684 When optional argument VISIBLE-ONLY is non-nil, don't export
1685 contents of hidden elements.
1687 When optional argument BODY-ONLY is non-nil, only write code
1688 between \"\\begin{document}\" and \"\\end{document}\".
1690 EXT-PLIST, when provided, is a property list with external
1691 parameters overriding Org default settings, but still inferior to
1692 file-local settings.
1694 When optional argument PUB-DIR is set, use it as the publishing
1697 Return INFO file's name."
1700 (let ((outfile (org-export-output-file-name ".texi" subtreep
)))
1701 (org-export-async-start
1702 (lambda (f) (org-export-add-to-stack f
'texinfo
))
1704 (org-texinfo-compile
1706 'texinfo
,outfile
,subtreep
,visible-only
,body-only
1708 (org-texinfo-compile
1709 (org-texinfo-export-to-texinfo
1710 nil subtreep visible-only body-only ext-plist
))))
1712 (defun org-texinfo-compile (file)
1713 "Compile a texinfo file.
1715 FILE is the name of the file being compiled. Processing is
1716 done through the command specified in `org-texinfo-info-process'.
1718 Return INFO file name or an error if it couldn't be produced."
1719 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file
)))
1720 (full-name (file-truename file
))
1721 (out-dir (file-name-directory file
))
1722 ;; Make sure `default-directory' is set to FILE directory,
1723 ;; not to whatever value the current buffer may have.
1724 (default-directory (file-name-directory full-name
))
1726 (message (format "Processing Texinfo file %s ..." file
))
1727 (save-window-excursion
1729 ;; A function is provided: Apply it.
1730 ((functionp org-texinfo-info-process
)
1731 (funcall org-texinfo-info-process
(shell-quote-argument file
)))
1732 ;; A list is provided: Replace %b, %f and %o with appropriate
1733 ;; values in each command before applying it. Output is
1734 ;; redirected to "*Org INFO Texinfo Output*" buffer.
1735 ((consp org-texinfo-info-process
)
1736 (let ((outbuf (get-buffer-create "*Org INFO Texinfo Output*")))
1740 (replace-regexp-in-string
1741 "%b" (shell-quote-argument base-name
)
1742 (replace-regexp-in-string
1743 "%f" (shell-quote-argument full-name
)
1744 (replace-regexp-in-string
1745 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
1747 org-texinfo-info-process
)
1748 ;; Collect standard errors from output buffer.
1749 (setq errors
(org-texinfo-collect-errors outbuf
))))
1750 (t (error "No valid command to process to Info")))
1751 (let ((infofile (concat out-dir base-name
".info")))
1752 ;; Check for process failure. Provide collected errors if
1754 (if (not (file-exists-p infofile
))
1755 (error (concat (format "INFO file %s wasn't produced" infofile
)
1756 (when errors
(concat ": " errors
))))
1757 ;; Else remove log files, when specified, and signal end of
1758 ;; process to user, along with any error encountered.
1759 (message (concat "Process completed"
1760 (if (not errors
) "."
1761 (concat " with errors: " errors
)))))
1762 ;; Return output file name.
1765 (defun org-texinfo-collect-errors (buffer)
1766 "Collect some kind of errors from \"makeinfo\" command output.
1768 BUFFER is the buffer containing output.
1770 Return collected error types as a string, or nil if there was
1772 (with-current-buffer buffer
1774 (goto-char (point-min))
1775 ;; Find final "makeinfo" run.
1777 (let ((case-fold-search t
)
1779 (when (save-excursion
1780 (re-search-forward "perhaps incorrect sectioning?" nil t
))
1781 (setq errors
(concat errors
" [incorrect sectioning]")))
1782 (when (save-excursion
1783 (re-search-forward "missing close brace" nil t
))
1784 (setq errors
(concat errors
" [syntax error]")))
1785 (when (save-excursion
1786 (re-search-forward "Unknown command" nil t
))
1787 (setq errors
(concat errors
" [undefined @command]")))
1788 (when (save-excursion
1789 (re-search-forward "No matching @end" nil t
))
1790 (setq errors
(concat errors
" [block incomplete]")))
1791 (when (save-excursion
1792 (re-search-forward "requires a sectioning" nil t
))
1793 (setq errors
(concat errors
" [invalid section command]")))
1794 (when (save-excursion
1795 (re-search-forward "\\[unexpected\]" nil t
))
1796 (setq errors
(concat errors
" [unexpected error]")))
1797 (when (save-excursion
1798 (re-search-forward "misplaced " nil t
))
1799 (setq errors
(concat errors
" [syntax error]")))
1800 (and (org-string-nw-p errors
) (org-trim errors
)))))))
1803 (provide 'ox-texinfo
)
1806 ;; generated-autoload-file: "org-loaddefs.el"
1809 ;;; ox-texinfo.el ends here