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 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-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
)))
135 ;;; User Configurable Variables
137 (defgroup org-export-texinfo nil
138 "Options for exporting Org mode files to Texinfo."
139 :tag
"Org Export Texinfo"
141 :package-version
'(Org .
"8.0")
146 (defcustom org-texinfo-filename nil
147 "Default filename for Texinfo output."
148 :group
'org-export-texinfo
149 :type
'(string :tag
"Export Filename"))
151 (defcustom org-texinfo-coding-system nil
152 "Default document encoding for Texinfo output."
153 :group
'org-export-texinfo
154 :type
'coding-system
)
156 (defcustom org-texinfo-default-class
"info"
157 "The default Texinfo class."
158 :group
'org-export-texinfo
159 :type
'(string :tag
"Texinfo class"))
161 (defcustom org-texinfo-classes
163 "\\input texinfo @c -*- texinfo -*-"
164 ("@chapter %s" .
"@unnumbered %s")
165 ("@section %s" .
"@unnumberedsec %s")
166 ("@subsection %s" .
"@unnumberedsubsec %s")
167 ("@subsubsection %s" .
"@unnumberedsubsubsec %s")))
168 "Alist of Texinfo classes and associated header and structure.
169 If #+Texinfo_CLASS is set in the buffer, use its value and the
170 associated information. Here is the structure of each cell:
174 \(numbered-section . unnumbered-section\)
177 The sectioning structure
178 ------------------------
180 The sectioning structure of the class is given by the elements
181 following the header string. For each sectioning level, a number
182 of strings is specified. A %s formatter is mandatory in each
183 section string and will be replaced by the title of the section.
185 Instead of a list of sectioning commands, you can also specify
186 a function name. That function will be called with two
187 parameters, the \(reduced) level of the headline, and a predicate
188 non-nil when the headline should be numbered. It must return
189 a format string in which the section title will be added."
190 :group
'org-export-texinfo
192 (list (string :tag
"Texinfo class")
193 (string :tag
"Texinfo header")
194 (repeat :tag
"Levels" :inline t
197 (string :tag
" numbered")
198 (string :tag
"unnumbered"))
199 (function :tag
"Hook computing sectioning"))))))
203 (defcustom org-texinfo-format-headline-function nil
204 "Function to format headline text.
206 This function will be called with 5 arguments:
207 TODO the todo keyword (string or nil).
208 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
209 PRIORITY the priority of the headline (integer or nil)
210 TEXT the main headline text (string).
211 TAGS the tags as a list of strings (list of strings or nil).
213 The function result will be used in the section format string.
215 As an example, one could set the variable to the following, in
216 order to reproduce the default set-up:
218 \(defun org-texinfo-format-headline (todo todo-type priority text tags)
219 \"Default format function for a headline.\"
221 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
223 \(format \"\\\\framebox{\\\\#%c} \" priority))
226 \(format \"\\\\hfill{}\\\\textsc{%s}\"
227 \(mapconcat 'identity tags \":\"))))"
228 :group
'org-export-texinfo
231 ;;; Node listing (menu)
233 (defcustom org-texinfo-node-description-column
32
234 "Column at which to start the description in the node
237 If a node title is greater than this length, the description will
238 be placed after the end of the title."
239 :group
'org-export-texinfo
244 ;; Footnotes are inserted directly
248 (defcustom org-texinfo-active-timestamp-format
"@emph{%s}"
249 "A printf format string to be applied to active timestamps."
250 :group
'org-export-texinfo
253 (defcustom org-texinfo-inactive-timestamp-format
"@emph{%s}"
254 "A printf format string to be applied to inactive timestamps."
255 :group
'org-export-texinfo
258 (defcustom org-texinfo-diary-timestamp-format
"@emph{%s}"
259 "A printf format string to be applied to diary timestamps."
260 :group
'org-export-texinfo
265 (defcustom org-texinfo-link-with-unknown-path-format
"@indicateurl{%s}"
266 "Format string for links with unknown path type."
267 :group
'org-export-texinfo
272 (defcustom org-texinfo-tables-verbatim nil
273 "When non-nil, tables are exported verbatim."
274 :group
'org-export-texinfo
277 (defcustom org-texinfo-table-scientific-notation
"%s\\,(%s)"
278 "Format string to display numbers in scientific notation.
279 The format should have \"%s\" twice, for mantissa and exponent
280 \(i.e. \"%s\\\\times10^{%s}\").
282 When nil, no transformation is made."
283 :group
'org-export-texinfo
285 (string :tag
"Format string")
286 (const :tag
"No formatting")))
288 (defcustom org-texinfo-def-table-markup
"@samp"
289 "Default setting for @table environments.")
293 (defcustom org-texinfo-text-markup-alist
'((bold .
"@strong{%s}")
295 (italic .
"@emph{%s}")
298 "Alist of Texinfo expressions to convert text markup.
300 The key must be a symbol among `bold', `italic' and `comment'.
301 The value is a formatting string to wrap fontified text with.
303 Value can also be set to the following symbols: `verb' and
304 `code'. For the former, Org will use \"@verb\" to
305 create a format string and select a delimiter character that
306 isn't in the string. For the latter, Org will use \"@code\"
307 to typeset and try to protect special characters.
309 If no association can be found for a given markup, text will be
311 :group
'org-export-texinfo
313 :options
'(bold code italic verbatim comment
))
317 (defcustom org-texinfo-format-drawer-function nil
318 "Function called to format a drawer in Texinfo code.
320 The function must accept two parameters:
321 NAME the drawer name, like \"LOGBOOK\"
322 CONTENTS the contents of the drawer.
324 The function should return the string to be exported.
326 For example, the variable could be set to the following function
327 in order to mimic default behaviour:
329 \(defun org-texinfo-format-drawer-default \(name contents\)
330 \"Format a drawer element for Texinfo export.\"
332 :group
'org-export-texinfo
337 (defcustom org-texinfo-format-inlinetask-function nil
338 "Function called to format an inlinetask in Texinfo code.
340 The function must accept six parameters:
341 TODO the todo keyword, as a string
342 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
343 PRIORITY the inlinetask priority, as a string
344 NAME the inlinetask name, as a string.
345 TAGS the inlinetask tags, as a list of strings.
346 CONTENTS the contents of the inlinetask, as a string.
348 The function should return the string to be exported.
350 For example, the variable could be set to the following function
351 in order to mimic default behaviour:
353 \(defun org-texinfo-format-inlinetask \(todo type priority name tags contents\)
354 \"Format an inline task element for Texinfo export.\"
358 \(format \"@strong{%s} \" todo))
359 \(when priority (format \"#%c \" priority))
363 \(mapconcat 'identity tags \":\")))))
364 \(format (concat \"@center %s\n\n\"
367 full-title contents))"
368 :group
'org-export-texinfo
373 ;; Src Blocks are example blocks, except for LISP
377 (defcustom org-texinfo-info-process
379 "Commands to process a Texinfo file to an INFO file.
380 This is list of strings, each of them will be given to the shell
381 as a command. %f in the command will be replaced by the full
382 file name, %b by the file base name \(i.e without extension) and
383 %o by the base directory of the file."
384 :group
'org-export-texinfo
385 :type
'(repeat :tag
"Shell command sequence"
386 (string :tag
"Shell command")))
389 (defconst org-texinfo-max-toc-depth
4
390 "Maximum depth for creation of detailed menu listings. Beyond
391 this depth Texinfo will not recognize the nodes and will cause
392 errors. Left as a constant in case this value ever changes.")
395 ;;; Internal Functions
397 (defun org-texinfo-filter-section-blank-lines (headline back-end info
)
398 "Filter controlling number of blank lines after a section."
399 (let ((blanks (make-string 2 ?
\n)))
400 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline
)))
402 (defun org-texinfo--find-verb-separator (s)
403 "Return a character not used in string S.
404 This is used to choose a separator for constructs like \\verb."
405 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
406 (loop for c across ll
407 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
408 return
(char-to-string c
))))
410 (defun org-texinfo--make-option-string (options)
411 "Return a comma separated string of keywords and values.
412 OPTIONS is an alist where the key is the options keyword as
413 a string, and the value a list containing the keyword value, or
415 (mapconcat (lambda (pair)
417 (when (> (length (second pair
)) 0)
418 (concat "=" (second pair
)))))
422 (defun org-texinfo--text-markup (text markup
)
423 "Format TEXT depending on MARKUP text markup.
424 See `org-texinfo-text-markup-alist' for details."
425 (let ((fmt (cdr (assq markup org-texinfo-text-markup-alist
))))
427 ;; No format string: Return raw text.
430 (let ((separator (org-texinfo--find-verb-separator text
)))
431 (concat "@verb{" separator text separator
"}")))
436 (while (string-match "[@{}]" text
)
437 (setq char
(match-string 0 text
))
438 (if (> (match-beginning 0) 0)
439 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
440 (setq text
(substring text
(1+ (match-beginning 0))))
441 (setq char
(concat "@" char
)
442 rtn
(concat rtn char
)))
443 (setq text
(concat rtn text
)
446 ;; Else use format string.
447 (t (format fmt text
)))))
449 (defun org-texinfo--get-node (headline info
)
450 "Return node entry associated to HEADLINE.
451 INFO is a plist used as a communication channel."
452 (let ((menu-title (org-export-get-alt-title headline info
)))
453 (org-texinfo--sanitize-menu
454 (replace-regexp-in-string
456 (if menu-title
(org-export-data menu-title info
)
457 (org-texinfo--sanitize-headline
458 (org-element-property :title headline
) info
))))))
460 ;;; Headline sanitizing
462 (defun org-texinfo--sanitize-headline (headline info
)
463 "Remove all formatting from the text of a headline for use in
464 node and menu listing."
466 (org-texinfo--sanitize-headline-contents headline info
) " "))
468 (defun org-texinfo--sanitize-headline-contents (headline info
)
469 "Retrieve the content of the headline.
471 Any content that can contain further formatting is checked
472 recursively, to ensure that nested content is also properly
474 (loop for contents in headline append
478 (list (replace-regexp-in-string " $" "" contents
)))
479 ;; Is exported as-is (value)
480 ((org-element-map contents
'(verbatim code
)
481 (lambda (value) (org-element-property :value value
)) info
))
482 ;; Has content and recurse into the content
483 ((org-element-contents contents
)
484 (org-texinfo--sanitize-headline-contents
485 (org-element-contents contents
) info
)))))
489 (defun org-texinfo--sanitize-menu (title)
490 "Remove invalid characters from TITLE for use in menus and
493 Based on Texinfo specifications, the following must be removed:
495 (replace-regexp-in-string "[@{}():,.]" "" title
))
497 ;;; Content sanitizing
499 (defun org-texinfo--sanitize-content (text)
500 "Ensure characters are properly escaped when used in headlines or blocks.
502 Escape characters are: @ { }"
503 (replace-regexp-in-string "\\\([@{}]\\\)" "@\\1" text
))
507 (defun org-texinfo--build-menu (tree level info
&optional detailed
)
508 "Create the @menu/@end menu information from TREE at headline
511 TREE contains the parse-tree to work with, either of the entire
512 document or of a specific parent headline. LEVEL indicates what
513 level of headlines to look at when generating the menu. INFO is
514 a plist containing contextual information.
516 Detailed determines whether to build a single level of menu, or
517 recurse into all children as well."
518 (let ((menu (org-texinfo--generate-menu-list tree level info
))
522 ;; Looping is done within the menu generation.
523 (setq text-menu
(org-texinfo--generate-detailed menu level info
)))
525 (setq text-menu
(org-texinfo--generate-menu-items menu info
))))
527 (setq output
(org-texinfo--format-menu text-menu
))
528 (mapconcat 'identity output
"\n"))))
530 (defun org-texinfo--generate-detailed (menu level info
)
531 "Generate a detailed listing of all subheadings within MENU starting at LEVEL.
533 MENU is the parse-tree to work with. LEVEL is the starting level
534 for the menu headlines and from which recursion occurs. INFO is
535 a plist containing contextual information."
537 (let ((max-depth (min org-texinfo-max-toc-depth
538 (plist-get info
:headline-levels
))))
539 (when (> max-depth level
)
540 (loop for headline in menu append
541 (let* ((title (org-texinfo--menu-headlines headline info
))
542 ;; Create list of menu entries for the next level
543 (sublist (org-texinfo--generate-menu-list
544 headline
(1+ level
) info
))
545 ;; Generate the menu items for that level. If
546 ;; there are none omit that heading completely,
547 ;; otherwise join the title to it's related entries.
548 (submenu (if (org-texinfo--generate-menu-items sublist info
)
550 (org-texinfo--generate-menu-items sublist info
))
552 ;; Start the process over the next level down.
553 (recursion (org-texinfo--generate-detailed sublist
(1+ level
) info
)))
554 (setq recursion
(append submenu recursion
))
557 (defun org-texinfo--generate-menu-list (tree level info
)
558 "Generate the list of headlines that are within a given level
559 of the tree for further formatting.
561 TREE is the parse-tree containing the headlines. LEVEL is the
562 headline level to generate a list of. INFO is a plist holding
563 contextual information."
564 (org-element-map tree
'headline
566 (and (= (org-export-get-relative-level head info
) level
)
567 ;; Do not take note of footnotes or copying headlines.
568 (not (org-element-property :COPYING head
))
569 (not (org-element-property :footnote-section-p head
))
574 (defun org-texinfo--generate-menu-items (items info
)
575 "Generate a list of headline information from the listing ITEMS.
577 ITEMS is a list of the headlines to be converted into entries.
578 INFO is a plist containing contextual information.
580 Returns a list containing the following information from each
581 headline: length, title, description. This is used to format the
582 menu using `org-texinfo--format-menu'."
583 (loop for headline in items collect
584 (let* ((menu-title (org-texinfo--sanitize-menu
586 (org-export-get-alt-title headline info
)
588 (title (org-texinfo--sanitize-menu
589 (org-texinfo--sanitize-headline
590 (org-element-property :title headline
) info
)))
591 (descr (org-export-data
592 (org-element-property :DESCRIPTION headline
)
594 (menu-entry (if (string= "" menu-title
) title menu-title
))
595 (len (length menu-entry
))
596 (output (list len menu-entry descr
)))
599 (defun org-texinfo--menu-headlines (headline info
)
600 "Retrieve the title from HEADLINE.
602 INFO is a plist holding contextual information.
604 Return the headline as a list of (length title description) with
605 length of -1 and nil description. This is used in
606 `org-texinfo--format-menu' to identify headlines as opposed to
608 (let ((title (org-export-data
609 (org-element-property :title headline
) info
)))
610 (list -
1 title
'nil
)))
612 (defun org-texinfo--format-menu (text-menu)
613 "Format the TEXT-MENU items to be properly printed in the menu.
615 Each entry in the menu should be provided as (length title
618 Headlines in the detailed menu are given length -1 to ensure they
619 are never confused with other entries. They also have no
622 Other menu items are output as:
625 With the spacing between :: and description based on the length
626 of the longest menu entry."
630 (mapcar (lambda (name)
631 (let* ((title (nth 1 name
))
633 (length (nth 0 name
))
635 ;;6 is "* " ":: " for inserted text
638 org-texinfo-node-description-column
640 (spacing (- column length
)
643 (concat "* " title
":: "
644 (make-string spacing ?\s
)
647 (concat "\n" title
"\n"))))
653 (defun org-texinfo-template (contents info
)
654 "Return complete document string after Texinfo conversion.
655 CONTENTS is the transcoded contents string. INFO is a plist
656 holding export options."
657 (let* ((title (org-export-data (plist-get info
:title
) info
))
658 (info-filename (or (plist-get info
:texinfo-filename
)
659 (file-name-nondirectory
660 (org-export-output-file-name ".info"))))
661 (author (org-export-data (plist-get info
:author
) info
))
662 (lang (org-export-data (plist-get info
:language
) info
))
663 (texinfo-header (plist-get info
:texinfo-header
))
664 (texinfo-post-header (plist-get info
:texinfo-post-header
))
665 (subtitle (plist-get info
:subtitle
))
666 (subauthor (plist-get info
:subauthor
))
667 (class (plist-get info
:texinfo-class
))
668 (header (nth 1 (assoc class org-texinfo-classes
)))
670 (org-element-map (plist-get info
:parse-tree
) 'headline
671 (lambda (hl) (and (org-element-property :COPYING hl
) hl
)) info t
))
672 (dircat (plist-get info
:texinfo-dircat
))
673 (dirtitle (plist-get info
:texinfo-dirtitle
))
674 (dirdesc (plist-get info
:texinfo-dirdesc
))
675 ;; Spacing to align description (column 32 - 3 for `* ' and
677 (dirspacing (- 29 (length dirtitle
)))
678 (menu (org-texinfo-make-menu info
'main
))
679 (detail-menu (org-texinfo-make-menu info
'detailed
)))
683 "@c %**start of header\n"
684 ;; Filename and Title
685 "@setfilename " info-filename
"\n"
686 "@settitle " title
"\n"
687 (if org-texinfo-coding-system
688 (format "@documentencoding %s\n"
689 (upcase (symbol-name org-texinfo-coding-system
))) "\n")
690 (format "@documentlanguage %s\n" lang
)
692 "@c Version and Contact Info\n"
693 "@set AUTHOR " author
"\n"
695 ;; Additional Header Options set by `#+TEXINFO_HEADER
701 "@c %**end of header\n"
705 ;; Additional Header Options set by #+TEXINFO_POST_HEADER
706 (if texinfo-post-header
713 ;; Only export the content of the headline, do not need the
715 (org-export-data (nth 2 copying
) info
)
719 ;; Info directory information
720 ;; Only supply if both title and category are provided
721 (if (and dircat dirtitle
)
722 (concat "@dircategory " dircat
"\n"
725 (make-string dirspacing ?\s
)
732 "@title " title
"\n\n"
734 (concat "@subtitle " subtitle
"\n"))
735 "@author " author
"\n"
737 (concat subauthor
"\n"))
739 "@c The following two commands start the copyright page.\n"
741 "@vskip 0pt plus 1filll\n"
744 "@c Output the table of contents at the beginning.\n"
747 ;; Configure Top Node when not for Tex
750 "@top " title
" Manual\n"
754 ;; Do not output menus if they are empty
762 (concat "@detailmenu\n"
763 " --- The Detailed Node Listing ---\n"
766 "@end detailmenu\n"))
774 (let ((creator-info (plist-get info
:with-creator
)))
776 ((not creator-info
) "")
777 ((eq creator-info
'comment
)
778 (format "@c %s\n" (plist-get info
:creator
)))
779 (t (concat (plist-get info
:creator
) "\n"))))
785 ;;; Transcode Functions
789 (defun org-texinfo-bold (bold contents info
)
790 "Transcode BOLD from Org to Texinfo.
791 CONTENTS is the text with bold markup. INFO is a plist holding
792 contextual information."
793 (org-texinfo--text-markup contents
'bold
))
797 (defun org-texinfo-center-block (center-block contents info
)
798 "Transcode a CENTER-BLOCK element from Org to Texinfo.
799 CONTENTS holds the contents of the block. INFO is a plist used
800 as a communication channel."
805 (defun org-texinfo-clock (clock contents info
)
806 "Transcode a CLOCK element from Org to Texinfo.
807 CONTENTS is nil. INFO is a plist holding contextual
811 (format "@strong{%s} " org-clock-string
)
812 (format org-texinfo-inactive-timestamp-format
813 (concat (org-translate-time
814 (org-element-property :raw-value
815 (org-element-property :value clock
)))
816 (let ((time (org-element-property :duration clock
)))
817 (and time
(format " (%s)" time
)))))
822 (defun org-texinfo-code (code contents info
)
823 "Transcode a CODE object from Org to Texinfo.
824 CONTENTS is nil. INFO is a plist used as a communication
826 (org-texinfo--text-markup (org-element-property :value code
) 'code
))
830 (defun org-texinfo-comment (comment contents info
)
831 "Transcode a COMMENT object from Org to Texinfo.
832 CONTENTS is the text in the comment. INFO is a plist holding
833 contextual information."
834 (org-texinfo--text-markup (org-element-property :value comment
) 'comment
))
838 (defun org-texinfo-comment-block (comment-block contents info
)
839 "Transcode a COMMENT-BLOCK object from Org to Texinfo.
840 CONTENTS is the text within the block. INFO is a plist holding
841 contextual information."
842 (format "@ignore\n%s@end ignore" (org-element-property :value comment-block
)))
846 (defun org-texinfo-drawer (drawer contents info
)
847 "Transcode a DRAWER element from Org to Texinfo.
848 CONTENTS holds the contents of the block. INFO is a plist
849 holding contextual information."
850 (let* ((name (org-element-property :drawer-name drawer
))
851 (output (if (functionp org-texinfo-format-drawer-function
)
852 (funcall org-texinfo-format-drawer-function
854 ;; If there's no user defined function: simply
855 ;; display contents of the drawer.
861 (defun org-texinfo-dynamic-block (dynamic-block contents info
)
862 "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
863 CONTENTS holds the contents of the block. INFO is a plist
864 holding contextual information. See `org-export-data'."
869 (defun org-texinfo-entity (entity contents info
)
870 "Transcode an ENTITY object from Org to Texinfo.
871 CONTENTS are the definition itself. INFO is a plist holding
872 contextual information."
873 (let ((ent (org-element-property :latex entity
)))
874 (if (org-element-property :latex-math-p entity
) (format "@math{%s}" ent
) ent
)))
878 (defun org-texinfo-example-block (example-block contents info
)
879 "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
880 CONTENTS is nil. INFO is a plist holding contextual
882 (format "@verbatim\n%s@end verbatim"
883 (org-export-format-code-default example-block info
)))
887 (defun org-texinfo-export-block (export-block contents info
)
888 "Transcode a EXPORT-BLOCK element from Org to Texinfo.
889 CONTENTS is nil. INFO is a plist holding contextual information."
890 (when (string= (org-element-property :type export-block
) "TEXINFO")
891 (org-remove-indentation (org-element-property :value export-block
))))
895 (defun org-texinfo-export-snippet (export-snippet contents info
)
896 "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
897 CONTENTS is nil. INFO is a plist holding contextual information."
898 (when (eq (org-export-snippet-backend export-snippet
) 'texinfo
)
899 (org-element-property :value export-snippet
)))
903 (defun org-texinfo-fixed-width (fixed-width contents info
)
904 "Transcode a FIXED-WIDTH element from Org to Texinfo.
905 CONTENTS is nil. INFO is a plist holding contextual information."
906 (format "@example\n%s\n@end example"
907 (org-remove-indentation
908 (org-texinfo--sanitize-content
909 (org-element-property :value fixed-width
)))))
911 ;;; Footnote Reference
914 (defun org-texinfo-footnote-reference (footnote contents info
)
915 "Create a footnote reference for FOOTNOTE.
917 FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
918 plist holding contextual information."
919 (let ((def (org-export-get-footnote-definition footnote info
)))
920 (format "@footnote{%s}"
921 (org-trim (org-export-data def info
)))))
925 (defun org-texinfo-headline (headline contents info
)
926 "Transcode a HEADLINE element from Org to Texinfo.
927 CONTENTS holds the contents of the headline. INFO is a plist
928 holding contextual information."
929 (let* ((class (plist-get info
:texinfo-class
))
930 (level (org-export-get-relative-level headline info
))
931 (numberedp (org-export-numbered-headline-p headline info
))
932 (class-sectionning (assoc class org-texinfo-classes
))
933 ;; Find the index type, if any
934 (index (org-element-property :INDEX headline
))
935 ;; Check if it is an appendix
936 (appendix (org-element-property :APPENDIX headline
))
937 ;; Retrieve headline text
938 (text (org-texinfo--sanitize-headline
939 (org-element-property :title headline
) info
))
940 ;; Create node info, to insert it before section formatting.
941 ;; Use custom menu title if present
942 (node (format "@node %s\n" (org-texinfo--get-node headline info
)))
943 ;; Menus must be generated with first child, otherwise they
944 ;; will not nest properly
945 (menu (let* ((first (org-export-first-sibling-p headline info
))
946 (parent (org-export-get-parent-headline headline
))
947 (title (org-texinfo--sanitize-headline
948 (org-element-property :title parent
) info
))
950 (tree (plist-get info
:parse-tree
)))
952 (org-element-map (plist-get info
:parse-tree
) 'headline
954 (if (member title
(org-element-property :title ref
))
957 (setq listing
(org-texinfo--build-menu
958 (car heading
) level info
))
960 (setq listing
(replace-regexp-in-string
963 "\n@menu\n%s\n@end menu\n\n" listing
))
965 ;; Section formatting will set two placeholders: one for the
966 ;; title and the other for the contents.
968 (let ((sec (if (and (symbolp (nth 2 class-sectionning
))
969 (fboundp (nth 2 class-sectionning
)))
970 (funcall (nth 2 class-sectionning
) level numberedp
)
971 (nth (1+ level
) class-sectionning
))))
973 ;; No section available for that LEVEL.
975 ;; Section format directly returned by a function.
977 ;; (numbered-section . unnumbered-section)
978 ((not (consp (cdr sec
)))
980 ;;If an index, always unnumbered
982 (concat menu node
(cdr sec
) "\n%s"))
984 (concat menu node
(replace-regexp-in-string
988 ;; Otherwise number as needed.
992 (if numberedp
#'car
#'cdr
) sec
) "\n%s")))))))
994 (and (plist-get info
:with-todo-keywords
)
995 (let ((todo (org-element-property :todo-keyword headline
)))
996 (and todo
(org-export-data todo info
)))))
997 (todo-type (and todo
(org-element-property :todo-type headline
)))
998 (tags (and (plist-get info
:with-tags
)
999 (org-export-get-tags headline info
)))
1000 (priority (and (plist-get info
:with-priority
)
1001 (org-element-property :priority headline
)))
1002 ;; Create the headline text along with a no-tag version. The
1003 ;; latter is required to remove tags from table of contents.
1004 (full-text (org-texinfo--sanitize-content
1005 (if (functionp org-texinfo-format-headline-function
)
1006 ;; User-defined formatting function.
1007 (funcall org-texinfo-format-headline-function
1008 todo todo-type priority text tags
)
1009 ;; Default formatting.
1012 (format "@strong{%s} " todo
))
1013 (when priority
(format "@emph{#%s} " priority
))
1017 (mapconcat 'identity tags
":")))))))
1019 (org-texinfo--sanitize-content
1020 (if (functionp org-texinfo-format-headline-function
)
1021 ;; User-defined formatting function.
1022 (funcall org-texinfo-format-headline-function
1023 todo todo-type priority text nil
)
1024 ;; Default formatting.
1026 (when todo
(format "@strong{%s} " todo
))
1027 (when priority
(format "@emph{#%c} " priority
))
1030 (make-string (org-element-property :pre-blank headline
) 10)))
1032 ;; Case 1: This is a footnote section: ignore it.
1033 ((org-element-property :footnote-section-p headline
) nil
)
1034 ;; Case 2: This is the `copying' section: ignore it
1035 ;; This is used elsewhere.
1036 ((org-element-property :COPYING headline
) nil
)
1037 ;; Case 3: An index. If it matches one of the known indexes,
1038 ;; print it as such following the contents, otherwise
1039 ;; print the contents and leave the index up to the user.
1042 section-fmt full-text
1043 (concat pre-blanks contents
"\n"
1044 (if (member index
'("cp" "fn" "ky" "pg" "tp" "vr"))
1045 (concat "@printindex " index
)))))
1046 ;; Case 4: This is a deep sub-tree: export it as a list item.
1047 ;; Also export as items headlines for which no section
1048 ;; format has been found.
1049 ((or (not section-fmt
) (org-export-low-level-p headline info
))
1050 ;; Build the real contents of the sub-tree.
1051 (let ((low-level-body
1053 ;; If the headline is the first sibling, start a list.
1054 (when (org-export-first-sibling-p headline info
)
1055 (format "@%s\n" (if numberedp
'enumerate
'itemize
)))
1057 "@item\n" full-text
"\n" pre-blanks contents
)))
1058 ;; If headline is not the last sibling simply return
1059 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
1061 (if (not (org-export-last-sibling-p headline info
)) low-level-body
1062 (replace-regexp-in-string
1064 (format "\n@end %s" (if numberedp
'enumerate
'itemize
))
1066 ;; Case 5: Standard headline. Export it as a section.
1069 ((not (and tags
(eq (plist-get info
:with-tags
) 'not-in-toc
)))
1070 ;; Regular section. Use specified format string.
1071 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1072 (concat pre-blanks contents
)))
1073 ((string-match "\\`@\\(.*?\\){" section-fmt
)
1074 ;; If tags should be removed from table of contents, insert
1075 ;; title without tags as an alternative heading in sectioning
1077 (format (replace-match (concat (match-string 1 section-fmt
) "[%s]")
1078 nil nil section-fmt
1)
1079 ;; Replace square brackets with parenthesis since
1080 ;; square brackets are not supported in optional
1082 (replace-regexp-in-string
1084 (replace-regexp-in-string
1088 (concat pre-blanks contents
)))
1090 ;; Impossible to add an alternative heading. Fallback to
1091 ;; regular sectioning format string.
1092 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1093 (concat pre-blanks contents
))))))))
1095 ;;; Inline Src Block
1097 (defun org-texinfo-inline-src-block (inline-src-block contents info
)
1098 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
1099 CONTENTS holds the contents of the item. INFO is a plist holding
1100 contextual information."
1101 (let* ((code (org-element-property :value inline-src-block
))
1102 (separator (org-texinfo--find-verb-separator code
)))
1103 (concat "@verb{" separator code separator
"}")))
1107 (defun org-texinfo-inlinetask (inlinetask contents info
)
1108 "Transcode an INLINETASK element from Org to Texinfo.
1109 CONTENTS holds the contents of the block. INFO is a plist
1110 holding contextual information."
1111 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
1112 (todo (and (plist-get info
:with-todo-keywords
)
1113 (let ((todo (org-element-property :todo-keyword inlinetask
)))
1114 (and todo
(org-export-data todo info
)))))
1115 (todo-type (org-element-property :todo-type inlinetask
))
1116 (tags (and (plist-get info
:with-tags
)
1117 (org-export-get-tags inlinetask info
)))
1118 (priority (and (plist-get info
:with-priority
)
1119 (org-element-property :priority inlinetask
))))
1120 ;; If `org-texinfo-format-inlinetask-function' is provided, call it
1121 ;; with appropriate arguments.
1122 (if (functionp org-texinfo-format-inlinetask-function
)
1123 (funcall org-texinfo-format-inlinetask-function
1124 todo todo-type priority title tags contents
)
1125 ;; Otherwise, use a default template.
1128 (when todo
(format "@strong{%s} " todo
))
1129 (when priority
(format "#%c " priority
))
1131 (when tags
(format ":%s:"
1132 (mapconcat 'identity tags
":"))))))
1133 (format (concat "@center %s\n\n"
1136 full-title contents
)))))
1140 (defun org-texinfo-italic (italic contents info
)
1141 "Transcode ITALIC from Org to Texinfo.
1142 CONTENTS is the text with italic markup. INFO is a plist holding
1143 contextual information."
1144 (org-texinfo--text-markup contents
'italic
))
1148 (defun org-texinfo-item (item contents info
)
1149 "Transcode an ITEM element from Org to Texinfo.
1150 CONTENTS holds the contents of the item. INFO is a plist holding
1151 contextual information."
1152 (let* ((tag (org-element-property :tag item
))
1153 (desc (org-export-data tag info
)))
1154 (concat "\n@item " (if tag desc
) "\n"
1155 (and contents
(org-trim contents
)) "\n")))
1159 (defun org-texinfo-keyword (keyword contents info
)
1160 "Transcode a KEYWORD element from Org to Texinfo.
1161 CONTENTS is nil. INFO is a plist holding contextual information."
1162 (let ((key (org-element-property :key keyword
))
1163 (value (org-element-property :value keyword
)))
1165 ((string= key
"TEXINFO") value
)
1166 ((string= key
"CINDEX") (format "@cindex %s" value
))
1167 ((string= key
"FINDEX") (format "@findex %s" value
))
1168 ((string= key
"KINDEX") (format "@kindex %s" value
))
1169 ((string= key
"PINDEX") (format "@pindex %s" value
))
1170 ((string= key
"TINDEX") (format "@tindex %s" value
))
1171 ((string= key
"VINDEX") (format "@vindex %s" value
)))))
1175 (defun org-texinfo-line-break (line-break contents info
)
1176 "Transcode a LINE-BREAK object from Org to Texinfo.
1177 CONTENTS is nil. INFO is a plist holding contextual information."
1182 (defun org-texinfo-link (link desc info
)
1183 "Transcode a LINK object from Org to Texinfo.
1185 DESC is the description part of the link, or the empty string.
1186 INFO is a plist holding contextual information. See
1188 (let* ((type (org-element-property :type link
))
1189 (raw-path (org-element-property :path link
))
1190 ;; Ensure DESC really exists, or set it to nil.
1191 (desc (and (not (string= desc
"")) desc
))
1193 ((member type
'("http" "https" "ftp"))
1194 (concat type
":" raw-path
))
1195 ((string= type
"file")
1196 (if (file-name-absolute-p raw-path
)
1197 (concat "file://" (expand-file-name raw-path
))
1198 (concat "file://" raw-path
)))
1200 (email (if (string= type
"mailto")
1201 (let ((text (replace-regexp-in-string
1202 "@" "@@" raw-path
)))
1203 (concat text
(if desc
(concat "," desc
))))))
1206 ;; Links pointing to a headline: Find destination and build
1207 ;; appropriate referencing command.
1208 ((member type
'("custom-id" "id"))
1209 (let ((destination (org-export-resolve-id-link link info
)))
1210 (case (org-element-type destination
)
1211 ;; Id link points to an external file.
1213 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1214 (format "@uref{file://%s}" destination
)))
1215 ;; LINK points to a headline. Use the headline as the NODE target
1217 (format "@ref{%s,%s}"
1218 (org-texinfo--get-node destination info
)
1221 (let ((path (org-export-solidify-link-text path
)))
1222 (if (not desc
) (format "@ref{%s}" path
)
1223 (format "@ref{%s,,%s}" path desc
)))))))
1224 ((member type
'("info"))
1225 (let* ((info-path (split-string path
"[:#]"))
1226 (info-manual (car info-path
))
1227 (info-node (or (cadr info-path
) "top"))
1228 (title (or desc
"")))
1229 (format "@ref{%s,%s,,%s,}" info-node title info-manual
)))
1230 ((member type
'("fuzzy"))
1231 (let ((destination (org-export-resolve-fuzzy-link link info
)))
1232 (case (org-element-type destination
)
1233 ;; Id link points to an external file.
1235 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1236 (format "@uref{file://%s}" destination
)))
1237 ;; LINK points to a headline. Use the headline as the NODE target
1239 (format "@ref{%s,%s}"
1240 (org-texinfo--get-node destination info
)
1243 (let ((path (org-export-solidify-link-text path
)))
1244 (if (not desc
) (format "@ref{%s}" path
)
1245 (format "@ref{%s,,%s}" path desc
)))))))
1246 ;; Special case for email addresses
1248 (format "@email{%s}" email
))
1249 ;; External link with a description part.
1250 ((and path desc
) (format "@uref{%s,%s}" path desc
))
1251 ;; External link without a description part.
1252 (path (format "@uref{%s}" path
))
1253 ;; No path, only description. Try to do something useful.
1254 (t (format org-texinfo-link-with-unknown-path-format desc
)))))
1259 (defun org-texinfo-make-menu (info level
)
1260 "Create the menu for inclusion in the texifo document.
1262 INFO is the parsed buffer that contains the headlines. LEVEL
1263 determines whether to make the main menu, or the detailed menu.
1265 This is only used for generating the primary menu. In-Node menus
1266 are generated directly."
1267 (let ((parse (plist-get info
:parse-tree
)))
1269 ;; Generate the main menu
1270 ((eq level
'main
) (org-texinfo--build-menu parse
1 info
))
1271 ;; Generate the detailed (recursive) menu
1272 ((eq level
'detailed
)
1273 ;; Requires recursion
1274 ;;(org-texinfo--build-detailed-menu parse top info)
1275 (org-texinfo--build-menu parse
1 info
'detailed
)))))
1279 (defun org-texinfo-paragraph (paragraph contents info
)
1280 "Transcode a PARAGRAPH element from Org to Texinfo.
1281 CONTENTS is the contents of the paragraph, as a string. INFO is
1282 the plist used as a communication channel."
1287 (defun org-texinfo-plain-list (plain-list contents info
)
1288 "Transcode a PLAIN-LIST element from Org to Texinfo.
1289 CONTENTS is the contents of the list. INFO is a plist holding
1290 contextual information."
1291 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1292 (indic (or (plist-get attr
:indic
)
1293 org-texinfo-def-table-markup
))
1294 (type (org-element-property :type plain-list
))
1295 (table-type (plist-get attr
:table-type
))
1296 ;; Ensure valid texinfo table type.
1297 (table-type (if (member table-type
'("ftable" "vtable")) table-type
1300 ((eq type
'ordered
) "enumerate")
1301 ((eq type
'unordered
) "itemize")
1302 ((eq type
'descriptive
) table-type
))))
1303 (format "@%s%s\n@end %s"
1304 (if (eq type
'descriptive
)
1305 (concat list-type
" " indic
)
1312 (defun org-texinfo-plain-text (text info
)
1313 "Transcode a TEXT string from Org to Texinfo.
1314 TEXT is the string to transcode. INFO is a plist holding
1315 contextual information."
1316 ;; First protect @, { and }.
1317 (let ((output (org-texinfo--sanitize-content text
)))
1318 ;; Activate smart quotes. Be sure to provide original TEXT string
1319 ;; since OUTPUT may have been modified.
1320 (when (plist-get info
:with-smart-quotes
)
1322 (org-export-activate-smart-quotes output
:texinfo info text
)))
1323 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1324 (let ((case-fold-search nil
)
1326 (while (string-match "\\(\\(?:La\\)?TeX\\)" output start
)
1327 (setq output
(replace-match
1328 (format "@%s{}" (match-string 1 output
)) nil t output
)
1329 start
(match-end 0))))
1330 ;; Convert special strings.
1331 (when (plist-get info
:with-special-strings
)
1332 (while (string-match (regexp-quote "...") output
)
1333 (setq output
(replace-match "@dots{}" nil t output
))))
1334 ;; Handle break preservation if required.
1335 (when (plist-get info
:preserve-breaks
)
1336 (setq output
(replace-regexp-in-string
1337 "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output
)))
1343 (defun org-texinfo-planning (planning contents info
)
1344 "Transcode a PLANNING element from Org to Texinfo.
1345 CONTENTS is nil. INFO is a plist holding contextual
1353 (let ((closed (org-element-property :closed planning
)))
1356 (format "@strong{%s} " org-closed-string
)
1357 (format org-texinfo-inactive-timestamp-format
1359 (org-element-property :raw-value closed
))))))
1360 (let ((deadline (org-element-property :deadline planning
)))
1363 (format "@strong{%s} " org-deadline-string
)
1364 (format org-texinfo-active-timestamp-format
1366 (org-element-property :raw-value deadline
))))))
1367 (let ((scheduled (org-element-property :scheduled planning
)))
1370 (format "@strong{%s} " org-scheduled-string
)
1371 (format org-texinfo-active-timestamp-format
1373 (org-element-property :raw-value scheduled
))))))))
1379 (defun org-texinfo-property-drawer (property-drawer contents info
)
1380 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1381 CONTENTS is nil. INFO is a plist holding contextual
1383 ;; The property drawer isn't exported but we want separating blank
1384 ;; lines nonetheless.
1389 (defun org-texinfo-quote-block (quote-block contents info
)
1390 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1391 CONTENTS holds the contents of the block. INFO is a plist
1392 holding contextual information."
1393 (let* ((title (org-element-property :name quote-block
))
1394 (start-quote (concat "@quotation"
1396 (format " %s" title
)))))
1397 (format "%s\n%s@end quotation" start-quote contents
)))
1401 (defun org-texinfo-quote-section (quote-section contents info
)
1402 "Transcode a QUOTE-SECTION element from Org to Texinfo.
1403 CONTENTS is nil. INFO is a plist holding contextual information."
1404 (let ((value (org-remove-indentation
1405 (org-element-property :value quote-section
))))
1406 (when value
(format "@verbatim\n%s@end verbatim" value
))))
1410 (defun org-texinfo-radio-target (radio-target text info
)
1411 "Transcode a RADIO-TARGET object from Org to Texinfo.
1412 TEXT is the text of the target. INFO is a plist holding
1413 contextual information."
1414 (format "@anchor{%s}%s"
1415 (org-export-solidify-link-text
1416 (org-element-property :value radio-target
))
1421 (defun org-texinfo-section (section contents info
)
1422 "Transcode a SECTION element from Org to Texinfo.
1423 CONTENTS holds the contents of the section. INFO is a plist
1424 holding contextual information."
1429 (defun org-texinfo-special-block (special-block contents info
)
1430 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1431 CONTENTS holds the contents of the block. INFO is a plist used
1432 as a communication channel."
1437 (defun org-texinfo-src-block (src-block contents info
)
1438 "Transcode a SRC-BLOCK element from Org to Texinfo.
1439 CONTENTS holds the contents of the item. INFO is a plist holding
1440 contextual information."
1441 (let* ((lang (org-element-property :language src-block
))
1442 (lisp-p (string-match-p "lisp" lang
))
1443 (src-contents (org-texinfo--sanitize-content
1444 (org-export-format-code-default src-block info
))))
1446 ;; Case 1. Lisp Block
1448 (format "@lisp\n%s@end lisp"
1450 ;; Case 2. Other blocks
1452 (format "@example\n%s@end example"
1455 ;;; Statistics Cookie
1457 (defun org-texinfo-statistics-cookie (statistics-cookie contents info
)
1458 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1459 CONTENTS is nil. INFO is a plist holding contextual information."
1460 (org-element-property :value statistics-cookie
))
1464 (defun org-texinfo-subscript (subscript contents info
)
1465 "Transcode a SUBSCRIPT object from Org to Texinfo.
1466 CONTENTS is the contents of the object. INFO is a plist holding
1467 contextual information."
1468 (format "@math{_%s}" contents
))
1472 (defun org-texinfo-superscript (superscript contents info
)
1473 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1474 CONTENTS is the contents of the object. INFO is a plist holding
1475 contextual information."
1476 (format "@math{^%s}" contents
))
1480 ;; `org-texinfo-table' is the entry point for table transcoding. It
1481 ;; takes care of tables with a "verbatim" attribute. Otherwise, it
1482 ;; delegates the job to either `org-texinfo-table--table.el-table' or
1483 ;; `org-texinfo-table--org-table' functions, depending of the type of
1486 ;; `org-texinfo-table--align-string' is a subroutine used to build
1487 ;; alignment string for Org tables.
1489 (defun org-texinfo-table (table contents info
)
1490 "Transcode a TABLE element from Org to Texinfo.
1491 CONTENTS is the contents of the table. INFO is a plist holding
1492 contextual information."
1494 ;; Case 1: verbatim table.
1495 ((or org-texinfo-tables-verbatim
1496 (let ((attr (mapconcat 'identity
1497 (org-element-property :attr_latex table
)
1499 (and attr
(string-match "\\<verbatim\\>" attr
))))
1500 (format "@verbatim \n%s\n@end verbatim"
1501 ;; Re-create table, without affiliated keywords.
1503 (org-element-interpret-data
1504 `(table nil
,@(org-element-contents table
))))))
1505 ;; Case 2: table.el table. Convert it using appropriate tools.
1506 ((eq (org-element-property :type table
) 'table.el
)
1507 (org-texinfo-table--table.el-table table contents info
))
1508 ;; Case 3: Standard table.
1509 (t (org-texinfo-table--org-table table contents info
))))
1511 (defun org-texinfo-table-column-widths (table info
)
1512 "Determine the largest table cell in each column to process alignment.
1514 TABLE is the table element to transcode. INFO is a plist used as
1515 a communication channel."
1516 (let* ((rows (org-element-map table
'table-row
'identity info
))
1517 (collected (loop for row in rows collect
1518 (org-element-map row
'table-cell
'identity info
)))
1519 (number-cells (length (car collected
)))
1521 (loop for row in collected do
1522 (push (mapcar (lambda (ref)
1523 (let* ((start (org-element-property :contents-begin ref
))
1524 (end (org-element-property :contents-end ref
))
1525 (length (- end start
)))
1526 length
)) row
) cells
))
1527 (setq cells
(org-remove-if 'null cells
))
1528 (push (loop for count from
0 to
(- number-cells
1) collect
1529 (loop for item in cells collect
1530 (nth count item
))) counts
)
1531 (mapconcat (lambda (size)
1532 (make-string size ?a
)) (mapcar (lambda (ref)
1533 (apply 'max
`,@ref
)) (car counts
))
1536 (defun org-texinfo-table--org-table (table contents info
)
1537 "Return appropriate Texinfo code for an Org table.
1539 TABLE is the table type element to transcode. CONTENTS is its
1540 contents, as a string. INFO is a plist used as a communication
1543 This function assumes TABLE has `org' as its `:type' attribute."
1544 (let* ((attr (org-export-read-attribute :attr_texinfo table
))
1545 (col-width (plist-get attr
:columns
))
1546 (columns (if col-width
1547 (format "@columnfractions %s"
1550 (org-texinfo-table-column-widths
1552 ;; Prepare the final format string for the table.
1557 (format "@multitable %s\n%s@end multitable"
1561 (defun org-texinfo-table--table.el-table
(table contents info
)
1564 Rather than return an invalid table, nothing is returned."
1569 (defun org-texinfo-table-cell (table-cell contents info
)
1570 "Transcode a TABLE-CELL element from Org to Texinfo.
1571 CONTENTS is the cell contents. INFO is a plist used as
1572 a communication channel."
1573 (concat (if (and contents
1574 org-texinfo-table-scientific-notation
1575 (string-match orgtbl-exp-regexp contents
))
1576 ;; Use appropriate format string for scientific
1578 (format org-texinfo-table-scientific-notation
1579 (match-string 1 contents
)
1580 (match-string 2 contents
))
1582 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1586 (defun org-texinfo-table-row (table-row contents info
)
1587 "Transcode a TABLE-ROW element from Org to Texinfo.
1588 CONTENTS is the contents of the row. INFO is a plist used as
1589 a communication channel."
1590 ;; Rules are ignored since table separators are deduced from
1591 ;; borders of the current row.
1592 (when (eq (org-element-property :type table-row
) 'standard
)
1595 ;; Case 1: Belongs to second or subsequent rowgroup.
1596 ((not (= 1 (org-export-table-row-group table-row info
)))
1598 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
1599 ((org-export-table-has-header-p
1600 (org-export-get-parent-table table-row
) info
)
1602 ;; Case 3: Row is from first and only row group.
1604 (when (eq (org-element-property :type table-row
) 'standard
)
1605 (concat rowgroup-tag contents
"\n")))))
1609 (defun org-texinfo-target (target contents info
)
1610 "Transcode a TARGET object from Org to Texinfo.
1611 CONTENTS is nil. INFO is a plist holding contextual
1613 (format "@anchor{%s}"
1614 (org-export-solidify-link-text (org-element-property :value target
))))
1618 (defun org-texinfo-timestamp (timestamp contents info
)
1619 "Transcode a TIMESTAMP object from Org to Texinfo.
1620 CONTENTS is nil. INFO is a plist holding contextual
1622 (let ((value (org-texinfo-plain-text
1623 (org-timestamp-translate timestamp
) info
)))
1624 (case (org-element-property :type timestamp
)
1625 ((active active-range
)
1626 (format org-texinfo-active-timestamp-format value
))
1627 ((inactive inactive-range
)
1628 (format org-texinfo-inactive-timestamp-format value
))
1629 (t (format org-texinfo-diary-timestamp-format value
)))))
1633 (defun org-texinfo-verbatim (verbatim contents info
)
1634 "Transcode a VERBATIM object from Org to Texinfo.
1635 CONTENTS is nil. INFO is a plist used as a communication
1637 (org-texinfo--text-markup (org-element-property :value verbatim
) 'verbatim
))
1641 (defun org-texinfo-verse-block (verse-block contents info
)
1642 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1643 CONTENTS is verse block contents. INFO is a plist holding
1644 contextual information."
1645 ;; In a verse environment, add a line break to each newline
1646 ;; character and change each white space at beginning of a line
1647 ;; into a space of 1 em. Also change each blank line with
1648 ;; a vertical space of 1 em.
1650 (setq contents
(replace-regexp-in-string
1651 "^ *\\\\\\\\$" "\\\\vspace*{1em}"
1652 (replace-regexp-in-string
1653 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" contents
)))
1654 (while (string-match "^[ \t]+" contents
)
1655 (let ((new-str (format "\\hspace*{%dem}"
1656 (length (match-string 0 contents
)))))
1657 (setq contents
(replace-match new-str nil t contents
))))
1658 (format "\\begin{verse}\n%s\\end{verse}" contents
)))
1661 ;;; Interactive functions
1663 (defun org-texinfo-export-to-texinfo
1664 (&optional async subtreep visible-only body-only ext-plist
)
1665 "Export current buffer to a Texinfo file.
1667 If narrowing is active in the current buffer, only export its
1670 If a region is active, export that region.
1672 A non-nil optional argument ASYNC means the process should happen
1673 asynchronously. The resulting file should be accessible through
1674 the `org-export-stack' interface.
1676 When optional argument SUBTREEP is non-nil, export the sub-tree
1677 at point, extracting information from the headline properties
1680 When optional argument VISIBLE-ONLY is non-nil, don't export
1681 contents of hidden elements.
1683 When optional argument BODY-ONLY is non-nil, only write code
1684 between \"\\begin{document}\" and \"\\end{document}\".
1686 EXT-PLIST, when provided, is a property list with external
1687 parameters overriding Org default settings, but still inferior to
1688 file-local settings.
1690 Return output file's name."
1692 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1693 (org-export-coding-system org-texinfo-coding-system
))
1695 (org-export-async-start
1696 (lambda (f) (org-export-add-to-stack f
'texinfo
))
1697 (let ((org-export-coding-system org-texinfo-coding-system
))
1700 'texinfo
,outfile
,subtreep
,visible-only
,body-only
1702 (let ((org-export-coding-system org-texinfo-coding-system
))
1704 'texinfo outfile subtreep visible-only body-only ext-plist
)))))
1706 (defun org-texinfo-export-to-info
1707 (&optional async subtreep visible-only body-only ext-plist
)
1708 "Export current buffer to Texinfo then process through to INFO.
1710 If narrowing is active in the current buffer, only export its
1713 If a region is active, export that region.
1715 A non-nil optional argument ASYNC means the process should happen
1716 asynchronously. The resulting file should be accessible through
1717 the `org-export-stack' interface.
1719 When optional argument SUBTREEP is non-nil, export the sub-tree
1720 at point, extracting information from the headline properties
1723 When optional argument VISIBLE-ONLY is non-nil, don't export
1724 contents of hidden elements.
1726 When optional argument BODY-ONLY is non-nil, only write code
1727 between \"\\begin{document}\" and \"\\end{document}\".
1729 EXT-PLIST, when provided, is a property list with external
1730 parameters overriding Org default settings, but still inferior to
1731 file-local settings.
1733 When optional argument PUB-DIR is set, use it as the publishing
1736 Return INFO file's name."
1739 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1740 (org-export-coding-system org-texinfo-coding-system
))
1741 (org-export-async-start
1742 (lambda (f) (org-export-add-to-stack f
'texinfo
))
1743 (let ((org-export-coding-system org-texinfo-coding-system
))
1745 (org-texinfo-compile
1747 'texinfo
,outfile
,subtreep
,visible-only
,body-only
1749 (org-texinfo-compile
1750 (let ((org-export-coding-system org-texinfo-coding-system
))
1751 (org-texinfo-export-to-texinfo
1752 nil subtreep visible-only body-only ext-plist
)))))
1755 (defun org-texinfo-publish-to-texinfo (plist filename pub-dir
)
1756 "Publish an org file to Texinfo.
1758 FILENAME is the filename of the Org file to be published. PLIST
1759 is the property list for the given project. PUB-DIR is the
1760 publishing directory.
1762 Return output file name."
1763 (org-publish-org-to 'texinfo filename
".texi" plist pub-dir
))
1765 (defun org-texinfo-compile (file)
1766 "Compile a texinfo file.
1768 FILE is the name of the file being compiled. Processing is
1769 done through the command specified in `org-texinfo-info-process'.
1771 Return INFO file name or an error if it couldn't be produced."
1772 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file
)))
1773 (full-name (file-truename file
))
1774 (out-dir (file-name-directory file
))
1775 ;; Make sure `default-directory' is set to FILE directory,
1776 ;; not to whatever value the current buffer may have.
1777 (default-directory (file-name-directory full-name
))
1779 (message (format "Processing Texinfo file %s ..." file
))
1780 (save-window-excursion
1782 ;; A function is provided: Apply it.
1783 ((functionp org-texinfo-info-process
)
1784 (funcall org-texinfo-info-process
(shell-quote-argument file
)))
1785 ;; A list is provided: Replace %b, %f and %o with appropriate
1786 ;; values in each command before applying it. Output is
1787 ;; redirected to "*Org INFO Texinfo Output*" buffer.
1788 ((consp org-texinfo-info-process
)
1789 (let ((outbuf (get-buffer-create "*Org INFO Texinfo Output*")))
1793 (replace-regexp-in-string
1794 "%b" (shell-quote-argument base-name
)
1795 (replace-regexp-in-string
1796 "%f" (shell-quote-argument full-name
)
1797 (replace-regexp-in-string
1798 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
1800 org-texinfo-info-process
)
1801 ;; Collect standard errors from output buffer.
1802 (setq errors
(org-texinfo-collect-errors outbuf
))))
1803 (t (error "No valid command to process to Info")))
1804 (let ((infofile (concat out-dir base-name
".info")))
1805 ;; Check for process failure. Provide collected errors if
1807 (if (not (file-exists-p infofile
))
1808 (error (concat (format "INFO file %s wasn't produced" infofile
)
1809 (when errors
(concat ": " errors
))))
1810 ;; Else remove log files, when specified, and signal end of
1811 ;; process to user, along with any error encountered.
1812 (message (concat "Process completed"
1813 (if (not errors
) "."
1814 (concat " with errors: " errors
)))))
1815 ;; Return output file name.
1818 (defun org-texinfo-collect-errors (buffer)
1819 "Collect some kind of errors from \"makeinfo\" command output.
1821 BUFFER is the buffer containing output.
1823 Return collected error types as a string, or nil if there was
1825 (with-current-buffer buffer
1827 (goto-char (point-min))
1828 ;; Find final "makeinfo" run.
1830 (let ((case-fold-search t
)
1832 (when (save-excursion
1833 (re-search-forward "perhaps incorrect sectioning?" nil t
))
1834 (setq errors
(concat errors
" [incorrect sectioning]")))
1835 (when (save-excursion
1836 (re-search-forward "missing close brace" nil t
))
1837 (setq errors
(concat errors
" [syntax error]")))
1838 (when (save-excursion
1839 (re-search-forward "Unknown command" nil t
))
1840 (setq errors
(concat errors
" [undefined @command]")))
1841 (when (save-excursion
1842 (re-search-forward "No matching @end" nil t
))
1843 (setq errors
(concat errors
" [block incomplete]")))
1844 (when (save-excursion
1845 (re-search-forward "requires a sectioning" nil t
))
1846 (setq errors
(concat errors
" [invalid section command]")))
1847 (when (save-excursion
1848 (re-search-forward "\\[unexpected\]" nil t
))
1849 (setq errors
(concat errors
" [unexpected error]")))
1850 (when (save-excursion
1851 (re-search-forward "misplaced " nil t
))
1852 (setq errors
(concat errors
" [syntax error]")))
1853 (and (org-string-nw-p errors
) (org-trim errors
)))))))
1856 (provide 'ox-texinfo
)
1859 ;; generated-autoload-file: "org-loaddefs.el"
1862 ;;; ox-texinfo.el ends here