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