1 ;;; ox-texinfo.el --- Texinfo Back-End for Org Export Engine
3 ;; Copyright (C) 2012-2014 Free Software Foundation, Inc.
4 ;; Author: Jonathan Leech-Pepin <jonathan.leechpepin at gmail dot com>
5 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; This library implements a Texinfo back-end for Org generic
29 ;; M-: (org-export-to-buffer 'texinfo "*Test Texinfo*") RET
31 ;; in an Org mode buffer then switch to the buffer to see the Texinfo
32 ;; export. See ox.el for more details on how this exporter works.
35 ;; It introduces nine new buffer keywords: "TEXINFO_CLASS",
36 ;; "TEXINFO_FILENAME", "TEXINFO_HEADER", "TEXINFO_POST_HEADER",
37 ;; "TEXINFO_DIR_CATEGORY", "TEXINFO_DIR_TITLE", "TEXINFO_DIR_DESC"
38 ;; "SUBTITLE" and "SUBAUTHOR".
41 ;; It introduces 1 new headline property keywords:
42 ;; "TEXINFO_MENU_TITLE" for optional menu titles.
44 ;; To include inline code snippets (for example for generating @kbd{}
45 ;; and @key{} commands), the following export-snippet keys are
51 ;; You can add them for export snippets via any of the below:
53 ;; (add-to-list 'org-export-snippet-translation-alist
54 ;; '("info" . "texinfo"))
59 (eval-when-compile (require 'cl
))
62 (defvar orgtbl-exp-regexp
)
68 (org-export-define-backend 'texinfo
69 '((bold . org-texinfo-bold
)
70 (center-block . org-texinfo-center-block
)
71 (clock . org-texinfo-clock
)
72 (code . org-texinfo-code
)
73 (comment .
(lambda (&rest args
) ""))
74 (comment-block .
(lambda (&rest args
) ""))
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 nil 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-printed-title
"TEXINFO_PRINTED_TITLE" nil nil t
)))
136 ;;; User Configurable Variables
138 (defgroup org-export-texinfo nil
139 "Options for exporting Org mode files to Texinfo."
140 :tag
"Org Export Texinfo"
142 :package-version
'(Org .
"8.0")
147 (defcustom org-texinfo-coding-system nil
148 "Default document encoding for Texinfo output.
150 If `nil' it will default to `buffer-file-coding-system'."
151 :group
'org-export-texinfo
152 :type
'coding-system
)
154 (defcustom org-texinfo-default-class
"info"
155 "The default Texinfo class."
156 :group
'org-export-texinfo
157 :type
'(string :tag
"Texinfo class"))
159 (defcustom org-texinfo-classes
161 "@documentencoding AUTO\n@documentlanguage AUTO"
162 ("@chapter %s" .
"@unnumbered %s")
163 ("@section %s" .
"@unnumberedsec %s")
164 ("@subsection %s" .
"@unnumberedsubsec %s")
165 ("@subsubsection %s" .
"@unnumberedsubsubsec %s")))
166 "Alist of Texinfo classes and associated header and structure.
167 If #+TEXINFO_CLASS is set in the buffer, use its value and the
168 associated information. Here is the structure of each cell:
172 \(numbered-section . unnumbered-section)
179 The header string is inserted in the header of the generated
180 document, right after \"@setfilename\" and \"@settitle\"
183 If it contains the special string
185 \"@documentencoding AUTO\"
187 \"AUTO\" will be replaced with an appropriate coding system. See
188 `org-texinfo-coding-system' for more information. Likewise, if
189 the string contains the special string
191 \"@documentlanguage AUTO\"
193 \"AUTO\" will be replaced with the language defined in the
194 buffer, through #+LANGUAGE keyword, or globally, with
195 `org-export-default-language', which see.
198 The sectioning structure
199 ------------------------
201 The sectioning structure of the class is given by the elements
202 following the header string. For each sectioning level, a number
203 of strings is specified. A %s formatter is mandatory in each
204 section string and will be replaced by the title of the section.
206 Instead of a list of sectioning commands, you can also specify
207 a function name. That function will be called with two
208 parameters, the reduced) level of the headline, and a predicate
209 non-nil when the headline should be numbered. It must return
210 a format string in which the section title will be added."
211 :group
'org-export-texinfo
213 :package-version
'(Org .
"8.2")
215 (list (string :tag
"Texinfo class")
216 (string :tag
"Texinfo header")
217 (repeat :tag
"Levels" :inline t
220 (string :tag
" numbered")
221 (string :tag
"unnumbered"))
222 (function :tag
"Hook computing sectioning"))))))
226 (defcustom org-texinfo-format-headline-function
'ignore
227 "Function to format headline text.
229 This function will be called with 5 arguments:
230 TODO the todo keyword (string or nil).
231 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
232 PRIORITY the priority of the headline (integer or nil)
233 TEXT the main headline text (string).
234 TAGS the tags as a list of strings (list of strings or nil).
236 The function result will be used in the section format string.
238 As an example, one could set the variable to the following, in
239 order to reproduce the default set-up:
241 \(defun org-texinfo-format-headline (todo todo-type priority text tags)
242 \"Default format function for a headline.\"
244 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
246 \(format \"\\\\framebox{\\\\#%c} \" priority))
249 \(format \"\\\\hfill{}\\\\textsc{%s}\"
250 \(mapconcat 'identity tags \":\"))))"
251 :group
'org-export-texinfo
254 ;;; Node listing (menu)
256 (defcustom org-texinfo-node-description-column
32
257 "Column at which to start the description in the node listings.
258 If a node title is greater than this length, the description will
259 be placed after the end of the title."
260 :group
'org-export-texinfo
265 ;; Footnotes are inserted directly
269 (defcustom org-texinfo-active-timestamp-format
"@emph{%s}"
270 "A printf format string to be applied to active timestamps."
271 :group
'org-export-texinfo
274 (defcustom org-texinfo-inactive-timestamp-format
"@emph{%s}"
275 "A printf format string to be applied to inactive timestamps."
276 :group
'org-export-texinfo
279 (defcustom org-texinfo-diary-timestamp-format
"@emph{%s}"
280 "A printf format string to be applied to diary timestamps."
281 :group
'org-export-texinfo
286 (defcustom org-texinfo-link-with-unknown-path-format
"@indicateurl{%s}"
287 "Format string for links with unknown path type."
288 :group
'org-export-texinfo
293 (defcustom org-texinfo-tables-verbatim nil
294 "When non-nil, tables are exported verbatim."
295 :group
'org-export-texinfo
298 (defcustom org-texinfo-table-scientific-notation
"%s\\,(%s)"
299 "Format string to display numbers in scientific notation.
300 The format should have \"%s\" twice, for mantissa and exponent
301 \(i.e. \"%s\\\\times10^{%s}\").
303 When nil, no transformation is made."
304 :group
'org-export-texinfo
306 (string :tag
"Format string")
307 (const :tag
"No formatting" nil
)))
309 (defcustom org-texinfo-def-table-markup
"@samp"
310 "Default setting for @table environments."
311 :group
'org-export-texinfo
316 (defcustom org-texinfo-text-markup-alist
'((bold .
"@strong{%s}")
318 (italic .
"@emph{%s}")
321 "Alist of Texinfo expressions to convert text markup.
323 The key must be a symbol among `bold', `italic' and `comment'.
324 The value is a formatting string to wrap fontified text with.
326 Value can also be set to the following symbols: `verb' and
327 `code'. For the former, Org will use \"@verb\" to
328 create a format string and select a delimiter character that
329 isn't in the string. For the latter, Org will use \"@code\"
330 to typeset and try to protect special characters.
332 If no association can be found for a given markup, text will be
334 :group
'org-export-texinfo
336 :options
'(bold code italic verbatim comment
))
340 (defcustom org-texinfo-format-drawer-function
341 (lambda (name contents
) contents
)
342 "Function called to format a drawer in Texinfo code.
344 The function must accept two parameters:
345 NAME the drawer name, like \"LOGBOOK\"
346 CONTENTS the contents of the drawer.
348 The function should return the string to be exported.
350 The default function simply returns the value of CONTENTS."
351 :group
'org-export-texinfo
353 :package-version
'(Org .
"8.2")
358 (defcustom org-texinfo-format-inlinetask-function
'ignore
359 "Function called to format an inlinetask in Texinfo code.
361 The function must accept six parameters:
362 TODO the todo keyword, as a string
363 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
364 PRIORITY the inlinetask priority, as a string
365 NAME the inlinetask name, as a string.
366 TAGS the inlinetask tags, as a list of strings.
367 CONTENTS the contents of the inlinetask, as a string.
369 The function should return the string to be exported.
371 For example, the variable could be set to the following function
372 in order to mimic default behavior:
374 \(defun org-texinfo-format-inlinetask \(todo type priority name tags contents\)
375 \"Format an inline task element for Texinfo export.\"
379 \(format \"@strong{%s} \" todo))
380 \(when priority (format \"#%c \" priority))
384 \(mapconcat 'identity tags \":\")))))
385 \(format (concat \"@center %s\n\n\"
388 full-title contents))"
389 :group
'org-export-texinfo
394 ;; Src Blocks are example blocks, except for LISP
398 (defcustom org-texinfo-info-process
400 "Commands to process a Texinfo file to an INFO file.
401 This is list of strings, each of them will be given to the shell
402 as a command. %f in the command will be replaced by the full
403 file name, %b by the file base name \(i.e without extension) and
404 %o by the base directory of the file."
405 :group
'org-export-texinfo
406 :type
'(repeat :tag
"Shell command sequence"
407 (string :tag
"Shell command")))
409 (defcustom org-texinfo-logfiles-extensions
410 '("aux" "toc" "cp" "fn" "ky" "pg" "tp" "vr")
411 "The list of file extensions to consider as Texinfo logfiles.
412 The logfiles will be remove if `org-texinfo-remove-logfiles' is
414 :group
'org-export-texinfo
415 :type
'(repeat (string :tag
"Extension")))
417 (defcustom org-texinfo-remove-logfiles t
418 "Non-nil means remove the logfiles produced by compiling a Texinfo file.
419 By default, logfiles are files with these extensions: .aux, .toc,
420 .cp, .fn, .ky, .pg and .tp. To define the set of logfiles to remove,
421 set `org-texinfo-logfiles-extensions'."
422 :group
'org-export-latex
427 (defconst org-texinfo-max-toc-depth
4
428 "Maximum depth for creation of detailed menu listings. Beyond
429 this depth Texinfo will not recognize the nodes and will cause
430 errors. Left as a constant in case this value ever changes.")
432 (defconst org-texinfo-supported-coding-systems
433 '("US-ASCII" "UTF-8" "ISO-8859-15" "ISO-8859-1" "ISO-8859-2" "koi8-r" "koi8-u")
434 "List of coding systems supported by Texinfo, as strings.
435 Specified coding system will be matched against these strings.
436 If two strings share the same prefix (e.g. \"ISO-8859-1\" and
437 \"ISO-8859-15\"), the most specific one has to be listed first.")
440 ;;; Internal Functions
442 (defun org-texinfo-filter-section-blank-lines (headline back-end info
)
443 "Filter controlling number of blank lines after a section."
444 (let ((blanks (make-string 2 ?
\n)))
445 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline
)))
447 (defun org-texinfo--find-verb-separator (s)
448 "Return a character not used in string S.
449 This is used to choose a separator for constructs like \\verb."
450 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
451 (loop for c across ll
452 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
453 return
(char-to-string c
))))
455 (defun org-texinfo--make-option-string (options)
456 "Return a comma separated string of keywords and values.
457 OPTIONS is an alist where the key is the options keyword as
458 a string, and the value a list containing the keyword value, or
460 (mapconcat (lambda (pair)
462 (when (> (length (second pair
)) 0)
463 (concat "=" (second pair
)))))
467 (defun org-texinfo--text-markup (text markup
)
468 "Format TEXT depending on MARKUP text markup.
469 See `org-texinfo-text-markup-alist' for details."
470 (let ((fmt (cdr (assq markup org-texinfo-text-markup-alist
))))
472 ;; No format string: Return raw text.
475 (let ((separator (org-texinfo--find-verb-separator text
)))
476 (concat "@verb{" separator text separator
"}")))
481 (while (string-match "[@{}]" text
)
482 (setq char
(match-string 0 text
))
483 (if (> (match-beginning 0) 0)
484 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
485 (setq text
(substring text
(1+ (match-beginning 0))))
486 (setq char
(concat "@" char
)
487 rtn
(concat rtn char
)))
488 (setq text
(concat rtn text
)
491 ;; Else use format string.
492 (t (format fmt text
)))))
494 (defun org-texinfo--get-node (headline info
)
495 "Return node entry associated to HEADLINE.
496 INFO is a plist used as a communication channel."
497 (let ((menu-title (org-export-get-alt-title headline info
)))
498 (org-texinfo--sanitize-menu
499 (replace-regexp-in-string
501 (if menu-title
(org-export-data menu-title info
)
502 (org-texinfo--sanitize-headline
503 (org-element-property :title headline
) info
))))))
505 ;;; Headline sanitizing
507 (defun org-texinfo--sanitize-headline (headline info
)
508 "Remove all formatting from the text of a headline for use in
509 node and menu listing."
511 (org-texinfo--sanitize-headline-contents headline info
) " "))
513 (defun org-texinfo--sanitize-headline-contents (headline info
)
514 "Retrieve the content of the headline.
516 Any content that can contain further formatting is checked
517 recursively, to ensure that nested content is also properly
519 (loop for contents in headline append
523 (list (replace-regexp-in-string " $" "" contents
)))
524 ;; Is exported as-is (value)
525 ((org-element-map contents
'(verbatim code
)
526 (lambda (value) (org-element-property :value value
)) info
))
527 ;; Has content and recurse into the content
528 ((org-element-contents contents
)
529 (org-texinfo--sanitize-headline-contents
530 (org-element-contents contents
) info
)))))
534 (defun org-texinfo--sanitize-menu (title)
535 "Remove invalid characters from TITLE for use in menus and
538 Based on Texinfo specifications, the following must be removed:
540 (replace-regexp-in-string "[@{}():,.]" "" title
))
542 ;;; Content sanitizing
544 (defun org-texinfo--sanitize-content (text)
545 "Ensure characters are properly escaped when used in headlines or blocks.
547 Escape characters are: @ { }"
548 (replace-regexp-in-string "\\\([@{}]\\\)" "@\\1" text
))
552 (defun org-texinfo--build-menu (tree level info
&optional detailed
)
553 "Create the @menu/@end menu information from TREE at headline
556 TREE contains the parse-tree to work with, either of the entire
557 document or of a specific parent headline. LEVEL indicates what
558 level of headlines to look at when generating the menu. INFO is
559 a plist containing contextual information.
561 Detailed determines whether to build a single level of menu, or
562 recurse into all children as well."
563 (let ((menu (org-texinfo--generate-menu-list tree level info
))
567 ;; Looping is done within the menu generation.
568 (setq text-menu
(org-texinfo--generate-detailed menu level info
)))
570 (setq text-menu
(org-texinfo--generate-menu-items menu info
))))
572 (setq output
(org-texinfo--format-menu text-menu
))
573 (mapconcat 'identity output
"\n"))))
575 (defun org-texinfo--generate-detailed (menu level info
)
576 "Generate a detailed listing of all subheadings within MENU starting at LEVEL.
578 MENU is the parse-tree to work with. LEVEL is the starting level
579 for the menu headlines and from which recursion occurs. INFO is
580 a plist containing contextual information."
582 (let ((max-depth (min org-texinfo-max-toc-depth
583 (plist-get info
:headline-levels
))))
584 (when (> max-depth level
)
585 (loop for headline in menu append
586 (let* ((title (org-texinfo--menu-headlines headline info
))
587 ;; Create list of menu entries for the next level
588 (sublist (org-texinfo--generate-menu-list
589 headline
(1+ level
) info
))
590 ;; Generate the menu items for that level. If
591 ;; there are none omit that heading completely,
592 ;; otherwise join the title to it's related entries.
593 (submenu (if (org-texinfo--generate-menu-items sublist info
)
595 (org-texinfo--generate-menu-items sublist info
))
597 ;; Start the process over the next level down.
598 (recursion (org-texinfo--generate-detailed sublist
(1+ level
) info
)))
599 (setq recursion
(append submenu recursion
))
602 (defun org-texinfo--generate-menu-list (tree level info
)
603 "Generate the list of headlines that are within a given level
604 of the tree for further formatting.
606 TREE is the parse-tree containing the headlines. LEVEL is the
607 headline level to generate a list of. INFO is a plist holding
608 contextual information."
609 (org-element-map tree
'headline
611 (and (= (org-export-get-relative-level head info
) level
)
612 ;; Do not take note of footnotes or copying headlines.
613 (not (org-element-property :COPYING head
))
614 (not (org-element-property :footnote-section-p head
))
619 (defun org-texinfo--generate-menu-items (items info
)
620 "Generate a list of headline information from the listing ITEMS.
622 ITEMS is a list of the headlines to be converted into entries.
623 INFO is a plist containing contextual information.
625 Returns a list containing the following information from each
626 headline: length, title, description. This is used to format the
627 menu using `org-texinfo--format-menu'."
628 (loop for headline in items collect
629 (let* ((menu-title (org-texinfo--sanitize-menu
631 (org-export-get-alt-title headline info
)
633 (title (org-texinfo--sanitize-menu
634 (org-texinfo--sanitize-headline
635 (org-element-property :title headline
) info
)))
636 (descr (org-export-data
637 (org-element-property :DESCRIPTION headline
)
639 (menu-entry (if (string= "" menu-title
) title menu-title
))
640 (len (length menu-entry
))
641 (output (list len menu-entry descr
)))
644 (defun org-texinfo--menu-headlines (headline info
)
645 "Retrieve the title from HEADLINE.
647 INFO is a plist holding contextual information.
649 Return the headline as a list of (length title description) with
650 length of -1 and nil description. This is used in
651 `org-texinfo--format-menu' to identify headlines as opposed to
653 (let ((title (org-export-data
654 (org-element-property :title headline
) info
)))
655 (list -
1 title
'nil
)))
657 (defun org-texinfo--format-menu (text-menu)
658 "Format the TEXT-MENU items to be properly printed in the menu.
660 Each entry in the menu should be provided as (length title
663 Headlines in the detailed menu are given length -1 to ensure they
664 are never confused with other entries. They also have no
667 Other menu items are output as:
670 With the spacing between :: and description based on the length
671 of the longest menu entry."
675 (mapcar (lambda (name)
676 (let* ((title (nth 1 name
))
678 (length (nth 0 name
))
680 ;;6 is "* " ":: " for inserted text
683 org-texinfo-node-description-column
685 (spacing (- column length
)
688 (concat "* " title
":: "
689 (make-string spacing ?\s
)
692 (concat "\n" title
"\n"))))
698 (defun org-texinfo-template (contents info
)
699 "Return complete document string after Texinfo conversion.
700 CONTENTS is the transcoded contents string. INFO is a plist
701 holding export options."
702 (let ((title (org-export-data (plist-get info
:title
) info
))
703 ;; Copying data is the contents of the first headline in
704 ;; parse tree with a non-nil copying property.
705 (copying (org-element-map (plist-get info
:parse-tree
) 'headline
707 (and (org-not-nil (org-element-property :COPYING hl
))
708 (org-element-contents hl
)))
711 "\\input texinfo @c -*- texinfo -*-\n"
712 "@c %**start of header\n"
713 (let ((file (or (plist-get info
:texinfo-filename
)
714 (let ((f (plist-get info
:output-file
)))
715 (and f
(concat (file-name-sans-extension f
) ".info"))))))
716 (and file
(format "@setfilename %s\n" file
)))
717 (format "@settitle %s\n" title
)
718 ;; Insert class-defined header.
719 (org-element-normalize-string
720 (let ((header (nth 1 (assoc (plist-get info
:texinfo-class
)
721 org-texinfo-classes
)))
723 (catch 'coding-system
724 (let ((case-fold-search t
)
725 (name (symbol-name (or org-texinfo-coding-system
726 buffer-file-coding-system
))))
727 (dolist (system org-texinfo-supported-coding-systems
"UTF-8")
728 (when (org-string-match-p (regexp-quote system
) name
)
729 (throw 'coding-system system
))))))
730 (language (plist-get info
:language
))
731 (case-fold-search nil
))
732 ;; Auto coding system.
733 (replace-regexp-in-string
734 "^@documentencoding \\(AUTO\\)$"
736 (replace-regexp-in-string
737 "^@documentlanguage \\(AUTO\\)$" language header nil nil
1)
739 ;; Additional header options set by #+TEXINFO_HEADER.
740 (let ((texinfo-header (plist-get info
:texinfo-header
)))
741 (and texinfo-header
(org-element-normalize-string texinfo-header
)))
742 "@c %**end of header\n\n"
743 ;; Additional options set by #+TEXINFO_POST_HEADER.
744 (let ((texinfo-post-header (plist-get info
:texinfo-post-header
)))
745 (and texinfo-post-header
746 (org-element-normalize-string texinfo-post-header
)))
749 (format "@copying\n%s@end copying\n\n"
750 (org-element-normalize-string
751 (org-export-data copying info
))))
752 ;; Info directory information. Only supply if both title and
753 ;; category are provided.
754 (let ((dircat (plist-get info
:texinfo-dircat
))
756 (let ((title (plist-get info
:texinfo-dirtitle
)))
758 (string-match "^\\(?:\\* \\)?\\(.*?\\)\\(\\.\\)?$" title
)
759 (format "* %s." (match-string 1 title
))))))
760 (when (and dircat dirtitle
)
761 (concat "@dircategory " dircat
"\n"
764 (let ((desc (plist-get info
:texinfo-dirdesc
)))
765 (cond ((not desc
) nil
)
766 ((org-string-match-p "\\.$" desc
) desc
)
767 (t (concat desc
"."))))))
768 (if dirdesc
(format "%-23s %s" dirtitle dirdesc
) dirtitle
))
770 "@end direntry\n\n")))
774 (format "@title %s\n" (or (plist-get info
:texinfo-printed-title
) title
))
775 (let ((subtitle (plist-get info
:subtitle
)))
777 (org-element-normalize-string
778 (replace-regexp-in-string "^" "@subtitle " subtitle
))))
779 (when (plist-get info
:with-author
)
782 (let ((author (org-string-nw-p
783 (org-export-data (plist-get info
:author
) info
)))
784 (email (and (plist-get info
:with-email
)
786 (org-export-data (plist-get info
:email
) info
)))))
787 (cond ((and author email
)
788 (format "@author %s (@email{%s})\n" author email
))
789 (author (format "@author %s\n" author
))
790 (email (format "@author @email{%s}\n" email
))))
792 (let ((subauthor (plist-get info
:subauthor
)))
794 (org-element-normalize-string
795 (replace-regexp-in-string "^" "@author " subauthor
))))))
796 (and copying
"@page\n@vskip 0pt plus 1filll\n@insertcopying\n")
798 ;; Table of contents.
799 (and (plist-get info
:with-toc
) "@contents\n\n")
800 ;; Configure Top Node when not for Tex
803 (format "@top %s\n" title
)
804 (and copying
"@insertcopying\n")
807 (let ((menu (org-texinfo-make-menu info
'main
))
808 (detail-menu (org-texinfo-make-menu info
'detailed
)))
813 (concat "\n@detailmenu\n"
814 " --- The Detailed Node Listing ---\n"
816 "@end detailmenu\n"))
821 (case (plist-get info
:with-creator
)
823 (comment (format "@c %s\n" (plist-get info
:creator
)))
824 (otherwise (concat (plist-get info
:creator
) "\n")))
830 ;;; Transcode Functions
834 (defun org-texinfo-bold (bold contents info
)
835 "Transcode BOLD from Org to Texinfo.
836 CONTENTS is the text with bold markup. INFO is a plist holding
837 contextual information."
838 (org-texinfo--text-markup contents
'bold
))
842 (defun org-texinfo-center-block (center-block contents info
)
843 "Transcode a CENTER-BLOCK element from Org to Texinfo.
844 CONTENTS holds the contents of the block. INFO is a plist used
845 as a communication channel."
850 (defun org-texinfo-clock (clock contents info
)
851 "Transcode a CLOCK element from Org to Texinfo.
852 CONTENTS is nil. INFO is a plist holding contextual
856 (format "@strong{%s} " org-clock-string
)
857 (format org-texinfo-inactive-timestamp-format
858 (concat (org-translate-time
859 (org-element-property :raw-value
860 (org-element-property :value clock
)))
861 (let ((time (org-element-property :duration clock
)))
862 (and time
(format " (%s)" time
)))))
867 (defun org-texinfo-code (code contents info
)
868 "Transcode a CODE object from Org to Texinfo.
869 CONTENTS is nil. INFO is a plist used as a communication
871 (org-texinfo--text-markup (org-element-property :value code
) 'code
))
875 (defun org-texinfo-drawer (drawer contents info
)
876 "Transcode a DRAWER element from Org to Texinfo.
877 CONTENTS holds the contents of the block. INFO is a plist
878 holding contextual information."
879 (let* ((name (org-element-property :drawer-name drawer
))
880 (output (funcall org-texinfo-format-drawer-function
886 (defun org-texinfo-dynamic-block (dynamic-block contents info
)
887 "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
888 CONTENTS holds the contents of the block. INFO is a plist
889 holding contextual information. See `org-export-data'."
894 (defun org-texinfo-entity (entity contents info
)
895 "Transcode an ENTITY object from Org to Texinfo.
896 CONTENTS are the definition itself. INFO is a plist holding
897 contextual information."
898 (let ((ent (org-element-property :latex entity
)))
899 (if (org-element-property :latex-math-p entity
) (format "@math{%s}" ent
) ent
)))
903 (defun org-texinfo-example-block (example-block contents info
)
904 "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
905 CONTENTS is nil. INFO is a plist holding contextual
907 (format "@verbatim\n%s@end verbatim"
908 (org-export-format-code-default example-block info
)))
912 (defun org-texinfo-export-block (export-block contents info
)
913 "Transcode a EXPORT-BLOCK element from Org to Texinfo.
914 CONTENTS is nil. INFO is a plist holding contextual information."
915 (when (string= (org-element-property :type export-block
) "TEXINFO")
916 (org-remove-indentation (org-element-property :value export-block
))))
920 (defun org-texinfo-export-snippet (export-snippet contents info
)
921 "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
922 CONTENTS is nil. INFO is a plist holding contextual information."
923 (when (eq (org-export-snippet-backend export-snippet
) 'texinfo
)
924 (org-element-property :value export-snippet
)))
928 (defun org-texinfo-fixed-width (fixed-width contents info
)
929 "Transcode a FIXED-WIDTH element from Org to Texinfo.
930 CONTENTS is nil. INFO is a plist holding contextual information."
931 (format "@example\n%s\n@end example"
932 (org-remove-indentation
933 (org-texinfo--sanitize-content
934 (org-element-property :value fixed-width
)))))
936 ;;; Footnote Reference
939 (defun org-texinfo-footnote-reference (footnote contents info
)
940 "Create a footnote reference for FOOTNOTE.
942 FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
943 plist holding contextual information."
944 (let ((def (org-export-get-footnote-definition footnote info
)))
945 (format "@footnote{%s}"
946 (org-trim (org-export-data def info
)))))
950 (defun org-texinfo-headline (headline contents info
)
951 "Transcode a HEADLINE element from Org to Texinfo.
952 CONTENTS holds the contents of the headline. INFO is a plist
953 holding contextual information."
954 (let* ((class (plist-get info
:texinfo-class
))
955 (level (org-export-get-relative-level headline info
))
956 (numberedp (org-export-numbered-headline-p headline info
))
957 (class-sectioning (assoc class org-texinfo-classes
))
958 ;; Find the index type, if any
959 (index (org-element-property :INDEX headline
))
960 ;; Retrieve headline text
961 (text (org-texinfo--sanitize-headline
962 (org-element-property :title headline
) info
))
963 ;; Create node info, to insert it before section formatting.
964 ;; Use custom menu title if present
965 (node (format "@node %s\n" (org-texinfo--get-node headline info
)))
966 ;; Menus must be generated with first child, otherwise they
967 ;; will not nest properly
968 (menu (let* ((first (org-export-first-sibling-p headline info
))
969 (parent (org-export-get-parent-headline headline
))
970 (title (org-texinfo--sanitize-headline
971 (org-element-property :title parent
) info
))
973 (tree (plist-get info
:parse-tree
)))
975 (org-element-map (plist-get info
:parse-tree
) 'headline
977 (if (member title
(org-element-property :title ref
))
980 (setq listing
(org-texinfo--build-menu
981 (car heading
) level info
))
983 (setq listing
(replace-regexp-in-string
986 "\n@menu\n%s\n@end menu\n\n" listing
))
988 ;; Section formatting will set two placeholders: one for the
989 ;; title and the other for the contents.
991 (if (org-not-nil (org-element-property :APPENDIX headline
))
992 (concat menu node
"appendix\n%s")
993 (let ((sec (if (and (symbolp (nth 2 class-sectioning
))
994 (fboundp (nth 2 class-sectioning
)))
995 (funcall (nth 2 class-sectioning
) level numberedp
)
996 (nth (1+ level
) class-sectioning
))))
998 ;; No section available for that LEVEL.
1000 ;; Section format directly returned by a function.
1002 ;; (numbered-section . unnumbered-section)
1003 ((not (consp (cdr sec
)))
1006 ;; An index is always unnumbered.
1007 (if (or index
(not numberedp
)) (cdr sec
) (car sec
))
1010 (and (plist-get info
:with-todo-keywords
)
1011 (let ((todo (org-element-property :todo-keyword headline
)))
1012 (and todo
(org-export-data todo info
)))))
1013 (todo-type (and todo
(org-element-property :todo-type headline
)))
1014 (tags (and (plist-get info
:with-tags
)
1015 (org-export-get-tags headline info
)))
1016 (priority (and (plist-get info
:with-priority
)
1017 (org-element-property :priority headline
)))
1018 ;; Create the headline text along with a no-tag version. The
1019 ;; latter is required to remove tags from table of contents.
1020 (full-text (org-texinfo--sanitize-content
1021 (if (not (eq org-texinfo-format-headline-function
'ignore
))
1022 ;; User-defined formatting function.
1023 (funcall org-texinfo-format-headline-function
1024 todo todo-type priority text tags
)
1025 ;; Default formatting.
1028 (format "@strong{%s} " todo
))
1029 (when priority
(format "@emph{#%s} " priority
))
1033 (mapconcat 'identity tags
":")))))))
1035 (org-texinfo--sanitize-content
1036 (if (not (eq org-texinfo-format-headline-function
'ignore
))
1037 ;; User-defined formatting function.
1038 (funcall org-texinfo-format-headline-function
1039 todo todo-type priority text nil
)
1040 ;; Default formatting.
1042 (when todo
(format "@strong{%s} " todo
))
1043 (when priority
(format "@emph{#%c} " priority
))
1046 (make-string (org-element-property :pre-blank headline
) 10)))
1048 ;; Case 1: This is a footnote section: ignore it.
1049 ((org-element-property :footnote-section-p headline
) nil
)
1050 ;; Case 2: This is the `copying' section: ignore it
1051 ;; This is used elsewhere.
1052 ((org-element-property :COPYING headline
) nil
)
1053 ;; Case 3: An index. If it matches one of the known indexes,
1054 ;; print it as such following the contents, otherwise
1055 ;; print the contents and leave the index up to the user.
1058 section-fmt full-text
1059 (concat pre-blanks contents
"\n"
1060 (if (member index
'("cp" "fn" "ky" "pg" "tp" "vr"))
1061 (concat "@printindex " index
)))))
1062 ;; Case 4: This is a deep sub-tree: export it as a list item.
1063 ;; Also export as items headlines for which no section
1064 ;; format has been found.
1065 ((or (not section-fmt
) (org-export-low-level-p headline info
))
1066 ;; Build the real contents of the sub-tree.
1067 (let ((low-level-body
1069 ;; If the headline is the first sibling, start a list.
1070 (when (org-export-first-sibling-p headline info
)
1071 (format "@%s\n" (if numberedp
'enumerate
'itemize
)))
1073 "@item\n" full-text
"\n" pre-blanks contents
)))
1074 ;; If headline is not the last sibling simply return
1075 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
1077 (if (not (org-export-last-sibling-p headline info
)) low-level-body
1078 (replace-regexp-in-string
1080 (format "\n@end %s" (if numberedp
'enumerate
'itemize
))
1082 ;; Case 5: Standard headline. Export it as a section.
1085 ((not (and tags
(eq (plist-get info
:with-tags
) 'not-in-toc
)))
1086 ;; Regular section. Use specified format string.
1087 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1088 (concat pre-blanks contents
)))
1089 ((string-match "\\`@\\(.*?\\){" section-fmt
)
1090 ;; If tags should be removed from table of contents, insert
1091 ;; title without tags as an alternative heading in sectioning
1093 (format (replace-match (concat (match-string 1 section-fmt
) "[%s]")
1094 nil nil section-fmt
1)
1095 ;; Replace square brackets with parenthesis since
1096 ;; square brackets are not supported in optional
1098 (replace-regexp-in-string
1100 (replace-regexp-in-string
1104 (concat pre-blanks contents
)))
1106 ;; Impossible to add an alternative heading. Fallback to
1107 ;; regular sectioning format string.
1108 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1109 (concat pre-blanks contents
))))))))
1111 ;;; Inline Src Block
1113 (defun org-texinfo-inline-src-block (inline-src-block contents info
)
1114 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
1115 CONTENTS holds the contents of the item. INFO is a plist holding
1116 contextual information."
1117 (let* ((code (org-element-property :value inline-src-block
))
1118 (separator (org-texinfo--find-verb-separator code
)))
1119 (concat "@verb{" separator code separator
"}")))
1123 (defun org-texinfo-inlinetask (inlinetask contents info
)
1124 "Transcode an INLINETASK element from Org to Texinfo.
1125 CONTENTS holds the contents of the block. INFO is a plist
1126 holding contextual information."
1127 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
1128 (todo (and (plist-get info
:with-todo-keywords
)
1129 (let ((todo (org-element-property :todo-keyword inlinetask
)))
1130 (and todo
(org-export-data todo info
)))))
1131 (todo-type (org-element-property :todo-type inlinetask
))
1132 (tags (and (plist-get info
:with-tags
)
1133 (org-export-get-tags inlinetask info
)))
1134 (priority (and (plist-get info
:with-priority
)
1135 (org-element-property :priority inlinetask
))))
1136 ;; If `org-texinfo-format-inlinetask-function' is provided, call it
1137 ;; with appropriate arguments.
1138 (if (not (eq org-texinfo-format-inlinetask-function
'ignore
))
1139 (funcall org-texinfo-format-inlinetask-function
1140 todo todo-type priority title tags contents
)
1141 ;; Otherwise, use a default template.
1144 (when todo
(format "@strong{%s} " todo
))
1145 (when priority
(format "#%c " priority
))
1147 (when tags
(format ":%s:"
1148 (mapconcat 'identity tags
":"))))))
1149 (format (concat "@center %s\n\n"
1152 full-title contents
)))))
1156 (defun org-texinfo-italic (italic contents info
)
1157 "Transcode ITALIC from Org to Texinfo.
1158 CONTENTS is the text with italic markup. INFO is a plist holding
1159 contextual information."
1160 (org-texinfo--text-markup contents
'italic
))
1164 (defun org-texinfo-item (item contents info
)
1165 "Transcode an ITEM element from Org to Texinfo.
1166 CONTENTS holds the contents of the item. INFO is a plist holding
1167 contextual information."
1168 (let* ((tag (org-element-property :tag item
))
1169 (desc (org-export-data tag info
)))
1170 (concat "\n@item " (if tag desc
) "\n"
1171 (and contents
(org-trim contents
)) "\n")))
1175 (defun org-texinfo-keyword (keyword contents info
)
1176 "Transcode a KEYWORD element from Org to Texinfo.
1177 CONTENTS is nil. INFO is a plist holding contextual information."
1178 (let ((key (org-element-property :key keyword
))
1179 (value (org-element-property :value keyword
)))
1181 ((string= key
"TEXINFO") value
)
1182 ((string= key
"CINDEX") (format "@cindex %s" value
))
1183 ((string= key
"FINDEX") (format "@findex %s" value
))
1184 ((string= key
"KINDEX") (format "@kindex %s" value
))
1185 ((string= key
"PINDEX") (format "@pindex %s" value
))
1186 ((string= key
"TINDEX") (format "@tindex %s" value
))
1187 ((string= key
"VINDEX") (format "@vindex %s" value
)))))
1191 (defun org-texinfo-line-break (line-break contents info
)
1192 "Transcode a LINE-BREAK object from Org to Texinfo.
1193 CONTENTS is nil. INFO is a plist holding contextual information."
1198 (defun org-texinfo-link (link desc info
)
1199 "Transcode a LINK object from Org to Texinfo.
1201 DESC is the description part of the link, or the empty string.
1202 INFO is a plist holding contextual information. See
1204 (let* ((type (org-element-property :type link
))
1205 (raw-path (org-element-property :path link
))
1206 ;; Ensure DESC really exists, or set it to nil.
1207 (desc (and (not (string= desc
"")) desc
))
1209 ((member type
'("http" "https" "ftp"))
1210 (concat type
":" raw-path
))
1211 ((and (string= type
"file") (file-name-absolute-p raw-path
))
1212 (concat "file:" raw-path
))
1214 (email (if (string= type
"mailto")
1215 (let ((text (replace-regexp-in-string
1216 "@" "@@" raw-path
)))
1217 (concat text
(if desc
(concat "," desc
))))))
1220 ;; Links pointing to a headline: Find destination and build
1221 ;; appropriate referencing command.
1222 ((member type
'("custom-id" "id"))
1223 (let ((destination (org-export-resolve-id-link link info
)))
1224 (case (org-element-type destination
)
1225 ;; Id link points to an external file.
1227 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1228 (format "@uref{file://%s}" destination
)))
1229 ;; LINK points to a headline. Use the headline as the NODE target
1231 (format "@ref{%s,%s}"
1232 (org-texinfo--get-node destination info
)
1235 (let ((path (org-export-solidify-link-text path
)))
1236 (if (not desc
) (format "@ref{%s}" path
)
1237 (format "@ref{%s,,%s}" path desc
)))))))
1238 ((member type
'("info"))
1239 (let* ((info-path (split-string path
"[:#]"))
1240 (info-manual (car info-path
))
1241 (info-node (or (cadr info-path
) "top"))
1242 (title (or desc
"")))
1243 (format "@ref{%s,%s,,%s,}" info-node title info-manual
)))
1244 ((member type
'("fuzzy"))
1245 (let ((destination (org-export-resolve-fuzzy-link link info
)))
1246 (case (org-element-type destination
)
1247 ;; Id link points to an external file.
1249 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1250 (format "@uref{file://%s}" destination
)))
1251 ;; LINK points to a headline. Use the headline as the NODE target
1253 (format "@ref{%s,%s}"
1254 (org-texinfo--get-node destination info
)
1257 (let ((path (org-export-solidify-link-text path
)))
1258 (if (not desc
) (format "@ref{%s}" path
)
1259 (format "@ref{%s,,%s}" path desc
)))))))
1260 ;; Special case for email addresses
1262 (format "@email{%s}" email
))
1263 ;; External link with a description part.
1264 ((and path desc
) (format "@uref{%s,%s}" path desc
))
1265 ;; External link without a description part.
1266 (path (format "@uref{%s}" path
))
1267 ;; No path, only description. Try to do something useful.
1268 (t (format org-texinfo-link-with-unknown-path-format desc
)))))
1273 (defun org-texinfo-make-menu (info level
)
1274 "Create the menu for inclusion in the texifo document.
1276 INFO is the parsed buffer that contains the headlines. LEVEL
1277 determines whether to make the main menu, or the detailed menu.
1279 This is only used for generating the primary menu. In-Node menus
1280 are generated directly."
1281 (let ((parse (plist-get info
:parse-tree
)))
1283 ;; Generate the main menu
1284 ((eq level
'main
) (org-texinfo--build-menu parse
1 info
))
1285 ;; Generate the detailed (recursive) menu
1286 ((eq level
'detailed
)
1287 ;; Requires recursion
1288 ;;(org-texinfo--build-detailed-menu parse top info)
1289 (org-texinfo--build-menu parse
1 info
'detailed
)))))
1293 (defun org-texinfo-paragraph (paragraph contents info
)
1294 "Transcode a PARAGRAPH element from Org to Texinfo.
1295 CONTENTS is the contents of the paragraph, as a string. INFO is
1296 the plist used as a communication channel."
1301 (defun org-texinfo-plain-list (plain-list contents info
)
1302 "Transcode a PLAIN-LIST element from Org to Texinfo.
1303 CONTENTS is the contents of the list. INFO is a plist holding
1304 contextual information."
1305 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1306 (indic (or (plist-get attr
:indic
) org-texinfo-def-table-markup
))
1307 (table-type (plist-get attr
:table-type
))
1308 (type (org-element-property :type plain-list
))
1310 ((eq type
'ordered
) "enumerate")
1311 ((eq type
'unordered
) "itemize")
1312 ((member table-type
'("ftable" "vtable")) table-type
)
1314 (format "@%s\n%s@end %s"
1315 (if (eq type
'descriptive
) (concat list-type
" " indic
) list-type
)
1321 (defun org-texinfo-plain-text (text info
)
1322 "Transcode a TEXT string from Org to Texinfo.
1323 TEXT is the string to transcode. INFO is a plist holding
1324 contextual information."
1325 ;; First protect @, { and }.
1326 (let ((output (org-texinfo--sanitize-content text
)))
1327 ;; Activate smart quotes. Be sure to provide original TEXT string
1328 ;; since OUTPUT may have been modified.
1329 (when (plist-get info
:with-smart-quotes
)
1331 (org-export-activate-smart-quotes output
:texinfo info text
)))
1332 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1333 (let ((case-fold-search nil
)
1335 (while (string-match "\\(\\(?:La\\)?TeX\\)" output start
)
1336 (setq output
(replace-match
1337 (format "@%s{}" (match-string 1 output
)) nil t output
)
1338 start
(match-end 0))))
1339 ;; Convert special strings.
1340 (when (plist-get info
:with-special-strings
)
1341 (while (string-match (regexp-quote "...") output
)
1342 (setq output
(replace-match "@dots{}" nil t output
))))
1343 ;; Handle break preservation if required.
1344 (when (plist-get info
:preserve-breaks
)
1345 (setq output
(replace-regexp-in-string
1346 "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output
)))
1352 (defun org-texinfo-planning (planning contents info
)
1353 "Transcode a PLANNING element from Org to Texinfo.
1354 CONTENTS is nil. INFO is a plist holding contextual
1362 (let ((closed (org-element-property :closed planning
)))
1365 (format "@strong{%s} " org-closed-string
)
1366 (format org-texinfo-inactive-timestamp-format
1368 (org-element-property :raw-value closed
))))))
1369 (let ((deadline (org-element-property :deadline planning
)))
1372 (format "@strong{%s} " org-deadline-string
)
1373 (format org-texinfo-active-timestamp-format
1375 (org-element-property :raw-value deadline
))))))
1376 (let ((scheduled (org-element-property :scheduled planning
)))
1379 (format "@strong{%s} " org-scheduled-string
)
1380 (format org-texinfo-active-timestamp-format
1382 (org-element-property :raw-value scheduled
))))))))
1388 (defun org-texinfo-property-drawer (property-drawer contents info
)
1389 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1390 CONTENTS is nil. INFO is a plist holding contextual
1392 ;; The property drawer isn't exported but we want separating blank
1393 ;; lines nonetheless.
1398 (defun org-texinfo-quote-block (quote-block contents info
)
1399 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1400 CONTENTS holds the contents of the block. INFO is a plist
1401 holding contextual information."
1402 (let* ((title (org-element-property :name quote-block
))
1403 (start-quote (concat "@quotation"
1405 (format " %s" title
)))))
1406 (format "%s\n%s@end quotation" start-quote contents
)))
1410 (defun org-texinfo-quote-section (quote-section contents info
)
1411 "Transcode a QUOTE-SECTION element from Org to Texinfo.
1412 CONTENTS is nil. INFO is a plist holding contextual information."
1413 (let ((value (org-remove-indentation
1414 (org-element-property :value quote-section
))))
1415 (when value
(format "@verbatim\n%s@end verbatim" value
))))
1419 (defun org-texinfo-radio-target (radio-target text info
)
1420 "Transcode a RADIO-TARGET object from Org to Texinfo.
1421 TEXT is the text of the target. INFO is a plist holding
1422 contextual information."
1423 (format "@anchor{%s}%s"
1424 (org-export-solidify-link-text
1425 (org-element-property :value radio-target
))
1430 (defun org-texinfo-section (section contents info
)
1431 "Transcode a SECTION element from Org to Texinfo.
1432 CONTENTS holds the contents of the section. INFO is a plist
1433 holding contextual information."
1438 (defun org-texinfo-special-block (special-block contents info
)
1439 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1440 CONTENTS holds the contents of the block. INFO is a plist used
1441 as a communication channel."
1446 (defun org-texinfo-src-block (src-block contents info
)
1447 "Transcode a SRC-BLOCK element from Org to Texinfo.
1448 CONTENTS holds the contents of the item. INFO is a plist holding
1449 contextual information."
1450 (let* ((lang (org-element-property :language src-block
))
1451 (lisp-p (string-match-p "lisp" lang
))
1452 (src-contents (org-texinfo--sanitize-content
1453 (org-export-format-code-default src-block info
))))
1455 ;; Case 1. Lisp Block
1457 (format "@lisp\n%s@end lisp"
1459 ;; Case 2. Other blocks
1461 (format "@example\n%s@end example"
1464 ;;; Statistics Cookie
1466 (defun org-texinfo-statistics-cookie (statistics-cookie contents info
)
1467 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1468 CONTENTS is nil. INFO is a plist holding contextual information."
1469 (org-element-property :value statistics-cookie
))
1473 (defun org-texinfo-subscript (subscript contents info
)
1474 "Transcode a SUBSCRIPT object from Org to Texinfo.
1475 CONTENTS is the contents of the object. INFO is a plist holding
1476 contextual information."
1477 (format "@math{_%s}" contents
))
1481 (defun org-texinfo-superscript (superscript contents info
)
1482 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1483 CONTENTS is the contents of the object. INFO is a plist holding
1484 contextual information."
1485 (format "@math{^%s}" contents
))
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."
1493 (if (eq (org-element-property :type table
) 'table.el
)
1494 (format "@verbatim\n%s@end verbatim"
1495 (org-element-normalize-string
1496 (org-element-property :value table
)))
1497 (let* ((col-width (org-export-read-attribute :attr_texinfo table
:columns
))
1499 (if col-width
(format "@columnfractions %s" col-width
)
1500 (org-texinfo-table-column-widths table info
))))
1501 (format "@multitable %s\n%s@end multitable"
1505 (defun org-texinfo-table-column-widths (table info
)
1506 "Determine the largest table cell in each column to process alignment.
1507 TABLE is the table element to transcode. INFO is a plist used as
1508 a communication channel."
1509 (let ((widths (make-vector (cdr (org-export-table-dimensions table info
)) 0)))
1510 (org-element-map table
'table-row
1513 (org-element-map row
'table-cell
1515 ;; Length of the cell in the original buffer is only an
1516 ;; approximation of the length of the cell in the
1517 ;; output. It can sometimes fail (e.g. it considers
1518 ;; "/a/" being larger than "ab").
1519 (let ((w (- (org-element-property :contents-end cell
)
1520 (org-element-property :contents-begin cell
))))
1521 (aset widths idx
(max w
(aref widths idx
))))
1525 (format "{%s}" (mapconcat (lambda (w) (make-string w ?a
)) widths
"} {"))))
1529 (defun org-texinfo-table-cell (table-cell contents info
)
1530 "Transcode a TABLE-CELL element from Org to Texinfo.
1531 CONTENTS is the cell contents. INFO is a plist used as
1532 a communication channel."
1533 (concat (if (and contents
1534 org-texinfo-table-scientific-notation
1535 (string-match orgtbl-exp-regexp contents
))
1536 ;; Use appropriate format string for scientific
1538 (format org-texinfo-table-scientific-notation
1539 (match-string 1 contents
)
1540 (match-string 2 contents
))
1542 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1546 (defun org-texinfo-table-row (table-row contents info
)
1547 "Transcode a TABLE-ROW element from Org to Texinfo.
1548 CONTENTS is the contents of the row. INFO is a plist used as
1549 a communication channel."
1550 ;; Rules are ignored since table separators are deduced from
1551 ;; borders of the current row.
1552 (when (eq (org-element-property :type table-row
) 'standard
)
1554 (if (and (= 1 (org-export-table-row-group table-row info
))
1555 (org-export-table-has-header-p
1556 (org-export-get-parent-table table-row
) info
))
1559 (concat rowgroup-tag contents
"\n"))))
1563 (defun org-texinfo-target (target contents info
)
1564 "Transcode a TARGET object from Org to Texinfo.
1565 CONTENTS is nil. INFO is a plist holding contextual
1567 (format "@anchor{%s}"
1568 (org-export-solidify-link-text (org-element-property :value target
))))
1572 (defun org-texinfo-timestamp (timestamp contents info
)
1573 "Transcode a TIMESTAMP object from Org to Texinfo.
1574 CONTENTS is nil. INFO is a plist holding contextual
1576 (let ((value (org-texinfo-plain-text
1577 (org-timestamp-translate timestamp
) info
)))
1578 (case (org-element-property :type timestamp
)
1579 ((active active-range
)
1580 (format org-texinfo-active-timestamp-format value
))
1581 ((inactive inactive-range
)
1582 (format org-texinfo-inactive-timestamp-format value
))
1583 (t (format org-texinfo-diary-timestamp-format value
)))))
1587 (defun org-texinfo-verbatim (verbatim contents info
)
1588 "Transcode a VERBATIM object from Org to Texinfo.
1589 CONTENTS is nil. INFO is a plist used as a communication
1591 (org-texinfo--text-markup (org-element-property :value verbatim
) 'verbatim
))
1595 (defun org-texinfo-verse-block (verse-block contents info
)
1596 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1597 CONTENTS is verse block contents. INFO is a plist holding
1598 contextual information."
1599 (format "@display\n%s@end display" contents
))
1602 ;;; Interactive functions
1604 (defun org-texinfo-export-to-texinfo
1605 (&optional async subtreep visible-only body-only ext-plist
)
1606 "Export current buffer to a Texinfo file.
1608 If narrowing is active in the current buffer, only export its
1611 If a region is active, export that region.
1613 A non-nil optional argument ASYNC means the process should happen
1614 asynchronously. The resulting file should be accessible through
1615 the `org-export-stack' interface.
1617 When optional argument SUBTREEP is non-nil, export the sub-tree
1618 at point, extracting information from the headline properties
1621 When optional argument VISIBLE-ONLY is non-nil, don't export
1622 contents of hidden elements.
1624 When optional argument BODY-ONLY is non-nil, only write code
1625 between \"\\begin{document}\" and \"\\end{document}\".
1627 EXT-PLIST, when provided, is a property list with external
1628 parameters overriding Org default settings, but still inferior to
1629 file-local settings.
1631 Return output file's name."
1633 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1634 (org-export-coding-system `,org-texinfo-coding-system
))
1635 (org-export-to-file 'texinfo outfile
1636 async subtreep visible-only body-only ext-plist
)))
1638 (defun org-texinfo-export-to-info
1639 (&optional async subtreep visible-only body-only ext-plist
)
1640 "Export current buffer to Texinfo then process through to INFO.
1642 If narrowing is active in the current buffer, only export its
1645 If a region is active, export that region.
1647 A non-nil optional argument ASYNC means the process should happen
1648 asynchronously. The resulting file should be accessible through
1649 the `org-export-stack' interface.
1651 When optional argument SUBTREEP is non-nil, export the sub-tree
1652 at point, extracting information from the headline properties
1655 When optional argument VISIBLE-ONLY is non-nil, don't export
1656 contents of hidden elements.
1658 When optional argument BODY-ONLY is non-nil, only write code
1659 between \"\\begin{document}\" and \"\\end{document}\".
1661 EXT-PLIST, when provided, is a property list with external
1662 parameters overriding Org default settings, but still inferior to
1663 file-local settings.
1665 When optional argument PUB-DIR is set, use it as the publishing
1668 Return INFO file's name."
1670 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1671 (org-export-coding-system `,org-texinfo-coding-system
))
1672 (org-export-to-file 'texinfo outfile
1673 async subtreep visible-only body-only ext-plist
1674 (lambda (file) (org-texinfo-compile file
)))))
1677 (defun org-texinfo-publish-to-texinfo (plist filename pub-dir
)
1678 "Publish an org file to Texinfo.
1680 FILENAME is the filename of the Org file to be published. PLIST
1681 is the property list for the given project. PUB-DIR is the
1682 publishing directory.
1684 Return output file name."
1685 (org-publish-org-to 'texinfo filename
".texi" plist pub-dir
))
1688 (defun org-texinfo-convert-region-to-texinfo ()
1689 "Assume the current region has org-mode syntax, and convert it to Texinfo.
1690 This can be used in any buffer. For example, you can write an
1691 itemized list in org-mode syntax in an Texinfo buffer and use
1692 this command to convert it."
1694 (org-export-replace-region-by 'texinfo
))
1696 (defun org-texinfo-compile (file)
1697 "Compile a texinfo file.
1699 FILE is the name of the file being compiled. Processing is
1700 done through the command specified in `org-texinfo-info-process'.
1702 Return INFO file name or an error if it couldn't be produced."
1703 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file
)))
1704 (full-name (file-truename file
))
1705 (out-dir (file-name-directory file
))
1706 ;; Properly set working directory for compilation.
1707 (default-directory (if (file-name-absolute-p file
)
1708 (file-name-directory full-name
)
1711 (message (format "Processing Texinfo file %s..." file
))
1712 (save-window-excursion
1714 ;; A function is provided: Apply it.
1715 ((functionp org-texinfo-info-process
)
1716 (funcall org-texinfo-info-process
(shell-quote-argument file
)))
1717 ;; A list is provided: Replace %b, %f and %o with appropriate
1718 ;; values in each command before applying it. Output is
1719 ;; redirected to "*Org INFO Texinfo Output*" buffer.
1720 ((consp org-texinfo-info-process
)
1721 (let ((outbuf (get-buffer-create "*Org INFO Texinfo Output*")))
1725 (replace-regexp-in-string
1726 "%b" (shell-quote-argument base-name
)
1727 (replace-regexp-in-string
1728 "%f" (shell-quote-argument full-name
)
1729 (replace-regexp-in-string
1730 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
1732 org-texinfo-info-process
)
1733 ;; Collect standard errors from output buffer.
1734 (setq errors
(org-texinfo-collect-errors outbuf
))))
1735 (t (error "No valid command to process to Info")))
1736 (let ((infofile (concat out-dir base-name
".info")))
1737 ;; Check for process failure. Provide collected errors if
1739 (if (not (file-exists-p infofile
))
1740 (error (concat (format "INFO file %s wasn't produced" infofile
)
1741 (when errors
(concat ": " errors
))))
1742 ;; Else remove log files, when specified, and signal end of
1743 ;; process to user, along with any error encountered.
1744 (when org-texinfo-remove-logfiles
1745 (dolist (ext org-texinfo-logfiles-extensions
)
1746 (let ((file (concat out-dir base-name
"." ext
)))
1747 (when (file-exists-p file
) (delete-file file
)))))
1748 (message (concat "Process completed"
1749 (if (not errors
) "."
1750 (concat " with errors: " errors
)))))
1751 ;; Return output file name.
1754 (defun org-texinfo-collect-errors (buffer)
1755 "Collect some kind of errors from \"makeinfo\" command output.
1757 BUFFER is the buffer containing output.
1759 Return collected error types as a string, or nil if there was
1761 (with-current-buffer buffer
1763 (goto-char (point-min))
1764 ;; Find final "makeinfo" run.
1766 (let ((case-fold-search t
)
1768 (when (save-excursion
1769 (re-search-forward "perhaps incorrect sectioning?" nil t
))
1770 (setq errors
(concat errors
" [incorrect sectioning]")))
1771 (when (save-excursion
1772 (re-search-forward "missing close brace" nil t
))
1773 (setq errors
(concat errors
" [syntax error]")))
1774 (when (save-excursion
1775 (re-search-forward "Unknown command" nil t
))
1776 (setq errors
(concat errors
" [undefined @command]")))
1777 (when (save-excursion
1778 (re-search-forward "No matching @end" nil t
))
1779 (setq errors
(concat errors
" [block incomplete]")))
1780 (when (save-excursion
1781 (re-search-forward "requires a sectioning" nil t
))
1782 (setq errors
(concat errors
" [invalid section command]")))
1783 (when (save-excursion
1784 (re-search-forward "\\[unexpected\]" nil t
))
1785 (setq errors
(concat errors
" [unexpected error]")))
1786 (when (save-excursion
1787 (re-search-forward "misplaced " nil t
))
1788 (setq errors
(concat errors
" [syntax error]")))
1789 (and (org-string-nw-p errors
) (org-trim errors
)))))))
1792 (provide 'ox-texinfo
)
1795 ;; generated-autoload-file: "org-loaddefs.el"
1798 ;;; ox-texinfo.el ends here