1 ;;; ox-texinfo.el --- Texinfo Back-End for Org Export Engine -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2012-2015 Free Software Foundation, Inc.
4 ;; Author: Jonathan Leech-Pepin <jonathan.leechpepin at gmail dot com>
5 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; See Org manual for details.
28 (eval-when-compile (require 'cl
))
31 (defvar orgtbl-exp-regexp
)
37 (org-export-define-backend 'texinfo
38 '((bold . org-texinfo-bold
)
39 (center-block . org-texinfo-center-block
)
40 (clock . org-texinfo-clock
)
41 (code . org-texinfo-code
)
42 (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 (subscript . org-texinfo-subscript
)
72 (superscript . org-texinfo-superscript
)
73 (table . org-texinfo-table
)
74 (table-cell . org-texinfo-table-cell
)
75 (table-row . org-texinfo-table-row
)
76 (target . org-texinfo-target
)
77 (template . org-texinfo-template
)
78 (timestamp . org-texinfo-timestamp
)
79 (verbatim . org-texinfo-verbatim
)
80 (verse-block . org-texinfo-verse-block
))
81 :export-block
"TEXINFO"
83 '((:filter-headline . org-texinfo--filter-section-blank-lines
)
84 (:filter-parse-tree . org-texinfo--normalize-headlines
)
85 (:filter-section . org-texinfo--filter-section-blank-lines
))
87 '(?i
"Export to Texinfo"
88 ((?t
"As TEXI file" org-texinfo-export-to-texinfo
)
89 (?i
"As INFO file" org-texinfo-export-to-info
)
90 (?o
"As INFO file and open"
92 (if a
(org-texinfo-export-to-info t s v b
)
93 (org-open-file (org-texinfo-export-to-info nil s v b
)))))))
95 '((:texinfo-filename
"TEXINFO_FILENAME" nil nil t
)
96 (:texinfo-class
"TEXINFO_CLASS" nil org-texinfo-default-class t
)
97 (:texinfo-header
"TEXINFO_HEADER" nil nil newline
)
98 (:texinfo-post-header
"TEXINFO_POST_HEADER" nil nil newline
)
99 (:subtitle
"SUBTITLE" nil nil parse
)
100 (:subauthor
"SUBAUTHOR" nil nil newline
)
101 (:texinfo-dircat
"TEXINFO_DIR_CATEGORY" nil nil t
)
102 (:texinfo-dirtitle
"TEXINFO_DIR_TITLE" nil nil t
)
103 (:texinfo-dirdesc
"TEXINFO_DIR_DESC" nil nil t
)
104 (:texinfo-printed-title
"TEXINFO_PRINTED_TITLE" nil nil t
)
106 (:texinfo-classes nil nil org-texinfo-classes
)
107 (:texinfo-format-headline-function nil nil org-texinfo-format-headline-function
)
108 (:texinfo-node-description-column nil nil org-texinfo-node-description-column
)
109 (:texinfo-active-timestamp-format nil nil org-texinfo-active-timestamp-format
)
110 (:texinfo-inactive-timestamp-format nil nil org-texinfo-inactive-timestamp-format
)
111 (:texinfo-diary-timestamp-format nil nil org-texinfo-diary-timestamp-format
)
112 (:texinfo-link-with-unknown-path-format nil nil org-texinfo-link-with-unknown-path-format
)
113 (:texinfo-tables-verbatim nil nil org-texinfo-tables-verbatim
)
114 (:texinfo-table-scientific-notation nil nil org-texinfo-table-scientific-notation
)
115 (:texinfo-def-table-markup nil nil org-texinfo-def-table-markup
)
116 (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist
)
117 (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function
)
118 (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function
)))
122 ;;; User Configurable Variables
124 (defgroup org-export-texinfo nil
125 "Options for exporting Org mode files to Texinfo."
126 :tag
"Org Export Texinfo"
128 :package-version
'(Org .
"8.0")
133 (defcustom org-texinfo-coding-system nil
134 "Default document encoding for Texinfo output.
136 If nil it will default to `buffer-file-coding-system'."
137 :group
'org-export-texinfo
138 :type
'coding-system
)
140 (defcustom org-texinfo-default-class
"info"
141 "The default Texinfo class."
142 :group
'org-export-texinfo
143 :type
'(string :tag
"Texinfo class"))
145 (defcustom org-texinfo-classes
147 "@documentencoding AUTO\n@documentlanguage AUTO"
148 ("@chapter %s" .
"@unnumbered %s")
149 ("@section %s" .
"@unnumberedsec %s")
150 ("@subsection %s" .
"@unnumberedsubsec %s")
151 ("@subsubsection %s" .
"@unnumberedsubsubsec %s")))
152 "Alist of Texinfo classes and associated header and structure.
153 If #+TEXINFO_CLASS is set in the buffer, use its value and the
154 associated information. Here is the structure of each cell:
158 (numbered-section . unnumbered-section)
165 The header string is inserted in the header of the generated
166 document, right after \"@setfilename\" and \"@settitle\"
169 If it contains the special string
171 \"@documentencoding AUTO\"
173 \"AUTO\" will be replaced with an appropriate coding system. See
174 `org-texinfo-coding-system' for more information. Likewise, if
175 the string contains the special string
177 \"@documentlanguage AUTO\"
179 \"AUTO\" will be replaced with the language defined in the
180 buffer, through #+LANGUAGE keyword, or globally, with
181 `org-export-default-language', which see.
184 The sectioning structure
185 ------------------------
187 The sectioning structure of the class is given by the elements
188 following the header string. For each sectioning level, a number
189 of strings is specified. A %s formatter is mandatory in each
190 section string and will be replaced by the title of the section.
192 Instead of a list of sectioning commands, you can also specify
193 a function name. That function will be called with two
194 parameters, the reduced) level of the headline, and a predicate
195 non-nil when the headline should be numbered. It must return
196 a format string in which the section title will be added."
197 :group
'org-export-texinfo
199 :package-version
'(Org .
"8.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 (function :tag
"Hook computing sectioning"))))))
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.
271 The format should have \"%s\" twice, for mantissa and exponent
272 \(i.e. \"%s\\\\times10^{%s}\").
274 When nil, no transformation is made."
275 :group
'org-export-texinfo
277 (string :tag
"Format string")
278 (const :tag
"No formatting" nil
)))
280 (defcustom org-texinfo-def-table-markup
"@samp"
281 "Default setting for @table environments."
282 :group
'org-export-texinfo
287 (defcustom org-texinfo-text-markup-alist
'((bold .
"@strong{%s}")
289 (italic .
"@emph{%s}")
292 "Alist of Texinfo expressions to convert text markup.
294 The key must be a symbol among `bold', `italic' and `comment'.
295 The value is a formatting string to wrap fontified text with.
297 Value can also be set to the following symbols: `verb' and
298 `code'. For the former, Org will use \"@verb\" to
299 create a format string and select a delimiter character that
300 isn't in the string. For the latter, Org will use \"@code\"
301 to typeset and try to protect special characters.
303 If no association can be found for a given markup, text will be
305 :group
'org-export-texinfo
307 :options
'(bold code italic verbatim comment
))
311 (defcustom org-texinfo-format-drawer-function
(lambda (_name contents
) contents
)
312 "Function called to format a drawer in Texinfo code.
314 The function must accept two parameters:
315 NAME the drawer name, like \"LOGBOOK\"
316 CONTENTS the contents of the drawer.
318 The function should return the string to be exported.
320 The default function simply returns the value of CONTENTS."
321 :group
'org-export-texinfo
323 :package-version
'(Org .
"8.2")
328 (defcustom org-texinfo-format-inlinetask-function
329 'org-texinfo-format-inlinetask-default-function
330 "Function called to format an inlinetask in Texinfo code.
332 The function must accept six parameters:
333 TODO the todo keyword, as a string
334 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
335 PRIORITY the inlinetask priority, as a string
336 NAME the inlinetask name, as a string.
337 TAGS the inlinetask tags, as a list of strings.
338 CONTENTS the contents of the inlinetask, as a string.
340 The function should return the string to be exported."
341 :group
'org-export-texinfo
346 (defcustom org-texinfo-info-process
'("makeinfo %f")
347 "Commands to process a Texinfo file to an INFO file.
348 This is list of strings, each of them will be given to the shell
349 as a command. %f in the command will be replaced by the full
350 file name, %b by the file base name (i.e without extension) and
351 %o by the base directory of the file."
352 :group
'org-export-texinfo
353 :type
'(repeat :tag
"Shell command sequence"
354 (string :tag
"Shell command")))
356 (defcustom org-texinfo-logfiles-extensions
357 '("aux" "toc" "cp" "fn" "ky" "pg" "tp" "vr")
358 "The list of file extensions to consider as Texinfo logfiles.
359 The logfiles will be remove if `org-texinfo-remove-logfiles' is
361 :group
'org-export-texinfo
362 :type
'(repeat (string :tag
"Extension")))
364 (defcustom org-texinfo-remove-logfiles t
365 "Non-nil means remove the logfiles produced by compiling a Texinfo file.
366 By default, logfiles are files with these extensions: .aux, .toc,
367 .cp, .fn, .ky, .pg and .tp. To define the set of logfiles to remove,
368 set `org-texinfo-logfiles-extensions'."
369 :group
'org-export-latex
374 (defconst org-texinfo-max-toc-depth
4
375 "Maximum depth for creation of detailed menu listings.
376 Beyond this depth, Texinfo will not recognize the nodes and will
377 cause errors. Left as a constant in case this value ever
380 (defconst org-texinfo-supported-coding-systems
381 '("US-ASCII" "UTF-8" "ISO-8859-15" "ISO-8859-1" "ISO-8859-2" "koi8-r" "koi8-u")
382 "List of coding systems supported by Texinfo, as strings.
383 Specified coding system will be matched against these strings.
384 If two strings share the same prefix (e.g. \"ISO-8859-1\" and
385 \"ISO-8859-15\"), the most specific one has to be listed first.")
387 (defconst org-texinfo-inline-image-rules
389 (regexp-opt '("eps" "pdf" "png" "jpg" "jpeg" "gif" "svg"))))
390 "Rules characterizing image files that can be inlined.")
393 ;;; Internal Functions
395 (defun org-texinfo--filter-section-blank-lines (headline _backend _info
)
396 "Filter controlling number of blank lines after a section."
397 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" "\n\n" headline
))
399 (defun org-texinfo--normalize-headlines (tree _backend info
)
400 "Normalize headlines in TREE.
402 BACK-END is the symbol specifying back-end used for export. INFO
403 is a plist used as a communication channel.
405 Make sure every headline in TREE contains a section, since those
406 are required to install a menu. Also put exactly one blank line
407 at the end of each section.
410 (org-element-map tree
'headline
412 (org-element-put-property hl
:post-blank
1)
413 (let ((contents (org-element-contents hl
)))
415 (let ((first (org-element-map contents
'(headline section
)
417 (unless (eq (org-element-type first
) 'section
)
418 (apply #'org-element-set-contents
420 (cons `(section (:parent
,hl
)) contents
)))))))
424 (defun org-texinfo--find-verb-separator (s)
425 "Return a character not used in string S.
426 This is used to choose a separator for constructs like \\verb."
427 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
428 (loop for c across ll
429 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
430 return
(char-to-string c
))))
432 (defun org-texinfo--text-markup (text markup _info
)
433 "Format TEXT depending on MARKUP text markup.
434 INFO is a plist used as a communication channel. See
435 `org-texinfo-text-markup-alist' for details."
436 (pcase (cdr (assq markup org-texinfo-text-markup-alist
))
437 ;; No format string: Return raw text.
440 (let ((separator (org-texinfo--find-verb-separator text
)))
441 (concat "@verb{" separator text separator
"}")))
443 (format "@code{%s}" (replace-regexp-in-string "[@{}]" "@\\&" text
)))
444 ;; Else use format string.
445 (fmt (format fmt text
))))
447 (defun org-texinfo--get-node (blob info
)
448 "Return node or anchor associated to BLOB.
449 BLOB is an element or object. INFO is a plist used as
450 a communication channel. The function guarantees the node or
451 anchor name is unique."
452 (let ((cache (plist-get info
:texinfo-node-cache
)))
453 (or (cdr (assq blob cache
))
455 (org-texinfo--sanitize-node
456 (if (eq (org-element-type blob
) 'headline
)
457 (org-export-data (org-export-get-alt-title blob info
) info
)
458 (org-export-get-reference blob info
)))))
459 ;; Ensure NAME is unique.
460 (while (rassoc name cache
) (setq name
(concat name
"x")))
461 (plist-put info
:texinfo-node-cache
(cons (cons blob name
) cache
))
464 (defun org-texinfo--sanitize-node (title)
465 "Bend string TITLE to node line requirements.
466 Trim string and collapse multiple whitespace characters as they
467 are not significant. Also remove the following characters: @
469 (replace-regexp-in-string
471 (replace-regexp-in-string
472 "\\`(\\(.*)\\)" "[\\1"
473 (org-trim (replace-regexp-in-string "[ \t]\\{2,\\}" " " title
)))))
475 (defun org-texinfo--sanitize-content (text)
476 "Escape special characters in string TEXT.
477 Special characters are: @ { }"
478 (replace-regexp-in-string "[@{}]" "@\\&" text
))
480 (defun org-texinfo--wrap-float (value info
&optional type label caption short
)
481 "Wrap string VALUE within a @float command.
482 INFO is the current export state, as a plist. TYPE is float
483 type, as a string. LABEL is the cross reference label for the
484 float, as a string. CAPTION and SHORT are, respectively, the
485 caption and shortcaption used for the float, as secondary
486 strings (e.g., returned by `org-export-get-caption')."
488 (org-export-create-backend
490 :transcoders
'((link .
(lambda (object c i
) c
))
491 (radio-target .
(lambda (object c i
) c
))
494 (org-export-create-backend
496 :transcoders
'((footnote-reference . ignore
)
497 (inline-src-block . ignore
)
498 (link .
(lambda (object c i
) c
))
499 (radio-target .
(lambda (object c i
) c
))
501 (verbatim . ignore
))))
503 (if (and short caption
)
504 (format "@shortcaption{%s}\n"
505 (org-export-data-with-backend short short-backend info
))
508 (if (or short caption
)
509 (format "@caption{%s}\n"
510 (org-export-data-with-backend
512 (if (equal short-str
"") short-backend backend
)
515 (format "@float %s%s\n%s\n%s%s@end float"
516 type
(if label
(concat "," label
) "") value caption-str short-str
)))
520 (defun org-texinfo-template (contents info
)
521 "Return complete document string after Texinfo conversion.
522 CONTENTS is the transcoded contents string. INFO is a plist
523 holding export options."
524 (let ((title (org-export-data (plist-get info
:title
) info
))
525 ;; Copying data is the contents of the first headline in
526 ;; parse tree with a non-nil copying property.
527 (copying (org-element-map (plist-get info
:parse-tree
) 'headline
529 (and (org-not-nil (org-element-property :COPYING hl
))
530 (org-element-contents hl
)))
533 "\\input texinfo @c -*- texinfo -*-\n"
534 "@c %**start of header\n"
535 (let ((file (or (plist-get info
:texinfo-filename
)
536 (let ((f (plist-get info
:output-file
)))
537 (and f
(concat (file-name-sans-extension f
) ".info"))))))
538 (and file
(format "@setfilename %s\n" file
)))
539 (format "@settitle %s\n" title
)
540 ;; Insert class-defined header.
541 (org-element-normalize-string
542 (let ((header (nth 1 (assoc (plist-get info
:texinfo-class
)
543 org-texinfo-classes
)))
545 (catch 'coding-system
546 (let ((case-fold-search t
)
547 (name (symbol-name (or org-texinfo-coding-system
548 buffer-file-coding-system
))))
549 (dolist (system org-texinfo-supported-coding-systems
"UTF-8")
550 (when (org-string-match-p (regexp-quote system
) name
)
551 (throw 'coding-system system
))))))
552 (language (plist-get info
:language
))
553 (case-fold-search nil
))
554 ;; Auto coding system.
555 (replace-regexp-in-string
556 "^@documentencoding \\(AUTO\\)$"
558 (replace-regexp-in-string
559 "^@documentlanguage \\(AUTO\\)$" language header t nil
1) t nil
1)))
560 ;; Additional header options set by #+TEXINFO_HEADER.
561 (let ((texinfo-header (plist-get info
:texinfo-header
)))
562 (and texinfo-header
(org-element-normalize-string texinfo-header
)))
563 "@c %**end of header\n\n"
564 ;; Additional options set by #+TEXINFO_POST_HEADER.
565 (let ((texinfo-post-header (plist-get info
:texinfo-post-header
)))
566 (and texinfo-post-header
567 (org-element-normalize-string texinfo-post-header
)))
570 (format "@copying\n%s@end copying\n\n"
571 (org-element-normalize-string
572 (org-export-data copying info
))))
573 ;; Info directory information. Only supply if both title and
574 ;; category are provided.
575 (let ((dircat (plist-get info
:texinfo-dircat
))
577 (let ((title (plist-get info
:texinfo-dirtitle
)))
579 (string-match "^\\(?:\\* \\)?\\(.*?\\)\\(\\.\\)?$" title
)
580 (format "* %s." (match-string 1 title
))))))
581 (when (and dircat dirtitle
)
582 (concat "@dircategory " dircat
"\n"
585 (let ((desc (plist-get info
:texinfo-dirdesc
)))
586 (cond ((not desc
) nil
)
587 ((org-string-match-p "\\.$" desc
) desc
)
588 (t (concat desc
"."))))))
589 (if dirdesc
(format "%-23s %s" dirtitle dirdesc
) dirtitle
))
591 "@end direntry\n\n")))
595 (when (plist-get info
:with-title
)
597 (format "@title %s\n" (or (plist-get info
:texinfo-printed-title
) title
""))
598 (let ((subtitle (plist-get info
:subtitle
)))
600 (format "@subtitle %s\n"
601 (org-export-data subtitle info
))))))
602 (when (plist-get info
:with-author
)
605 (let ((author (org-string-nw-p
606 (org-export-data (plist-get info
:author
) info
)))
607 (email (and (plist-get info
:with-email
)
609 (org-export-data (plist-get info
:email
) info
)))))
610 (cond ((and author email
)
611 (format "@author %s (@email{%s})\n" author email
))
612 (author (format "@author %s\n" author
))
613 (email (format "@author @email{%s}\n" email
))))
615 (let ((subauthor (plist-get info
:subauthor
)))
617 (org-element-normalize-string
618 (replace-regexp-in-string "^" "@author " subauthor
))))))
619 (and copying
"@page\n@vskip 0pt plus 1filll\n@insertcopying\n")
621 ;; Table of contents.
622 (and (plist-get info
:with-toc
) "@contents\n\n")
623 ;; Configure Top Node when not for Tex
626 (format "@top %s\n" title
)
627 (and copying
"@insertcopying\n")
630 (org-texinfo-make-menu (plist-get info
:parse-tree
) info
'master
)
635 (and (plist-get info
:with-creator
)
636 (concat (plist-get info
:creator
) "\n"))
642 ;;; Transcode Functions
646 (defun org-texinfo-bold (_bold contents info
)
647 "Transcode BOLD from Org to Texinfo.
648 CONTENTS is the text with bold markup. INFO is a plist holding
649 contextual information."
650 (org-texinfo--text-markup contents
'bold info
))
654 (defun org-texinfo-center-block (_center-block contents _info
)
655 "Transcode a CENTER-BLOCK element from Org to Texinfo.
656 CONTENTS holds the contents of the block. INFO is a plist used
657 as a communication channel."
662 (defun org-texinfo-clock (clock _contents info
)
663 "Transcode a CLOCK element from Org to Texinfo.
664 CONTENTS is nil. INFO is a plist holding contextual
668 (format "@strong{%s} " org-clock-string
)
669 (format (plist-get info
:texinfo-inactive-timestamp-format
)
670 (concat (org-timestamp-translate (org-element-property :value clock
))
671 (let ((time (org-element-property :duration clock
)))
672 (and time
(format " (%s)" time
)))))
677 (defun org-texinfo-code (code _contents info
)
678 "Transcode a CODE object from Org to Texinfo.
679 CONTENTS is nil. INFO is a plist used as a communication
681 (org-texinfo--text-markup (org-element-property :value code
) 'code info
))
685 (defun org-texinfo-drawer (drawer contents info
)
686 "Transcode a DRAWER element from Org to Texinfo.
687 CONTENTS holds the contents of the block. INFO is a plist
688 holding contextual information."
689 (let* ((name (org-element-property :drawer-name drawer
))
690 (output (funcall (plist-get info
:texinfo-format-drawer-function
)
696 (defun org-texinfo-dynamic-block (_dynamic-block contents _info
)
697 "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
698 CONTENTS holds the contents of the block. INFO is a plist
699 holding contextual information."
704 (defun org-texinfo-entity (entity _contents _info
)
705 "Transcode an ENTITY object from Org to Texinfo.
706 CONTENTS are the definition itself. INFO is a plist holding
707 contextual information."
708 (let ((ent (org-element-property :latex entity
)))
709 (if (org-element-property :latex-math-p entity
) (format "@math{%s}" ent
) ent
)))
713 (defun org-texinfo-example-block (example-block _contents info
)
714 "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
715 CONTENTS is nil. INFO is a plist holding contextual
717 (format "@verbatim\n%s@end verbatim"
718 (org-export-format-code-default example-block info
)))
722 (defun org-texinfo-export-block (export-block _contents _info
)
723 "Transcode a EXPORT-BLOCK element from Org to Texinfo.
724 CONTENTS is nil. INFO is a plist holding contextual information."
725 (when (string= (org-element-property :type export-block
) "TEXINFO")
726 (org-remove-indentation (org-element-property :value export-block
))))
730 (defun org-texinfo-export-snippet (export-snippet _contents _info
)
731 "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
732 CONTENTS is nil. INFO is a plist holding contextual information."
733 (when (eq (org-export-snippet-backend export-snippet
) 'texinfo
)
734 (org-element-property :value export-snippet
)))
738 (defun org-texinfo-fixed-width (fixed-width _contents _info
)
739 "Transcode a FIXED-WIDTH element from Org to Texinfo.
740 CONTENTS is nil. INFO is a plist holding contextual information."
741 (format "@example\n%s\n@end example"
742 (org-remove-indentation
743 (org-texinfo--sanitize-content
744 (org-element-property :value fixed-width
)))))
746 ;;;; Footnote Reference
748 (defun org-texinfo-footnote-reference (footnote _contents info
)
749 "Create a footnote reference for FOOTNOTE.
751 FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
752 plist holding contextual information."
753 (let ((def (org-export-get-footnote-definition footnote info
)))
754 (format "@footnote{%s}"
755 (org-trim (org-export-data def info
)))))
759 (defun org-texinfo-headline (headline contents info
)
760 "Transcode a HEADLINE element from Org to Texinfo.
761 CONTENTS holds the contents of the headline. INFO is a plist
762 holding contextual information."
763 (let* ((class (plist-get info
:texinfo-class
))
764 (level (org-export-get-relative-level headline info
))
765 (numberedp (org-export-numbered-headline-p headline info
))
766 (class-sectioning (assoc class
(plist-get info
:texinfo-classes
)))
767 ;; Find the index type, if any.
768 (index (org-element-property :INDEX headline
))
769 ;; Create node info, to insert it before section formatting.
770 ;; Use custom menu title if present.
771 (node (format "@node %s\n" (org-texinfo--get-node headline info
)))
772 ;; Section formatting will set two placeholders: one for the
773 ;; title and the other for the contents.
775 (if (org-not-nil (org-element-property :APPENDIX headline
))
777 (let ((sec (if (and (symbolp (nth 2 class-sectioning
))
778 (fboundp (nth 2 class-sectioning
)))
779 (funcall (nth 2 class-sectioning
) level numberedp
)
780 (nth (1+ level
) class-sectioning
))))
782 ;; No section available for that LEVEL.
784 ;; Section format directly returned by a function.
786 ;; (numbered-section . unnumbered-section)
787 ((not (consp (cdr sec
)))
788 (concat (if (or index
(not numberedp
)) (cdr sec
) (car sec
))
791 (and (plist-get info
:with-todo-keywords
)
792 (let ((todo (org-element-property :todo-keyword headline
)))
793 (and todo
(org-export-data todo info
)))))
794 (todo-type (and todo
(org-element-property :todo-type headline
)))
795 (tags (and (plist-get info
:with-tags
)
796 (org-export-get-tags headline info
)))
797 (priority (and (plist-get info
:with-priority
)
798 (org-element-property :priority headline
)))
799 (text (org-export-data (org-element-property :title headline
) info
))
800 (full-text (funcall (plist-get info
:texinfo-format-headline-function
)
801 todo todo-type priority text tags
))
802 (contents (if (org-string-nw-p contents
) (concat "\n" contents
) "")))
804 ;; Case 1: This is a footnote section: ignore it.
805 ((org-element-property :footnote-section-p headline
) nil
)
806 ;; Case 2: This is the `copying' section: ignore it
807 ;; This is used elsewhere.
808 ((org-not-nil (org-element-property :COPYING headline
)) nil
)
809 ;; Case 3: An index. If it matches one of the known indexes,
810 ;; print it as such following the contents, otherwise
811 ;; print the contents and leave the index up to the user.
818 (and (member index
'("cp" "fn" "ky" "pg" "tp" "vr"))
819 (concat "\n@printindex " index
))))))
820 ;; Case 4: This is a deep sub-tree: export it as a list item.
821 ;; Also export as items headlines for which no section
822 ;; format has been found.
823 ((or (not section-fmt
) (org-export-low-level-p headline info
))
824 ;; Build the real contents of the sub-tree.
825 (concat (and (org-export-first-sibling-p headline info
)
826 (format "@%s\n" (if numberedp
'enumerate
'itemize
)))
827 "@item\n" full-text
"\n"
829 (if (org-export-last-sibling-p headline info
)
830 (format "@end %s" (if numberedp
'enumerate
'itemize
))
832 ;; Case 5: Standard headline. Export it as a section.
833 (t (concat node
(format section-fmt full-text contents
))))))
835 (defun org-texinfo-format-headline-default-function
836 (todo _todo-type priority text tags
)
837 "Default format function for a headline.
838 See `org-texinfo-format-headline-function' for details."
839 (concat (when todo
(format "@strong{%s} " todo
))
840 (when priority
(format "@emph{#%s} " priority
))
842 (when tags
(format " :%s:" (mapconcat 'identity tags
":")))))
844 ;;;; Inline Src Block
846 (defun org-texinfo-inline-src-block (inline-src-block _contents _info
)
847 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
848 CONTENTS holds the contents of the item. INFO is a plist holding
849 contextual information."
850 (let* ((code (org-element-property :value inline-src-block
))
851 (separator (org-texinfo--find-verb-separator code
)))
852 (concat "@verb{" separator code separator
"}")))
856 (defun org-texinfo-inlinetask (inlinetask contents info
)
857 "Transcode an INLINETASK element from Org to Texinfo.
858 CONTENTS holds the contents of the block. INFO is a plist
859 holding contextual information."
860 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
861 (todo (and (plist-get info
:with-todo-keywords
)
862 (let ((todo (org-element-property :todo-keyword inlinetask
)))
863 (and todo
(org-export-data todo info
)))))
864 (todo-type (org-element-property :todo-type inlinetask
))
865 (tags (and (plist-get info
:with-tags
)
866 (org-export-get-tags inlinetask info
)))
867 (priority (and (plist-get info
:with-priority
)
868 (org-element-property :priority inlinetask
))))
869 (funcall (plist-get info
:texinfo-format-inlinetask-function
)
870 todo todo-type priority title tags contents
)))
872 (defun org-texinfo-format-inlinetask-default-function
873 (todo _todo-type priority title tags contents
)
874 "Default format function for a inlinetasks.
875 See `org-texinfo-format-inlinetask-function' for details."
877 (concat (when todo
(format "@strong{%s} " todo
))
878 (when priority
(format "#%c " priority
))
880 (when tags
(format ":%s:" (mapconcat #'identity tags
":"))))))
881 (format "@center %s\n\n%s\n" full-title contents
)))
885 (defun org-texinfo-italic (_italic contents info
)
886 "Transcode ITALIC from Org to Texinfo.
887 CONTENTS is the text with italic markup. INFO is a plist holding
888 contextual information."
889 (org-texinfo--text-markup contents
'italic info
))
893 (defun org-texinfo-item (item contents info
)
894 "Transcode an ITEM element from Org to Texinfo.
895 CONTENTS holds the contents of the item. INFO is a plist holding
896 contextual information."
897 (format "@item%s\n%s"
898 (let ((tag (org-element-property :tag item
)))
899 (if tag
(concat " " (org-export-data tag info
)) ""))
904 (defun org-texinfo-keyword (keyword _contents info
)
905 "Transcode a KEYWORD element from Org to Texinfo.
906 CONTENTS is nil. INFO is a plist holding contextual information."
907 (let ((key (org-element-property :key keyword
))
908 (value (org-element-property :value keyword
)))
910 ((string= key
"TEXINFO") value
)
911 ((string= key
"CINDEX") (format "@cindex %s" value
))
912 ((string= key
"FINDEX") (format "@findex %s" value
))
913 ((string= key
"KINDEX") (format "@kindex %s" value
))
914 ((string= key
"PINDEX") (format "@pindex %s" value
))
915 ((string= key
"TINDEX") (format "@tindex %s" value
))
916 ((string= key
"VINDEX") (format "@vindex %s" value
))
918 (cond ((org-string-match-p "\\<tables\\>" value
)
919 (concat "@listoffloats "
920 (org-export-translate "Table" :utf-8 info
)))
921 ((org-string-match-p "\\<listings\\>" value
)
922 (concat "@listoffloats "
923 (org-export-translate "Listing" :utf-8 info
))))))))
927 (defun org-texinfo-line-break (_line-break _contents _info
)
928 "Transcode a LINE-BREAK object from Org to Texinfo.
929 CONTENTS is nil. INFO is a plist holding contextual information."
934 (defun org-texinfo-link (link desc info
)
935 "Transcode a LINK object from Org to Texinfo.
937 DESC is the description part of the link, or the empty string.
938 INFO is a plist holding contextual information. See
940 (let* ((type (org-element-property :type link
))
941 (raw-path (org-element-property :path link
))
942 ;; Ensure DESC really exists, or set it to nil.
943 (desc (and (not (string= desc
"")) desc
))
945 ((member type
'("http" "https" "ftp"))
946 (concat type
":" raw-path
))
947 ((string= type
"file") (org-export-file-uri raw-path
))
950 ((org-export-custom-protocol-maybe link desc
'texinfo
))
951 ((org-export-inline-image-p link org-texinfo-inline-image-rules
)
952 (org-texinfo--inline-image link info
))
953 ((equal type
"radio")
954 (let ((destination (org-export-resolve-radio-link link info
)))
955 (if (not destination
) desc
956 (format "@ref{%s,,%s}"
957 (org-texinfo--get-node destination info
)
959 ((member type
'("custom-id" "id" "fuzzy"))
961 (if (equal type
"fuzzy")
962 (org-export-resolve-fuzzy-link link info
)
963 (org-export-resolve-id-link link info
))))
964 (case (org-element-type destination
)
966 (format org-texinfo-link-with-unknown-path-format
967 (org-texinfo--sanitize-content path
)))
968 ;; Id link points to an external file.
970 (if desc
(format "@uref{file://%s,%s}" destination desc
)
971 (format "@uref{file://%s}" destination
)))
973 (format "@ref{%s,%s}"
974 (org-texinfo--get-node destination info
)
977 ((org-export-numbered-headline-p destination info
)
980 (org-export-get-headline-number destination info
) "."))
982 (org-element-property :title destination
) info
)))))
984 (format "@ref{%s,,%s}"
985 (org-texinfo--get-node destination info
)
988 ;; No description is provided: first try to
989 ;; associate destination to a number.
990 ((let ((n (org-export-get-ordinal destination info
)))
993 (t (mapconcat #'number-to-string n
".")))))
994 ;; Then grab title of headline containing
996 ((let ((h (org-element-lineage destination
'(headline) t
)))
999 (org-element-property :title destination
) info
))))
1000 ;; Eventually, just return "Top" to refer to the
1001 ;; beginning of the info file.
1003 ((equal type
"info")
1004 (let* ((info-path (split-string path
"[:#]"))
1005 (info-manual (car info-path
))
1006 (info-node (or (cadr info-path
) "Top"))
1007 (title (or desc
"")))
1008 (format "@ref{%s,%s,,%s,}" info-node title info-manual
)))
1009 ((string= type
"mailto")
1010 (format "@email{%s}"
1011 (concat (org-texinfo--sanitize-content path
)
1012 (and desc
(concat "," desc
)))))
1013 ;; External link with a description part.
1014 ((and path desc
) (format "@uref{%s,%s}" path desc
))
1015 ;; External link without a description part.
1016 (path (format "@uref{%s}" path
))
1017 ;; No path, only description. Try to do something useful.
1019 (format (plist-get info
:texinfo-link-with-unknown-path-format
) desc
)))))
1021 (defun org-texinfo--inline-image (link info
)
1022 "Return Texinfo code for an inline image.
1023 LINK is the link pointing to the inline image. INFO is the
1024 current state of the export, as a plist."
1025 (let* ((parent (org-export-get-parent-element link
))
1026 (label (and (org-element-property :name parent
)
1027 (org-texinfo--get-node parent info
)))
1028 (caption (org-export-get-caption parent
))
1029 (shortcaption (org-export-get-caption parent t
))
1030 (path (org-element-property :path link
))
1032 (file-name-sans-extension
1033 (if (file-name-absolute-p path
) (expand-file-name path
) path
)))
1034 (extension (file-name-extension path
))
1035 (attributes (org-export-read-attribute :attr_texinfo parent
))
1036 (height (or (plist-get attributes
:height
) ""))
1037 (width (or (plist-get attributes
:width
) ""))
1038 (alt (or (plist-get attributes
:alt
) ""))
1039 (image (format "@image{%s,%s,%s,%s,%s}"
1040 filename width height alt extension
)))
1041 (cond ((or caption shortcaption
)
1042 (org-texinfo--wrap-float image
1044 (org-export-translate "Figure" :utf-8 info
)
1048 (label (concat "@anchor{" label
"}\n" image
))
1054 (defun org-texinfo-make-menu (scope info
&optional master
)
1055 "Create the menu for inclusion in the Texinfo document.
1057 SCOPE is a headline or a full parse tree. INFO is the
1058 communication channel, as a plist.
1060 When optional argument MASTER is non-nil, generate a master menu,
1061 including detailed node listing."
1062 (let ((menu (org-texinfo--build-menu scope info
)))
1063 (when (org-string-nw-p menu
)
1064 (org-element-normalize-string
1066 "@menu\n%s@end menu"
1070 (org-texinfo--build-menu
1072 (let ((toc-depth (plist-get info
:with-toc
)))
1073 (if (wholenump toc-depth
) toc-depth
1074 org-texinfo-max-toc-depth
)))))
1075 (when (org-string-nw-p detailmenu
)
1076 (concat "\n@detailmenu\n"
1077 "--- The Detailed Node Listing ---\n\n"
1079 "@end detailmenu\n"))))))))))
1081 (defun org-texinfo--build-menu (scope info
&optional level
)
1082 "Build menu for entries within SCOPE.
1083 SCOPE is a headline or a full parse tree. INFO is a plist
1084 containing contextual information. When optional argument LEVEL
1085 is an integer, build the menu recursively, down to this depth."
1088 (org-texinfo--format-entries (org-texinfo--menu-entries scope info
) info
))
1091 (org-element-normalize-string
1094 (let ((entries (org-texinfo--menu-entries h info
)))
1097 (format "%s\n\n%s\n"
1098 (org-export-data (org-export-get-alt-title h info
) info
)
1099 (org-texinfo--format-entries entries info
))
1100 (org-texinfo--build-menu h info
(1- level
))))))
1101 (org-texinfo--menu-entries scope info
) "")))))
1103 (defun org-texinfo--format-entries (entries info
)
1104 "Format all direct menu entries in SCOPE, as a string.
1105 SCOPE is either a headline or a full Org document. INFO is
1106 a plist containing contextual information."
1107 (org-element-normalize-string
1110 (let* ((title (org-export-data
1111 (org-export-get-alt-title h info
) info
))
1112 (node (org-texinfo--get-node h info
))
1113 (entry (concat "* " title
":"
1114 (if (string= title node
) ":"
1115 (concat " " node
". "))))
1116 (desc (org-element-property :DESCRIPTION h
)))
1117 (if (not desc
) entry
1118 (format (format "%%-%ds %%s" org-texinfo-node-description-column
)
1122 (defun org-texinfo--menu-entries (scope info
)
1123 "List direct children in SCOPE needing a menu entry.
1124 SCOPE is a headline or a full parse tree. INFO is a plist
1125 holding contextual information."
1126 (let* ((cache (or (plist-get info
:texinfo-entries-cache
)
1127 (plist-get (plist-put info
:texinfo-entries-cache
1128 (make-hash-table :test
#'eq
))
1129 :texinfo-entries-cache
)))
1130 (cached-entries (gethash scope cache
'no-cache
)))
1131 (if (not (eq cached-entries
'no-cache
)) cached-entries
1133 (org-element-map (org-element-contents scope
) 'headline
1135 (and (not (org-not-nil (org-element-property :COPYING h
)))
1136 (not (org-element-property :footnote-section-p h
))
1137 (not (org-export-low-level-p h info
))
1144 (defun org-texinfo-node-property (node-property _contents _info
)
1145 "Transcode a NODE-PROPERTY element from Org to Texinfo.
1146 CONTENTS is nil. INFO is a plist holding contextual
1149 (org-element-property :key node-property
)
1150 (let ((value (org-element-property :value node-property
)))
1151 (if value
(concat " " value
) ""))))
1155 (defun org-texinfo-paragraph (_paragraph contents _info
)
1156 "Transcode a PARAGRAPH element from Org to Texinfo.
1157 CONTENTS is the contents of the paragraph, as a string. INFO is
1158 the plist used as a communication channel."
1163 (defun org-texinfo-plain-list (plain-list contents info
)
1164 "Transcode a PLAIN-LIST element from Org to Texinfo.
1165 CONTENTS is the contents of the list. INFO is a plist holding
1166 contextual information."
1167 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1168 (indic (or (plist-get attr
:indic
)
1169 (plist-get info
:texinfo-def-table-markup
)))
1170 (table-type (plist-get attr
:table-type
))
1171 (type (org-element-property :type plain-list
))
1173 ((eq type
'ordered
) "enumerate")
1174 ((eq type
'unordered
) "itemize")
1175 ((member table-type
'("ftable" "vtable")) table-type
)
1177 (format "@%s\n%s@end %s"
1178 (if (eq type
'descriptive
) (concat list-type
" " indic
) list-type
)
1184 (defun org-texinfo-plain-text (text info
)
1185 "Transcode a TEXT string from Org to Texinfo.
1186 TEXT is the string to transcode. INFO is a plist holding
1187 contextual information."
1188 ;; First protect @, { and }.
1189 (let ((output (org-texinfo--sanitize-content text
)))
1190 ;; Activate smart quotes. Be sure to provide original TEXT string
1191 ;; since OUTPUT may have been modified.
1192 (when (plist-get info
:with-smart-quotes
)
1194 (org-export-activate-smart-quotes output
:texinfo info text
)))
1195 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1196 (let ((case-fold-search nil
)
1198 (while (string-match "\\(\\(?:La\\)?TeX\\)" output start
)
1199 (setq output
(replace-match
1200 (format "@%s{}" (match-string 1 output
)) nil t output
)
1201 start
(match-end 0))))
1202 ;; Convert special strings.
1203 (when (plist-get info
:with-special-strings
)
1204 (while (string-match (regexp-quote "...") output
)
1205 (setq output
(replace-match "@dots{}" nil t output
))))
1206 ;; Handle break preservation if required.
1207 (when (plist-get info
:preserve-breaks
)
1208 (setq output
(replace-regexp-in-string
1209 "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output
)))
1215 (defun org-texinfo-planning (planning _contents info
)
1216 "Transcode a PLANNING element from Org to Texinfo.
1217 CONTENTS is nil. INFO is a plist holding contextual
1225 (let ((closed (org-element-property :closed planning
)))
1228 (format "@strong{%s} " org-closed-string
)
1229 (format (plist-get info
:texinfo-inactive-timestamp-format
)
1230 (org-timestamp-translate closed
)))))
1231 (let ((deadline (org-element-property :deadline planning
)))
1234 (format "@strong{%s} " org-deadline-string
)
1235 (format (plist-get info
:texinfo-active-timestamp-format
)
1236 (org-timestamp-translate deadline
)))))
1237 (let ((scheduled (org-element-property :scheduled planning
)))
1240 (format "@strong{%s} " org-scheduled-string
)
1241 (format (plist-get info
:texinfo-active-timestamp-format
)
1242 (org-timestamp-translate scheduled
)))))))
1246 ;;;; Property Drawer
1248 (defun org-texinfo-property-drawer (_property-drawer contents _info
)
1249 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1250 CONTENTS holds the contents of the drawer. INFO is a plist
1251 holding contextual information."
1252 (and (org-string-nw-p contents
)
1253 (format "@verbatim\n%s@end verbatim" contents
)))
1257 (defun org-texinfo-quote-block (quote-block contents _info
)
1258 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1259 CONTENTS holds the contents of the block. INFO is a plist
1260 holding contextual information."
1261 (let* ((title (org-element-property :name quote-block
))
1262 (start-quote (concat "@quotation"
1264 (format " %s" title
)))))
1265 (format "%s\n%s@end quotation" start-quote contents
)))
1269 (defun org-texinfo-radio-target (radio-target text info
)
1270 "Transcode a RADIO-TARGET object from Org to Texinfo.
1271 TEXT is the text of the target. INFO is a plist holding
1272 contextual information."
1273 (format "@anchor{%s}%s"
1274 (org-export-get-reference radio-target info
)
1279 (defun org-texinfo-section (section contents info
)
1280 "Transcode a SECTION element from Org to Texinfo.
1281 CONTENTS holds the contents of the section. INFO is a plist
1282 holding contextual information."
1284 (let ((parent (org-export-get-parent-headline section
)))
1285 (and parent
(org-texinfo-make-menu parent info
)))))
1289 (defun org-texinfo-special-block (special-block contents _info
)
1290 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1291 CONTENTS holds the contents of the block. INFO is a plist used
1292 as a communication channel."
1293 (let ((type (org-element-property :type special-block
)))
1294 (format "@%s\n%s@end %s" type contents type
)))
1298 (defun org-texinfo-src-block (src-block _contents info
)
1299 "Transcode a SRC-BLOCK element from Org to Texinfo.
1300 CONTENTS holds the contents of the item. INFO is a plist holding
1301 contextual information."
1302 (let* ((lisp (org-string-match-p "lisp"
1303 (org-element-property :language src-block
)))
1304 (code (org-texinfo--sanitize-content
1305 (org-export-format-code-default src-block info
)))
1307 (if lisp
"@lisp\n%s@end lisp" "@example\n%s@end example")
1309 (caption (org-export-get-caption src-block
))
1310 (shortcaption (org-export-get-caption src-block t
)))
1311 (if (not (or caption shortcaption
)) value
1312 (org-texinfo--wrap-float value
1314 (org-export-translate "Listing" :utf-8 info
)
1315 (org-export-get-reference src-block info
)
1319 ;;;; Statistics Cookie
1321 (defun org-texinfo-statistics-cookie (statistics-cookie _contents _info
)
1322 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1323 CONTENTS is nil. INFO is a plist holding contextual information."
1324 (org-element-property :value statistics-cookie
))
1328 (defun org-texinfo-subscript (_subscript contents _info
)
1329 "Transcode a SUBSCRIPT object from Org to Texinfo.
1330 CONTENTS is the contents of the object. INFO is a plist holding
1331 contextual information."
1332 (format "@math{_%s}" contents
))
1336 (defun org-texinfo-superscript (_superscript contents _info
)
1337 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1338 CONTENTS is the contents of the object. INFO is a plist holding
1339 contextual information."
1340 (format "@math{^%s}" contents
))
1344 (defun org-texinfo-table (table contents info
)
1345 "Transcode a TABLE element from Org to Texinfo.
1346 CONTENTS is the contents of the table. INFO is a plist holding
1347 contextual information."
1348 (if (eq (org-element-property :type table
) 'table.el
)
1349 (format "@verbatim\n%s@end verbatim"
1350 (org-element-normalize-string
1351 (org-element-property :value table
)))
1352 (let* ((col-width (org-export-read-attribute :attr_texinfo table
:columns
))
1354 (if col-width
(format "@columnfractions %s" col-width
)
1355 (org-texinfo-table-column-widths table info
)))
1356 (caption (org-export-get-caption table
))
1357 (shortcaption (org-export-get-caption table t
))
1358 (table-str (format "@multitable %s\n%s@end multitable"
1361 (if (not (or caption shortcaption
)) table-str
1362 (org-texinfo--wrap-float table-str
1364 (org-export-translate "Table" :utf-8 info
)
1365 (org-export-get-reference table info
)
1369 (defun org-texinfo-table-column-widths (table info
)
1370 "Determine the largest table cell in each column to process alignment.
1371 TABLE is the table element to transcode. INFO is a plist used as
1372 a communication channel."
1373 (let ((widths (make-vector (cdr (org-export-table-dimensions table info
)) 0)))
1374 (org-element-map table
'table-row
1377 (org-element-map row
'table-cell
1379 ;; Length of the cell in the original buffer is only an
1380 ;; approximation of the length of the cell in the
1381 ;; output. It can sometimes fail (e.g. it considers
1382 ;; "/a/" being larger than "ab").
1383 (let ((w (- (org-element-property :contents-end cell
)
1384 (org-element-property :contents-begin cell
))))
1385 (aset widths idx
(max w
(aref widths idx
))))
1389 (format "{%s}" (mapconcat (lambda (w) (make-string w ?a
)) widths
"} {"))))
1393 (defun org-texinfo-table-cell (table-cell contents info
)
1394 "Transcode a TABLE-CELL element from Org to Texinfo.
1395 CONTENTS is the cell contents. INFO is a plist used as
1396 a communication channel."
1398 (let ((scientific-notation
1399 (plist-get info
:texinfo-table-scientific-notation
)))
1402 (string-match orgtbl-exp-regexp contents
))
1403 ;; Use appropriate format string for scientific notation.
1404 (format scientific-notation
1405 (match-string 1 contents
)
1406 (match-string 2 contents
))
1408 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1412 (defun org-texinfo-table-row (table-row contents info
)
1413 "Transcode a TABLE-ROW element from Org to Texinfo.
1414 CONTENTS is the contents of the row. INFO is a plist used as
1415 a communication channel."
1416 ;; Rules are ignored since table separators are deduced from
1417 ;; borders of the current row.
1418 (when (eq (org-element-property :type table-row
) 'standard
)
1420 (if (and (= 1 (org-export-table-row-group table-row info
))
1421 (org-export-table-has-header-p
1422 (org-export-get-parent-table table-row
) info
))
1425 (concat rowgroup-tag contents
"\n"))))
1429 (defun org-texinfo-target (target _contents info
)
1430 "Transcode a TARGET object from Org to Texinfo.
1431 CONTENTS is nil. INFO is a plist holding contextual
1433 (format "@anchor{%s}" (org-export-get-reference target info
)))
1437 (defun org-texinfo-timestamp (timestamp _contents info
)
1438 "Transcode a TIMESTAMP object from Org to Texinfo.
1439 CONTENTS is nil. INFO is a plist holding contextual
1441 (let ((value (org-texinfo-plain-text
1442 (org-timestamp-translate timestamp
) info
)))
1443 (case (org-element-property :type timestamp
)
1444 ((active active-range
)
1445 (format (plist-get info
:texinfo-active-timestamp-format
) value
))
1446 ((inactive inactive-range
)
1447 (format (plist-get info
:texinfo-inactive-timestamp-format
) value
))
1448 (t (format (plist-get info
:texinfo-diary-timestamp-format
) value
)))))
1452 (defun org-texinfo-verbatim (verbatim _contents info
)
1453 "Transcode a VERBATIM object from Org to Texinfo.
1454 CONTENTS is nil. INFO is a plist used as a communication
1456 (org-texinfo--text-markup
1457 (org-element-property :value verbatim
) 'verbatim info
))
1461 (defun org-texinfo-verse-block (_verse-block contents _info
)
1462 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1463 CONTENTS is verse block contents. INFO is a plist holding
1464 contextual information."
1465 (format "@display\n%s@end display" contents
))
1468 ;;; Interactive functions
1470 (defun org-texinfo-export-to-texinfo
1471 (&optional async subtreep visible-only body-only ext-plist
)
1472 "Export current buffer to a Texinfo file.
1474 If narrowing is active in the current buffer, only export its
1477 If a region is active, export that region.
1479 A non-nil optional argument ASYNC means the process should happen
1480 asynchronously. The resulting file should be accessible through
1481 the `org-export-stack' interface.
1483 When optional argument SUBTREEP is non-nil, export the sub-tree
1484 at point, extracting information from the headline properties
1487 When optional argument VISIBLE-ONLY is non-nil, don't export
1488 contents of hidden elements.
1490 When optional argument BODY-ONLY is non-nil, only write code
1491 between \"\\begin{document}\" and \"\\end{document}\".
1493 EXT-PLIST, when provided, is a property list with external
1494 parameters overriding Org default settings, but still inferior to
1495 file-local settings.
1497 Return output file's name."
1499 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1500 (org-export-coding-system org-texinfo-coding-system
))
1501 (org-export-to-file 'texinfo outfile
1502 async subtreep visible-only body-only ext-plist
)))
1504 (defun org-texinfo-export-to-info
1505 (&optional async subtreep visible-only body-only ext-plist
)
1506 "Export current buffer to Texinfo then process through to INFO.
1508 If narrowing is active in the current buffer, only export its
1511 If a region is active, export that region.
1513 A non-nil optional argument ASYNC means the process should happen
1514 asynchronously. The resulting file should be accessible through
1515 the `org-export-stack' interface.
1517 When optional argument SUBTREEP is non-nil, export the sub-tree
1518 at point, extracting information from the headline properties
1521 When optional argument VISIBLE-ONLY is non-nil, don't export
1522 contents of hidden elements.
1524 When optional argument BODY-ONLY is non-nil, only write code
1525 between \"\\begin{document}\" and \"\\end{document}\".
1527 EXT-PLIST, when provided, is a property list with external
1528 parameters overriding Org default settings, but still inferior to
1529 file-local settings.
1531 When optional argument PUB-DIR is set, use it as the publishing
1534 Return INFO file's name."
1536 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1537 (org-export-coding-system org-texinfo-coding-system
))
1538 (org-export-to-file 'texinfo outfile
1539 async subtreep visible-only body-only ext-plist
1540 (lambda (file) (org-texinfo-compile file
)))))
1543 (defun org-texinfo-publish-to-texinfo (plist filename pub-dir
)
1544 "Publish an org file to Texinfo.
1546 FILENAME is the filename of the Org file to be published. PLIST
1547 is the property list for the given project. PUB-DIR is the
1548 publishing directory.
1550 Return output file name."
1551 (org-publish-org-to 'texinfo filename
".texi" plist pub-dir
))
1554 (defun org-texinfo-convert-region-to-texinfo ()
1555 "Assume the current region has org-mode syntax, and convert it to Texinfo.
1556 This can be used in any buffer. For example, you can write an
1557 itemized list in org-mode syntax in an Texinfo buffer and use
1558 this command to convert it."
1560 (org-export-replace-region-by 'texinfo
))
1562 (defun org-texinfo-compile (file)
1563 "Compile a texinfo file.
1565 FILE is the name of the file being compiled. Processing is
1566 done through the command specified in `org-texinfo-info-process'.
1568 Return INFO file name or an error if it couldn't be produced."
1569 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file
)))
1570 (full-name (file-truename file
))
1571 (out-dir (file-name-directory file
))
1572 ;; Properly set working directory for compilation.
1573 (default-directory (if (file-name-absolute-p file
)
1574 (file-name-directory full-name
)
1577 (message "Processing Texinfo file %s..." file
)
1578 (save-window-excursion
1579 ;; Replace %b, %f and %o with appropriate values in each command
1580 ;; before applying it. Output is redirected to "*Org INFO
1581 ;; Texinfo Output*" buffer.
1582 (let ((outbuf (get-buffer-create "*Org INFO Texinfo Output*")))
1583 (with-current-buffer outbuf
(compilation-mode))
1584 (dolist (command org-texinfo-info-process
)
1586 (replace-regexp-in-string
1587 "%b" (shell-quote-argument base-name
)
1588 (replace-regexp-in-string
1589 "%f" (shell-quote-argument full-name
)
1590 (replace-regexp-in-string
1591 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
1593 ;; Collect standard errors from output buffer.
1594 (setq errors
(org-texinfo-collect-errors outbuf
)))
1595 (let ((infofile (concat out-dir base-name
".info")))
1596 ;; Check for process failure. Provide collected errors if
1598 (if (not (file-exists-p infofile
))
1599 (error "INFO file %s wasn't produced%s" infofile
1600 (if errors
(concat ": " errors
) ""))
1601 ;; Else remove log files, when specified, and signal end of
1602 ;; process to user, along with any error encountered.
1603 (when org-texinfo-remove-logfiles
1604 (dolist (ext org-texinfo-logfiles-extensions
)
1605 (let ((file (concat out-dir base-name
"." ext
)))
1606 (when (file-exists-p file
) (delete-file file
)))))
1607 (message (concat "Process completed"
1608 (if (not errors
) "."
1609 (concat " with errors: " errors
)))))
1610 ;; Return output file name.
1613 (defun org-texinfo-collect-errors (buffer)
1614 "Collect some kind of errors from \"makeinfo\" command output.
1616 BUFFER is the buffer containing output.
1618 Return collected error types as a string, or nil if there was
1620 (with-current-buffer buffer
1622 (goto-char (point-min))
1623 ;; Find final "makeinfo" run.
1625 (let ((case-fold-search t
)
1627 (when (save-excursion
1628 (re-search-forward "perhaps incorrect sectioning?" nil t
))
1629 (setq errors
(concat errors
" [incorrect sectioning]")))
1630 (when (save-excursion
1631 (re-search-forward "missing close brace" nil t
))
1632 (setq errors
(concat errors
" [syntax error]")))
1633 (when (save-excursion
1634 (re-search-forward "Unknown command" nil t
))
1635 (setq errors
(concat errors
" [undefined @command]")))
1636 (when (save-excursion
1637 (re-search-forward "No matching @end" nil t
))
1638 (setq errors
(concat errors
" [block incomplete]")))
1639 (when (save-excursion
1640 (re-search-forward "requires a sectioning" nil t
))
1641 (setq errors
(concat errors
" [invalid section command]")))
1642 (when (save-excursion
1643 (re-search-forward "\\[unexpected\ ]" nil t
))
1644 (setq errors
(concat errors
" [unexpected error]")))
1645 (when (save-excursion
1646 (re-search-forward "misplaced " nil t
))
1647 (setq errors
(concat errors
" [syntax error]")))
1648 (and (org-string-nw-p errors
) (org-trim errors
)))))))
1651 (provide 'ox-texinfo
)
1654 ;; generated-autoload-file: "org-loaddefs.el"
1657 ;;; ox-texinfo.el ends here