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
))
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
)
91 (?o
"As INFO file and open"
93 (if a
(org-texinfo-export-to-info t s v b
)
94 (org-open-file (org-texinfo-export-to-info nil s v b
)))))))
96 '((:texinfo-filename
"TEXINFO_FILENAME" nil nil t
)
97 (:texinfo-class
"TEXINFO_CLASS" nil org-texinfo-default-class t
)
98 (:texinfo-header
"TEXINFO_HEADER" nil nil newline
)
99 (:texinfo-post-header
"TEXINFO_POST_HEADER" nil nil newline
)
100 (:subtitle
"SUBTITLE" nil nil parse
)
101 (:subauthor
"SUBAUTHOR" nil nil newline
)
102 (:texinfo-dircat
"TEXINFO_DIR_CATEGORY" nil nil t
)
103 (:texinfo-dirtitle
"TEXINFO_DIR_TITLE" nil nil t
)
104 (:texinfo-dirdesc
"TEXINFO_DIR_DESC" nil nil t
)
105 (:texinfo-printed-title
"TEXINFO_PRINTED_TITLE" nil nil t
)
107 (:texinfo-classes nil nil org-texinfo-classes
)
108 (:texinfo-format-headline-function nil nil org-texinfo-format-headline-function
)
109 (:texinfo-node-description-column nil nil org-texinfo-node-description-column
)
110 (:texinfo-active-timestamp-format nil nil org-texinfo-active-timestamp-format
)
111 (:texinfo-inactive-timestamp-format nil nil org-texinfo-inactive-timestamp-format
)
112 (:texinfo-diary-timestamp-format nil nil org-texinfo-diary-timestamp-format
)
113 (:texinfo-link-with-unknown-path-format nil nil org-texinfo-link-with-unknown-path-format
)
114 (:texinfo-tables-verbatim nil nil org-texinfo-tables-verbatim
)
115 (:texinfo-table-scientific-notation nil nil org-texinfo-table-scientific-notation
)
116 (:texinfo-table-default-markup nil nil org-texinfo-table-default-markup
)
117 (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist
)
118 (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function
)
119 (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function
)))
123 ;;; User Configurable Variables
125 (defgroup org-export-texinfo nil
126 "Options for exporting Org mode files to Texinfo."
127 :tag
"Org Export Texinfo"
129 :package-version
'(Org .
"8.0")
134 (defcustom org-texinfo-coding-system nil
135 "Default document encoding for Texinfo output.
137 If nil it will default to `buffer-file-coding-system'."
138 :group
'org-export-texinfo
139 :type
'coding-system
)
141 (defcustom org-texinfo-default-class
"info"
142 "The default Texinfo class."
143 :group
'org-export-texinfo
144 :type
'(string :tag
"Texinfo class"))
146 (defcustom org-texinfo-classes
148 "@documentencoding AUTO\n@documentlanguage AUTO"
149 ("@chapter %s" "@unnumbered %s" "@chapheading %s" "@appendix %s")
150 ("@section %s" "@unnumberedsec %s" "@heading %s" "@appendixsec %s")
151 ("@subsection %s" "@unnumberedsubsec %s" "@subheading %s"
152 "@appendixsubsec %s")
153 ("@subsubsection %s" "@unnumberedsubsubsec %s" "@subsubheading %s"
154 "@appendixsubsubsec %s")))
155 "Alist of Texinfo classes and associated header and structure.
156 If #+TEXINFO_CLASS is set in the buffer, use its value and the
157 associated information. Here is the structure of a class
162 (numbered-1 unnumbered-1 unnumbered-no-toc-1 appendix-1)
163 (numbered-2 unnumbered-2 unnumbered-no-toc-2 appendix-2)
170 The header string is inserted in the header of the generated
171 document, right after \"@setfilename\" and \"@settitle\"
174 If it contains the special string
176 \"@documentencoding AUTO\"
178 \"AUTO\" will be replaced with an appropriate coding system. See
179 `org-texinfo-coding-system' for more information. Likewise, if
180 the string contains the special string
182 \"@documentlanguage AUTO\"
184 \"AUTO\" will be replaced with the language defined in the
185 buffer, through #+LANGUAGE keyword, or globally, with
186 `org-export-default-language', which see.
189 The sectioning structure
190 ------------------------
192 The sectioning structure of the class is given by the elements
193 following the header string. For each sectioning level, a number
194 of strings is specified. A %s formatter is mandatory in each
195 section string and will be replaced by the title of the section."
196 :group
'org-export-texinfo
198 :package-version
'(Org .
"9.2")
200 (list (string :tag
"Texinfo class")
201 (string :tag
"Texinfo header")
202 (repeat :tag
"Levels" :inline t
205 (string :tag
" numbered")
206 (string :tag
" unnumbered")
207 (string :tag
"unnumbered-no-toc")
208 (string :tag
" appendix")))))))
212 (defcustom org-texinfo-format-headline-function
213 'org-texinfo-format-headline-default-function
214 "Function to format headline text.
216 This function will be called with 5 arguments:
217 TODO the todo keyword (string or nil).
218 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
219 PRIORITY the priority of the headline (integer or nil)
220 TEXT the main headline text (string).
221 TAGS the tags as a list of strings (list of strings or nil).
223 The function result will be used in the section format string."
224 :group
'org-export-texinfo
227 :package-version
'(Org .
"8.3"))
229 ;;;; Node listing (menu)
231 (defcustom org-texinfo-node-description-column
32
232 "Column at which to start the description in the node listings.
233 If a node title is greater than this length, the description will
234 be placed after the end of the title."
235 :group
'org-export-texinfo
240 (defcustom org-texinfo-active-timestamp-format
"@emph{%s}"
241 "A printf format string to be applied to active timestamps."
242 :group
'org-export-texinfo
245 (defcustom org-texinfo-inactive-timestamp-format
"@emph{%s}"
246 "A printf format string to be applied to inactive timestamps."
247 :group
'org-export-texinfo
250 (defcustom org-texinfo-diary-timestamp-format
"@emph{%s}"
251 "A printf format string to be applied to diary timestamps."
252 :group
'org-export-texinfo
257 (defcustom org-texinfo-link-with-unknown-path-format
"@indicateurl{%s}"
258 "Format string for links with unknown path type."
259 :group
'org-export-texinfo
264 (defcustom org-texinfo-tables-verbatim nil
265 "When non-nil, tables are exported verbatim."
266 :group
'org-export-texinfo
269 (defcustom org-texinfo-table-scientific-notation
"%s\\,(%s)"
270 "Format string to display numbers in scientific notation.
272 The format should have \"%s\" twice, for mantissa and exponent
273 \(i.e. \"%s\\\\times10^{%s}\").
275 When nil, no transformation is made."
276 :group
'org-export-texinfo
278 (string :tag
"Format string")
279 (const :tag
"No formatting" nil
)))
281 (defcustom org-texinfo-table-default-markup
"@asis"
282 "Default markup for first column in two-column tables.
284 This should an indicating command, e.g., \"@code\", \"@kbd\" or
287 It can be overridden locally using the \":indic\" attribute."
288 :group
'org-export-texinfo
291 :package-version
'(Org .
"9.1")
296 (defcustom org-texinfo-text-markup-alist
'((bold .
"@strong{%s}")
298 (italic .
"@emph{%s}")
300 "Alist of Texinfo expressions to convert text markup.
302 The key must be a symbol among `bold', `code', `italic',
303 `strike-through', `underscore' and `verbatim'. The value is
304 a formatting string to wrap fontified text with.
306 Value can also be set to the following symbols: `verb', `samp'
307 and `code'. With the first one, Org uses \"@verb\" to create
308 a format string and selects a delimiter character that isn't in
309 the string. For the other two, Org uses \"@samp\" or \"@code\"
310 to typeset and protects special characters.
312 When no association is found for a given markup, text is returned
314 :group
'org-export-texinfo
316 :package-version
'(Org .
"9.1")
318 :options
'(bold code italic strike-through underscore verbatim
))
322 (defcustom org-texinfo-format-drawer-function
(lambda (_name contents
) contents
)
323 "Function called to format a drawer in Texinfo code.
325 The function must accept two parameters:
326 NAME the drawer name, like \"LOGBOOK\"
327 CONTENTS the contents of the drawer.
329 The function should return the string to be exported.
331 The default function simply returns the value of CONTENTS."
332 :group
'org-export-texinfo
334 :package-version
'(Org .
"8.2")
339 (defcustom org-texinfo-format-inlinetask-function
340 'org-texinfo-format-inlinetask-default-function
341 "Function called to format an inlinetask in Texinfo code.
343 The function must accept six parameters:
344 TODO the todo keyword, as a string
345 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
346 PRIORITY the inlinetask priority, as a string
347 NAME the inlinetask name, as a string.
348 TAGS the inlinetask tags, as a list of strings.
349 CONTENTS the contents of the inlinetask, as a string.
351 The function should return the string to be exported."
352 :group
'org-export-texinfo
357 (defcustom org-texinfo-info-process
'("makeinfo --no-split %f")
358 "Commands to process a Texinfo file to an INFO file.
360 This is a list of strings, each of them will be given to the
361 shell as a command. %f in the command will be replaced by the
362 relative file name, %F by the absolute file name, %b by the file
363 base name (i.e. without directory and extension parts), %o by the
364 base directory of the file and %O by the absolute file name of
366 :group
'org-export-texinfo
368 :package-version
'(Org .
"9.1")
369 :type
'(repeat :tag
"Shell command sequence"
370 (string :tag
"Shell command")))
372 (defcustom org-texinfo-logfiles-extensions
373 '("aux" "toc" "cp" "fn" "ky" "pg" "tp" "vr")
374 "The list of file extensions to consider as Texinfo logfiles.
375 The logfiles will be remove if `org-texinfo-remove-logfiles' is
377 :group
'org-export-texinfo
378 :type
'(repeat (string :tag
"Extension")))
380 (defcustom org-texinfo-remove-logfiles t
381 "Non-nil means remove the logfiles produced by compiling a Texinfo file.
382 By default, logfiles are files with these extensions: .aux, .toc,
383 .cp, .fn, .ky, .pg and .tp. To define the set of logfiles to remove,
384 set `org-texinfo-logfiles-extensions'."
385 :group
'org-export-latex
390 (defconst org-texinfo-max-toc-depth
4
391 "Maximum depth for creation of detailed menu listings.
392 Beyond this depth, Texinfo will not recognize the nodes and will
393 cause errors. Left as a constant in case this value ever
396 (defconst org-texinfo-supported-coding-systems
397 '("US-ASCII" "UTF-8" "ISO-8859-15" "ISO-8859-1" "ISO-8859-2" "koi8-r" "koi8-u")
398 "List of coding systems supported by Texinfo, as strings.
399 Specified coding system will be matched against these strings.
400 If two strings share the same prefix (e.g. \"ISO-8859-1\" and
401 \"ISO-8859-15\"), the most specific one has to be listed first.")
403 (defconst org-texinfo-inline-image-rules
405 (regexp-opt '("eps" "pdf" "png" "jpg" "jpeg" "gif" "svg"))))
406 "Rules characterizing image files that can be inlined.")
409 ;;; Internal Functions
411 (defun org-texinfo--filter-section-blank-lines (headline _backend _info
)
412 "Filter controlling number of blank lines after a section."
413 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" "\n\n" headline
))
415 (defun org-texinfo--normalize-headlines (tree _backend info
)
416 "Normalize headlines in TREE.
418 BACK-END is the symbol specifying back-end used for export. INFO
419 is a plist used as a communication channel.
421 Make sure every headline in TREE contains a section, since those
422 are required to install a menu. Also put exactly one blank line
423 at the end of each section.
426 (org-element-map tree
'headline
428 (org-element-put-property hl
:post-blank
1)
429 (let ((contents (org-element-contents hl
)))
431 (let ((first (org-element-map contents
'(headline section
)
433 (unless (eq (org-element-type first
) 'section
)
434 (apply #'org-element-set-contents
436 (cons `(section (:parent
,hl
)) contents
)))))))
440 (defun org-texinfo--find-verb-separator (s)
441 "Return a character not used in string S.
442 This is used to choose a separator for constructs like \\verb."
443 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
444 (cl-loop for c across ll
445 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
446 return
(char-to-string c
))))
448 (defun org-texinfo--text-markup (text markup _info
)
449 "Format TEXT depending on MARKUP text markup.
450 INFO is a plist used as a communication channel. See
451 `org-texinfo-text-markup-alist' for details."
452 (pcase (cdr (assq markup org-texinfo-text-markup-alist
))
453 (`nil text
) ;no markup: return raw text
454 (`code
(format "@code{%s}" (org-texinfo--sanitize-content text
)))
455 (`samp
(format "@samp{%s}" (org-texinfo--sanitize-content text
)))
457 (let ((separator (org-texinfo--find-verb-separator text
)))
458 (format "@verb{%s%s%s}" separator text separator
)))
459 ;; Else use format string.
460 (fmt (format fmt text
))))
462 (defun org-texinfo--get-node (datum info
)
463 "Return node or anchor associated to DATUM.
464 DATUM is an element or object. INFO is a plist used as
465 a communication channel. The function guarantees the node or
466 anchor name is unique."
467 (let ((cache (plist-get info
:texinfo-node-cache
)))
468 (or (cdr (assq datum cache
))
471 (org-texinfo--sanitize-node
472 (if (eq (org-element-type datum
) 'headline
)
473 (org-texinfo--sanitize-title
474 (org-export-get-alt-title datum info
) info
)
475 (org-export-get-reference datum info
))))
477 ;; Ensure NAME is unique and not reserved node name "Top".
478 (while (or (equal name
"Top") (rassoc name cache
))
479 (setq name
(concat basename
(format " %d" (cl-incf salt
)))))
480 (plist-put info
:texinfo-node-cache
(cons (cons datum name
) cache
))
483 (defun org-texinfo--sanitize-node (title)
484 "Bend string TITLE to node line requirements.
485 Trim string and collapse multiple whitespace characters as they
486 are not significant. Replace leading left parenthesis, when
487 followed by a right parenthesis, with a square bracket. Remove
488 periods, commas and colons."
490 (replace-regexp-in-string
492 (replace-regexp-in-string
494 (replace-regexp-in-string "\\`(\\(.*?)\\)" "[\\1" title
)))))
496 (defun org-texinfo--sanitize-title (title info
)
497 "Make TITLE suitable as a section name.
498 TITLE is a string or a secondary string. INFO is the current
499 export state, as a plist."
500 (org-export-data-with-backend
502 (org-export-create-backend
504 :transcoders
'((footnote-reference . ignore
)
505 (link .
(lambda (l c i
)
508 (org-element-property :raw-link l
)
510 (radio-target .
(lambda (_r c _i
) c
))
514 (defun org-texinfo--sanitize-content (text)
515 "Escape special characters in string TEXT.
516 Special characters are: @ { }"
517 (replace-regexp-in-string "[@{}]" "@\\&" text
))
519 (defun org-texinfo--wrap-float (value info
&optional type label caption short
)
520 "Wrap string VALUE within a @float command.
521 INFO is the current export state, as a plist. TYPE is float
522 type, as a string. LABEL is the cross reference label for the
523 float, as a string. CAPTION and SHORT are, respectively, the
524 caption and shortcaption used for the float, as secondary
525 strings (e.g., returned by `org-export-get-caption')."
527 (org-export-create-backend
529 :transcoders
'((link .
(lambda (l c i
)
532 (org-element-property :raw-link l
)
534 (radio-target .
(lambda (_r c _i
) c
))
537 (org-export-create-backend
540 '((footnote-reference . ignore
)
541 (inline-src-block . ignore
)
542 (link .
(lambda (l c i
)
545 (org-element-property :raw-link l
)
547 (radio-target .
(lambda (_r c _i
) c
))
549 (verbatim . ignore
))))
551 (if (and short caption
)
552 (format "@shortcaption{%s}\n"
553 (org-export-data-with-backend short short-backend info
))
556 (if (or short caption
)
557 (format "@caption{%s}\n"
558 (org-export-data-with-backend
560 (if (equal short-str
"") short-backend backend
)
563 (format "@float %s%s\n%s\n%s%s@end float"
564 type
(if label
(concat "," label
) "") value caption-str short-str
)))
568 (defun org-texinfo-template (contents info
)
569 "Return complete document string after Texinfo conversion.
570 CONTENTS is the transcoded contents string. INFO is a plist
571 holding export options."
572 (let ((title (org-export-data (plist-get info
:title
) info
))
573 ;; Copying data is the contents of the first headline in
574 ;; parse tree with a non-nil copying property.
575 (copying (org-element-map (plist-get info
:parse-tree
) 'headline
577 (and (org-not-nil (org-element-property :COPYING hl
))
578 (org-element-contents hl
)))
581 "\\input texinfo @c -*- texinfo -*-\n"
582 "@c %**start of header\n"
583 (let ((file (or (plist-get info
:texinfo-filename
)
584 (let ((f (plist-get info
:output-file
)))
585 (and f
(concat (file-name-sans-extension f
) ".info"))))))
586 (and file
(format "@setfilename %s\n" file
)))
587 (format "@settitle %s\n" title
)
588 ;; Insert class-defined header.
589 (org-element-normalize-string
590 (let ((header (nth 1 (assoc (plist-get info
:texinfo-class
)
591 org-texinfo-classes
)))
593 (catch 'coding-system
594 (let ((case-fold-search t
)
595 (name (symbol-name (or org-texinfo-coding-system
596 buffer-file-coding-system
))))
597 (dolist (system org-texinfo-supported-coding-systems
"UTF-8")
598 (when (string-match-p (regexp-quote system
) name
)
599 (throw 'coding-system system
))))))
600 (language (plist-get info
:language
))
601 (case-fold-search nil
))
602 ;; Auto coding system.
603 (replace-regexp-in-string
604 "^@documentencoding \\(AUTO\\)$"
606 (replace-regexp-in-string
607 "^@documentlanguage \\(AUTO\\)$" language header t nil
1) t nil
1)))
608 ;; Additional header options set by #+TEXINFO_HEADER.
609 (let ((texinfo-header (plist-get info
:texinfo-header
)))
610 (and texinfo-header
(org-element-normalize-string texinfo-header
)))
611 "@c %**end of header\n\n"
612 ;; Additional options set by #+TEXINFO_POST_HEADER.
613 (let ((texinfo-post-header (plist-get info
:texinfo-post-header
)))
614 (and texinfo-post-header
615 (org-element-normalize-string texinfo-post-header
)))
618 (format "@copying\n%s@end copying\n\n"
619 (org-element-normalize-string
620 (org-export-data copying info
))))
621 ;; Info directory information. Only supply if both title and
622 ;; category are provided.
623 (let ((dircat (plist-get info
:texinfo-dircat
))
625 (let ((title (plist-get info
:texinfo-dirtitle
)))
627 (string-match "^\\(?:\\* \\)?\\(.*?\\)\\(\\.\\)?$" title
)
628 (format "* %s." (match-string 1 title
))))))
629 (when (and dircat dirtitle
)
630 (concat "@dircategory " dircat
"\n"
633 (let ((desc (plist-get info
:texinfo-dirdesc
)))
634 (cond ((not desc
) nil
)
635 ((string-suffix-p "." desc
) desc
)
636 (t (concat desc
"."))))))
637 (if dirdesc
(format "%-23s %s" dirtitle dirdesc
) dirtitle
))
639 "@end direntry\n\n")))
643 (when (plist-get info
:with-title
)
645 (format "@title %s\n"
646 (or (plist-get info
:texinfo-printed-title
) title
""))
647 (let ((subtitle (plist-get info
:subtitle
)))
649 (format "@subtitle %s\n"
650 (org-export-data subtitle info
))))))
651 (when (plist-get info
:with-author
)
654 (let ((author (org-string-nw-p
655 (org-export-data (plist-get info
:author
) info
)))
656 (email (and (plist-get info
:with-email
)
658 (org-export-data (plist-get info
:email
) info
)))))
659 (cond ((and author email
)
660 (format "@author %s (@email{%s})\n" author email
))
661 (author (format "@author %s\n" author
))
662 (email (format "@author @email{%s}\n" email
))))
664 (let ((subauthor (plist-get info
:subauthor
)))
666 (org-element-normalize-string
667 (replace-regexp-in-string "^" "@author " subauthor
))))))
668 (and copying
"@page\n@vskip 0pt plus 1filll\n@insertcopying\n")
670 ;; Table of contents.
671 (and (plist-get info
:with-toc
) "@contents\n\n")
672 ;; Configure Top Node when not for TeX. Also include contents
673 ;; from the first section of the document.
676 (format "@top %s\n" title
)
677 (let* ((first-section
678 (org-element-map (plist-get info
:parse-tree
) 'section
679 #'identity info t
'(headline)))
681 (org-export-data (org-element-contents first-section
) info
)))
682 (and (org-string-nw-p top-contents
) (concat "\n" top-contents
)))
685 (org-texinfo-make-menu (plist-get info
:parse-tree
) info
'master
)
690 (and (plist-get info
:with-creator
)
691 (concat (plist-get info
:creator
) "\n"))
697 ;;; Transcode Functions
701 (defun org-texinfo-bold (_bold contents info
)
702 "Transcode BOLD from Org to Texinfo.
703 CONTENTS is the text with bold markup. INFO is a plist holding
704 contextual information."
705 (org-texinfo--text-markup contents
'bold info
))
709 (defun org-texinfo-center-block (_center-block contents _info
)
710 "Transcode a CENTER-BLOCK element from Org to Texinfo.
711 CONTENTS holds the contents of the block. INFO is a plist used
712 as a communication channel."
717 (defun org-texinfo-clock (clock _contents info
)
718 "Transcode a CLOCK element from Org to Texinfo.
719 CONTENTS is nil. INFO is a plist holding contextual
723 (format "@strong{%s} " org-clock-string
)
724 (format (plist-get info
:texinfo-inactive-timestamp-format
)
725 (concat (org-timestamp-translate (org-element-property :value clock
))
726 (let ((time (org-element-property :duration clock
)))
727 (and time
(format " (%s)" time
)))))
732 (defun org-texinfo-code (code _contents info
)
733 "Transcode a CODE object from Org to Texinfo.
734 CONTENTS is nil. INFO is a plist used as a communication
736 (org-texinfo--text-markup (org-element-property :value code
) 'code info
))
740 (defun org-texinfo-drawer (drawer contents info
)
741 "Transcode a DRAWER element from Org to Texinfo.
742 CONTENTS holds the contents of the block. INFO is a plist
743 holding contextual information."
744 (let* ((name (org-element-property :drawer-name drawer
))
745 (output (funcall (plist-get info
:texinfo-format-drawer-function
)
751 (defun org-texinfo-dynamic-block (_dynamic-block contents _info
)
752 "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
753 CONTENTS holds the contents of the block. INFO is a plist
754 holding contextual information."
759 (defun org-texinfo-entity (entity _contents _info
)
760 "Transcode an ENTITY object from Org to Texinfo."
761 ;; Since there is not specific Texinfo entry in entities, use
762 ;; Texinfo-specific commands whenever possible, and fallback to
764 (pcase (org-element-property :name entity
)
767 ((or "bull" "bullet") "@bullet{}")
768 ("copy" "@copyright{}")
769 ("deg" "@textdegree{}")
770 ((or "dots" "hellip") "@dots{}")
772 ((or "euro" "EUR") "@euro{}")
773 ((or "ge" "geq") "@geq{}")
774 ("laquo" "@guillemetleft{}")
775 ("iexcl" "@exclamdown{}")
776 ("imath" "@dotless{i}")
777 ("iquest" "@questiondown{}")
778 ("jmath" "@dotless{j}")
779 ((or "le" "leq") "@leq{}")
780 ("lsaquo" "@guilsinglleft{}")
790 ("raquo" "@guillemetright{}")
791 ((or "rArr" "Rightarrow") "@result{}")
792 ("reg" "@registeredsymbol{}")
793 ((or "rightarrow" "to" "rarr") "@arrow{}")
794 ("rsaquo" "@guilsinglright{}")
797 ((and (pred (string-prefix-p "_")) name
) ;spacing entities
798 (format "@w{%s}" (substring name
1)))
799 (_ (org-element-property :utf-8 entity
))))
803 (defun org-texinfo-example-block (example-block _contents info
)
804 "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
805 CONTENTS is nil. INFO is a plist holding contextual
807 (format "@example\n%s@end example"
808 (org-texinfo--sanitize-content
809 (org-export-format-code-default example-block info
))))
813 (defun org-texinfo-export-block (export-block _contents _info
)
814 "Transcode a EXPORT-BLOCK element from Org to Texinfo.
815 CONTENTS is nil. INFO is a plist holding contextual information."
816 (when (string= (org-element-property :type export-block
) "TEXINFO")
817 (org-remove-indentation (org-element-property :value export-block
))))
821 (defun org-texinfo-export-snippet (export-snippet _contents _info
)
822 "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
823 CONTENTS is nil. INFO is a plist holding contextual information."
824 (when (eq (org-export-snippet-backend export-snippet
) 'texinfo
)
825 (org-element-property :value export-snippet
)))
829 (defun org-texinfo-fixed-width (fixed-width _contents _info
)
830 "Transcode a FIXED-WIDTH element from Org to Texinfo.
831 CONTENTS is nil. INFO is a plist holding contextual information."
832 (format "@example\n%s@end example"
833 (org-remove-indentation
834 (org-texinfo--sanitize-content
835 (org-element-property :value fixed-width
)))))
837 ;;;; Footnote Reference
839 (defun org-texinfo-footnote-reference (footnote _contents info
)
840 "Create a footnote reference for FOOTNOTE.
842 FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
843 plist holding contextual information."
844 (let ((def (org-export-get-footnote-definition footnote info
)))
845 (format "@footnote{%s}"
846 (org-trim (org-export-data def info
)))))
850 (defun org-texinfo-headline (headline contents info
)
851 "Transcode a HEADLINE element from Org to Texinfo.
852 CONTENTS holds the contents of the headline. INFO is a plist
853 holding contextual information."
855 ((org-element-property :footnote-section-p headline
) nil
)
856 ((org-not-nil (org-export-get-node-property :COPYING headline t
)) nil
)
858 (let* ((index (let ((i (org-export-get-node-property :INDEX headline t
)))
859 (and (member i
'("cp" "fn" "ky" "pg" "tp" "vr")) i
)))
860 (numbered?
(org-export-numbered-headline-p headline info
))
861 (notoc?
(org-export-excluded-from-toc-p headline info
))
864 (not (org-export-low-level-p headline info
))
865 (let ((class (plist-get info
:texinfo-class
)))
866 (pcase (assoc class
(plist-get info
:texinfo-classes
))
867 (`(,_
,_ .
,sections
)
868 (pcase (nth (1- (org-export-get-relative-level headline info
))
870 (`(,numbered
,unnumbered
,unnumbered-no-toc
,appendix
)
873 (org-export-get-node-property :APPENDIX headline t
))
877 (notoc? unnumbered-no-toc
)
880 (_ (user-error "Invalid Texinfo class specification: %S"
882 (_ (user-error "Unknown Texinfo class: %S" class
))))))
884 (and (plist-get info
:with-todo-keywords
)
885 (let ((todo (org-element-property :todo-keyword headline
)))
886 (and todo
(org-export-data todo info
)))))
887 (todo-type (and todo
(org-element-property :todo-type headline
)))
888 (tags (and (plist-get info
:with-tags
)
889 (org-export-get-tags headline info
)))
890 (priority (and (plist-get info
:with-priority
)
891 (org-element-property :priority headline
)))
892 (text (org-texinfo--sanitize-title
893 (org-element-property :title headline
) info
))
895 (funcall (plist-get info
:texinfo-format-headline-function
)
896 todo todo-type priority text tags
))
899 (if (org-string-nw-p contents
) (concat "\n" contents
) "")
900 (and index
(format "\n@printindex %s\n" index
)))))
902 (concat (and (org-export-first-sibling-p headline info
)
903 (format "@%s\n" (if numbered?
'enumerate
'itemize
)))
904 "@item\n" full-text
"\n"
906 (if (org-export-last-sibling-p headline info
)
907 (format "@end %s" (if numbered?
'enumerate
'itemize
))
911 (format "@node %s\n" (org-texinfo--get-node headline info
)))
912 (format command full-text
)
915 (defun org-texinfo-format-headline-default-function
916 (todo _todo-type priority text tags
)
917 "Default format function for a headline.
918 See `org-texinfo-format-headline-function' for details."
919 (concat (when todo
(format "@strong{%s} " todo
))
920 (when priority
(format "@emph{#%s} " priority
))
922 (when tags
(format " :%s:" (mapconcat 'identity tags
":")))))
924 ;;;; Inline Src Block
926 (defun org-texinfo-inline-src-block (inline-src-block _contents _info
)
927 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
928 CONTENTS holds the contents of the item. INFO is a plist holding
929 contextual information."
931 (org-texinfo--sanitize-content
932 (org-element-property :value inline-src-block
))))
936 (defun org-texinfo-inlinetask (inlinetask contents info
)
937 "Transcode an INLINETASK element from Org to Texinfo.
938 CONTENTS holds the contents of the block. INFO is a plist
939 holding contextual information."
940 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
941 (todo (and (plist-get info
:with-todo-keywords
)
942 (let ((todo (org-element-property :todo-keyword inlinetask
)))
943 (and todo
(org-export-data todo info
)))))
944 (todo-type (org-element-property :todo-type inlinetask
))
945 (tags (and (plist-get info
:with-tags
)
946 (org-export-get-tags inlinetask info
)))
947 (priority (and (plist-get info
:with-priority
)
948 (org-element-property :priority inlinetask
))))
949 (funcall (plist-get info
:texinfo-format-inlinetask-function
)
950 todo todo-type priority title tags contents
)))
952 (defun org-texinfo-format-inlinetask-default-function
953 (todo _todo-type priority title tags contents
)
954 "Default format function for a inlinetasks.
955 See `org-texinfo-format-inlinetask-function' for details."
957 (concat (when todo
(format "@strong{%s} " todo
))
958 (when priority
(format "#%c " priority
))
960 (when tags
(format ":%s:" (mapconcat #'identity tags
":"))))))
961 (format "@center %s\n\n%s\n" full-title contents
)))
965 (defun org-texinfo-italic (_italic contents info
)
966 "Transcode ITALIC from Org to Texinfo.
967 CONTENTS is the text with italic markup. INFO is a plist holding
968 contextual information."
969 (org-texinfo--text-markup contents
'italic info
))
973 (defun org-texinfo-item (item contents info
)
974 "Transcode an ITEM element from Org to Texinfo.
975 CONTENTS holds the contents of the item. INFO is a plist holding
976 contextual information."
977 (let* ((tag (org-element-property :tag item
))
978 (split (org-string-nw-p
979 (org-export-read-attribute :attr_texinfo
980 (org-element-property :parent item
)
983 (let ((tag (org-export-data tag info
)))
985 (split-string tag
(regexp-quote split
) t
"[ \t\n]+")
990 (`(,item
) (concat "@item " item
))
992 (concat "@item " item
"\n"
993 (mapconcat (lambda (i) (concat "@itemx " i
))
1000 (defun org-texinfo-keyword (keyword _contents info
)
1001 "Transcode a KEYWORD element from Org to Texinfo.
1002 CONTENTS is nil. INFO is a plist holding contextual information."
1003 (let ((value (org-element-property :value keyword
)))
1004 (pcase (org-element-property :key keyword
)
1006 ("CINDEX" (format "@cindex %s" value
))
1007 ("FINDEX" (format "@findex %s" value
))
1008 ("KINDEX" (format "@kindex %s" value
))
1009 ("PINDEX" (format "@pindex %s" value
))
1010 ("TINDEX" (format "@tindex %s" value
))
1011 ("VINDEX" (format "@vindex %s" value
))
1013 (cond ((string-match-p "\\<tables\\>" value
)
1014 (concat "@listoffloats "
1015 (org-export-translate "Table" :utf-8 info
)))
1016 ((string-match-p "\\<listings\\>" value
)
1017 (concat "@listoffloats "
1018 (org-export-translate "Listing" :utf-8 info
))))))))
1022 (defun org-texinfo-line-break (_line-break _contents _info
)
1023 "Transcode a LINE-BREAK object from Org to Texinfo.
1024 CONTENTS is nil. INFO is a plist holding contextual information."
1029 (defun org-texinfo--@ref
(datum description info
)
1030 "Return @ref command for element or object DATUM.
1031 DESCRIPTION is the name of the section to print, as a string."
1032 (let ((node-name (org-texinfo--get-node datum info
))
1033 ;; Sanitize DESCRIPTION for cross-reference use. In
1034 ;; particular, remove colons as they seem to cause (even
1035 ;; within @asis{...} to the Texinfo reader.
1036 (title (replace-regexp-in-string
1038 (replace-regexp-in-string "," "@comma{}" description
))))
1039 (if (equal title node-name
)
1040 (format "@ref{%s}" node-name
)
1041 (format "@ref{%s, , %s}" node-name title
))))
1043 (defun org-texinfo-link (link desc info
)
1044 "Transcode a LINK object from Org to Texinfo.
1045 DESC is the description part of the link, or the empty string.
1046 INFO is a plist holding contextual information. See
1048 (let* ((type (org-element-property :type link
))
1049 (raw-path (org-element-property :path link
))
1050 ;; Ensure DESC really exists, or set it to nil.
1051 (desc (and (not (string= desc
"")) desc
))
1053 ((member type
'("http" "https" "ftp"))
1054 (concat type
":" raw-path
))
1055 ((string= type
"file") (org-export-file-uri raw-path
))
1058 ((org-export-custom-protocol-maybe link desc
'texinfo
))
1059 ((org-export-inline-image-p link org-texinfo-inline-image-rules
)
1060 (org-texinfo--inline-image link info
))
1061 ((equal type
"radio")
1062 (let ((destination (org-export-resolve-radio-link link info
)))
1063 (if (not destination
) desc
1064 (org-texinfo--@ref destination desc info
))))
1065 ((member type
'("custom-id" "id" "fuzzy"))
1067 (if (equal type
"fuzzy")
1068 (org-export-resolve-fuzzy-link link info
)
1069 (org-export-resolve-id-link link info
))))
1070 (pcase (org-element-type destination
)
1072 (format org-texinfo-link-with-unknown-path-format
1073 (org-texinfo--sanitize-content path
)))
1074 ;; Id link points to an external file.
1076 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1077 (format "@uref{file://%s}" destination
)))
1079 ;; Targets within headlines cannot be turned into
1080 ;; @anchor{}, so we refer to the headline parent
1083 (guard (eq 'headline
1085 (org-element-property :parent destination
))))))
1086 (let ((headline (org-element-lineage destination
'(headline) t
)))
1089 (or desc
(org-texinfo--sanitize-title
1090 (org-element-property :title headline
) info
))
1096 (pcase (org-export-get-ordinal destination info
)
1097 ((and (pred integerp
) n
) (number-to-string n
))
1098 ((and (pred consp
) n
) (mapconcat #'number-to-string n
"."))
1099 (_ "???"))) ;cannot guess the description
1101 ((string= type
"mailto")
1102 (format "@email{%s}"
1103 (concat (org-texinfo--sanitize-content path
)
1104 (and desc
(concat ", " desc
)))))
1105 ;; External link with a description part.
1106 ((and path desc
) (format "@uref{%s, %s}" path desc
))
1107 ;; External link without a description part.
1108 (path (format "@uref{%s}" path
))
1109 ;; No path, only description. Try to do something useful.
1111 (format (plist-get info
:texinfo-link-with-unknown-path-format
) desc
)))))
1113 (defun org-texinfo--inline-image (link info
)
1114 "Return Texinfo code for an inline image.
1115 LINK is the link pointing to the inline image. INFO is the
1116 current state of the export, as a plist."
1117 (let* ((parent (org-export-get-parent-element link
))
1118 (label (and (org-element-property :name parent
)
1119 (org-texinfo--get-node parent info
)))
1120 (caption (org-export-get-caption parent
))
1121 (shortcaption (org-export-get-caption parent t
))
1122 (path (org-element-property :path link
))
1124 (file-name-sans-extension
1125 (if (file-name-absolute-p path
) (expand-file-name path
) path
)))
1126 (extension (file-name-extension path
))
1127 (attributes (org-export-read-attribute :attr_texinfo parent
))
1128 (height (or (plist-get attributes
:height
) ""))
1129 (width (or (plist-get attributes
:width
) ""))
1130 (alt (or (plist-get attributes
:alt
) ""))
1131 (image (format "@image{%s,%s,%s,%s,%s}"
1132 filename width height alt extension
)))
1133 (cond ((or caption shortcaption
)
1134 (org-texinfo--wrap-float image
1136 (org-export-translate "Figure" :utf-8 info
)
1140 (label (concat "@anchor{" label
"}\n" image
))
1146 (defun org-texinfo-make-menu (scope info
&optional master
)
1147 "Create the menu for inclusion in the Texinfo document.
1149 SCOPE is a headline or a full parse tree. INFO is the
1150 communication channel, as a plist.
1152 When optional argument MASTER is non-nil, generate a master menu,
1153 including detailed node listing."
1154 (let ((menu (org-texinfo--build-menu scope info
)))
1155 (when (org-string-nw-p menu
)
1156 (org-element-normalize-string
1158 "@menu\n%s@end menu"
1162 (org-texinfo--build-menu
1164 (let ((toc-depth (plist-get info
:with-toc
)))
1165 (if (wholenump toc-depth
) toc-depth
1166 org-texinfo-max-toc-depth
)))))
1167 (when (org-string-nw-p detailmenu
)
1168 (concat "\n@detailmenu\n"
1169 "--- The Detailed Node Listing ---\n\n"
1171 "@end detailmenu\n"))))))))))
1173 (defun org-texinfo--build-menu (scope info
&optional level
)
1174 "Build menu for entries within SCOPE.
1175 SCOPE is a headline or a full parse tree. INFO is a plist
1176 containing contextual information. When optional argument LEVEL
1177 is an integer, build the menu recursively, down to this depth."
1180 (org-texinfo--format-entries (org-texinfo--menu-entries scope info
) info
))
1183 (org-element-normalize-string
1186 (let ((entries (org-texinfo--menu-entries h info
)))
1189 (format "%s\n\n%s\n"
1190 (org-export-data (org-export-get-alt-title h info
) info
)
1191 (org-texinfo--format-entries entries info
))
1192 (org-texinfo--build-menu h info
(1- level
))))))
1193 (org-texinfo--menu-entries scope info
) "\n")))))
1195 (defun org-texinfo--format-entries (entries info
)
1196 "Format all direct menu entries in SCOPE, as a string.
1197 SCOPE is either a headline or a full Org document. INFO is
1198 a plist containing contextual information."
1199 (org-element-normalize-string
1203 ;; Colons are used as a separator between title and node
1204 ;; name. Remove them.
1205 (replace-regexp-in-string
1207 (org-texinfo--sanitize-title
1208 (org-export-get-alt-title h info
) info
)))
1209 (node (org-texinfo--get-node h info
))
1210 (entry (concat "* " title
":"
1211 (if (string= title node
) ":"
1212 (concat " " node
". "))))
1213 (desc (org-element-property :DESCRIPTION h
)))
1214 (if (not desc
) entry
1215 (format (format "%%-%ds %%s" org-texinfo-node-description-column
)
1219 (defun org-texinfo--menu-entries (scope info
)
1220 "List direct children in SCOPE needing a menu entry.
1221 SCOPE is a headline or a full parse tree. INFO is a plist
1222 holding contextual information."
1223 (let* ((cache (or (plist-get info
:texinfo-entries-cache
)
1224 (plist-get (plist-put info
:texinfo-entries-cache
1225 (make-hash-table :test
#'eq
))
1226 :texinfo-entries-cache
)))
1227 (cached-entries (gethash scope cache
'no-cache
)))
1228 (if (not (eq cached-entries
'no-cache
)) cached-entries
1232 (org-not-nil (org-export-get-node-property :COPYING h t
)))
1233 (org-export-collect-headlines info
1 scope
))
1238 (defun org-texinfo-node-property (node-property _contents _info
)
1239 "Transcode a NODE-PROPERTY element from Org to Texinfo.
1240 CONTENTS is nil. INFO is a plist holding contextual
1243 (org-element-property :key node-property
)
1244 (let ((value (org-element-property :value node-property
)))
1245 (if value
(concat " " value
) ""))))
1249 (defun org-texinfo-paragraph (_paragraph contents _info
)
1250 "Transcode a PARAGRAPH element from Org to Texinfo.
1251 CONTENTS is the contents of the paragraph, as a string. INFO is
1252 the plist used as a communication channel."
1257 (defun org-texinfo-plain-list (plain-list contents info
)
1258 "Transcode a PLAIN-LIST element from Org to Texinfo.
1259 CONTENTS is the contents of the list. INFO is a plist holding
1260 contextual information."
1261 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1262 (indic (let ((i (or (plist-get attr
:indic
)
1263 (plist-get info
:texinfo-table-default-markup
))))
1264 ;; Allow indicating commands with missing @ sign.
1265 (if (string-prefix-p "@" i
) i
(concat "@" i
))))
1266 (table-type (plist-get attr
:table-type
))
1267 (type (org-element-property :type plain-list
))
1269 ((eq type
'ordered
) "enumerate")
1270 ((eq type
'unordered
) "itemize")
1271 ((member table-type
'("ftable" "vtable")) table-type
)
1273 (format "@%s\n%s@end %s"
1274 (if (eq type
'descriptive
) (concat list-type
" " indic
) list-type
)
1280 (defun org-texinfo-plain-text (text info
)
1281 "Transcode a TEXT string from Org to Texinfo.
1282 TEXT is the string to transcode. INFO is a plist holding
1283 contextual information."
1284 ;; First protect @, { and }.
1285 (let ((output (org-texinfo--sanitize-content text
)))
1286 ;; Activate smart quotes. Be sure to provide original TEXT string
1287 ;; since OUTPUT may have been modified.
1288 (when (plist-get info
:with-smart-quotes
)
1290 (org-export-activate-smart-quotes output
:texinfo info text
)))
1291 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1292 (let ((case-fold-search nil
))
1293 (setq output
(replace-regexp-in-string "\\(?:La\\)?TeX" "@\\&{}" output
)))
1294 ;; Convert special strings.
1295 (when (plist-get info
:with-special-strings
)
1297 (replace-regexp-in-string
1298 "\\.\\.\\." "@dots{}"
1299 (replace-regexp-in-string "\\\\-" "@-" 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 (plist-get info
:texinfo-inactive-timestamp-format
)
1324 (org-timestamp-translate closed
)))))
1325 (let ((deadline (org-element-property :deadline planning
)))
1328 (format "@strong{%s} " org-deadline-string
)
1329 (format (plist-get info
:texinfo-active-timestamp-format
)
1330 (org-timestamp-translate deadline
)))))
1331 (let ((scheduled (org-element-property :scheduled planning
)))
1334 (format "@strong{%s} " org-scheduled-string
)
1335 (format (plist-get info
:texinfo-active-timestamp-format
)
1336 (org-timestamp-translate scheduled
)))))))
1340 ;;;; Property Drawer
1342 (defun org-texinfo-property-drawer (_property-drawer contents _info
)
1343 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1344 CONTENTS holds the contents of the drawer. INFO is a plist
1345 holding contextual information."
1346 (and (org-string-nw-p contents
)
1347 (format "@verbatim\n%s@end verbatim" contents
)))
1351 (defun org-texinfo-quote-block (quote-block contents _info
)
1352 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1353 CONTENTS holds the contents of the block. INFO is a plist
1354 holding contextual information."
1355 (let* ((title (org-element-property :name quote-block
))
1356 (start-quote (concat "@quotation"
1358 (format " %s" title
)))))
1359 (format "%s\n%s@end quotation" start-quote contents
)))
1363 (defun org-texinfo-radio-target (radio-target text info
)
1364 "Transcode a RADIO-TARGET object from Org to Texinfo.
1365 TEXT is the text of the target. INFO is a plist holding
1366 contextual information."
1367 (format "@anchor{%s}%s"
1368 (org-texinfo--get-node radio-target info
)
1373 (defun org-texinfo-section (section contents info
)
1374 "Transcode a SECTION element from Org to Texinfo.
1375 CONTENTS holds the contents of the section. INFO is a plist
1376 holding contextual information."
1377 (let ((parent (org-export-get-parent-headline section
)))
1378 (when (and parent
(not (org-export-excluded-from-toc-p parent info
)))
1379 (org-trim (concat contents
"\n" (org-texinfo-make-menu parent info
))))))
1383 (defun org-texinfo-special-block (special-block contents _info
)
1384 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1385 CONTENTS holds the contents of the block. INFO is a plist used
1386 as a communication channel."
1387 (let ((opt (org-export-read-attribute :attr_texinfo special-block
:options
))
1388 (type (org-element-property :type special-block
)))
1389 (format "@%s%s\n%s@end %s"
1391 (if opt
(concat " " opt
) "")
1397 (defun org-texinfo-src-block (src-block _contents info
)
1398 "Transcode a SRC-BLOCK element from Org to Texinfo.
1399 CONTENTS holds the contents of the item. INFO is a plist holding
1400 contextual information."
1401 (let* ((lisp (string-match-p "lisp"
1402 (org-element-property :language src-block
)))
1403 (code (org-texinfo--sanitize-content
1404 (org-export-format-code-default src-block info
)))
1406 (if lisp
"@lisp\n%s@end lisp" "@example\n%s@end example")
1408 (caption (org-export-get-caption src-block
))
1409 (shortcaption (org-export-get-caption src-block t
)))
1410 (if (not (or caption shortcaption
)) value
1411 (org-texinfo--wrap-float value
1413 (org-export-translate "Listing" :utf-8 info
)
1414 (org-texinfo--get-node src-block info
)
1418 ;;;; Statistics Cookie
1420 (defun org-texinfo-statistics-cookie (statistics-cookie _contents _info
)
1421 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1422 CONTENTS is nil. INFO is a plist holding contextual information."
1423 (org-element-property :value statistics-cookie
))
1428 (defun org-texinfo-strike-through (_strike-through contents info
)
1429 "Transcode STRIKE-THROUGH from Org to Texinfo.
1430 CONTENTS is the text with strike-through markup. INFO is a plist
1431 holding contextual information."
1432 (org-texinfo--text-markup contents
'strike-through info
))
1436 (defun org-texinfo-subscript (_subscript contents _info
)
1437 "Transcode a SUBSCRIPT object from Org to Texinfo.
1438 CONTENTS is the contents of the object. INFO is a plist holding
1439 contextual information."
1440 (format "@math{_%s}" contents
))
1444 (defun org-texinfo-superscript (_superscript contents _info
)
1445 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1446 CONTENTS is the contents of the object. INFO is a plist holding
1447 contextual information."
1448 (format "@math{^%s}" contents
))
1452 (defun org-texinfo-table (table contents info
)
1453 "Transcode a TABLE element from Org to Texinfo.
1454 CONTENTS is the contents of the table. INFO is a plist holding
1455 contextual information."
1456 (if (eq (org-element-property :type table
) 'table.el
)
1457 (format "@verbatim\n%s@end verbatim"
1458 (org-element-normalize-string
1459 (org-element-property :value table
)))
1460 (let* ((col-width (org-export-read-attribute :attr_texinfo table
:columns
))
1462 (if col-width
(format "@columnfractions %s" col-width
)
1463 (org-texinfo-table-column-widths table info
)))
1464 (caption (org-export-get-caption table
))
1465 (shortcaption (org-export-get-caption table t
))
1466 (table-str (format "@multitable %s\n%s@end multitable"
1469 (if (not (or caption shortcaption
)) table-str
1470 (org-texinfo--wrap-float table-str
1472 (org-export-translate "Table" :utf-8 info
)
1473 (org-texinfo--get-node table info
)
1477 (defun org-texinfo-table-column-widths (table info
)
1478 "Determine the largest table cell in each column to process alignment.
1479 TABLE is the table element to transcode. INFO is a plist used as
1480 a communication channel."
1481 (let ((widths (make-vector (cdr (org-export-table-dimensions table info
)) 0)))
1482 (org-element-map table
'table-row
1485 (org-element-map row
'table-cell
1487 ;; Length of the cell in the original buffer is only an
1488 ;; approximation of the length of the cell in the
1489 ;; output. It can sometimes fail (e.g. it considers
1490 ;; "/a/" being larger than "ab").
1491 (let ((w (- (org-element-property :contents-end cell
)
1492 (org-element-property :contents-begin cell
))))
1493 (aset widths idx
(max w
(aref widths idx
))))
1497 (format "{%s}" (mapconcat (lambda (w) (make-string w ?a
)) widths
"} {"))))
1501 (defun org-texinfo-table-cell (table-cell contents info
)
1502 "Transcode a TABLE-CELL element from Org to Texinfo.
1503 CONTENTS is the cell contents. INFO is a plist used as
1504 a communication channel."
1506 (let ((scientific-notation
1507 (plist-get info
:texinfo-table-scientific-notation
)))
1510 (string-match orgtbl-exp-regexp contents
))
1511 ;; Use appropriate format string for scientific notation.
1512 (format scientific-notation
1513 (match-string 1 contents
)
1514 (match-string 2 contents
))
1516 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1520 (defun org-texinfo-table-row (table-row contents info
)
1521 "Transcode a TABLE-ROW element from Org to Texinfo.
1522 CONTENTS is the contents of the row. INFO is a plist used as
1523 a communication channel."
1524 ;; Rules are ignored since table separators are deduced from
1525 ;; borders of the current row.
1526 (when (eq (org-element-property :type table-row
) 'standard
)
1528 (if (and (= 1 (org-export-table-row-group table-row info
))
1529 (org-export-table-has-header-p
1530 (org-export-get-parent-table table-row
) info
))
1533 (concat rowgroup-tag contents
"\n"))))
1537 (defun org-texinfo-target (target _contents info
)
1538 "Transcode a TARGET object from Org to Texinfo.
1539 CONTENTS is nil. INFO is a plist holding contextual
1541 (format "@anchor{%s}" (org-texinfo--get-node target info
)))
1545 (defun org-texinfo-timestamp (timestamp _contents info
)
1546 "Transcode a TIMESTAMP object from Org to Texinfo.
1547 CONTENTS is nil. INFO is a plist holding contextual
1549 (let ((value (org-texinfo-plain-text
1550 (org-timestamp-translate timestamp
) info
)))
1551 (pcase (org-element-property :type timestamp
)
1552 ((or `active
`active-range
)
1553 (format (plist-get info
:texinfo-active-timestamp-format
) value
))
1554 ((or `inactive
`inactive-range
)
1555 (format (plist-get info
:texinfo-inactive-timestamp-format
) value
))
1556 (_ (format (plist-get info
:texinfo-diary-timestamp-format
) value
)))))
1560 (defun org-texinfo-underline (_underline contents info
)
1561 "Transcode UNDERLINE from Org to Texinfo.
1562 CONTENTS is the text with underline markup. INFO is a plist
1563 holding contextual information."
1564 (org-texinfo--text-markup contents
'underline info
))
1568 (defun org-texinfo-verbatim (verbatim _contents info
)
1569 "Transcode a VERBATIM object from Org to Texinfo.
1570 CONTENTS is nil. INFO is a plist used as a communication
1572 (org-texinfo--text-markup
1573 (org-element-property :value verbatim
) 'verbatim info
))
1577 (defun org-texinfo-verse-block (_verse-block contents _info
)
1578 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1579 CONTENTS is verse block contents. INFO is a plist holding
1580 contextual information."
1581 (format "@display\n%s@end display" contents
))
1584 ;;; Interactive functions
1587 (defun org-texinfo-export-to-texinfo
1588 (&optional async subtreep visible-only body-only ext-plist
)
1589 "Export current buffer to a Texinfo file.
1591 If narrowing is active in the current buffer, only export its
1594 If a region is active, export that region.
1596 A non-nil optional argument ASYNC means the process should happen
1597 asynchronously. The resulting file should be accessible through
1598 the `org-export-stack' interface.
1600 When optional argument SUBTREEP is non-nil, export the sub-tree
1601 at point, extracting information from the headline properties
1604 When optional argument VISIBLE-ONLY is non-nil, don't export
1605 contents of hidden elements.
1607 When optional argument BODY-ONLY is non-nil, only write code
1608 between \"\\begin{document}\" and \"\\end{document}\".
1610 EXT-PLIST, when provided, is a property list with external
1611 parameters overriding Org default settings, but still inferior to
1612 file-local settings.
1614 Return output file's name."
1616 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1617 (org-export-coding-system org-texinfo-coding-system
))
1618 (org-export-to-file 'texinfo outfile
1619 async subtreep visible-only body-only ext-plist
)))
1622 (defun org-texinfo-export-to-info
1623 (&optional async subtreep visible-only body-only ext-plist
)
1624 "Export current buffer to Texinfo then process through to INFO.
1626 If narrowing is active in the current buffer, only export its
1629 If a region is active, export that region.
1631 A non-nil optional argument ASYNC means the process should happen
1632 asynchronously. The resulting file should be accessible through
1633 the `org-export-stack' interface.
1635 When optional argument SUBTREEP is non-nil, export the sub-tree
1636 at point, extracting information from the headline properties
1639 When optional argument VISIBLE-ONLY is non-nil, don't export
1640 contents of hidden elements.
1642 When optional argument BODY-ONLY is non-nil, only write code
1643 between \"\\begin{document}\" and \"\\end{document}\".
1645 EXT-PLIST, when provided, is a property list with external
1646 parameters overriding Org default settings, but still inferior to
1647 file-local settings.
1649 When optional argument PUB-DIR is set, use it as the publishing
1652 Return INFO file's name."
1654 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1655 (org-export-coding-system org-texinfo-coding-system
))
1656 (org-export-to-file 'texinfo outfile
1657 async subtreep visible-only body-only ext-plist
1658 (lambda (file) (org-texinfo-compile file
)))))
1661 (defun org-texinfo-publish-to-texinfo (plist filename pub-dir
)
1662 "Publish an org file to Texinfo.
1664 FILENAME is the filename of the Org file to be published. PLIST
1665 is the property list for the given project. PUB-DIR is the
1666 publishing directory.
1668 Return output file name."
1669 (org-publish-org-to 'texinfo filename
".texi" plist pub-dir
))
1672 (defun org-texinfo-convert-region-to-texinfo ()
1673 "Assume the current region has Org syntax, and convert it to Texinfo.
1674 This can be used in any buffer. For example, you can write an
1675 itemized list in Org syntax in an Texinfo buffer and use this
1676 command to convert it."
1678 (org-export-replace-region-by 'texinfo
))
1680 (defun org-texinfo-compile (file)
1681 "Compile a texinfo file.
1683 FILE is the name of the file being compiled. Processing is done
1684 through the command specified in `org-texinfo-info-process',
1685 which see. Output is redirected to \"*Org INFO Texinfo Output*\"
1688 Return INFO file name or an error if it couldn't be produced."
1689 (message "Processing Texinfo file %s..." file
)
1690 (let* ((log-name "*Org INFO Texinfo Output*")
1691 (log (get-buffer-create log-name
))
1693 (org-compile-file file org-texinfo-info-process
"info"
1694 (format "See %S for details" log-name
)
1696 (when org-texinfo-remove-logfiles
1697 (let ((base (file-name-sans-extension output
)))
1698 (dolist (ext org-texinfo-logfiles-extensions
)
1699 (let ((file (concat base
"." ext
)))
1700 (when (file-exists-p file
) (delete-file file
))))))
1701 (message "Process completed.")
1705 (provide 'ox-texinfo
)
1708 ;; generated-autoload-file: "org-loaddefs.el"
1711 ;;; ox-texinfo.el ends here