1 ;;; ox-texinfo.el --- Texinfo Back-End for Org Export Engine
3 ;; Copyright (C) 2012-2014 Free Software Foundation, Inc.
4 ;; Author: Jonathan Leech-Pepin <jonathan.leechpepin at gmail dot com>
5 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; See Org manual for details.
28 (eval-when-compile (require 'cl
))
31 (defvar orgtbl-exp-regexp
)
37 (org-export-define-backend 'texinfo
38 '((bold . org-texinfo-bold
)
39 (center-block . org-texinfo-center-block
)
40 (clock . org-texinfo-clock
)
41 (code . org-texinfo-code
)
42 (comment .
(lambda (&rest args
) ""))
43 (comment-block .
(lambda (&rest args
) ""))
44 (drawer . org-texinfo-drawer
)
45 (dynamic-block . org-texinfo-dynamic-block
)
46 (entity . org-texinfo-entity
)
47 (example-block . org-texinfo-example-block
)
48 (export-block . org-texinfo-export-block
)
49 (export-snippet . org-texinfo-export-snippet
)
50 (fixed-width . org-texinfo-fixed-width
)
51 (footnote-definition . org-texinfo-footnote-definition
)
52 (footnote-reference . org-texinfo-footnote-reference
)
53 (headline . org-texinfo-headline
)
54 (inline-src-block . org-texinfo-inline-src-block
)
55 (inlinetask . org-texinfo-inlinetask
)
56 (italic . org-texinfo-italic
)
57 (item . org-texinfo-item
)
58 (keyword . org-texinfo-keyword
)
59 (line-break . org-texinfo-line-break
)
60 (link . org-texinfo-link
)
61 (paragraph . org-texinfo-paragraph
)
62 (plain-list . org-texinfo-plain-list
)
63 (plain-text . org-texinfo-plain-text
)
64 (planning . org-texinfo-planning
)
65 (property-drawer . org-texinfo-property-drawer
)
66 (quote-block . org-texinfo-quote-block
)
67 (quote-section . org-texinfo-quote-section
)
68 (radio-target . org-texinfo-radio-target
)
69 (section . org-texinfo-section
)
70 (special-block . org-texinfo-special-block
)
71 (src-block . org-texinfo-src-block
)
72 (statistics-cookie . org-texinfo-statistics-cookie
)
73 (subscript . org-texinfo-subscript
)
74 (superscript . org-texinfo-superscript
)
75 (table . org-texinfo-table
)
76 (table-cell . org-texinfo-table-cell
)
77 (table-row . org-texinfo-table-row
)
78 (target . org-texinfo-target
)
79 (template . org-texinfo-template
)
80 (timestamp . org-texinfo-timestamp
)
81 (verbatim . org-texinfo-verbatim
)
82 (verse-block . org-texinfo-verse-block
))
83 :export-block
"TEXINFO"
85 '((:filter-headline . org-texinfo-filter-section-blank-lines
)
86 (:filter-section . org-texinfo-filter-section-blank-lines
))
88 '(?i
"Export to Texinfo"
89 ((?t
"As TEXI file" org-texinfo-export-to-texinfo
)
90 (?i
"As INFO file" org-texinfo-export-to-info
)))
92 '((:texinfo-filename
"TEXINFO_FILENAME" nil nil t
)
93 (:texinfo-class
"TEXINFO_CLASS" nil org-texinfo-default-class t
)
94 (:texinfo-header
"TEXINFO_HEADER" nil nil newline
)
95 (:texinfo-post-header
"TEXINFO_POST_HEADER" nil nil newline
)
96 (:subtitle
"SUBTITLE" nil nil newline
)
97 (:subauthor
"SUBAUTHOR" nil nil newline
)
98 (:texinfo-dircat
"TEXINFO_DIR_CATEGORY" nil nil t
)
99 (:texinfo-dirtitle
"TEXINFO_DIR_TITLE" nil nil t
)
100 (:texinfo-dirdesc
"TEXINFO_DIR_DESC" nil nil t
)
101 (:texinfo-printed-title
"TEXINFO_PRINTED_TITLE" nil nil t
)))
105 ;;; User Configurable Variables
107 (defgroup org-export-texinfo nil
108 "Options for exporting Org mode files to Texinfo."
109 :tag
"Org Export Texinfo"
111 :package-version
'(Org .
"8.0")
116 (defcustom org-texinfo-coding-system nil
117 "Default document encoding for Texinfo output.
119 If `nil' it will default to `buffer-file-coding-system'."
120 :group
'org-export-texinfo
121 :type
'coding-system
)
123 (defcustom org-texinfo-default-class
"info"
124 "The default Texinfo class."
125 :group
'org-export-texinfo
126 :type
'(string :tag
"Texinfo class"))
128 (defcustom org-texinfo-classes
130 "@documentencoding AUTO\n@documentlanguage AUTO"
131 ("@chapter %s" .
"@unnumbered %s")
132 ("@section %s" .
"@unnumberedsec %s")
133 ("@subsection %s" .
"@unnumberedsubsec %s")
134 ("@subsubsection %s" .
"@unnumberedsubsubsec %s")))
135 "Alist of Texinfo classes and associated header and structure.
136 If #+TEXINFO_CLASS is set in the buffer, use its value and the
137 associated information. Here is the structure of each cell:
141 \(numbered-section . unnumbered-section)
148 The header string is inserted in the header of the generated
149 document, right after \"@setfilename\" and \"@settitle\"
152 If it contains the special string
154 \"@documentencoding AUTO\"
156 \"AUTO\" will be replaced with an appropriate coding system. See
157 `org-texinfo-coding-system' for more information. Likewise, if
158 the string contains the special string
160 \"@documentlanguage AUTO\"
162 \"AUTO\" will be replaced with the language defined in the
163 buffer, through #+LANGUAGE keyword, or globally, with
164 `org-export-default-language', which see.
167 The sectioning structure
168 ------------------------
170 The sectioning structure of the class is given by the elements
171 following the header string. For each sectioning level, a number
172 of strings is specified. A %s formatter is mandatory in each
173 section string and will be replaced by the title of the section.
175 Instead of a list of sectioning commands, you can also specify
176 a function name. That function will be called with two
177 parameters, the reduced) level of the headline, and a predicate
178 non-nil when the headline should be numbered. It must return
179 a format string in which the section title will be added."
180 :group
'org-export-texinfo
182 :package-version
'(Org .
"8.2")
184 (list (string :tag
"Texinfo class")
185 (string :tag
"Texinfo header")
186 (repeat :tag
"Levels" :inline t
189 (string :tag
" numbered")
190 (string :tag
"unnumbered"))
191 (function :tag
"Hook computing sectioning"))))))
195 (defcustom org-texinfo-format-headline-function
'ignore
196 "Function to format headline text.
198 This function will be called with 5 arguments:
199 TODO the todo keyword (string or nil).
200 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
201 PRIORITY the priority of the headline (integer or nil)
202 TEXT the main headline text (string).
203 TAGS the tags as a list of strings (list of strings or nil).
205 The function result will be used in the section format string.
207 As an example, one could set the variable to the following, in
208 order to reproduce the default set-up:
210 \(defun org-texinfo-format-headline (todo todo-type priority text tags)
211 \"Default format function for a headline.\"
213 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
215 \(format \"\\\\framebox{\\\\#%c} \" priority))
218 \(format \"\\\\hfill{}\\\\textsc{%s}\"
219 \(mapconcat 'identity tags \":\"))))"
220 :group
'org-export-texinfo
223 ;;;; Node listing (menu)
225 (defcustom org-texinfo-node-description-column
32
226 "Column at which to start the description in the node listings.
227 If a node title is greater than this length, the description will
228 be placed after the end of the title."
229 :group
'org-export-texinfo
234 (defcustom org-texinfo-active-timestamp-format
"@emph{%s}"
235 "A printf format string to be applied to active timestamps."
236 :group
'org-export-texinfo
239 (defcustom org-texinfo-inactive-timestamp-format
"@emph{%s}"
240 "A printf format string to be applied to inactive timestamps."
241 :group
'org-export-texinfo
244 (defcustom org-texinfo-diary-timestamp-format
"@emph{%s}"
245 "A printf format string to be applied to diary timestamps."
246 :group
'org-export-texinfo
251 (defcustom org-texinfo-link-with-unknown-path-format
"@indicateurl{%s}"
252 "Format string for links with unknown path type."
253 :group
'org-export-texinfo
258 (defcustom org-texinfo-tables-verbatim nil
259 "When non-nil, tables are exported verbatim."
260 :group
'org-export-texinfo
263 (defcustom org-texinfo-table-scientific-notation
"%s\\,(%s)"
264 "Format string to display numbers in scientific notation.
265 The format should have \"%s\" twice, for mantissa and exponent
266 \(i.e. \"%s\\\\times10^{%s}\").
268 When nil, no transformation is made."
269 :group
'org-export-texinfo
271 (string :tag
"Format string")
272 (const :tag
"No formatting" nil
)))
274 (defcustom org-texinfo-def-table-markup
"@samp"
275 "Default setting for @table environments."
276 :group
'org-export-texinfo
281 (defcustom org-texinfo-text-markup-alist
'((bold .
"@strong{%s}")
283 (italic .
"@emph{%s}")
286 "Alist of Texinfo expressions to convert text markup.
288 The key must be a symbol among `bold', `italic' and `comment'.
289 The value is a formatting string to wrap fontified text with.
291 Value can also be set to the following symbols: `verb' and
292 `code'. For the former, Org will use \"@verb\" to
293 create a format string and select a delimiter character that
294 isn't in the string. For the latter, Org will use \"@code\"
295 to typeset and try to protect special characters.
297 If no association can be found for a given markup, text will be
299 :group
'org-export-texinfo
301 :options
'(bold code italic verbatim comment
))
305 (defcustom org-texinfo-format-drawer-function
306 (lambda (name contents
) contents
)
307 "Function called to format a drawer in Texinfo code.
309 The function must accept two parameters:
310 NAME the drawer name, like \"LOGBOOK\"
311 CONTENTS the contents of the drawer.
313 The function should return the string to be exported.
315 The default function simply returns the value of CONTENTS."
316 :group
'org-export-texinfo
318 :package-version
'(Org .
"8.2")
323 (defcustom org-texinfo-format-inlinetask-function
'ignore
324 "Function called to format an inlinetask in Texinfo code.
326 The function must accept six parameters:
327 TODO the todo keyword, as a string
328 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
329 PRIORITY the inlinetask priority, as a string
330 NAME the inlinetask name, as a string.
331 TAGS the inlinetask tags, as a list of strings.
332 CONTENTS the contents of the inlinetask, as a string.
334 The function should return the string to be exported.
336 For example, the variable could be set to the following function
337 in order to mimic default behavior:
339 \(defun org-texinfo-format-inlinetask \(todo type priority name tags contents\)
340 \"Format an inline task element for Texinfo export.\"
344 \(format \"@strong{%s} \" todo))
345 \(when priority (format \"#%c \" priority))
349 \(mapconcat 'identity tags \":\")))))
350 \(format (concat \"@center %s\n\n\"
353 full-title contents))"
354 :group
'org-export-texinfo
359 (defcustom org-texinfo-info-process
361 "Commands to process a Texinfo file to an INFO file.
362 This is list of strings, each of them will be given to the shell
363 as a command. %f in the command will be replaced by the full
364 file name, %b by the file base name \(i.e without extension) and
365 %o by the base directory of the file."
366 :group
'org-export-texinfo
367 :type
'(repeat :tag
"Shell command sequence"
368 (string :tag
"Shell command")))
370 (defcustom org-texinfo-logfiles-extensions
371 '("aux" "toc" "cp" "fn" "ky" "pg" "tp" "vr")
372 "The list of file extensions to consider as Texinfo logfiles.
373 The logfiles will be remove if `org-texinfo-remove-logfiles' is
375 :group
'org-export-texinfo
376 :type
'(repeat (string :tag
"Extension")))
378 (defcustom org-texinfo-remove-logfiles t
379 "Non-nil means remove the logfiles produced by compiling a Texinfo file.
380 By default, logfiles are files with these extensions: .aux, .toc,
381 .cp, .fn, .ky, .pg and .tp. To define the set of logfiles to remove,
382 set `org-texinfo-logfiles-extensions'."
383 :group
'org-export-latex
388 (defconst org-texinfo-max-toc-depth
4
389 "Maximum depth for creation of detailed menu listings. Beyond
390 this depth Texinfo will not recognize the nodes and will cause
391 errors. Left as a constant in case this value ever changes.")
393 (defconst org-texinfo-supported-coding-systems
394 '("US-ASCII" "UTF-8" "ISO-8859-15" "ISO-8859-1" "ISO-8859-2" "koi8-r" "koi8-u")
395 "List of coding systems supported by Texinfo, as strings.
396 Specified coding system will be matched against these strings.
397 If two strings share the same prefix (e.g. \"ISO-8859-1\" and
398 \"ISO-8859-15\"), the most specific one has to be listed first.")
401 ;;; Internal Functions
403 (defun org-texinfo-filter-section-blank-lines (headline back-end info
)
404 "Filter controlling number of blank lines after a section."
405 (let ((blanks (make-string 2 ?
\n)))
406 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline
)))
408 (defun org-texinfo--find-verb-separator (s)
409 "Return a character not used in string S.
410 This is used to choose a separator for constructs like \\verb."
411 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
412 (loop for c across ll
413 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
414 return
(char-to-string c
))))
416 (defun org-texinfo--make-option-string (options)
417 "Return a comma separated string of keywords and values.
418 OPTIONS is an alist where the key is the options keyword as
419 a string, and the value a list containing the keyword value, or
421 (mapconcat (lambda (pair)
423 (when (> (length (second pair
)) 0)
424 (concat "=" (second pair
)))))
428 (defun org-texinfo--text-markup (text markup
)
429 "Format TEXT depending on MARKUP text markup.
430 See `org-texinfo-text-markup-alist' for details."
431 (let ((fmt (cdr (assq markup org-texinfo-text-markup-alist
))))
433 ;; No format string: Return raw text.
436 (let ((separator (org-texinfo--find-verb-separator text
)))
437 (concat "@verb{" separator text separator
"}")))
442 (while (string-match "[@{}]" text
)
443 (setq char
(match-string 0 text
))
444 (if (> (match-beginning 0) 0)
445 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
446 (setq text
(substring text
(1+ (match-beginning 0))))
447 (setq char
(concat "@" char
)
448 rtn
(concat rtn char
)))
449 (setq text
(concat rtn text
)
452 ;; Else use format string.
453 (t (format fmt text
)))))
455 (defun org-texinfo--get-node (headline info
)
456 "Return node entry associated to HEADLINE.
457 INFO is a plist used as a communication channel."
458 (let ((menu-title (org-export-get-alt-title headline info
)))
459 (org-texinfo--sanitize-menu
460 (replace-regexp-in-string
462 (if menu-title
(org-export-data menu-title info
)
463 (org-texinfo--sanitize-headline
464 (org-element-property :title headline
) info
))))))
466 ;;;; Headline sanitizing
468 (defun org-texinfo--sanitize-headline (headline info
)
469 "Remove all formatting from the text of a headline for use in
470 node and menu listing."
472 (org-texinfo--sanitize-headline-contents headline info
) " "))
474 (defun org-texinfo--sanitize-headline-contents (headline info
)
475 "Retrieve the content of the headline.
477 Any content that can contain further formatting is checked
478 recursively, to ensure that nested content is also properly
480 (loop for contents in headline append
484 (list (replace-regexp-in-string " $" "" contents
)))
485 ;; Is exported as-is (value)
486 ((org-element-map contents
'(verbatim code
)
487 (lambda (value) (org-element-property :value value
)) info
))
488 ;; Has content and recurse into the content
489 ((org-element-contents contents
)
490 (org-texinfo--sanitize-headline-contents
491 (org-element-contents contents
) info
)))))
495 (defun org-texinfo--sanitize-menu (title)
496 "Remove invalid characters from TITLE for use in menus and
499 Based on Texinfo specifications, the following must be removed:
501 (replace-regexp-in-string "[@{}():,.]" "" title
))
503 ;;;; Content sanitizing
505 (defun org-texinfo--sanitize-content (text)
506 "Ensure characters are properly escaped when used in headlines or blocks.
508 Escape characters are: @ { }"
509 (replace-regexp-in-string "\\\([@{}]\\\)" "@\\1" text
))
513 (defun org-texinfo--build-menu (tree level info
&optional detailed
)
514 "Create the @menu/@end menu information from TREE at headline
517 TREE contains the parse-tree to work with, either of the entire
518 document or of a specific parent headline. LEVEL indicates what
519 level of headlines to look at when generating the menu. INFO is
520 a plist containing contextual information.
522 Detailed determines whether to build a single level of menu, or
523 recurse into all children as well."
524 (let ((menu (org-texinfo--generate-menu-list tree level info
))
528 ;; Looping is done within the menu generation.
529 (setq text-menu
(org-texinfo--generate-detailed menu level info
)))
531 (setq text-menu
(org-texinfo--generate-menu-items menu info
))))
533 (setq output
(org-texinfo--format-menu text-menu
))
534 (mapconcat 'identity output
"\n"))))
536 (defun org-texinfo--generate-detailed (menu level info
)
537 "Generate a detailed listing of all subheadings within MENU starting at LEVEL.
539 MENU is the parse-tree to work with. LEVEL is the starting level
540 for the menu headlines and from which recursion occurs. INFO is
541 a plist containing contextual information."
543 (let ((max-depth (min org-texinfo-max-toc-depth
544 (plist-get info
:headline-levels
))))
545 (when (> max-depth level
)
546 (loop for headline in menu append
547 (let* ((title (org-texinfo--menu-headlines headline info
))
548 ;; Create list of menu entries for the next level
549 (sublist (org-texinfo--generate-menu-list
550 headline
(1+ level
) info
))
551 ;; Generate the menu items for that level. If
552 ;; there are none omit that heading completely,
553 ;; otherwise join the title to it's related entries.
554 (submenu (if (org-texinfo--generate-menu-items sublist info
)
556 (org-texinfo--generate-menu-items sublist info
))
558 ;; Start the process over the next level down.
559 (recursion (org-texinfo--generate-detailed sublist
(1+ level
) info
)))
560 (setq recursion
(append submenu recursion
))
563 (defun org-texinfo--generate-menu-list (tree level info
)
564 "Generate the list of headlines that are within a given level
565 of the tree for further formatting.
567 TREE is the parse-tree containing the headlines. LEVEL is the
568 headline level to generate a list of. INFO is a plist holding
569 contextual information."
570 (org-element-map tree
'headline
572 (and (= (org-export-get-relative-level head info
) level
)
573 ;; Do not take note of footnotes or copying headlines.
574 (not (org-not-nil (org-element-property :COPYING head
)))
575 (not (org-element-property :footnote-section-p head
))
580 (defun org-texinfo--generate-menu-items (items info
)
581 "Generate a list of headline information from the listing ITEMS.
583 ITEMS is a list of the headlines to be converted into entries.
584 INFO is a plist containing contextual information.
586 Returns a list containing the following information from each
587 headline: length, title, description. This is used to format the
588 menu using `org-texinfo--format-menu'."
589 (loop for headline in items collect
590 (let* ((menu-title (org-texinfo--sanitize-menu
592 (org-export-get-alt-title headline info
)
594 (title (org-texinfo--sanitize-menu
595 (org-texinfo--sanitize-headline
596 (org-element-property :title headline
) info
)))
597 (descr (org-export-data
598 (org-element-property :DESCRIPTION headline
)
600 (menu-entry (if (string= "" menu-title
) title menu-title
))
601 (len (length menu-entry
))
602 (output (list len menu-entry descr
)))
605 (defun org-texinfo--menu-headlines (headline info
)
606 "Retrieve the title from HEADLINE.
608 INFO is a plist holding contextual information.
610 Return the headline as a list of (length title description) with
611 length of -1 and nil description. This is used in
612 `org-texinfo--format-menu' to identify headlines as opposed to
614 (let ((title (org-export-data
615 (org-element-property :title headline
) info
)))
616 (list -
1 title
'nil
)))
618 (defun org-texinfo--format-menu (text-menu)
619 "Format the TEXT-MENU items to be properly printed in the menu.
621 Each entry in the menu should be provided as (length title
624 Headlines in the detailed menu are given length -1 to ensure they
625 are never confused with other entries. They also have no
628 Other menu items are output as:
631 With the spacing between :: and description based on the length
632 of the longest menu entry."
636 (mapcar (lambda (name)
637 (let* ((title (nth 1 name
))
639 (length (nth 0 name
))
641 ;;6 is "* " ":: " for inserted text
644 org-texinfo-node-description-column
646 (spacing (- column length
)
649 (concat "* " title
":: "
650 (make-string spacing ?\s
)
653 (concat "\n" title
"\n"))))
659 (defun org-texinfo-template (contents info
)
660 "Return complete document string after Texinfo conversion.
661 CONTENTS is the transcoded contents string. INFO is a plist
662 holding export options."
663 (let ((title (org-export-data (plist-get info
:title
) info
))
664 ;; Copying data is the contents of the first headline in
665 ;; parse tree with a non-nil copying property.
666 (copying (org-element-map (plist-get info
:parse-tree
) 'headline
668 (and (org-not-nil (org-element-property :COPYING hl
))
669 (org-element-contents hl
)))
672 "\\input texinfo @c -*- texinfo -*-\n"
673 "@c %**start of header\n"
674 (let ((file (or (plist-get info
:texinfo-filename
)
675 (let ((f (plist-get info
:output-file
)))
676 (and f
(concat (file-name-sans-extension f
) ".info"))))))
677 (and file
(format "@setfilename %s\n" file
)))
678 (format "@settitle %s\n" title
)
679 ;; Insert class-defined header.
680 (org-element-normalize-string
681 (let ((header (nth 1 (assoc (plist-get info
:texinfo-class
)
682 org-texinfo-classes
)))
684 (catch 'coding-system
685 (let ((case-fold-search t
)
686 (name (symbol-name (or org-texinfo-coding-system
687 buffer-file-coding-system
))))
688 (dolist (system org-texinfo-supported-coding-systems
"UTF-8")
689 (when (org-string-match-p (regexp-quote system
) name
)
690 (throw 'coding-system system
))))))
691 (language (plist-get info
:language
))
692 (case-fold-search nil
))
693 ;; Auto coding system.
694 (replace-regexp-in-string
695 "^@documentencoding \\(AUTO\\)$"
697 (replace-regexp-in-string
698 "^@documentlanguage \\(AUTO\\)$" language header nil nil
1)
700 ;; Additional header options set by #+TEXINFO_HEADER.
701 (let ((texinfo-header (plist-get info
:texinfo-header
)))
702 (and texinfo-header
(org-element-normalize-string texinfo-header
)))
703 "@c %**end of header\n\n"
704 ;; Additional options set by #+TEXINFO_POST_HEADER.
705 (let ((texinfo-post-header (plist-get info
:texinfo-post-header
)))
706 (and texinfo-post-header
707 (org-element-normalize-string texinfo-post-header
)))
710 (format "@copying\n%s@end copying\n\n"
711 (org-element-normalize-string
712 (org-export-data copying info
))))
713 ;; Info directory information. Only supply if both title and
714 ;; category are provided.
715 (let ((dircat (plist-get info
:texinfo-dircat
))
717 (let ((title (plist-get info
:texinfo-dirtitle
)))
719 (string-match "^\\(?:\\* \\)?\\(.*?\\)\\(\\.\\)?$" title
)
720 (format "* %s." (match-string 1 title
))))))
721 (when (and dircat dirtitle
)
722 (concat "@dircategory " dircat
"\n"
725 (let ((desc (plist-get info
:texinfo-dirdesc
)))
726 (cond ((not desc
) nil
)
727 ((org-string-match-p "\\.$" desc
) desc
)
728 (t (concat desc
"."))))))
729 (if dirdesc
(format "%-23s %s" dirtitle dirdesc
) dirtitle
))
731 "@end direntry\n\n")))
735 (format "@title %s\n" (or (plist-get info
:texinfo-printed-title
) title
))
736 (let ((subtitle (plist-get info
:subtitle
)))
738 (org-element-normalize-string
739 (replace-regexp-in-string "^" "@subtitle " subtitle
))))
740 (when (plist-get info
:with-author
)
743 (let ((author (org-string-nw-p
744 (org-export-data (plist-get info
:author
) info
)))
745 (email (and (plist-get info
:with-email
)
747 (org-export-data (plist-get info
:email
) info
)))))
748 (cond ((and author email
)
749 (format "@author %s (@email{%s})\n" author email
))
750 (author (format "@author %s\n" author
))
751 (email (format "@author @email{%s}\n" email
))))
753 (let ((subauthor (plist-get info
:subauthor
)))
755 (org-element-normalize-string
756 (replace-regexp-in-string "^" "@author " subauthor
))))))
757 (and copying
"@page\n@vskip 0pt plus 1filll\n@insertcopying\n")
759 ;; Table of contents.
760 (and (plist-get info
:with-toc
) "@contents\n\n")
761 ;; Configure Top Node when not for Tex
764 (format "@top %s\n" title
)
765 (and copying
"@insertcopying\n")
768 (let ((menu (org-texinfo-make-menu info
'main
))
769 (detail-menu (org-texinfo-make-menu info
'detailed
)))
774 (concat "\n@detailmenu\n"
775 " --- The Detailed Node Listing ---\n"
777 "@end detailmenu\n"))
782 (case (plist-get info
:with-creator
)
784 (comment (format "@c %s\n" (plist-get info
:creator
)))
785 (otherwise (concat (plist-get info
:creator
) "\n")))
791 ;;; Transcode Functions
795 (defun org-texinfo-bold (bold contents info
)
796 "Transcode BOLD from Org to Texinfo.
797 CONTENTS is the text with bold markup. INFO is a plist holding
798 contextual information."
799 (org-texinfo--text-markup contents
'bold
))
803 (defun org-texinfo-center-block (center-block contents info
)
804 "Transcode a CENTER-BLOCK element from Org to Texinfo.
805 CONTENTS holds the contents of the block. INFO is a plist used
806 as a communication channel."
811 (defun org-texinfo-clock (clock contents info
)
812 "Transcode a CLOCK element from Org to Texinfo.
813 CONTENTS is nil. INFO is a plist holding contextual
817 (format "@strong{%s} " org-clock-string
)
818 (format org-texinfo-inactive-timestamp-format
819 (concat (org-translate-time
820 (org-element-property :raw-value
821 (org-element-property :value clock
)))
822 (let ((time (org-element-property :duration clock
)))
823 (and time
(format " (%s)" time
)))))
828 (defun org-texinfo-code (code contents info
)
829 "Transcode a CODE object from Org to Texinfo.
830 CONTENTS is nil. INFO is a plist used as a communication
832 (org-texinfo--text-markup (org-element-property :value code
) 'code
))
836 (defun org-texinfo-drawer (drawer contents info
)
837 "Transcode a DRAWER element from Org to Texinfo.
838 CONTENTS holds the contents of the block. INFO is a plist
839 holding contextual information."
840 (let* ((name (org-element-property :drawer-name drawer
))
841 (output (funcall org-texinfo-format-drawer-function
847 (defun org-texinfo-dynamic-block (dynamic-block contents info
)
848 "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
849 CONTENTS holds the contents of the block. INFO is a plist
850 holding contextual information."
855 (defun org-texinfo-entity (entity contents info
)
856 "Transcode an ENTITY object from Org to Texinfo.
857 CONTENTS are the definition itself. INFO is a plist holding
858 contextual information."
859 (let ((ent (org-element-property :latex entity
)))
860 (if (org-element-property :latex-math-p entity
) (format "@math{%s}" ent
) ent
)))
864 (defun org-texinfo-example-block (example-block contents info
)
865 "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
866 CONTENTS is nil. INFO is a plist holding contextual
868 (format "@verbatim\n%s@end verbatim"
869 (org-export-format-code-default example-block info
)))
873 (defun org-texinfo-export-block (export-block contents info
)
874 "Transcode a EXPORT-BLOCK element from Org to Texinfo.
875 CONTENTS is nil. INFO is a plist holding contextual information."
876 (when (string= (org-element-property :type export-block
) "TEXINFO")
877 (org-remove-indentation (org-element-property :value export-block
))))
881 (defun org-texinfo-export-snippet (export-snippet contents info
)
882 "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
883 CONTENTS is nil. INFO is a plist holding contextual information."
884 (when (eq (org-export-snippet-backend export-snippet
) 'texinfo
)
885 (org-element-property :value export-snippet
)))
889 (defun org-texinfo-fixed-width (fixed-width contents info
)
890 "Transcode a FIXED-WIDTH element from Org to Texinfo.
891 CONTENTS is nil. INFO is a plist holding contextual information."
892 (format "@example\n%s\n@end example"
893 (org-remove-indentation
894 (org-texinfo--sanitize-content
895 (org-element-property :value fixed-width
)))))
897 ;;;; Footnote Reference
899 (defun org-texinfo-footnote-reference (footnote contents info
)
900 "Create a footnote reference for FOOTNOTE.
902 FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
903 plist holding contextual information."
904 (let ((def (org-export-get-footnote-definition footnote info
)))
905 (format "@footnote{%s}"
906 (org-trim (org-export-data def info
)))))
910 (defun org-texinfo-headline (headline contents info
)
911 "Transcode a HEADLINE element from Org to Texinfo.
912 CONTENTS holds the contents of the headline. INFO is a plist
913 holding contextual information."
914 (let* ((class (plist-get info
:texinfo-class
))
915 (level (org-export-get-relative-level headline info
))
916 (numberedp (org-export-numbered-headline-p headline info
))
917 (class-sectioning (assoc class org-texinfo-classes
))
918 ;; Find the index type, if any.
919 (index (org-element-property :INDEX headline
))
920 ;; Create node info, to insert it before section formatting.
921 ;; Use custom menu title if present.
922 (node (format "@node %s\n" (org-texinfo--get-node headline info
)))
923 ;; Menus must be generated with first child, otherwise they
924 ;; will not nest properly.
925 (menu (let* ((first (org-export-first-sibling-p headline info
))
926 (parent (org-export-get-parent-headline headline
))
927 (title (org-texinfo--sanitize-headline
928 (org-element-property :title parent
) info
))
930 (tree (plist-get info
:parse-tree
)))
932 (org-element-map (plist-get info
:parse-tree
) 'headline
934 (if (member title
(org-element-property :title ref
))
937 (setq listing
(org-texinfo--build-menu
938 (car heading
) level info
))
940 (setq listing
(replace-regexp-in-string
943 "\n@menu\n%s\n@end menu\n\n" listing
))
945 ;; Section formatting will set two placeholders: one for the
946 ;; title and the other for the contents.
948 (if (org-not-nil (org-element-property :APPENDIX headline
))
949 (concat menu node
"appendix\n%s")
950 (let ((sec (if (and (symbolp (nth 2 class-sectioning
))
951 (fboundp (nth 2 class-sectioning
)))
952 (funcall (nth 2 class-sectioning
) level numberedp
)
953 (nth (1+ level
) class-sectioning
))))
955 ;; No section available for that LEVEL.
957 ;; Section format directly returned by a function.
959 ;; (numbered-section . unnumbered-section)
960 ((not (consp (cdr sec
)))
963 ;; An index is always unnumbered.
964 (if (or index
(not numberedp
)) (cdr sec
) (car sec
))
967 (and (plist-get info
:with-todo-keywords
)
968 (let ((todo (org-element-property :todo-keyword headline
)))
969 (and todo
(org-export-data todo info
)))))
970 (todo-type (and todo
(org-element-property :todo-type headline
)))
971 (tags (and (plist-get info
:with-tags
)
972 (org-export-get-tags headline info
)))
973 (priority (and (plist-get info
:with-priority
)
974 (org-element-property :priority headline
)))
975 ;; Retrieve headline text for structuring command.
976 (text (org-export-data (org-element-property :title headline
) info
))
977 ;; Create the headline text along with a no-tag version. The
978 ;; latter is required to remove tags from table of contents.
979 (full-text (if (not (eq org-texinfo-format-headline-function
'ignore
))
980 ;; User-defined formatting function.
981 (funcall org-texinfo-format-headline-function
982 todo todo-type priority text tags
)
983 ;; Default formatting.
986 (format "@strong{%s} " todo
))
987 (when priority
(format "@emph{#%s} " priority
))
991 (mapconcat 'identity tags
":"))))))
993 (if (not (eq org-texinfo-format-headline-function
'ignore
))
994 ;; User-defined formatting function.
995 (funcall org-texinfo-format-headline-function
996 todo todo-type priority text nil
)
997 ;; Default formatting.
999 (when todo
(format "@strong{%s} " todo
))
1000 (when priority
(format "@emph{#%c} " priority
))
1003 (make-string (org-element-property :pre-blank headline
) 10)))
1005 ;; Case 1: This is a footnote section: ignore it.
1006 ((org-element-property :footnote-section-p headline
) nil
)
1007 ;; Case 2: This is the `copying' section: ignore it
1008 ;; This is used elsewhere.
1009 ((org-not-nil (org-element-property :COPYING headline
)) nil
)
1010 ;; Case 3: An index. If it matches one of the known indexes,
1011 ;; print it as such following the contents, otherwise
1012 ;; print the contents and leave the index up to the user.
1015 section-fmt full-text
1016 (concat pre-blanks contents
"\n"
1017 (if (member index
'("cp" "fn" "ky" "pg" "tp" "vr"))
1018 (concat "@printindex " index
)))))
1019 ;; Case 4: This is a deep sub-tree: export it as a list item.
1020 ;; Also export as items headlines for which no section
1021 ;; format has been found.
1022 ((or (not section-fmt
) (org-export-low-level-p headline info
))
1023 ;; Build the real contents of the sub-tree.
1024 (let ((low-level-body
1026 ;; If the headline is the first sibling, start a list.
1027 (when (org-export-first-sibling-p headline info
)
1028 (format "@%s\n" (if numberedp
'enumerate
'itemize
)))
1030 "@item\n" full-text
"\n" pre-blanks contents
)))
1031 ;; If headline is not the last sibling simply return
1032 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
1034 (if (not (org-export-last-sibling-p headline info
)) low-level-body
1035 (replace-regexp-in-string
1037 (format "\n@end %s" (if numberedp
'enumerate
'itemize
))
1039 ;; Case 5: Standard headline. Export it as a section.
1042 ((not (and tags
(eq (plist-get info
:with-tags
) 'not-in-toc
)))
1043 ;; Regular section. Use specified format string.
1044 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1045 (concat pre-blanks contents
)))
1046 ((string-match "\\`@\\(.*?\\){" section-fmt
)
1047 ;; If tags should be removed from table of contents, insert
1048 ;; title without tags as an alternative heading in sectioning
1050 (format (replace-match (concat (match-string 1 section-fmt
) "[%s]")
1051 nil nil section-fmt
1)
1052 ;; Replace square brackets with parenthesis since
1053 ;; square brackets are not supported in optional
1055 (replace-regexp-in-string
1057 (replace-regexp-in-string
1061 (concat pre-blanks contents
)))
1063 ;; Impossible to add an alternative heading. Fallback to
1064 ;; regular sectioning format string.
1065 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1066 (concat pre-blanks contents
))))))))
1068 ;;;; Inline Src Block
1070 (defun org-texinfo-inline-src-block (inline-src-block contents info
)
1071 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
1072 CONTENTS holds the contents of the item. INFO is a plist holding
1073 contextual information."
1074 (let* ((code (org-element-property :value inline-src-block
))
1075 (separator (org-texinfo--find-verb-separator code
)))
1076 (concat "@verb{" separator code separator
"}")))
1080 (defun org-texinfo-inlinetask (inlinetask contents info
)
1081 "Transcode an INLINETASK element from Org to Texinfo.
1082 CONTENTS holds the contents of the block. INFO is a plist
1083 holding contextual information."
1084 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
1085 (todo (and (plist-get info
:with-todo-keywords
)
1086 (let ((todo (org-element-property :todo-keyword inlinetask
)))
1087 (and todo
(org-export-data todo info
)))))
1088 (todo-type (org-element-property :todo-type inlinetask
))
1089 (tags (and (plist-get info
:with-tags
)
1090 (org-export-get-tags inlinetask info
)))
1091 (priority (and (plist-get info
:with-priority
)
1092 (org-element-property :priority inlinetask
))))
1093 ;; If `org-texinfo-format-inlinetask-function' is provided, call it
1094 ;; with appropriate arguments.
1095 (if (not (eq org-texinfo-format-inlinetask-function
'ignore
))
1096 (funcall org-texinfo-format-inlinetask-function
1097 todo todo-type priority title tags contents
)
1098 ;; Otherwise, use a default template.
1101 (when todo
(format "@strong{%s} " todo
))
1102 (when priority
(format "#%c " priority
))
1104 (when tags
(format ":%s:"
1105 (mapconcat 'identity tags
":"))))))
1106 (format (concat "@center %s\n\n"
1109 full-title contents
)))))
1113 (defun org-texinfo-italic (italic contents info
)
1114 "Transcode ITALIC from Org to Texinfo.
1115 CONTENTS is the text with italic markup. INFO is a plist holding
1116 contextual information."
1117 (org-texinfo--text-markup contents
'italic
))
1121 (defun org-texinfo-item (item contents info
)
1122 "Transcode an ITEM element from Org to Texinfo.
1123 CONTENTS holds the contents of the item. INFO is a plist holding
1124 contextual information."
1125 (format "@item%s\n%s"
1126 (let ((tag (org-element-property :tag item
)))
1127 (if tag
(concat " " (org-export-data tag info
)) ""))
1132 (defun org-texinfo-keyword (keyword contents info
)
1133 "Transcode a KEYWORD element from Org to Texinfo.
1134 CONTENTS is nil. INFO is a plist holding contextual information."
1135 (let ((key (org-element-property :key keyword
))
1136 (value (org-element-property :value keyword
)))
1138 ((string= key
"TEXINFO") value
)
1139 ((string= key
"CINDEX") (format "@cindex %s" value
))
1140 ((string= key
"FINDEX") (format "@findex %s" value
))
1141 ((string= key
"KINDEX") (format "@kindex %s" value
))
1142 ((string= key
"PINDEX") (format "@pindex %s" value
))
1143 ((string= key
"TINDEX") (format "@tindex %s" value
))
1144 ((string= key
"VINDEX") (format "@vindex %s" value
)))))
1148 (defun org-texinfo-line-break (line-break contents info
)
1149 "Transcode a LINE-BREAK object from Org to Texinfo.
1150 CONTENTS is nil. INFO is a plist holding contextual information."
1155 (defun org-texinfo-link (link desc info
)
1156 "Transcode a LINK object from Org to Texinfo.
1158 DESC is the description part of the link, or the empty string.
1159 INFO is a plist holding contextual information. See
1161 (let* ((type (org-element-property :type link
))
1162 (raw-path (org-element-property :path link
))
1163 ;; Ensure DESC really exists, or set it to nil.
1164 (desc (and (not (string= desc
"")) desc
))
1166 ((member type
'("http" "https" "ftp"))
1167 (concat type
":" raw-path
))
1168 ((and (string= type
"file") (file-name-absolute-p raw-path
))
1169 (concat "file:" raw-path
))
1171 (email (if (string= type
"mailto")
1172 (let ((text (replace-regexp-in-string
1173 "@" "@@" raw-path
)))
1174 (concat text
(if desc
(concat "," desc
))))))
1177 ;; Links pointing to a headline: Find destination and build
1178 ;; appropriate referencing command.
1179 ((member type
'("custom-id" "id"))
1180 (let ((destination (org-export-resolve-id-link link info
)))
1181 (case (org-element-type destination
)
1182 ;; Id link points to an external file.
1184 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1185 (format "@uref{file://%s}" destination
)))
1186 ;; LINK points to a headline. Use the headline as the NODE target
1188 (format "@ref{%s,%s}"
1189 (org-texinfo--get-node destination info
)
1192 (let ((path (org-export-solidify-link-text path
)))
1193 (if (not desc
) (format "@ref{%s}" path
)
1194 (format "@ref{%s,,%s}" path desc
)))))))
1195 ((member type
'("info"))
1196 (let* ((info-path (split-string path
"[:#]"))
1197 (info-manual (car info-path
))
1198 (info-node (or (cadr info-path
) "top"))
1199 (title (or desc
"")))
1200 (format "@ref{%s,%s,,%s,}" info-node title info-manual
)))
1201 ((member type
'("fuzzy"))
1202 (let ((destination (org-export-resolve-fuzzy-link link info
)))
1203 (case (org-element-type destination
)
1204 ;; Id link points to an external file.
1206 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1207 (format "@uref{file://%s}" destination
)))
1208 ;; LINK points to a headline. Use the headline as the NODE target
1210 (format "@ref{%s,%s}"
1211 (org-texinfo--get-node destination info
)
1214 (let ((path (org-export-solidify-link-text path
)))
1215 (if (not desc
) (format "@ref{%s}" path
)
1216 (format "@ref{%s,,%s}" path desc
)))))))
1217 ;; Special case for email addresses
1219 (format "@email{%s}" email
))
1220 ;; External link with a description part.
1221 ((and path desc
) (format "@uref{%s,%s}" path desc
))
1222 ;; External link without a description part.
1223 (path (format "@uref{%s}" path
))
1224 ;; No path, only description. Try to do something useful.
1225 (t (format org-texinfo-link-with-unknown-path-format desc
)))))
1230 (defun org-texinfo-make-menu (info level
)
1231 "Create the menu for inclusion in the texifo document.
1233 INFO is the parsed buffer that contains the headlines. LEVEL
1234 determines whether to make the main menu, or the detailed menu.
1236 This is only used for generating the primary menu. In-Node menus
1237 are generated directly."
1238 (let ((parse (plist-get info
:parse-tree
)))
1240 ;; Generate the main menu
1241 ((eq level
'main
) (org-texinfo--build-menu parse
1 info
))
1242 ;; Generate the detailed (recursive) menu
1243 ((eq level
'detailed
)
1244 ;; Requires recursion
1245 ;;(org-texinfo--build-detailed-menu parse top info)
1246 (org-texinfo--build-menu parse
1 info
'detailed
)))))
1250 (defun org-texinfo-paragraph (paragraph contents info
)
1251 "Transcode a PARAGRAPH element from Org to Texinfo.
1252 CONTENTS is the contents of the paragraph, as a string. INFO is
1253 the plist used as a communication channel."
1258 (defun org-texinfo-plain-list (plain-list contents info
)
1259 "Transcode a PLAIN-LIST element from Org to Texinfo.
1260 CONTENTS is the contents of the list. INFO is a plist holding
1261 contextual information."
1262 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1263 (indic (or (plist-get attr
:indic
) org-texinfo-def-table-markup
))
1264 (table-type (plist-get attr
:table-type
))
1265 (type (org-element-property :type plain-list
))
1267 ((eq type
'ordered
) "enumerate")
1268 ((eq type
'unordered
) "itemize")
1269 ((member table-type
'("ftable" "vtable")) table-type
)
1271 (format "@%s\n%s@end %s"
1272 (if (eq type
'descriptive
) (concat list-type
" " indic
) list-type
)
1278 (defun org-texinfo-plain-text (text info
)
1279 "Transcode a TEXT string from Org to Texinfo.
1280 TEXT is the string to transcode. INFO is a plist holding
1281 contextual information."
1282 ;; First protect @, { and }.
1283 (let ((output (org-texinfo--sanitize-content text
)))
1284 ;; Activate smart quotes. Be sure to provide original TEXT string
1285 ;; since OUTPUT may have been modified.
1286 (when (plist-get info
:with-smart-quotes
)
1288 (org-export-activate-smart-quotes output
:texinfo info text
)))
1289 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1290 (let ((case-fold-search nil
)
1292 (while (string-match "\\(\\(?:La\\)?TeX\\)" output start
)
1293 (setq output
(replace-match
1294 (format "@%s{}" (match-string 1 output
)) nil t output
)
1295 start
(match-end 0))))
1296 ;; Convert special strings.
1297 (when (plist-get info
:with-special-strings
)
1298 (while (string-match (regexp-quote "...") output
)
1299 (setq output
(replace-match "@dots{}" nil t output
))))
1300 ;; Handle break preservation if required.
1301 (when (plist-get info
:preserve-breaks
)
1302 (setq output
(replace-regexp-in-string
1303 "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output
)))
1309 (defun org-texinfo-planning (planning contents info
)
1310 "Transcode a PLANNING element from Org to Texinfo.
1311 CONTENTS is nil. INFO is a plist holding contextual
1319 (let ((closed (org-element-property :closed planning
)))
1322 (format "@strong{%s} " org-closed-string
)
1323 (format org-texinfo-inactive-timestamp-format
1325 (org-element-property :raw-value closed
))))))
1326 (let ((deadline (org-element-property :deadline planning
)))
1329 (format "@strong{%s} " org-deadline-string
)
1330 (format org-texinfo-active-timestamp-format
1332 (org-element-property :raw-value deadline
))))))
1333 (let ((scheduled (org-element-property :scheduled planning
)))
1336 (format "@strong{%s} " org-scheduled-string
)
1337 (format org-texinfo-active-timestamp-format
1339 (org-element-property :raw-value scheduled
))))))))
1343 ;;;; Property Drawer
1345 (defun org-texinfo-property-drawer (property-drawer contents info
)
1346 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1347 CONTENTS is nil. INFO is a plist holding contextual
1349 ;; The property drawer isn't exported but we want separating blank
1350 ;; lines nonetheless.
1355 (defun org-texinfo-quote-block (quote-block contents info
)
1356 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1357 CONTENTS holds the contents of the block. INFO is a plist
1358 holding contextual information."
1359 (let* ((title (org-element-property :name quote-block
))
1360 (start-quote (concat "@quotation"
1362 (format " %s" title
)))))
1363 (format "%s\n%s@end quotation" start-quote contents
)))
1367 (defun org-texinfo-quote-section (quote-section contents info
)
1368 "Transcode a QUOTE-SECTION element from Org to Texinfo.
1369 CONTENTS is nil. INFO is a plist holding contextual information."
1370 (let ((value (org-remove-indentation
1371 (org-element-property :value quote-section
))))
1372 (when value
(format "@verbatim\n%s@end verbatim" value
))))
1376 (defun org-texinfo-radio-target (radio-target text info
)
1377 "Transcode a RADIO-TARGET object from Org to Texinfo.
1378 TEXT is the text of the target. INFO is a plist holding
1379 contextual information."
1380 (format "@anchor{%s}%s"
1381 (org-export-solidify-link-text
1382 (org-element-property :value radio-target
))
1387 (defun org-texinfo-section (section contents info
)
1388 "Transcode a SECTION element from Org to Texinfo.
1389 CONTENTS holds the contents of the section. INFO is a plist
1390 holding contextual information."
1395 (defun org-texinfo-special-block (special-block contents info
)
1396 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1397 CONTENTS holds the contents of the block. INFO is a plist used
1398 as a communication channel."
1403 (defun org-texinfo-src-block (src-block contents info
)
1404 "Transcode a SRC-BLOCK element from Org to Texinfo.
1405 CONTENTS holds the contents of the item. INFO is a plist holding
1406 contextual information."
1407 (let* ((lang (org-element-property :language src-block
))
1408 (lisp-p (string-match-p "lisp" lang
))
1409 (src-contents (org-texinfo--sanitize-content
1410 (org-export-format-code-default src-block info
))))
1412 ;; Case 1. Lisp Block
1414 (format "@lisp\n%s@end lisp"
1416 ;; Case 2. Other blocks
1418 (format "@example\n%s@end example"
1421 ;;;; Statistics Cookie
1423 (defun org-texinfo-statistics-cookie (statistics-cookie contents info
)
1424 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1425 CONTENTS is nil. INFO is a plist holding contextual information."
1426 (org-element-property :value statistics-cookie
))
1430 (defun org-texinfo-subscript (subscript contents info
)
1431 "Transcode a SUBSCRIPT object from Org to Texinfo.
1432 CONTENTS is the contents of the object. INFO is a plist holding
1433 contextual information."
1434 (format "@math{_%s}" contents
))
1438 (defun org-texinfo-superscript (superscript contents info
)
1439 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1440 CONTENTS is the contents of the object. INFO is a plist holding
1441 contextual information."
1442 (format "@math{^%s}" contents
))
1446 (defun org-texinfo-table (table contents info
)
1447 "Transcode a TABLE element from Org to Texinfo.
1448 CONTENTS is the contents of the table. INFO is a plist holding
1449 contextual information."
1450 (if (eq (org-element-property :type table
) 'table.el
)
1451 (format "@verbatim\n%s@end verbatim"
1452 (org-element-normalize-string
1453 (org-element-property :value table
)))
1454 (let* ((col-width (org-export-read-attribute :attr_texinfo table
:columns
))
1456 (if col-width
(format "@columnfractions %s" col-width
)
1457 (org-texinfo-table-column-widths table info
))))
1458 (format "@multitable %s\n%s@end multitable"
1462 (defun org-texinfo-table-column-widths (table info
)
1463 "Determine the largest table cell in each column to process alignment.
1464 TABLE is the table element to transcode. INFO is a plist used as
1465 a communication channel."
1466 (let ((widths (make-vector (cdr (org-export-table-dimensions table info
)) 0)))
1467 (org-element-map table
'table-row
1470 (org-element-map row
'table-cell
1472 ;; Length of the cell in the original buffer is only an
1473 ;; approximation of the length of the cell in the
1474 ;; output. It can sometimes fail (e.g. it considers
1475 ;; "/a/" being larger than "ab").
1476 (let ((w (- (org-element-property :contents-end cell
)
1477 (org-element-property :contents-begin cell
))))
1478 (aset widths idx
(max w
(aref widths idx
))))
1482 (format "{%s}" (mapconcat (lambda (w) (make-string w ?a
)) widths
"} {"))))
1486 (defun org-texinfo-table-cell (table-cell contents info
)
1487 "Transcode a TABLE-CELL element from Org to Texinfo.
1488 CONTENTS is the cell contents. INFO is a plist used as
1489 a communication channel."
1490 (concat (if (and contents
1491 org-texinfo-table-scientific-notation
1492 (string-match orgtbl-exp-regexp contents
))
1493 ;; Use appropriate format string for scientific
1495 (format org-texinfo-table-scientific-notation
1496 (match-string 1 contents
)
1497 (match-string 2 contents
))
1499 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1503 (defun org-texinfo-table-row (table-row contents info
)
1504 "Transcode a TABLE-ROW element from Org to Texinfo.
1505 CONTENTS is the contents of the row. INFO is a plist used as
1506 a communication channel."
1507 ;; Rules are ignored since table separators are deduced from
1508 ;; borders of the current row.
1509 (when (eq (org-element-property :type table-row
) 'standard
)
1511 (if (and (= 1 (org-export-table-row-group table-row info
))
1512 (org-export-table-has-header-p
1513 (org-export-get-parent-table table-row
) info
))
1516 (concat rowgroup-tag contents
"\n"))))
1520 (defun org-texinfo-target (target contents info
)
1521 "Transcode a TARGET object from Org to Texinfo.
1522 CONTENTS is nil. INFO is a plist holding contextual
1524 (format "@anchor{%s}"
1525 (org-export-solidify-link-text (org-element-property :value target
))))
1529 (defun org-texinfo-timestamp (timestamp contents info
)
1530 "Transcode a TIMESTAMP object from Org to Texinfo.
1531 CONTENTS is nil. INFO is a plist holding contextual
1533 (let ((value (org-texinfo-plain-text
1534 (org-timestamp-translate timestamp
) info
)))
1535 (case (org-element-property :type timestamp
)
1536 ((active active-range
)
1537 (format org-texinfo-active-timestamp-format value
))
1538 ((inactive inactive-range
)
1539 (format org-texinfo-inactive-timestamp-format value
))
1540 (t (format org-texinfo-diary-timestamp-format value
)))))
1544 (defun org-texinfo-verbatim (verbatim contents info
)
1545 "Transcode a VERBATIM object from Org to Texinfo.
1546 CONTENTS is nil. INFO is a plist used as a communication
1548 (org-texinfo--text-markup (org-element-property :value verbatim
) 'verbatim
))
1552 (defun org-texinfo-verse-block (verse-block contents info
)
1553 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1554 CONTENTS is verse block contents. INFO is a plist holding
1555 contextual information."
1556 (format "@display\n%s@end display" contents
))
1559 ;;; Interactive functions
1561 (defun org-texinfo-export-to-texinfo
1562 (&optional async subtreep visible-only body-only ext-plist
)
1563 "Export current buffer to a Texinfo file.
1565 If narrowing is active in the current buffer, only export its
1568 If a region is active, export that region.
1570 A non-nil optional argument ASYNC means the process should happen
1571 asynchronously. The resulting file should be accessible through
1572 the `org-export-stack' interface.
1574 When optional argument SUBTREEP is non-nil, export the sub-tree
1575 at point, extracting information from the headline properties
1578 When optional argument VISIBLE-ONLY is non-nil, don't export
1579 contents of hidden elements.
1581 When optional argument BODY-ONLY is non-nil, only write code
1582 between \"\\begin{document}\" and \"\\end{document}\".
1584 EXT-PLIST, when provided, is a property list with external
1585 parameters overriding Org default settings, but still inferior to
1586 file-local settings.
1588 Return output file's name."
1590 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1591 (org-export-coding-system `,org-texinfo-coding-system
))
1592 (org-export-to-file 'texinfo outfile
1593 async subtreep visible-only body-only ext-plist
)))
1595 (defun org-texinfo-export-to-info
1596 (&optional async subtreep visible-only body-only ext-plist
)
1597 "Export current buffer to Texinfo then process through to INFO.
1599 If narrowing is active in the current buffer, only export its
1602 If a region is active, export that region.
1604 A non-nil optional argument ASYNC means the process should happen
1605 asynchronously. The resulting file should be accessible through
1606 the `org-export-stack' interface.
1608 When optional argument SUBTREEP is non-nil, export the sub-tree
1609 at point, extracting information from the headline properties
1612 When optional argument VISIBLE-ONLY is non-nil, don't export
1613 contents of hidden elements.
1615 When optional argument BODY-ONLY is non-nil, only write code
1616 between \"\\begin{document}\" and \"\\end{document}\".
1618 EXT-PLIST, when provided, is a property list with external
1619 parameters overriding Org default settings, but still inferior to
1620 file-local settings.
1622 When optional argument PUB-DIR is set, use it as the publishing
1625 Return INFO file's name."
1627 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1628 (org-export-coding-system `,org-texinfo-coding-system
))
1629 (org-export-to-file 'texinfo outfile
1630 async subtreep visible-only body-only ext-plist
1631 (lambda (file) (org-texinfo-compile file
)))))
1634 (defun org-texinfo-publish-to-texinfo (plist filename pub-dir
)
1635 "Publish an org file to Texinfo.
1637 FILENAME is the filename of the Org file to be published. PLIST
1638 is the property list for the given project. PUB-DIR is the
1639 publishing directory.
1641 Return output file name."
1642 (org-publish-org-to 'texinfo filename
".texi" plist pub-dir
))
1645 (defun org-texinfo-convert-region-to-texinfo ()
1646 "Assume the current region has org-mode syntax, and convert it to Texinfo.
1647 This can be used in any buffer. For example, you can write an
1648 itemized list in org-mode syntax in an Texinfo buffer and use
1649 this command to convert it."
1651 (org-export-replace-region-by 'texinfo
))
1653 (defun org-texinfo-compile (file)
1654 "Compile a texinfo file.
1656 FILE is the name of the file being compiled. Processing is
1657 done through the command specified in `org-texinfo-info-process'.
1659 Return INFO file name or an error if it couldn't be produced."
1660 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file
)))
1661 (full-name (file-truename file
))
1662 (out-dir (file-name-directory file
))
1663 ;; Properly set working directory for compilation.
1664 (default-directory (if (file-name-absolute-p file
)
1665 (file-name-directory full-name
)
1668 (message (format "Processing Texinfo file %s..." file
))
1669 (save-window-excursion
1671 ;; A function is provided: Apply it.
1672 ((functionp org-texinfo-info-process
)
1673 (funcall org-texinfo-info-process
(shell-quote-argument file
)))
1674 ;; A list is provided: Replace %b, %f and %o with appropriate
1675 ;; values in each command before applying it. Output is
1676 ;; redirected to "*Org INFO Texinfo Output*" buffer.
1677 ((consp org-texinfo-info-process
)
1678 (let ((outbuf (get-buffer-create "*Org INFO Texinfo Output*")))
1682 (replace-regexp-in-string
1683 "%b" (shell-quote-argument base-name
)
1684 (replace-regexp-in-string
1685 "%f" (shell-quote-argument full-name
)
1686 (replace-regexp-in-string
1687 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
1689 org-texinfo-info-process
)
1690 ;; Collect standard errors from output buffer.
1691 (setq errors
(org-texinfo-collect-errors outbuf
))))
1692 (t (error "No valid command to process to Info")))
1693 (let ((infofile (concat out-dir base-name
".info")))
1694 ;; Check for process failure. Provide collected errors if
1696 (if (not (file-exists-p infofile
))
1697 (error (concat (format "INFO file %s wasn't produced" infofile
)
1698 (when errors
(concat ": " errors
))))
1699 ;; Else remove log files, when specified, and signal end of
1700 ;; process to user, along with any error encountered.
1701 (when org-texinfo-remove-logfiles
1702 (dolist (ext org-texinfo-logfiles-extensions
)
1703 (let ((file (concat out-dir base-name
"." ext
)))
1704 (when (file-exists-p file
) (delete-file file
)))))
1705 (message (concat "Process completed"
1706 (if (not errors
) "."
1707 (concat " with errors: " errors
)))))
1708 ;; Return output file name.
1711 (defun org-texinfo-collect-errors (buffer)
1712 "Collect some kind of errors from \"makeinfo\" command output.
1714 BUFFER is the buffer containing output.
1716 Return collected error types as a string, or nil if there was
1718 (with-current-buffer buffer
1720 (goto-char (point-min))
1721 ;; Find final "makeinfo" run.
1723 (let ((case-fold-search t
)
1725 (when (save-excursion
1726 (re-search-forward "perhaps incorrect sectioning?" nil t
))
1727 (setq errors
(concat errors
" [incorrect sectioning]")))
1728 (when (save-excursion
1729 (re-search-forward "missing close brace" nil t
))
1730 (setq errors
(concat errors
" [syntax error]")))
1731 (when (save-excursion
1732 (re-search-forward "Unknown command" nil t
))
1733 (setq errors
(concat errors
" [undefined @command]")))
1734 (when (save-excursion
1735 (re-search-forward "No matching @end" nil t
))
1736 (setq errors
(concat errors
" [block incomplete]")))
1737 (when (save-excursion
1738 (re-search-forward "requires a sectioning" nil t
))
1739 (setq errors
(concat errors
" [invalid section command]")))
1740 (when (save-excursion
1741 (re-search-forward "\\[unexpected\]" nil t
))
1742 (setq errors
(concat errors
" [unexpected error]")))
1743 (when (save-excursion
1744 (re-search-forward "misplaced " nil t
))
1745 (setq errors
(concat errors
" [syntax error]")))
1746 (and (org-string-nw-p errors
) (org-trim errors
)))))))
1749 (provide 'ox-texinfo
)
1752 ;; generated-autoload-file: "org-loaddefs.el"
1755 ;;; ox-texinfo.el ends here