1 ;;; ox-texinfo.el --- Texinfo Back-End for Org Export Engine -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2012-2017 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 <https://www.gnu.org/licenses/>.
24 ;; See Org manual for details.
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 (drawer . org-texinfo-drawer
)
43 (dynamic-block . org-texinfo-dynamic-block
)
44 (entity . org-texinfo-entity
)
45 (example-block . org-texinfo-example-block
)
46 (export-block . org-texinfo-export-block
)
47 (export-snippet . org-texinfo-export-snippet
)
48 (fixed-width . org-texinfo-fixed-width
)
49 (footnote-definition . org-texinfo-footnote-definition
)
50 (footnote-reference . org-texinfo-footnote-reference
)
51 (headline . org-texinfo-headline
)
52 (inline-src-block . org-texinfo-inline-src-block
)
53 (inlinetask . org-texinfo-inlinetask
)
54 (italic . org-texinfo-italic
)
55 (item . org-texinfo-item
)
56 (keyword . org-texinfo-keyword
)
57 (line-break . org-texinfo-line-break
)
58 (link . org-texinfo-link
)
59 (node-property . org-texinfo-node-property
)
60 (paragraph . org-texinfo-paragraph
)
61 (plain-list . org-texinfo-plain-list
)
62 (plain-text . org-texinfo-plain-text
)
63 (planning . org-texinfo-planning
)
64 (property-drawer . org-texinfo-property-drawer
)
65 (quote-block . org-texinfo-quote-block
)
66 (radio-target . org-texinfo-radio-target
)
67 (section . org-texinfo-section
)
68 (special-block . org-texinfo-special-block
)
69 (src-block . org-texinfo-src-block
)
70 (statistics-cookie . org-texinfo-statistics-cookie
)
71 (strike-through . org-texinfo-strike-through
)
72 (subscript . org-texinfo-subscript
)
73 (superscript . org-texinfo-superscript
)
74 (table . org-texinfo-table
)
75 (table-cell . org-texinfo-table-cell
)
76 (table-row . org-texinfo-table-row
)
77 (target . org-texinfo-target
)
78 (template . org-texinfo-template
)
79 (timestamp . org-texinfo-timestamp
)
80 (underline . org-texinfo-underline
)
81 (verbatim . org-texinfo-verbatim
)
82 (verse-block . org-texinfo-verse-block
))
84 '((:filter-headline . org-texinfo--filter-section-blank-lines
)
85 (:filter-parse-tree . org-texinfo--normalize-headlines
)
86 (:filter-section . org-texinfo--filter-section-blank-lines
)
87 (:filter-final-output . org-texinfo--untabify
))
89 '(?i
"Export to Texinfo"
90 ((?t
"As TEXI file" org-texinfo-export-to-texinfo
)
91 (?i
"As INFO file" org-texinfo-export-to-info
)
92 (?o
"As INFO file and open"
94 (if a
(org-texinfo-export-to-info t s v b
)
95 (org-open-file (org-texinfo-export-to-info nil s v b
)))))))
97 '((:texinfo-filename
"TEXINFO_FILENAME" nil nil t
)
98 (:texinfo-class
"TEXINFO_CLASS" nil org-texinfo-default-class t
)
99 (:texinfo-header
"TEXINFO_HEADER" nil nil newline
)
100 (:texinfo-post-header
"TEXINFO_POST_HEADER" nil nil newline
)
101 (:subtitle
"SUBTITLE" nil nil parse
)
102 (:subauthor
"SUBAUTHOR" nil nil newline
)
103 (:texinfo-dircat
"TEXINFO_DIR_CATEGORY" nil nil t
)
104 (:texinfo-dirtitle
"TEXINFO_DIR_TITLE" nil nil t
)
105 (:texinfo-dirdesc
"TEXINFO_DIR_DESC" nil nil t
)
106 (:texinfo-printed-title
"TEXINFO_PRINTED_TITLE" nil nil t
)
108 (:texinfo-classes nil nil org-texinfo-classes
)
109 (:texinfo-format-headline-function nil nil org-texinfo-format-headline-function
)
110 (:texinfo-node-description-column nil nil org-texinfo-node-description-column
)
111 (:texinfo-active-timestamp-format nil nil org-texinfo-active-timestamp-format
)
112 (:texinfo-inactive-timestamp-format nil nil org-texinfo-inactive-timestamp-format
)
113 (:texinfo-diary-timestamp-format nil nil org-texinfo-diary-timestamp-format
)
114 (:texinfo-link-with-unknown-path-format nil nil org-texinfo-link-with-unknown-path-format
)
115 (:texinfo-tables-verbatim nil nil org-texinfo-tables-verbatim
)
116 (:texinfo-table-scientific-notation nil nil org-texinfo-table-scientific-notation
)
117 (:texinfo-table-default-markup nil nil org-texinfo-table-default-markup
)
118 (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist
)
119 (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function
)
120 (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function
)))
124 ;;; User Configurable Variables
126 (defgroup org-export-texinfo nil
127 "Options for exporting Org mode files to Texinfo."
128 :tag
"Org Export Texinfo"
130 :package-version
'(Org .
"8.0")
135 (defcustom org-texinfo-coding-system nil
136 "Default document encoding for Texinfo output.
138 If nil it will default to `buffer-file-coding-system'."
139 :group
'org-export-texinfo
140 :type
'coding-system
)
142 (defcustom org-texinfo-default-class
"info"
143 "The default Texinfo class."
144 :group
'org-export-texinfo
145 :type
'(string :tag
"Texinfo class"))
147 (defcustom org-texinfo-classes
149 "@documentencoding AUTO\n@documentlanguage AUTO"
150 ("@chapter %s" "@unnumbered %s" "@chapheading %s" "@appendix %s")
151 ("@section %s" "@unnumberedsec %s" "@heading %s" "@appendixsec %s")
152 ("@subsection %s" "@unnumberedsubsec %s" "@subheading %s"
153 "@appendixsubsec %s")
154 ("@subsubsection %s" "@unnumberedsubsubsec %s" "@subsubheading %s"
155 "@appendixsubsubsec %s")))
156 "Alist of Texinfo classes and associated header and structure.
157 If #+TEXINFO_CLASS is set in the buffer, use its value and the
158 associated information. Here is the structure of a class
163 (numbered-1 unnumbered-1 unnumbered-no-toc-1 appendix-1)
164 (numbered-2 unnumbered-2 unnumbered-no-toc-2 appendix-2)
171 The header string is inserted in the header of the generated
172 document, right after \"@setfilename\" and \"@settitle\"
175 If it contains the special string
177 \"@documentencoding AUTO\"
179 \"AUTO\" will be replaced with an appropriate coding system. See
180 `org-texinfo-coding-system' for more information. Likewise, if
181 the string contains the special string
183 \"@documentlanguage AUTO\"
185 \"AUTO\" will be replaced with the language defined in the
186 buffer, through #+LANGUAGE keyword, or globally, with
187 `org-export-default-language', which see.
190 The sectioning structure
191 ------------------------
193 The sectioning structure of the class is given by the elements
194 following the header string. For each sectioning level, a number
195 of strings is specified. A %s formatter is mandatory in each
196 section string and will be replaced by the title of the section."
197 :group
'org-export-texinfo
199 :package-version
'(Org .
"9.2")
201 (list (string :tag
"Texinfo class")
202 (string :tag
"Texinfo header")
203 (repeat :tag
"Levels" :inline t
206 (string :tag
" numbered")
207 (string :tag
" unnumbered")
208 (string :tag
"unnumbered-no-toc")
209 (string :tag
" appendix")))))))
213 (defcustom org-texinfo-format-headline-function
214 'org-texinfo-format-headline-default-function
215 "Function to format headline text.
217 This function will be called with 5 arguments:
218 TODO the todo keyword (string or nil).
219 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
220 PRIORITY the priority of the headline (integer or nil)
221 TEXT the main headline text (string).
222 TAGS the tags as a list of strings (list of strings or nil).
224 The function result will be used in the section format string."
225 :group
'org-export-texinfo
228 :package-version
'(Org .
"8.3"))
230 ;;;; Node listing (menu)
232 (defcustom org-texinfo-node-description-column
32
233 "Column at which to start the description in the node listings.
234 If a node title is greater than this length, the description will
235 be placed after the end of the title."
236 :group
'org-export-texinfo
241 (defcustom org-texinfo-active-timestamp-format
"@emph{%s}"
242 "A printf format string to be applied to active timestamps."
243 :group
'org-export-texinfo
246 (defcustom org-texinfo-inactive-timestamp-format
"@emph{%s}"
247 "A printf format string to be applied to inactive timestamps."
248 :group
'org-export-texinfo
251 (defcustom org-texinfo-diary-timestamp-format
"@emph{%s}"
252 "A printf format string to be applied to diary timestamps."
253 :group
'org-export-texinfo
258 (defcustom org-texinfo-link-with-unknown-path-format
"@indicateurl{%s}"
259 "Format string for links with unknown path type."
260 :group
'org-export-texinfo
265 (defcustom org-texinfo-tables-verbatim nil
266 "When non-nil, tables are exported verbatim."
267 :group
'org-export-texinfo
270 (defcustom org-texinfo-table-scientific-notation
"%s\\,(%s)"
271 "Format string to display numbers in scientific notation.
273 The format should have \"%s\" twice, for mantissa and exponent
274 \(i.e. \"%s\\\\times10^{%s}\").
276 When nil, no transformation is made."
277 :group
'org-export-texinfo
279 (string :tag
"Format string")
280 (const :tag
"No formatting" nil
)))
282 (defcustom org-texinfo-table-default-markup
"@asis"
283 "Default markup for first column in two-column tables.
285 This should an indicating command, e.g., \"@code\", \"@kbd\" or
288 It can be overridden locally using the \":indic\" attribute."
289 :group
'org-export-texinfo
292 :package-version
'(Org .
"9.1")
297 (defcustom org-texinfo-text-markup-alist
'((bold .
"@strong{%s}")
299 (italic .
"@emph{%s}")
301 "Alist of Texinfo expressions to convert text markup.
303 The key must be a symbol among `bold', `code', `italic',
304 `strike-through', `underscore' and `verbatim'. The value is
305 a formatting string to wrap fontified text with.
307 Value can also be set to the following symbols: `verb', `samp'
308 and `code'. With the first one, Org uses \"@verb\" to create
309 a format string and selects a delimiter character that isn't in
310 the string. For the other two, Org uses \"@samp\" or \"@code\"
311 to typeset and protects special characters.
313 When no association is found for a given markup, text is returned
315 :group
'org-export-texinfo
317 :package-version
'(Org .
"9.1")
319 :options
'(bold code italic strike-through underscore verbatim
))
323 (defcustom org-texinfo-format-drawer-function
(lambda (_name contents
) contents
)
324 "Function called to format a drawer in Texinfo code.
326 The function must accept two parameters:
327 NAME the drawer name, like \"LOGBOOK\"
328 CONTENTS the contents of the drawer.
330 The function should return the string to be exported.
332 The default function simply returns the value of CONTENTS."
333 :group
'org-export-texinfo
335 :package-version
'(Org .
"8.2")
340 (defcustom org-texinfo-format-inlinetask-function
341 'org-texinfo-format-inlinetask-default-function
342 "Function called to format an inlinetask in Texinfo code.
344 The function must accept six parameters:
345 TODO the todo keyword, as a string
346 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
347 PRIORITY the inlinetask priority, as a string
348 NAME the inlinetask name, as a string.
349 TAGS the inlinetask tags, as a list of strings.
350 CONTENTS the contents of the inlinetask, as a string.
352 The function should return the string to be exported."
353 :group
'org-export-texinfo
358 (defcustom org-texinfo-info-process
'("makeinfo --no-split %f")
359 "Commands to process a Texinfo file to an INFO file.
361 This is a list of strings, each of them will be given to the
362 shell as a command. %f in the command will be replaced by the
363 relative file name, %F by the absolute file name, %b by the file
364 base name (i.e. without directory and extension parts), %o by the
365 base directory of the file and %O by the absolute file name of
367 :group
'org-export-texinfo
369 :package-version
'(Org .
"9.1")
370 :type
'(repeat :tag
"Shell command sequence"
371 (string :tag
"Shell command")))
373 (defcustom org-texinfo-logfiles-extensions
374 '("aux" "toc" "cp" "fn" "ky" "pg" "tp" "vr")
375 "The list of file extensions to consider as Texinfo logfiles.
376 The logfiles will be remove if `org-texinfo-remove-logfiles' is
378 :group
'org-export-texinfo
379 :type
'(repeat (string :tag
"Extension")))
381 (defcustom org-texinfo-remove-logfiles t
382 "Non-nil means remove the logfiles produced by compiling a Texinfo file.
383 By default, logfiles are files with these extensions: .aux, .toc,
384 .cp, .fn, .ky, .pg and .tp. To define the set of logfiles to remove,
385 set `org-texinfo-logfiles-extensions'."
386 :group
'org-export-latex
391 (defconst org-texinfo-max-toc-depth
4
392 "Maximum depth for creation of detailed menu listings.
393 Beyond this depth, Texinfo will not recognize the nodes and will
394 cause errors. Left as a constant in case this value ever
397 (defconst org-texinfo-supported-coding-systems
398 '("US-ASCII" "UTF-8" "ISO-8859-15" "ISO-8859-1" "ISO-8859-2" "koi8-r" "koi8-u")
399 "List of coding systems supported by Texinfo, as strings.
400 Specified coding system will be matched against these strings.
401 If two strings share the same prefix (e.g. \"ISO-8859-1\" and
402 \"ISO-8859-15\"), the most specific one has to be listed first.")
404 (defconst org-texinfo-inline-image-rules
406 (regexp-opt '("eps" "pdf" "png" "jpg" "jpeg" "gif" "svg"))))
407 "Rules characterizing image files that can be inlined.")
410 ;;; Internal Functions
412 (defun org-texinfo--untabify (s _backend _info
)
413 "Remove TAB characters in string S."
414 (replace-regexp-in-string "\t" (make-string tab-width ?\s
) s
))
416 (defun org-texinfo--filter-section-blank-lines (headline _backend _info
)
417 "Filter controlling number of blank lines after a section."
418 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" "\n\n" headline
))
420 (defun org-texinfo--normalize-headlines (tree _backend info
)
421 "Normalize headlines in TREE.
423 BACK-END is the symbol specifying back-end used for export. INFO
424 is a plist used as a communication channel.
426 Make sure every headline in TREE contains a section, since those
427 are required to install a menu. Also put exactly one blank line
428 at the end of each section.
431 (org-element-map tree
'headline
433 (org-element-put-property hl
:post-blank
1)
434 (let ((contents (org-element-contents hl
)))
436 (let ((first (org-element-map contents
'(headline section
)
438 (unless (eq (org-element-type first
) 'section
)
439 (apply #'org-element-set-contents
441 (cons `(section (:parent
,hl
)) contents
)))))))
445 (defun org-texinfo--find-verb-separator (s)
446 "Return a character not used in string S.
447 This is used to choose a separator for constructs like \\verb."
448 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
449 (cl-loop for c across ll
450 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
451 return
(char-to-string c
))))
453 (defun org-texinfo--text-markup (text markup _info
)
454 "Format TEXT depending on MARKUP text markup.
455 INFO is a plist used as a communication channel. See
456 `org-texinfo-text-markup-alist' for details."
457 (pcase (cdr (assq markup org-texinfo-text-markup-alist
))
458 (`nil text
) ;no markup: return raw text
459 (`code
(format "@code{%s}" (org-texinfo--sanitize-content text
)))
460 (`samp
(format "@samp{%s}" (org-texinfo--sanitize-content text
)))
462 (let ((separator (org-texinfo--find-verb-separator text
)))
463 (format "@verb{%s%s%s}" separator text separator
)))
464 ;; Else use format string.
465 (fmt (format fmt text
))))
467 (defun org-texinfo--get-node (datum info
)
468 "Return node or anchor associated to DATUM.
469 DATUM is a headline, a radio-target or a target. INFO is a plist
470 used as a communication channel. The function guarantees the
471 node or anchor name is unique."
472 (let ((cache (plist-get info
:texinfo-node-cache
)))
473 (or (cdr (assq datum cache
))
476 (org-texinfo--sanitize-node
477 (pcase (org-element-type datum
)
479 (org-texinfo--sanitize-title
480 (org-export-get-alt-title datum info
) info
))
482 (org-texinfo--sanitize-title
483 (org-element-contents datum
) info
))
485 (org-export-data (org-element-property :value datum
) info
))
487 (error "Cannot generate node name for type: %S" type
)))))
489 ;; Ensure NAME is unique and not reserved node name "Top".
490 (while (or (equal name
"Top") (rassoc name cache
))
491 (setq name
(concat basename
(format " (%d)" (cl-incf salt
)))))
492 (plist-put info
:texinfo-node-cache
(cons (cons datum name
) cache
))
495 (defun org-texinfo--sanitize-node (title)
496 "Bend string TITLE to node line requirements.
497 Trim string and collapse multiple whitespace characters as they
498 are not significant. Replace leading left parenthesis, when
499 followed by a right parenthesis, with a square bracket. Remove
500 periods, commas and colons."
502 (replace-regexp-in-string
504 (replace-regexp-in-string
506 (replace-regexp-in-string "\\`(\\(.*?)\\)" "[\\1" title
)))))
508 (defun org-texinfo--sanitize-title (title info
)
509 "Make TITLE suitable as a section name.
510 TITLE is a string or a secondary string. INFO is the current
511 export state, as a plist."
512 (org-export-data-with-backend
513 title
(org-export-toc-entry-backend 'texinfo
) info
))
515 (defun org-texinfo--sanitize-content (text)
516 "Escape special characters in string TEXT.
517 Special characters are: @ { }"
518 (replace-regexp-in-string "[@{}]" "@\\&" text
))
520 (defun org-texinfo--wrap-float (value info
&optional type label caption short
)
521 "Wrap string VALUE within a @float command.
522 INFO is the current export state, as a plist. TYPE is float
523 type, as a string. LABEL is the cross reference label for the
524 float, as a string. CAPTION and SHORT are, respectively, the
525 caption and shortcaption used for the float, as secondary
526 strings (e.g., returned by `org-export-get-caption')."
528 (org-export-toc-entry-backend 'texinfo
529 (cons 'footnote-reference
530 (lambda (f c i
) (org-export-with-backend 'texinfo f c i
)))))
532 (org-export-toc-entry-backend 'texinfo
533 '(inline-src-block . ignore
)
534 '(verbatim . ignore
)))
536 (if (and short caption
)
537 (format "@shortcaption{%s}\n"
538 (org-export-data-with-backend short short-backend info
))
541 (if (or short caption
)
542 (format "@caption{%s}\n"
543 (org-export-data-with-backend
545 (if (equal short-str
"") short-backend backend
)
548 (format "@float %s%s\n%s\n%s%s@end float"
549 type
(if label
(concat "," label
) "") value caption-str short-str
)))
553 (defun org-texinfo-template (contents info
)
554 "Return complete document string after Texinfo conversion.
555 CONTENTS is the transcoded contents string. INFO is a plist
556 holding export options."
557 (let ((title (org-export-data (plist-get info
:title
) info
))
558 ;; Copying data is the contents of the first headline in
559 ;; parse tree with a non-nil copying property.
560 (copying (org-element-map (plist-get info
:parse-tree
) 'headline
562 (and (org-not-nil (org-element-property :COPYING hl
))
563 (org-element-contents hl
)))
566 "\\input texinfo @c -*- texinfo -*-\n"
567 "@c %**start of header\n"
568 (let ((file (or (plist-get info
:texinfo-filename
)
569 (let ((f (plist-get info
:output-file
)))
570 (and f
(concat (file-name-sans-extension f
) ".info"))))))
571 (and file
(format "@setfilename %s\n" file
)))
572 (format "@settitle %s\n" title
)
573 ;; Insert class-defined header.
574 (org-element-normalize-string
575 (let ((header (nth 1 (assoc (plist-get info
:texinfo-class
)
576 org-texinfo-classes
)))
578 (catch 'coding-system
579 (let ((case-fold-search t
)
580 (name (symbol-name (or org-texinfo-coding-system
581 buffer-file-coding-system
))))
582 (dolist (system org-texinfo-supported-coding-systems
"UTF-8")
583 (when (string-match-p (regexp-quote system
) name
)
584 (throw 'coding-system system
))))))
585 (language (plist-get info
:language
))
586 (case-fold-search nil
))
587 ;; Auto coding system.
588 (replace-regexp-in-string
589 "^@documentencoding \\(AUTO\\)$"
591 (replace-regexp-in-string
592 "^@documentlanguage \\(AUTO\\)$" language header t nil
1) t nil
1)))
593 ;; Additional header options set by #+TEXINFO_HEADER.
594 (let ((texinfo-header (plist-get info
:texinfo-header
)))
595 (and texinfo-header
(org-element-normalize-string texinfo-header
)))
596 "@c %**end of header\n\n"
597 ;; Additional options set by #+TEXINFO_POST_HEADER.
598 (let ((texinfo-post-header (plist-get info
:texinfo-post-header
)))
599 (and texinfo-post-header
600 (org-element-normalize-string texinfo-post-header
)))
603 (format "@copying\n%s@end copying\n\n"
604 (org-element-normalize-string
605 (org-export-data copying info
))))
606 ;; Info directory information. Only supply if both title and
607 ;; category are provided.
608 (let ((dircat (plist-get info
:texinfo-dircat
))
610 (let ((title (plist-get info
:texinfo-dirtitle
)))
612 (string-match "^\\(?:\\* \\)?\\(.*?\\)\\(\\.\\)?$" title
)
613 (format "* %s." (match-string 1 title
))))))
614 (when (and dircat dirtitle
)
615 (concat "@dircategory " dircat
"\n"
618 (let ((desc (plist-get info
:texinfo-dirdesc
)))
619 (cond ((not desc
) nil
)
620 ((string-suffix-p "." desc
) desc
)
621 (t (concat desc
"."))))))
622 (if dirdesc
(format "%-23s %s" dirtitle dirdesc
) dirtitle
))
624 "@end direntry\n\n")))
628 (when (plist-get info
:with-title
)
630 (format "@title %s\n"
631 (or (plist-get info
:texinfo-printed-title
) title
""))
632 (let ((subtitle (plist-get info
:subtitle
)))
634 (format "@subtitle %s\n"
635 (org-export-data subtitle info
))))))
636 (when (plist-get info
:with-author
)
639 (let ((author (org-string-nw-p
640 (org-export-data (plist-get info
:author
) info
)))
641 (email (and (plist-get info
:with-email
)
643 (org-export-data (plist-get info
:email
) info
)))))
644 (cond ((and author email
)
645 (format "@author %s (@email{%s})\n" author email
))
646 (author (format "@author %s\n" author
))
647 (email (format "@author @email{%s}\n" email
))))
649 (let ((subauthor (plist-get info
:subauthor
)))
651 (org-element-normalize-string
652 (replace-regexp-in-string "^" "@author " subauthor
))))))
653 (and copying
"@page\n@vskip 0pt plus 1filll\n@insertcopying\n")
655 ;; Table of contents.
656 (and (plist-get info
:with-toc
) "@contents\n\n")
657 ;; Configure Top Node when not for TeX. Also include contents
658 ;; from the first section of the document.
661 (format "@top %s\n" title
)
662 (let* ((first-section
663 (org-element-map (plist-get info
:parse-tree
) 'section
664 #'identity info t
'(headline)))
666 (org-export-data (org-element-contents first-section
) info
)))
667 (and (org-string-nw-p top-contents
) (concat "\n" top-contents
)))
670 (org-texinfo-make-menu (plist-get info
:parse-tree
) info
'master
)
675 (and (plist-get info
:with-creator
)
676 (concat (plist-get info
:creator
) "\n"))
682 ;;; Transcode Functions
686 (defun org-texinfo-bold (_bold contents info
)
687 "Transcode BOLD from Org to Texinfo.
688 CONTENTS is the text with bold markup. INFO is a plist holding
689 contextual information."
690 (org-texinfo--text-markup contents
'bold info
))
694 (defun org-texinfo-center-block (_center-block contents _info
)
695 "Transcode a CENTER-BLOCK element from Org to Texinfo.
696 CONTENTS holds the contents of the block. INFO is a plist used
697 as a communication channel."
702 (defun org-texinfo-clock (clock _contents info
)
703 "Transcode a CLOCK element from Org to Texinfo.
704 CONTENTS is nil. INFO is a plist holding contextual
708 (format "@strong{%s} " org-clock-string
)
709 (format (plist-get info
:texinfo-inactive-timestamp-format
)
710 (concat (org-timestamp-translate (org-element-property :value clock
))
711 (let ((time (org-element-property :duration clock
)))
712 (and time
(format " (%s)" time
)))))
717 (defun org-texinfo-code (code _contents info
)
718 "Transcode a CODE object from Org to Texinfo.
719 CONTENTS is nil. INFO is a plist used as a communication
721 (org-texinfo--text-markup (org-element-property :value code
) 'code info
))
725 (defun org-texinfo-drawer (drawer contents info
)
726 "Transcode a DRAWER element from Org to Texinfo.
727 CONTENTS holds the contents of the block. INFO is a plist
728 holding contextual information."
729 (let* ((name (org-element-property :drawer-name drawer
))
730 (output (funcall (plist-get info
:texinfo-format-drawer-function
)
736 (defun org-texinfo-dynamic-block (_dynamic-block contents _info
)
737 "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
738 CONTENTS holds the contents of the block. INFO is a plist
739 holding contextual information."
744 (defun org-texinfo-entity (entity _contents _info
)
745 "Transcode an ENTITY object from Org to Texinfo."
746 ;; Since there is not specific Texinfo entry in entities, use
747 ;; Texinfo-specific commands whenever possible, and fallback to
749 (pcase (org-element-property :name entity
)
752 ((or "bull" "bullet") "@bullet{}")
753 ("copy" "@copyright{}")
754 ("deg" "@textdegree{}")
755 ((or "dots" "hellip") "@dots{}")
757 ((or "euro" "EUR") "@euro{}")
758 ((or "ge" "geq") "@geq{}")
759 ("laquo" "@guillemetleft{}")
760 ("iexcl" "@exclamdown{}")
761 ("imath" "@dotless{i}")
762 ("iquest" "@questiondown{}")
763 ("jmath" "@dotless{j}")
764 ((or "le" "leq") "@leq{}")
765 ("lsaquo" "@guilsinglleft{}")
775 ("raquo" "@guillemetright{}")
776 ((or "rArr" "Rightarrow") "@result{}")
777 ("reg" "@registeredsymbol{}")
778 ((or "rightarrow" "to" "rarr") "@arrow{}")
779 ("rsaquo" "@guilsinglright{}")
782 ((and (pred (string-prefix-p "_")) name
) ;spacing entities
783 (format "@w{%s}" (substring name
1)))
784 (_ (org-element-property :utf-8 entity
))))
788 (defun org-texinfo-example-block (example-block _contents info
)
789 "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
790 CONTENTS is nil. INFO is a plist holding contextual
792 (format "@example\n%s@end example"
793 (org-texinfo--sanitize-content
794 (org-export-format-code-default example-block info
))))
798 (defun org-texinfo-export-block (export-block _contents _info
)
799 "Transcode a EXPORT-BLOCK element from Org to Texinfo.
800 CONTENTS is nil. INFO is a plist holding contextual information."
801 (when (string= (org-element-property :type export-block
) "TEXINFO")
802 (org-remove-indentation (org-element-property :value export-block
))))
806 (defun org-texinfo-export-snippet (export-snippet _contents _info
)
807 "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
808 CONTENTS is nil. INFO is a plist holding contextual information."
809 (when (eq (org-export-snippet-backend export-snippet
) 'texinfo
)
810 (org-element-property :value export-snippet
)))
814 (defun org-texinfo-fixed-width (fixed-width _contents _info
)
815 "Transcode a FIXED-WIDTH element from Org to Texinfo.
816 CONTENTS is nil. INFO is a plist holding contextual information."
817 (format "@example\n%s@end example"
818 (org-remove-indentation
819 (org-texinfo--sanitize-content
820 (org-element-property :value fixed-width
)))))
822 ;;;; Footnote Reference
824 (defun org-texinfo-footnote-reference (footnote _contents info
)
825 "Create a footnote reference for FOOTNOTE.
827 FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
828 plist holding contextual information."
829 (let ((def (org-export-get-footnote-definition footnote info
)))
830 (format "@footnote{%s}"
831 (org-trim (org-export-data def info
)))))
835 (defun org-texinfo-headline (headline contents info
)
836 "Transcode a HEADLINE element from Org to Texinfo.
837 CONTENTS holds the contents of the headline. INFO is a plist
838 holding contextual information."
840 ((org-element-property :footnote-section-p headline
) nil
)
841 ((org-not-nil (org-export-get-node-property :COPYING headline t
)) nil
)
843 (let* ((index (let ((i (org-export-get-node-property :INDEX headline t
)))
844 (and (member i
'("cp" "fn" "ky" "pg" "tp" "vr")) i
)))
845 (numbered?
(org-export-numbered-headline-p headline info
))
846 (notoc?
(org-export-excluded-from-toc-p headline info
))
849 (not (org-export-low-level-p headline info
))
850 (let ((class (plist-get info
:texinfo-class
)))
851 (pcase (assoc class
(plist-get info
:texinfo-classes
))
852 (`(,_
,_ .
,sections
)
853 (pcase (nth (1- (org-export-get-relative-level headline info
))
855 (`(,numbered
,unnumbered
,unnumbered-no-toc
,appendix
)
858 (org-export-get-node-property :APPENDIX headline t
))
862 (notoc? unnumbered-no-toc
)
865 (_ (user-error "Invalid Texinfo class specification: %S"
867 (_ (user-error "Unknown Texinfo class: %S" class
))))))
869 (and (plist-get info
:with-todo-keywords
)
870 (let ((todo (org-element-property :todo-keyword headline
)))
871 (and todo
(org-export-data todo info
)))))
872 (todo-type (and todo
(org-element-property :todo-type headline
)))
873 (tags (and (plist-get info
:with-tags
)
874 (org-export-get-tags headline info
)))
875 (priority (and (plist-get info
:with-priority
)
876 (org-element-property :priority headline
)))
877 (text (org-texinfo--sanitize-title
878 (org-element-property :title headline
) info
))
880 (funcall (plist-get info
:texinfo-format-headline-function
)
881 todo todo-type priority text tags
))
884 (if (org-string-nw-p contents
) (concat "\n" contents
) "")
885 (and index
(format "\n@printindex %s\n" index
)))))
887 (concat (and (org-export-first-sibling-p headline info
)
888 (format "@%s\n" (if numbered?
'enumerate
'itemize
)))
889 "@item\n" full-text
"\n"
891 (if (org-export-last-sibling-p headline info
)
892 (format "@end %s" (if numbered?
'enumerate
'itemize
))
895 ;; Even if HEADLINE is using @subheading and al., leave an
896 ;; anchor so cross-references in the Org document still work.
897 (format (if notoc?
"@anchor{%s}\n" "@node %s\n")
898 (org-texinfo--get-node headline info
))
899 (format command full-text
)
902 (defun org-texinfo-format-headline-default-function
903 (todo _todo-type priority text tags
)
904 "Default format function for a headline.
905 See `org-texinfo-format-headline-function' for details."
906 (concat (when todo
(format "@strong{%s} " todo
))
907 (when priority
(format "@emph{#%s} " priority
))
909 (when tags
(format " :%s:" (mapconcat 'identity tags
":")))))
911 ;;;; Inline Src Block
913 (defun org-texinfo-inline-src-block (inline-src-block _contents _info
)
914 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
915 CONTENTS holds the contents of the item. INFO is a plist holding
916 contextual information."
918 (org-texinfo--sanitize-content
919 (org-element-property :value inline-src-block
))))
923 (defun org-texinfo-inlinetask (inlinetask contents info
)
924 "Transcode an INLINETASK element from Org to Texinfo.
925 CONTENTS holds the contents of the block. INFO is a plist
926 holding contextual information."
927 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
928 (todo (and (plist-get info
:with-todo-keywords
)
929 (let ((todo (org-element-property :todo-keyword inlinetask
)))
930 (and todo
(org-export-data todo info
)))))
931 (todo-type (org-element-property :todo-type inlinetask
))
932 (tags (and (plist-get info
:with-tags
)
933 (org-export-get-tags inlinetask info
)))
934 (priority (and (plist-get info
:with-priority
)
935 (org-element-property :priority inlinetask
))))
936 (funcall (plist-get info
:texinfo-format-inlinetask-function
)
937 todo todo-type priority title tags contents
)))
939 (defun org-texinfo-format-inlinetask-default-function
940 (todo _todo-type priority title tags contents
)
941 "Default format function for a inlinetasks.
942 See `org-texinfo-format-inlinetask-function' for details."
944 (concat (when todo
(format "@strong{%s} " todo
))
945 (when priority
(format "#%c " priority
))
947 (when tags
(format ":%s:" (mapconcat #'identity tags
":"))))))
948 (format "@center %s\n\n%s\n" full-title contents
)))
952 (defun org-texinfo-italic (_italic contents info
)
953 "Transcode ITALIC from Org to Texinfo.
954 CONTENTS is the text with italic markup. INFO is a plist holding
955 contextual information."
956 (org-texinfo--text-markup contents
'italic info
))
960 (defun org-texinfo-item (item contents info
)
961 "Transcode an ITEM element from Org to Texinfo.
962 CONTENTS holds the contents of the item. INFO is a plist holding
963 contextual information."
964 (let* ((tag (org-element-property :tag item
))
965 (split (org-string-nw-p
966 (org-export-read-attribute :attr_texinfo
967 (org-element-property :parent item
)
970 (let ((tag (org-export-data tag info
)))
972 (split-string tag
(regexp-quote split
) t
"[ \t\n]+")
977 (`(,item
) (concat "@item " item
))
979 (concat "@item " item
"\n"
980 (mapconcat (lambda (i) (concat "@itemx " i
))
987 (defun org-texinfo-keyword (keyword _contents info
)
988 "Transcode a KEYWORD element from Org to Texinfo.
989 CONTENTS is nil. INFO is a plist holding contextual information."
990 (let ((value (org-element-property :value keyword
)))
991 (pcase (org-element-property :key keyword
)
993 ("CINDEX" (format "@cindex %s" value
))
994 ("FINDEX" (format "@findex %s" value
))
995 ("KINDEX" (format "@kindex %s" value
))
996 ("PINDEX" (format "@pindex %s" value
))
997 ("TINDEX" (format "@tindex %s" value
))
998 ("VINDEX" (format "@vindex %s" value
))
1000 (cond ((string-match-p "\\<tables\\>" value
)
1001 (concat "@listoffloats "
1002 (org-export-translate "Table" :utf-8 info
)))
1003 ((string-match-p "\\<listings\\>" value
)
1004 (concat "@listoffloats "
1005 (org-export-translate "Listing" :utf-8 info
))))))))
1009 (defun org-texinfo-line-break (_line-break _contents _info
)
1010 "Transcode a LINE-BREAK object from Org to Texinfo.
1011 CONTENTS is nil. INFO is a plist holding contextual information."
1016 (defun org-texinfo--@ref
(datum description info
)
1017 "Return @ref command for element or object DATUM.
1018 DESCRIPTION is the printed name of the section, as a string, or
1020 (let ((node-name (org-texinfo--get-node datum info
))
1021 ;; Sanitize DESCRIPTION for cross-reference use. In
1022 ;; particular, remove colons as they seem to cause pain (even
1023 ;; within @asis{...}) to the Texinfo reader.
1024 (title (and description
1025 (replace-regexp-in-string
1027 (replace-regexp-in-string "," "@comma{}" description
)))))
1028 (if (or (not title
) (equal title node-name
))
1029 (format "@ref{%s}" node-name
)
1030 (format "@ref{%s, , %s}" node-name title
))))
1032 (defun org-texinfo-link (link desc info
)
1033 "Transcode a LINK object from Org to Texinfo.
1034 DESC is the description part of the link, or the empty string.
1035 INFO is a plist holding contextual information. See
1037 (let* ((type (org-element-property :type link
))
1038 (raw-path (org-element-property :path link
))
1039 ;; Ensure DESC really exists, or set it to nil.
1040 (desc (and (not (string= desc
"")) desc
))
1042 ((member type
'("http" "https" "ftp"))
1043 (concat type
":" raw-path
))
1044 ((string= type
"file") (org-export-file-uri raw-path
))
1047 ((org-export-custom-protocol-maybe link desc
'texinfo
))
1048 ((org-export-inline-image-p link org-texinfo-inline-image-rules
)
1049 (org-texinfo--inline-image link info
))
1050 ((equal type
"radio")
1051 (let ((destination (org-export-resolve-radio-link link info
)))
1052 (if (not destination
) desc
1053 (org-texinfo--@ref destination desc info
))))
1054 ((member type
'("custom-id" "id" "fuzzy"))
1056 (if (equal type
"fuzzy")
1057 (org-export-resolve-fuzzy-link link info
)
1058 (org-export-resolve-id-link link info
))))
1059 (pcase (org-element-type destination
)
1061 (format org-texinfo-link-with-unknown-path-format
1062 (org-texinfo--sanitize-content path
)))
1063 ;; Id link points to an external file.
1065 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1066 (format "@uref{file://%s}" destination
)))
1068 ;; Targets within headlines cannot be turned into
1069 ;; @anchor{}, so we refer to the headline parent
1072 (guard (eq 'headline
1074 (org-element-property :parent destination
))))))
1075 (let ((headline (org-element-lineage destination
'(headline) t
)))
1076 (org-texinfo--@ref headline desc info
)))
1077 (_ (org-texinfo--@ref destination desc info
)))))
1078 ((string= type
"mailto")
1079 (format "@email{%s}"
1080 (concat (org-texinfo--sanitize-content path
)
1081 (and desc
(concat ", " desc
)))))
1082 ;; External link with a description part.
1083 ((and path desc
) (format "@uref{%s, %s}" path desc
))
1084 ;; External link without a description part.
1085 (path (format "@uref{%s}" path
))
1086 ;; No path, only description. Try to do something useful.
1088 (format (plist-get info
:texinfo-link-with-unknown-path-format
) desc
)))))
1090 (defun org-texinfo--inline-image (link info
)
1091 "Return Texinfo code for an inline image.
1092 LINK is the link pointing to the inline image. INFO is the
1093 current state of the export, as a plist."
1094 (let* ((parent (org-export-get-parent-element link
))
1095 (label (and (org-element-property :name parent
)
1096 (org-texinfo--get-node parent info
)))
1097 (caption (org-export-get-caption parent
))
1098 (shortcaption (org-export-get-caption parent t
))
1099 (path (org-element-property :path link
))
1101 (file-name-sans-extension
1102 (if (file-name-absolute-p path
) (expand-file-name path
) path
)))
1103 (extension (file-name-extension path
))
1104 (attributes (org-export-read-attribute :attr_texinfo parent
))
1105 (height (or (plist-get attributes
:height
) ""))
1106 (width (or (plist-get attributes
:width
) ""))
1107 (alt (or (plist-get attributes
:alt
) ""))
1108 (image (format "@image{%s,%s,%s,%s,%s}"
1109 filename width height alt extension
)))
1110 (cond ((or caption shortcaption
)
1111 (org-texinfo--wrap-float image
1113 (org-export-translate "Figure" :utf-8 info
)
1117 (label (concat "@anchor{" label
"}\n" image
))
1123 (defun org-texinfo-make-menu (scope info
&optional master
)
1124 "Create the menu for inclusion in the Texinfo document.
1126 SCOPE is a headline or a full parse tree. INFO is the
1127 communication channel, as a plist.
1129 When optional argument MASTER is non-nil, generate a master menu,
1130 including detailed node listing."
1131 (let ((menu (org-texinfo--build-menu scope info
)))
1132 (when (org-string-nw-p menu
)
1133 (org-element-normalize-string
1135 "@menu\n%s@end menu"
1139 (org-texinfo--build-menu
1141 (let ((toc-depth (plist-get info
:with-toc
)))
1142 (if (wholenump toc-depth
) toc-depth
1143 org-texinfo-max-toc-depth
)))))
1144 (when (org-string-nw-p detailmenu
)
1145 (concat "\n@detailmenu\n"
1146 "--- The Detailed Node Listing ---\n\n"
1148 "@end detailmenu\n"))))))))))
1150 (defun org-texinfo--build-menu (scope info
&optional level
)
1151 "Build menu for entries within SCOPE.
1152 SCOPE is a headline or a full parse tree. INFO is a plist
1153 containing contextual information. When optional argument LEVEL
1154 is an integer, build the menu recursively, down to this depth."
1157 (org-texinfo--format-entries (org-texinfo--menu-entries scope info
) info
))
1158 ((zerop level
) "\n")
1162 (let ((entries (org-texinfo--menu-entries h info
)))
1165 (format "%s\n\n%s\n"
1166 (org-export-data (org-export-get-alt-title h info
) info
)
1167 (org-texinfo--format-entries entries info
))
1168 (org-texinfo--build-menu h info
(1- level
))))))
1169 (org-texinfo--menu-entries scope info
)
1172 (defun org-texinfo--format-entries (entries info
)
1173 "Format all direct menu entries in SCOPE, as a string.
1174 SCOPE is either a headline or a full Org document. INFO is
1175 a plist containing contextual information."
1176 (org-element-normalize-string
1180 ;; Colons are used as a separator between title and node
1181 ;; name. Remove them.
1182 (replace-regexp-in-string
1184 (org-texinfo--sanitize-title
1185 (org-export-get-alt-title h info
) info
)))
1186 (node (org-texinfo--get-node h info
))
1187 (entry (concat "* " title
":"
1188 (if (string= title node
) ":"
1189 (concat " " node
". "))))
1190 (desc (org-element-property :DESCRIPTION h
)))
1191 (if (not desc
) entry
1192 (format (format "%%-%ds %%s" org-texinfo-node-description-column
)
1196 (defun org-texinfo--menu-entries (scope info
)
1197 "List direct children in SCOPE needing a menu entry.
1198 SCOPE is a headline or a full parse tree. INFO is a plist
1199 holding contextual information."
1200 (let* ((cache (or (plist-get info
:texinfo-entries-cache
)
1201 (plist-get (plist-put info
:texinfo-entries-cache
1202 (make-hash-table :test
#'eq
))
1203 :texinfo-entries-cache
)))
1204 (cached-entries (gethash scope cache
'no-cache
)))
1205 (if (not (eq cached-entries
'no-cache
)) cached-entries
1209 (org-not-nil (org-export-get-node-property :COPYING h t
)))
1210 (org-export-collect-headlines info
1 scope
))
1215 (defun org-texinfo-node-property (node-property _contents _info
)
1216 "Transcode a NODE-PROPERTY element from Org to Texinfo.
1217 CONTENTS is nil. INFO is a plist holding contextual
1220 (org-element-property :key node-property
)
1221 (let ((value (org-element-property :value node-property
)))
1222 (if value
(concat " " value
) ""))))
1226 (defun org-texinfo-paragraph (_paragraph contents _info
)
1227 "Transcode a PARAGRAPH element from Org to Texinfo.
1228 CONTENTS is the contents of the paragraph, as a string. INFO is
1229 the plist used as a communication channel."
1234 (defun org-texinfo-plain-list (plain-list contents info
)
1235 "Transcode a PLAIN-LIST element from Org to Texinfo.
1236 CONTENTS is the contents of the list. INFO is a plist holding
1237 contextual information."
1238 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1239 (indic (let ((i (or (plist-get attr
:indic
)
1240 (plist-get info
:texinfo-table-default-markup
))))
1241 ;; Allow indicating commands with missing @ sign.
1242 (if (string-prefix-p "@" i
) i
(concat "@" i
))))
1243 (table-type (plist-get attr
:table-type
))
1244 (type (org-element-property :type plain-list
))
1246 ((eq type
'ordered
) "enumerate")
1247 ((eq type
'unordered
) "itemize")
1248 ((member table-type
'("ftable" "vtable")) table-type
)
1250 (format "@%s\n%s@end %s"
1251 (if (eq type
'descriptive
) (concat list-type
" " indic
) list-type
)
1257 (defun org-texinfo-plain-text (text info
)
1258 "Transcode a TEXT string from Org to Texinfo.
1259 TEXT is the string to transcode. INFO is a plist holding
1260 contextual information."
1261 ;; First protect @, { and }.
1262 (let ((output (org-texinfo--sanitize-content text
)))
1263 ;; Activate smart quotes. Be sure to provide original TEXT string
1264 ;; since OUTPUT may have been modified.
1265 (when (plist-get info
:with-smart-quotes
)
1267 (org-export-activate-smart-quotes output
:texinfo info text
)))
1268 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1269 (let ((case-fold-search nil
))
1270 (setq output
(replace-regexp-in-string "\\(?:La\\)?TeX" "@\\&{}" output
)))
1271 ;; Convert special strings.
1272 (when (plist-get info
:with-special-strings
)
1274 (replace-regexp-in-string
1275 "\\.\\.\\." "@dots{}"
1276 (replace-regexp-in-string "\\\\-" "@-" output
))))
1277 ;; Handle break preservation if required.
1278 (when (plist-get info
:preserve-breaks
)
1279 (setq output
(replace-regexp-in-string
1280 "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output
)))
1286 (defun org-texinfo-planning (planning _contents info
)
1287 "Transcode a PLANNING element from Org to Texinfo.
1288 CONTENTS is nil. INFO is a plist holding contextual
1296 (let ((closed (org-element-property :closed planning
)))
1299 (format "@strong{%s} " org-closed-string
)
1300 (format (plist-get info
:texinfo-inactive-timestamp-format
)
1301 (org-timestamp-translate closed
)))))
1302 (let ((deadline (org-element-property :deadline planning
)))
1305 (format "@strong{%s} " org-deadline-string
)
1306 (format (plist-get info
:texinfo-active-timestamp-format
)
1307 (org-timestamp-translate deadline
)))))
1308 (let ((scheduled (org-element-property :scheduled planning
)))
1311 (format "@strong{%s} " org-scheduled-string
)
1312 (format (plist-get info
:texinfo-active-timestamp-format
)
1313 (org-timestamp-translate scheduled
)))))))
1317 ;;;; Property Drawer
1319 (defun org-texinfo-property-drawer (_property-drawer contents _info
)
1320 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1321 CONTENTS holds the contents of the drawer. INFO is a plist
1322 holding contextual information."
1323 (and (org-string-nw-p contents
)
1324 (format "@verbatim\n%s@end verbatim" contents
)))
1328 (defun org-texinfo-quote-block (quote-block contents _info
)
1329 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1330 CONTENTS holds the contents of the block. INFO is a plist
1331 holding contextual information."
1332 (let* ((title (org-element-property :name quote-block
))
1333 (start-quote (concat "@quotation"
1335 (format " %s" title
)))))
1336 (format "%s\n%s@end quotation" start-quote contents
)))
1340 (defun org-texinfo-radio-target (radio-target text info
)
1341 "Transcode a RADIO-TARGET object from Org to Texinfo.
1342 TEXT is the text of the target. INFO is a plist holding
1343 contextual information."
1344 (format "@anchor{%s}%s"
1345 (org-texinfo--get-node radio-target info
)
1350 (defun org-texinfo-section (section contents info
)
1351 "Transcode a SECTION element from Org to Texinfo.
1352 CONTENTS holds the contents of the section. INFO is a plist
1353 holding contextual information."
1354 (let ((parent (org-export-get-parent-headline section
)))
1355 (when parent
;first section is handled in `org-texinfo-template'
1359 (and (not (org-export-excluded-from-toc-p parent info
))
1360 (org-texinfo-make-menu parent info
)))))))
1364 (defun org-texinfo-special-block (special-block contents _info
)
1365 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1366 CONTENTS holds the contents of the block. INFO is a plist used
1367 as a communication channel."
1368 (let ((opt (org-export-read-attribute :attr_texinfo special-block
:options
))
1369 (type (org-element-property :type special-block
)))
1370 (format "@%s%s\n%s@end %s"
1372 (if opt
(concat " " opt
) "")
1378 (defun org-texinfo-src-block (src-block _contents info
)
1379 "Transcode a SRC-BLOCK element from Org to Texinfo.
1380 CONTENTS holds the contents of the item. INFO is a plist holding
1381 contextual information."
1382 (let* ((lisp (string-match-p "lisp"
1383 (org-element-property :language src-block
)))
1384 (code (org-texinfo--sanitize-content
1385 (org-export-format-code-default src-block info
)))
1387 (if lisp
"@lisp\n%s@end lisp" "@example\n%s@end example")
1389 (caption (org-export-get-caption src-block
))
1390 (shortcaption (org-export-get-caption src-block t
)))
1391 (if (not (or caption shortcaption
)) value
1392 (org-texinfo--wrap-float value
1394 (org-export-translate "Listing" :utf-8 info
)
1395 (org-texinfo--get-node src-block info
)
1399 ;;;; Statistics Cookie
1401 (defun org-texinfo-statistics-cookie (statistics-cookie _contents _info
)
1402 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1403 CONTENTS is nil. INFO is a plist holding contextual information."
1404 (org-element-property :value statistics-cookie
))
1409 (defun org-texinfo-strike-through (_strike-through contents info
)
1410 "Transcode STRIKE-THROUGH from Org to Texinfo.
1411 CONTENTS is the text with strike-through markup. INFO is a plist
1412 holding contextual information."
1413 (org-texinfo--text-markup contents
'strike-through info
))
1417 (defun org-texinfo-subscript (_subscript contents _info
)
1418 "Transcode a SUBSCRIPT object from Org to Texinfo.
1419 CONTENTS is the contents of the object. INFO is a plist holding
1420 contextual information."
1421 (format "@math{_%s}" contents
))
1425 (defun org-texinfo-superscript (_superscript contents _info
)
1426 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1427 CONTENTS is the contents of the object. INFO is a plist holding
1428 contextual information."
1429 (format "@math{^%s}" contents
))
1433 (defun org-texinfo-table (table contents info
)
1434 "Transcode a TABLE element from Org to Texinfo.
1435 CONTENTS is the contents of the table. INFO is a plist holding
1436 contextual information."
1437 (if (eq (org-element-property :type table
) 'table.el
)
1438 (format "@verbatim\n%s@end verbatim"
1439 (org-element-normalize-string
1440 (org-element-property :value table
)))
1441 (let* ((col-width (org-export-read-attribute :attr_texinfo table
:columns
))
1443 (if col-width
(format "@columnfractions %s" col-width
)
1444 (org-texinfo-table-column-widths table info
)))
1445 (caption (org-export-get-caption table
))
1446 (shortcaption (org-export-get-caption table t
))
1447 (table-str (format "@multitable %s\n%s@end multitable"
1450 (if (not (or caption shortcaption
)) table-str
1451 (org-texinfo--wrap-float table-str
1453 (org-export-translate "Table" :utf-8 info
)
1454 (org-texinfo--get-node table info
)
1458 (defun org-texinfo-table-column-widths (table info
)
1459 "Determine the largest table cell in each column to process alignment.
1460 TABLE is the table element to transcode. INFO is a plist used as
1461 a communication channel."
1462 (let ((widths (make-vector (cdr (org-export-table-dimensions table info
)) 0)))
1463 (org-element-map table
'table-row
1466 (org-element-map row
'table-cell
1468 ;; Length of the cell in the original buffer is only an
1469 ;; approximation of the length of the cell in the
1470 ;; output. It can sometimes fail (e.g. it considers
1471 ;; "/a/" being larger than "ab").
1472 (let ((w (- (org-element-property :contents-end cell
)
1473 (org-element-property :contents-begin cell
))))
1474 (aset widths idx
(max w
(aref widths idx
))))
1478 (format "{%s}" (mapconcat (lambda (w) (make-string w ?a
)) widths
"} {"))))
1482 (defun org-texinfo-table-cell (table-cell contents info
)
1483 "Transcode a TABLE-CELL element from Org to Texinfo.
1484 CONTENTS is the cell contents. INFO is a plist used as
1485 a communication channel."
1487 (let ((scientific-notation
1488 (plist-get info
:texinfo-table-scientific-notation
)))
1491 (string-match orgtbl-exp-regexp contents
))
1492 ;; Use appropriate format string for scientific notation.
1493 (format scientific-notation
1494 (match-string 1 contents
)
1495 (match-string 2 contents
))
1497 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1501 (defun org-texinfo-table-row (table-row contents info
)
1502 "Transcode a TABLE-ROW element from Org to Texinfo.
1503 CONTENTS is the contents of the row. INFO is a plist used as
1504 a communication channel."
1505 ;; Rules are ignored since table separators are deduced from
1506 ;; borders of the current row.
1507 (when (eq (org-element-property :type table-row
) 'standard
)
1509 (if (and (= 1 (org-export-table-row-group table-row info
))
1510 (org-export-table-has-header-p
1511 (org-export-get-parent-table table-row
) info
))
1514 (concat rowgroup-tag contents
"\n"))))
1518 (defun org-texinfo-target (target _contents info
)
1519 "Transcode a TARGET object from Org to Texinfo.
1520 CONTENTS is nil. INFO is a plist holding contextual
1522 (format "@anchor{%s}" (org-texinfo--get-node target info
)))
1526 (defun org-texinfo-timestamp (timestamp _contents info
)
1527 "Transcode a TIMESTAMP object from Org to Texinfo.
1528 CONTENTS is nil. INFO is a plist holding contextual
1530 (let ((value (org-texinfo-plain-text
1531 (org-timestamp-translate timestamp
) info
)))
1532 (pcase (org-element-property :type timestamp
)
1533 ((or `active
`active-range
)
1534 (format (plist-get info
:texinfo-active-timestamp-format
) value
))
1535 ((or `inactive
`inactive-range
)
1536 (format (plist-get info
:texinfo-inactive-timestamp-format
) value
))
1537 (_ (format (plist-get info
:texinfo-diary-timestamp-format
) value
)))))
1541 (defun org-texinfo-underline (_underline contents info
)
1542 "Transcode UNDERLINE from Org to Texinfo.
1543 CONTENTS is the text with underline markup. INFO is a plist
1544 holding contextual information."
1545 (org-texinfo--text-markup contents
'underline info
))
1549 (defun org-texinfo-verbatim (verbatim _contents info
)
1550 "Transcode a VERBATIM object from Org to Texinfo.
1551 CONTENTS is nil. INFO is a plist used as a communication
1553 (org-texinfo--text-markup
1554 (org-element-property :value verbatim
) 'verbatim info
))
1558 (defun org-texinfo-verse-block (_verse-block contents _info
)
1559 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1560 CONTENTS is verse block contents. INFO is a plist holding
1561 contextual information."
1562 (format "@display\n%s@end display" contents
))
1565 ;;; Interactive functions
1568 (defun org-texinfo-export-to-texinfo
1569 (&optional async subtreep visible-only body-only ext-plist
)
1570 "Export current buffer to a Texinfo file.
1572 If narrowing is active in the current buffer, only export its
1575 If a region is active, export that region.
1577 A non-nil optional argument ASYNC means the process should happen
1578 asynchronously. The resulting file should be accessible through
1579 the `org-export-stack' interface.
1581 When optional argument SUBTREEP is non-nil, export the sub-tree
1582 at point, extracting information from the headline properties
1585 When optional argument VISIBLE-ONLY is non-nil, don't export
1586 contents of hidden elements.
1588 When optional argument BODY-ONLY is non-nil, only write code
1589 between \"\\begin{document}\" and \"\\end{document}\".
1591 EXT-PLIST, when provided, is a property list with external
1592 parameters overriding Org default settings, but still inferior to
1593 file-local settings.
1595 Return output file's name."
1597 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1598 (org-export-coding-system org-texinfo-coding-system
))
1599 (org-export-to-file 'texinfo outfile
1600 async subtreep visible-only body-only ext-plist
)))
1603 (defun org-texinfo-export-to-info
1604 (&optional async subtreep visible-only body-only ext-plist
)
1605 "Export current buffer to Texinfo then process through to INFO.
1607 If narrowing is active in the current buffer, only export its
1610 If a region is active, export that region.
1612 A non-nil optional argument ASYNC means the process should happen
1613 asynchronously. The resulting file should be accessible through
1614 the `org-export-stack' interface.
1616 When optional argument SUBTREEP is non-nil, export the sub-tree
1617 at point, extracting information from the headline properties
1620 When optional argument VISIBLE-ONLY is non-nil, don't export
1621 contents of hidden elements.
1623 When optional argument BODY-ONLY is non-nil, only write code
1624 between \"\\begin{document}\" and \"\\end{document}\".
1626 EXT-PLIST, when provided, is a property list with external
1627 parameters overriding Org default settings, but still inferior to
1628 file-local settings.
1630 When optional argument PUB-DIR is set, use it as the publishing
1633 Return INFO file's name."
1635 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1636 (org-export-coding-system org-texinfo-coding-system
))
1637 (org-export-to-file 'texinfo outfile
1638 async subtreep visible-only body-only ext-plist
1639 (lambda (file) (org-texinfo-compile file
)))))
1642 (defun org-texinfo-publish-to-texinfo (plist filename pub-dir
)
1643 "Publish an org file to Texinfo.
1645 FILENAME is the filename of the Org file to be published. PLIST
1646 is the property list for the given project. PUB-DIR is the
1647 publishing directory.
1649 Return output file name."
1650 (org-publish-org-to 'texinfo filename
".texi" plist pub-dir
))
1653 (defun org-texinfo-convert-region-to-texinfo ()
1654 "Assume the current region has Org syntax, and convert it to Texinfo.
1655 This can be used in any buffer. For example, you can write an
1656 itemized list in Org syntax in an Texinfo buffer and use this
1657 command to convert it."
1659 (org-export-replace-region-by 'texinfo
))
1661 (defun org-texinfo-compile (file)
1662 "Compile a texinfo file.
1664 FILE is the name of the file being compiled. Processing is done
1665 through the command specified in `org-texinfo-info-process',
1666 which see. Output is redirected to \"*Org INFO Texinfo Output*\"
1669 Return INFO file name or an error if it couldn't be produced."
1670 (message "Processing Texinfo file %s..." file
)
1671 (let* ((log-name "*Org INFO Texinfo Output*")
1672 (log (get-buffer-create log-name
))
1674 (org-compile-file file org-texinfo-info-process
"info"
1675 (format "See %S for details" log-name
)
1677 (when org-texinfo-remove-logfiles
1678 (let ((base (file-name-sans-extension output
)))
1679 (dolist (ext org-texinfo-logfiles-extensions
)
1680 (let ((file (concat base
"." ext
)))
1681 (when (file-exists-p file
) (delete-file file
))))))
1682 (message "Process completed.")
1686 (provide 'ox-texinfo
)
1689 ;; generated-autoload-file: "org-loaddefs.el"
1692 ;;; ox-texinfo.el ends here