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 ;; This library implements a Texinfo back-end for Org generic
29 ;; M-: (org-export-to-buffer 'texinfo "*Test Texinfo*") RET
31 ;; in an Org mode buffer then switch to the buffer to see the Texinfo
32 ;; export. See ox.el for more details on how this exporter works.
35 ;; It introduces nine new buffer keywords: "TEXINFO_CLASS",
36 ;; "TEXINFO_FILENAME", "TEXINFO_HEADER", "TEXINFO_POST_HEADER",
37 ;; "TEXINFO_DIR_CATEGORY", "TEXINFO_DIR_TITLE", "TEXINFO_DIR_DESC"
38 ;; "SUBTITLE" and "SUBAUTHOR".
41 ;; It introduces 1 new headline property keywords:
42 ;; "TEXINFO_MENU_TITLE" for optional menu titles.
44 ;; To include inline code snippets (for example for generating @kbd{}
45 ;; and @key{} commands), the following export-snippet keys are
51 ;; You can add them for export snippets via any of the below:
53 ;; (add-to-list 'org-export-snippet-translation-alist
54 ;; '("info" . "texinfo"))
59 (eval-when-compile (require 'cl
))
62 (defvar orgtbl-exp-regexp
)
68 (org-export-define-backend 'texinfo
69 '((bold . org-texinfo-bold
)
70 (center-block . org-texinfo-center-block
)
71 (clock . org-texinfo-clock
)
72 (code . org-texinfo-code
)
73 (comment . org-texinfo-comment
)
74 (comment-block . org-texinfo-comment-block
)
75 (drawer . org-texinfo-drawer
)
76 (dynamic-block . org-texinfo-dynamic-block
)
77 (entity . org-texinfo-entity
)
78 (example-block . org-texinfo-example-block
)
79 (export-snippet . org-texinfo-export-snippet
)
80 (fixed-width . org-texinfo-fixed-width
)
81 (footnote-definition . org-texinfo-footnote-definition
)
82 (footnote-reference . org-texinfo-footnote-reference
)
83 (headline . org-texinfo-headline
)
84 (inline-src-block . org-texinfo-inline-src-block
)
85 (inlinetask . org-texinfo-inlinetask
)
86 (italic . org-texinfo-italic
)
87 (item . org-texinfo-item
)
88 (keyword . org-texinfo-keyword
)
89 (line-break . org-texinfo-line-break
)
90 (link . org-texinfo-link
)
91 (node-property . org-texinfo-node-property
)
92 (paragraph . org-texinfo-paragraph
)
93 (plain-list . org-texinfo-plain-list
)
94 (plain-text . org-texinfo-plain-text
)
95 (planning . org-texinfo-planning
)
96 (property-drawer . org-texinfo-property-drawer
)
97 (quote-block . org-texinfo-quote-block
)
98 (radio-target . org-texinfo-radio-target
)
99 (section . org-texinfo-section
)
100 (special-block . org-texinfo-special-block
)
101 (src-block . org-texinfo-src-block
)
102 (statistics-cookie . org-texinfo-statistics-cookie
)
103 (subscript . org-texinfo-subscript
)
104 (superscript . org-texinfo-superscript
)
105 (table . org-texinfo-table
)
106 (table-cell . org-texinfo-table-cell
)
107 (table-row . org-texinfo-table-row
)
108 (target . org-texinfo-target
)
109 (template . org-texinfo-template
)
110 (timestamp . org-texinfo-timestamp
)
111 (verbatim . org-texinfo-verbatim
)
112 (verse-block . org-texinfo-verse-block
))
113 :export-block
"TEXINFO"
115 '((:filter-headline . org-texinfo-filter-section-blank-lines
)
116 (:filter-section . org-texinfo-filter-section-blank-lines
))
118 '(?i
"Export to Texinfo"
119 ((?t
"As TEXI file" org-texinfo-export-to-texinfo
)
120 (?i
"As INFO file" org-texinfo-export-to-info
)))
122 '((:texinfo-filename
"TEXINFO_FILENAME" nil org-texinfo-filename t
)
123 (:texinfo-class
"TEXINFO_CLASS" nil org-texinfo-default-class t
)
124 (:texinfo-header
"TEXINFO_HEADER" nil nil newline
)
125 (:texinfo-post-header
"TEXINFO_POST_HEADER" nil nil newline
)
126 (:subtitle
"SUBTITLE" nil nil newline
)
127 (:subauthor
"SUBAUTHOR" nil nil newline
)
128 (:texinfo-dircat
"TEXINFO_DIR_CATEGORY" nil nil t
)
129 (:texinfo-dirtitle
"TEXINFO_DIR_TITLE" nil nil t
)
130 (:texinfo-dirdesc
"TEXINFO_DIR_DESC" nil nil t
)
132 (:texinfo-classes nil nil org-texinfo-classes
)
133 (:texinfo-format-headline-function nil nil org-texinfo-format-headline-function
)
134 (:texinfo-node-description-column nil nil org-texinfo-node-description-column
)
135 (:texinfo-active-timestamp-format nil nil org-texinfo-active-timestamp-format
)
136 (:texinfo-inactive-timestamp-format nil nil org-texinfo-inactive-timestamp-format
)
137 (:texinfo-diary-timestamp-format nil nil org-texinfo-diary-timestamp-format
)
138 (:texinfo-link-with-unknown-path-format nil nil org-texinfo-link-with-unknown-path-format
)
139 (:texinfo-tables-verbatim nil nil org-texinfo-tables-verbatim
)
140 (:texinfo-table-scientific-notation nil nil org-texinfo-table-scientific-notation
)
141 (:texinfo-def-table-markup nil nil org-texinfo-def-table-markup
)
142 (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist
)
143 (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function
)
144 (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function
)))
148 ;;; User Configurable Variables
150 (defgroup org-export-texinfo nil
151 "Options for exporting Org mode files to Texinfo."
152 :tag
"Org Export Texinfo"
154 :package-version
'(Org .
"8.0")
159 (defcustom org-texinfo-filename
""
160 "Default filename for Texinfo output."
161 :group
'org-export-texinfo
162 :type
'(string :tag
"Export Filename"))
164 (defcustom org-texinfo-coding-system nil
165 "Default document encoding for Texinfo output.
167 If `nil' it will default to `buffer-file-coding-system'."
168 :group
'org-export-texinfo
169 :type
'coding-system
)
171 (defcustom org-texinfo-default-class
"info"
172 "The default Texinfo class."
173 :group
'org-export-texinfo
174 :type
'(string :tag
"Texinfo class"))
176 (defcustom org-texinfo-classes
178 "\\input texinfo @c -*- texinfo -*-"
179 ("@chapter %s" .
"@unnumbered %s")
180 ("@section %s" .
"@unnumberedsec %s")
181 ("@subsection %s" .
"@unnumberedsubsec %s")
182 ("@subsubsection %s" .
"@unnumberedsubsubsec %s")))
183 "Alist of Texinfo classes and associated header and structure.
184 If #+Texinfo_CLASS is set in the buffer, use its value and the
185 associated information. Here is the structure of each cell:
189 \(numbered-section . unnumbered-section\)
192 The sectioning structure
193 ------------------------
195 The sectioning structure of the class is given by the elements
196 following the header string. For each sectioning level, a number
197 of strings is specified. A %s formatter is mandatory in each
198 section string and will be replaced by the title of the section.
200 Instead of a list of sectioning commands, you can also specify
201 a function name. That function will be called with two
202 parameters, the \(reduced) level of the headline, and a predicate
203 non-nil when the headline should be numbered. It must return
204 a format string in which the section title will be added."
205 :group
'org-export-texinfo
207 (list (string :tag
"Texinfo class")
208 (string :tag
"Texinfo header")
209 (repeat :tag
"Levels" :inline t
212 (string :tag
" numbered")
213 (string :tag
"unnumbered"))
214 (function :tag
"Hook computing sectioning"))))))
218 (defcustom org-texinfo-format-headline-function
'ignore
219 "Function to format headline text.
221 This function will be called with 5 arguments:
222 TODO the todo keyword (string or nil).
223 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
224 PRIORITY the priority of the headline (integer or nil)
225 TEXT the main headline text (string).
226 TAGS the tags as a list of strings (list of strings or nil).
228 The function result will be used in the section format string.
230 As an example, one could set the variable to the following, in
231 order to reproduce the default set-up:
233 \(defun org-texinfo-format-headline (todo todo-type priority text tags)
234 \"Default format function for a headline.\"
236 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
238 \(format \"\\\\framebox{\\\\#%c} \" priority))
241 \(format \"\\\\hfill{}\\\\textsc{%s}\"
242 \(mapconcat 'identity tags \":\"))))"
243 :group
'org-export-texinfo
246 ;;; Node listing (menu)
248 (defcustom org-texinfo-node-description-column
32
249 "Column at which to start the description in the node
252 If a node title is greater than this length, the description will
253 be placed after the end of the title."
254 :group
'org-export-texinfo
259 ;; Footnotes are inserted directly
263 (defcustom org-texinfo-active-timestamp-format
"@emph{%s}"
264 "A printf format string to be applied to active timestamps."
265 :group
'org-export-texinfo
268 (defcustom org-texinfo-inactive-timestamp-format
"@emph{%s}"
269 "A printf format string to be applied to inactive timestamps."
270 :group
'org-export-texinfo
273 (defcustom org-texinfo-diary-timestamp-format
"@emph{%s}"
274 "A printf format string to be applied to diary timestamps."
275 :group
'org-export-texinfo
280 (defcustom org-texinfo-link-with-unknown-path-format
"@indicateurl{%s}"
281 "Format string for links with unknown path type."
282 :group
'org-export-texinfo
287 (defcustom org-texinfo-tables-verbatim nil
288 "When non-nil, tables are exported verbatim."
289 :group
'org-export-texinfo
292 (defcustom org-texinfo-table-scientific-notation
"%s\\,(%s)"
293 "Format string to display numbers in scientific notation.
294 The format should have \"%s\" twice, for mantissa and exponent
295 \(i.e. \"%s\\\\times10^{%s}\").
297 When nil, no transformation is made."
298 :group
'org-export-texinfo
300 (string :tag
"Format string")
301 (const :tag
"No formatting")))
303 (defcustom org-texinfo-def-table-markup
"@samp"
304 "Default setting for @table environments."
305 :group
'org-export-texinfo
310 (defcustom org-texinfo-text-markup-alist
'((bold .
"@strong{%s}")
312 (italic .
"@emph{%s}")
315 "Alist of Texinfo expressions to convert text markup.
317 The key must be a symbol among `bold', `italic' and `comment'.
318 The value is a formatting string to wrap fontified text with.
320 Value can also be set to the following symbols: `verb' and
321 `code'. For the former, Org will use \"@verb\" to
322 create a format string and select a delimiter character that
323 isn't in the string. For the latter, Org will use \"@code\"
324 to typeset and try to protect special characters.
326 If no association can be found for a given markup, text will be
328 :group
'org-export-texinfo
330 :options
'(bold code italic verbatim comment
))
334 (defcustom org-texinfo-format-drawer-function
335 (lambda (name contents
) contents
)
336 "Function called to format a drawer in Texinfo code.
338 The function must accept two parameters:
339 NAME the drawer name, like \"LOGBOOK\"
340 CONTENTS the contents of the drawer.
342 The function should return the string to be exported.
344 The default function simply returns the value of CONTENTS."
345 :group
'org-export-texinfo
347 :package-version
'(Org .
"8.3")
352 (defcustom org-texinfo-format-inlinetask-function
'ignore
353 "Function called to format an inlinetask in Texinfo code.
355 The function must accept six parameters:
356 TODO the todo keyword, as a string
357 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
358 PRIORITY the inlinetask priority, as a string
359 NAME the inlinetask name, as a string.
360 TAGS the inlinetask tags, as a list of strings.
361 CONTENTS the contents of the inlinetask, as a string.
363 The function should return the string to be exported.
365 For example, the variable could be set to the following function
366 in order to mimic default behavior:
368 \(defun org-texinfo-format-inlinetask \(todo type priority name tags contents\)
369 \"Format an inline task element for Texinfo export.\"
373 \(format \"@strong{%s} \" todo))
374 \(when priority (format \"#%c \" priority))
378 \(mapconcat 'identity tags \":\")))))
379 \(format (concat \"@center %s\n\n\"
382 full-title contents))"
383 :group
'org-export-texinfo
388 ;; Src Blocks are example blocks, except for LISP
392 (defcustom org-texinfo-info-process
394 "Commands to process a Texinfo file to an INFO file.
395 This is list of strings, each of them will be given to the shell
396 as a command. %f in the command will be replaced by the full
397 file name, %b by the file base name \(i.e without extension) and
398 %o by the base directory of the file."
399 :group
'org-export-texinfo
400 :type
'(repeat :tag
"Shell command sequence"
401 (string :tag
"Shell command")))
403 (defcustom org-texinfo-logfiles-extensions
404 '("aux" "toc" "cp" "fn" "ky" "pg" "tp" "vr")
405 "The list of file extensions to consider as Texinfo logfiles.
406 The logfiles will be remove if `org-texinfo-remove-logfiles' is
408 :group
'org-export-texinfo
409 :type
'(repeat (string :tag
"Extension")))
411 (defcustom org-texinfo-remove-logfiles t
412 "Non-nil means remove the logfiles produced by compiling a Texinfo file.
413 By default, logfiles are files with these extensions: .aux, .toc,
414 .cp, .fn, .ky, .pg and .tp. To define the set of logfiles to remove,
415 set `org-texinfo-logfiles-extensions'."
416 :group
'org-export-latex
421 (defconst org-texinfo-max-toc-depth
4
422 "Maximum depth for creation of detailed menu listings. Beyond
423 this depth Texinfo will not recognize the nodes and will cause
424 errors. Left as a constant in case this value ever changes.")
426 (defconst org-texinfo-supported-coding-systems
427 '("US-ASCII" "UTF-8" "ISO-8859-15" "ISO-8859-1" "ISO-8859-2" "koi8-r" "koi8-u")
428 "List of coding systems supported by Texinfo, as strings.
429 Specified coding system will be matched against these strings.
430 If two strings share the same prefix (e.g. \"ISO-8859-1\" and
431 \"ISO-8859-15\"), the most specific one has to be listed first.")
434 ;;; Internal Functions
436 (defun org-texinfo-filter-section-blank-lines (headline back-end info
)
437 "Filter controlling number of blank lines after a section."
438 (let ((blanks (make-string 2 ?
\n)))
439 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline
)))
441 (defun org-texinfo--find-verb-separator (s)
442 "Return a character not used in string S.
443 This is used to choose a separator for constructs like \\verb."
444 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
445 (loop for c across ll
446 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
447 return
(char-to-string c
))))
449 (defun org-texinfo--make-option-string (options)
450 "Return a comma separated string of keywords and values.
451 OPTIONS is an alist where the key is the options keyword as
452 a string, and the value a list containing the keyword value, or
454 (mapconcat (lambda (pair)
456 (when (> (length (second pair
)) 0)
457 (concat "=" (second pair
)))))
461 (defun org-texinfo--text-markup (text markup
)
462 "Format TEXT depending on MARKUP text markup.
463 See `org-texinfo-text-markup-alist' for details."
464 (let ((fmt (cdr (assq markup org-texinfo-text-markup-alist
))))
466 ;; No format string: Return raw text.
469 (let ((separator (org-texinfo--find-verb-separator text
)))
470 (concat "@verb{" separator text separator
"}")))
475 (while (string-match "[@{}]" text
)
476 (setq char
(match-string 0 text
))
477 (if (> (match-beginning 0) 0)
478 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
479 (setq text
(substring text
(1+ (match-beginning 0))))
480 (setq char
(concat "@" char
)
481 rtn
(concat rtn char
)))
482 (setq text
(concat rtn text
)
485 ;; Else use format string.
486 (t (format fmt text
)))))
488 (defun org-texinfo--get-node (headline info
)
489 "Return node entry associated to HEADLINE.
490 INFO is a plist used as a communication channel."
491 (let ((menu-title (org-export-get-alt-title headline info
)))
492 (org-texinfo--sanitize-menu
493 (replace-regexp-in-string
495 (if menu-title
(org-export-data menu-title info
)
496 (org-texinfo--sanitize-headline
497 (org-element-property :title headline
) info
))))))
499 ;;; Headline sanitizing
501 (defun org-texinfo--sanitize-headline (headline info
)
502 "Remove all formatting from the text of a headline for use in
503 node and menu listing."
505 (org-texinfo--sanitize-headline-contents headline info
) " "))
507 (defun org-texinfo--sanitize-headline-contents (headline info
)
508 "Retrieve the content of the headline.
510 Any content that can contain further formatting is checked
511 recursively, to ensure that nested content is also properly
513 (loop for contents in headline append
517 (list (replace-regexp-in-string " $" "" contents
)))
518 ;; Is exported as-is (value)
519 ((org-element-map contents
'(verbatim code
)
520 (lambda (value) (org-element-property :value value
)) info
))
521 ;; Has content and recurse into the content
522 ((org-element-contents contents
)
523 (org-texinfo--sanitize-headline-contents
524 (org-element-contents contents
) info
)))))
528 (defun org-texinfo--sanitize-menu (title)
529 "Remove invalid characters from TITLE for use in menus and
532 Based on Texinfo specifications, the following must be removed:
534 (replace-regexp-in-string "[@{}():,.]" "" title
))
536 ;;; Content sanitizing
538 (defun org-texinfo--sanitize-content (text)
539 "Ensure characters are properly escaped when used in headlines or blocks.
541 Escape characters are: @ { }"
542 (replace-regexp-in-string "\\\([@{}]\\\)" "@\\1" text
))
546 (defun org-texinfo--build-menu (tree level info
&optional detailed
)
547 "Create the @menu/@end menu information from TREE at headline
550 TREE contains the parse-tree to work with, either of the entire
551 document or of a specific parent headline. LEVEL indicates what
552 level of headlines to look at when generating the menu. INFO is
553 a plist containing contextual information.
555 Detailed determines whether to build a single level of menu, or
556 recurse into all children as well."
557 (let ((menu (org-texinfo--generate-menu-list tree level info
))
561 ;; Looping is done within the menu generation.
562 (setq text-menu
(org-texinfo--generate-detailed menu level info
)))
564 (setq text-menu
(org-texinfo--generate-menu-items menu info
))))
566 (setq output
(org-texinfo--format-menu text-menu
))
567 (mapconcat 'identity output
"\n"))))
569 (defun org-texinfo--generate-detailed (menu level info
)
570 "Generate a detailed listing of all subheadings within MENU starting at LEVEL.
572 MENU is the parse-tree to work with. LEVEL is the starting level
573 for the menu headlines and from which recursion occurs. INFO is
574 a plist containing contextual information."
576 (let ((max-depth (min org-texinfo-max-toc-depth
577 (plist-get info
:headline-levels
))))
578 (when (> max-depth level
)
579 (loop for headline in menu append
580 (let* ((title (org-texinfo--menu-headlines headline info
))
581 ;; Create list of menu entries for the next level
582 (sublist (org-texinfo--generate-menu-list
583 headline
(1+ level
) info
))
584 ;; Generate the menu items for that level. If
585 ;; there are none omit that heading completely,
586 ;; otherwise join the title to it's related entries.
587 (submenu (if (org-texinfo--generate-menu-items sublist info
)
589 (org-texinfo--generate-menu-items sublist info
))
591 ;; Start the process over the next level down.
592 (recursion (org-texinfo--generate-detailed sublist
(1+ level
) info
)))
593 (setq recursion
(append submenu recursion
))
596 (defun org-texinfo--generate-menu-list (tree level info
)
597 "Generate the list of headlines that are within a given level
598 of the tree for further formatting.
600 TREE is the parse-tree containing the headlines. LEVEL is the
601 headline level to generate a list of. INFO is a plist holding
602 contextual information."
603 (org-element-map tree
'headline
605 (and (= (org-export-get-relative-level head info
) level
)
606 ;; Do not take note of footnotes or copying headlines.
607 (not (org-element-property :COPYING head
))
608 (not (org-element-property :footnote-section-p head
))
613 (defun org-texinfo--generate-menu-items (items info
)
614 "Generate a list of headline information from the listing ITEMS.
616 ITEMS is a list of the headlines to be converted into entries.
617 INFO is a plist containing contextual information.
619 Returns a list containing the following information from each
620 headline: length, title, description. This is used to format the
621 menu using `org-texinfo--format-menu'."
622 (loop for headline in items collect
623 (let* ((menu-title (org-texinfo--sanitize-menu
625 (org-export-get-alt-title headline info
)
627 (title (org-texinfo--sanitize-menu
628 (org-texinfo--sanitize-headline
629 (org-element-property :title headline
) info
)))
630 (descr (org-export-data
631 (org-element-property :DESCRIPTION headline
)
633 (menu-entry (if (string= "" menu-title
) title menu-title
))
634 (len (length menu-entry
))
635 (output (list len menu-entry descr
)))
638 (defun org-texinfo--menu-headlines (headline info
)
639 "Retrieve the title from HEADLINE.
641 INFO is a plist holding contextual information.
643 Return the headline as a list of (length title description) with
644 length of -1 and nil description. This is used in
645 `org-texinfo--format-menu' to identify headlines as opposed to
647 (let ((title (org-export-data
648 (org-element-property :title headline
) info
)))
649 (list -
1 title
'nil
)))
651 (defun org-texinfo--format-menu (text-menu)
652 "Format the TEXT-MENU items to be properly printed in the menu.
654 Each entry in the menu should be provided as (length title
657 Headlines in the detailed menu are given length -1 to ensure they
658 are never confused with other entries. They also have no
661 Other menu items are output as:
664 With the spacing between :: and description based on the length
665 of the longest menu entry."
669 (mapcar (lambda (name)
670 (let* ((title (nth 1 name
))
672 (length (nth 0 name
))
674 ;;6 is "* " ":: " for inserted text
677 org-texinfo-node-description-column
679 (spacing (- column length
)
682 (concat "* " title
":: "
683 (make-string spacing ?\s
)
686 (concat "\n" title
"\n"))))
692 (defun org-texinfo-template (contents info
)
693 "Return complete document string after Texinfo conversion.
694 CONTENTS is the transcoded contents string. INFO is a plist
695 holding export options."
696 (let* ((title (org-export-data (plist-get info
:title
) info
))
697 (info-filename (or (plist-get info
:texinfo-filename
)
698 (file-name-nondirectory
699 (org-export-output-file-name ".info"))))
700 (author (org-export-data (plist-get info
:author
) info
))
701 (lang (org-export-data (plist-get info
:language
) info
))
702 (texinfo-header (plist-get info
:texinfo-header
))
703 (texinfo-post-header (plist-get info
:texinfo-post-header
))
704 (subtitle (plist-get info
:subtitle
))
705 (subauthor (plist-get info
:subauthor
))
706 (class (plist-get info
:texinfo-class
))
707 (header (nth 1 (assoc class org-texinfo-classes
)))
709 (org-element-map (plist-get info
:parse-tree
) 'headline
710 (lambda (hl) (and (org-element-property :COPYING hl
) hl
)) info t
))
711 (dircat (plist-get info
:texinfo-dircat
))
712 (dirtitle (plist-get info
:texinfo-dirtitle
))
713 (dirdesc (plist-get info
:texinfo-dirdesc
))
714 ;; Spacing to align description (column 32 - 3 for `* ' and
716 (dirspacing (- 29 (length dirtitle
)))
717 (menu (org-texinfo-make-menu info
'main
))
718 (detail-menu (org-texinfo-make-menu info
'detailed
)))
722 "@c %**start of header\n"
723 ;; Filename and Title
724 "@setfilename " info-filename
"\n"
725 "@settitle " title
"\n"
728 "@documentencoding %s\n"
729 (catch 'coding-system
730 (let ((case-fold-search t
)
731 (name (symbol-name (or org-texinfo-coding-system
732 buffer-file-coding-system
))))
733 (dolist (system org-texinfo-supported-coding-systems
"UTF-8")
734 (when (org-string-match-p (regexp-quote system
) name
)
735 (throw 'coding-system system
))))))
737 (format "@documentlanguage %s\n" lang
)
739 "@c Version and Contact Info\n"
740 "@set AUTHOR " author
"\n"
742 ;; Additional Header Options set by `#+TEXINFO_HEADER
748 "@c %**end of header\n"
752 ;; Additional Header Options set by #+TEXINFO_POST_HEADER
753 (if texinfo-post-header
760 ;; Only export the content of the headline, do not need the
762 (org-export-data (nth 2 copying
) info
)
766 ;; Info directory information
767 ;; Only supply if both title and category are provided
768 (if (and dircat dirtitle
)
769 (concat "@dircategory " dircat
"\n"
772 (make-string dirspacing ?\s
)
779 "@title " title
"\n\n"
781 (concat "@subtitle " subtitle
"\n"))
782 "@author " author
"\n"
784 (concat subauthor
"\n"))
786 "@c The following two commands start the copyright page.\n"
788 "@vskip 0pt plus 1filll\n"
791 "@c Output the table of contents at the beginning.\n"
794 ;; Configure Top Node when not for Tex
797 "@top " title
" Manual\n"
801 ;; Do not output menus if they are empty
809 (concat "@detailmenu\n"
810 " --- The Detailed Node Listing ---\n"
813 "@end detailmenu\n"))
821 (let ((creator-info (plist-get info
:with-creator
)))
823 ((not creator-info
) "")
824 ((eq creator-info
'comment
)
825 (format "@c %s\n" (plist-get info
:creator
)))
826 (t (concat (plist-get info
:creator
) "\n"))))
832 ;;; Transcode Functions
836 (defun org-texinfo-bold (bold contents info
)
837 "Transcode BOLD from Org to Texinfo.
838 CONTENTS is the text with bold markup. INFO is a plist holding
839 contextual information."
840 (org-texinfo--text-markup contents
'bold
))
844 (defun org-texinfo-center-block (center-block contents info
)
845 "Transcode a CENTER-BLOCK element from Org to Texinfo.
846 CONTENTS holds the contents of the block. INFO is a plist used
847 as a communication channel."
852 (defun org-texinfo-clock (clock contents info
)
853 "Transcode a CLOCK element from Org to Texinfo.
854 CONTENTS is nil. INFO is a plist holding contextual
858 (format "@strong{%s} " org-clock-string
)
859 (format org-texinfo-inactive-timestamp-format
860 (concat (org-translate-time
861 (org-element-property :raw-value
862 (org-element-property :value clock
)))
863 (let ((time (org-element-property :duration clock
)))
864 (and time
(format " (%s)" time
)))))
869 (defun org-texinfo-code (code contents info
)
870 "Transcode a CODE object from Org to Texinfo.
871 CONTENTS is nil. INFO is a plist used as a communication
873 (org-texinfo--text-markup (org-element-property :value code
) 'code
))
877 (defun org-texinfo-comment (comment contents info
)
878 "Transcode a COMMENT object from Org to Texinfo.
879 CONTENTS is the text in the comment. INFO is a plist holding
880 contextual information."
881 (org-texinfo--text-markup (org-element-property :value comment
) 'comment
))
885 (defun org-texinfo-comment-block (comment-block contents info
)
886 "Transcode a COMMENT-BLOCK object from Org to Texinfo.
887 CONTENTS is the text within the block. INFO is a plist holding
888 contextual information."
889 (format "@ignore\n%s@end ignore" (org-element-property :value comment-block
)))
893 (defun org-texinfo-drawer (drawer contents info
)
894 "Transcode a DRAWER element from Org to Texinfo.
895 CONTENTS holds the contents of the block. INFO is a plist
896 holding contextual information."
897 (let* ((name (org-element-property :drawer-name drawer
))
898 (output (funcall org-texinfo-format-drawer-function
904 (defun org-texinfo-dynamic-block (dynamic-block contents info
)
905 "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
906 CONTENTS holds the contents of the block. INFO is a plist
907 holding contextual information. See `org-export-data'."
912 (defun org-texinfo-entity (entity contents info
)
913 "Transcode an ENTITY object from Org to Texinfo.
914 CONTENTS are the definition itself. INFO is a plist holding
915 contextual information."
916 (let ((ent (org-element-property :latex entity
)))
917 (if (org-element-property :latex-math-p entity
) (format "@math{%s}" ent
) ent
)))
921 (defun org-texinfo-example-block (example-block contents info
)
922 "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
923 CONTENTS is nil. INFO is a plist holding contextual
925 (format "@verbatim\n%s@end verbatim"
926 (org-export-format-code-default example-block info
)))
930 (defun org-texinfo-export-snippet (export-snippet contents info
)
931 "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
932 CONTENTS is nil. INFO is a plist holding contextual information."
933 (when (eq (org-export-snippet-backend export-snippet
) 'texinfo
)
934 (org-element-property :value export-snippet
)))
938 (defun org-texinfo-fixed-width (fixed-width contents info
)
939 "Transcode a FIXED-WIDTH element from Org to Texinfo.
940 CONTENTS is nil. INFO is a plist holding contextual information."
941 (format "@example\n%s\n@end example"
942 (org-remove-indentation
943 (org-texinfo--sanitize-content
944 (org-element-property :value fixed-width
)))))
946 ;;; Footnote Reference
949 (defun org-texinfo-footnote-reference (footnote contents info
)
950 "Create a footnote reference for FOOTNOTE.
952 FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
953 plist holding contextual information."
954 (let ((def (org-export-get-footnote-definition footnote info
)))
955 (format "@footnote{%s}"
956 (org-trim (org-export-data def info
)))))
960 (defun org-texinfo-headline (headline contents info
)
961 "Transcode a HEADLINE element from Org to Texinfo.
962 CONTENTS holds the contents of the headline. INFO is a plist
963 holding contextual information."
964 (let* ((class (plist-get info
:texinfo-class
))
965 (level (org-export-get-relative-level headline info
))
966 (numberedp (org-export-numbered-headline-p headline info
))
967 (class-sectioning (assoc class org-texinfo-classes
))
968 ;; Find the index type, if any
969 (index (org-element-property :INDEX headline
))
970 ;; Check if it is an appendix
971 (appendix (org-element-property :APPENDIX headline
))
972 ;; Retrieve headline text
973 (text (org-texinfo--sanitize-headline
974 (org-element-property :title headline
) info
))
975 ;; Create node info, to insert it before section formatting.
976 ;; Use custom menu title if present
977 (node (format "@node %s\n" (org-texinfo--get-node headline info
)))
978 ;; Menus must be generated with first child, otherwise they
979 ;; will not nest properly
980 (menu (let* ((first (org-export-first-sibling-p headline info
))
981 (parent (org-export-get-parent-headline headline
))
982 (title (org-texinfo--sanitize-headline
983 (org-element-property :title parent
) info
))
985 (tree (plist-get info
:parse-tree
)))
987 (org-element-map (plist-get info
:parse-tree
) 'headline
989 (if (member title
(org-element-property :title ref
))
992 (setq listing
(org-texinfo--build-menu
993 (car heading
) level info
))
995 (setq listing
(replace-regexp-in-string
998 "\n@menu\n%s\n@end menu\n\n" listing
))
1000 ;; Section formatting will set two placeholders: one for the
1001 ;; title and the other for the contents.
1003 (let ((sec (if (and (symbolp (nth 2 class-sectioning
))
1004 (fboundp (nth 2 class-sectioning
)))
1005 (funcall (nth 2 class-sectioning
) level numberedp
)
1006 (nth (1+ level
) class-sectioning
))))
1008 ;; No section available for that LEVEL.
1010 ;; Section format directly returned by a function.
1012 ;; (numbered-section . unnumbered-section)
1013 ((not (consp (cdr sec
)))
1015 ;;If an index, always unnumbered
1017 (concat menu node
(cdr sec
) "\n%s"))
1019 (concat menu node
(replace-regexp-in-string
1023 ;; Otherwise number as needed.
1027 (if numberedp
#'car
#'cdr
) sec
) "\n%s")))))))
1029 (and (plist-get info
:with-todo-keywords
)
1030 (let ((todo (org-element-property :todo-keyword headline
)))
1031 (and todo
(org-export-data todo info
)))))
1032 (todo-type (and todo
(org-element-property :todo-type headline
)))
1033 (tags (and (plist-get info
:with-tags
)
1034 (org-export-get-tags headline info
)))
1035 (priority (and (plist-get info
:with-priority
)
1036 (org-element-property :priority headline
)))
1037 ;; Create the headline text along with a no-tag version. The
1038 ;; latter is required to remove tags from table of contents.
1039 (full-text (org-texinfo--sanitize-content
1040 (if (not (eq org-texinfo-format-headline-function
'ignore
))
1041 ;; User-defined formatting function.
1042 (funcall org-texinfo-format-headline-function
1043 todo todo-type priority text tags
)
1044 ;; Default formatting.
1047 (format "@strong{%s} " todo
))
1048 (when priority
(format "@emph{#%s} " priority
))
1052 (mapconcat 'identity tags
":")))))))
1054 (org-texinfo--sanitize-content
1055 (if (not (eq org-texinfo-format-headline-function
'ignore
))
1056 ;; User-defined formatting function.
1057 (funcall org-texinfo-format-headline-function
1058 todo todo-type priority text nil
)
1059 ;; Default formatting.
1061 (when todo
(format "@strong{%s} " todo
))
1062 (when priority
(format "@emph{#%c} " priority
))
1065 (make-string (org-element-property :pre-blank headline
) 10)))
1067 ;; Case 1: This is a footnote section: ignore it.
1068 ((org-element-property :footnote-section-p headline
) nil
)
1069 ;; Case 2: This is the `copying' section: ignore it
1070 ;; This is used elsewhere.
1071 ((org-element-property :COPYING headline
) nil
)
1072 ;; Case 3: An index. If it matches one of the known indexes,
1073 ;; print it as such following the contents, otherwise
1074 ;; print the contents and leave the index up to the user.
1077 section-fmt full-text
1078 (concat pre-blanks contents
"\n"
1079 (if (member index
'("cp" "fn" "ky" "pg" "tp" "vr"))
1080 (concat "@printindex " index
)))))
1081 ;; Case 4: This is a deep sub-tree: export it as a list item.
1082 ;; Also export as items headlines for which no section
1083 ;; format has been found.
1084 ((or (not section-fmt
) (org-export-low-level-p headline info
))
1085 ;; Build the real contents of the sub-tree.
1086 (let ((low-level-body
1088 ;; If the headline is the first sibling, start a list.
1089 (when (org-export-first-sibling-p headline info
)
1090 (format "@%s\n" (if numberedp
'enumerate
'itemize
)))
1092 "@item\n" full-text
"\n" pre-blanks contents
)))
1093 ;; If headline is not the last sibling simply return
1094 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
1096 (if (not (org-export-last-sibling-p headline info
)) low-level-body
1097 (replace-regexp-in-string
1099 (format "\n@end %s" (if numberedp
'enumerate
'itemize
))
1101 ;; Case 5: Standard headline. Export it as a section.
1104 ((not (and tags
(eq (plist-get info
:with-tags
) 'not-in-toc
)))
1105 ;; Regular section. Use specified format string.
1106 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1107 (concat pre-blanks contents
)))
1108 ((string-match "\\`@\\(.*?\\){" section-fmt
)
1109 ;; If tags should be removed from table of contents, insert
1110 ;; title without tags as an alternative heading in sectioning
1112 (format (replace-match (concat (match-string 1 section-fmt
) "[%s]")
1113 nil nil section-fmt
1)
1114 ;; Replace square brackets with parenthesis since
1115 ;; square brackets are not supported in optional
1117 (replace-regexp-in-string
1119 (replace-regexp-in-string
1123 (concat pre-blanks contents
)))
1125 ;; Impossible to add an alternative heading. Fallback to
1126 ;; regular sectioning format string.
1127 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1128 (concat pre-blanks contents
))))))))
1130 ;;; Inline Src Block
1132 (defun org-texinfo-inline-src-block (inline-src-block contents info
)
1133 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
1134 CONTENTS holds the contents of the item. INFO is a plist holding
1135 contextual information."
1136 (let* ((code (org-element-property :value inline-src-block
))
1137 (separator (org-texinfo--find-verb-separator code
)))
1138 (concat "@verb{" separator code separator
"}")))
1142 (defun org-texinfo-inlinetask (inlinetask contents info
)
1143 "Transcode an INLINETASK element from Org to Texinfo.
1144 CONTENTS holds the contents of the block. INFO is a plist
1145 holding contextual information."
1146 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
1147 (todo (and (plist-get info
:with-todo-keywords
)
1148 (let ((todo (org-element-property :todo-keyword inlinetask
)))
1149 (and todo
(org-export-data todo info
)))))
1150 (todo-type (org-element-property :todo-type inlinetask
))
1151 (tags (and (plist-get info
:with-tags
)
1152 (org-export-get-tags inlinetask info
)))
1153 (priority (and (plist-get info
:with-priority
)
1154 (org-element-property :priority inlinetask
))))
1155 ;; If `org-texinfo-format-inlinetask-function' is provided, call it
1156 ;; with appropriate arguments.
1157 (if (not (eq org-texinfo-format-inlinetask-function
'ignore
))
1158 (funcall org-texinfo-format-inlinetask-function
1159 todo todo-type priority title tags contents
)
1160 ;; Otherwise, use a default template.
1163 (when todo
(format "@strong{%s} " todo
))
1164 (when priority
(format "#%c " priority
))
1166 (when tags
(format ":%s:"
1167 (mapconcat 'identity tags
":"))))))
1168 (format (concat "@center %s\n\n"
1171 full-title contents
)))))
1175 (defun org-texinfo-italic (italic contents info
)
1176 "Transcode ITALIC from Org to Texinfo.
1177 CONTENTS is the text with italic markup. INFO is a plist holding
1178 contextual information."
1179 (org-texinfo--text-markup contents
'italic
))
1183 (defun org-texinfo-item (item contents info
)
1184 "Transcode an ITEM element from Org to Texinfo.
1185 CONTENTS holds the contents of the item. INFO is a plist holding
1186 contextual information."
1187 (let* ((tag (org-element-property :tag item
))
1188 (desc (org-export-data tag info
)))
1189 (concat "\n@item " (if tag desc
) "\n"
1190 (and contents
(org-trim contents
)) "\n")))
1194 (defun org-texinfo-keyword (keyword contents info
)
1195 "Transcode a KEYWORD element from Org to Texinfo.
1196 CONTENTS is nil. INFO is a plist holding contextual information."
1197 (let ((key (org-element-property :key keyword
))
1198 (value (org-element-property :value keyword
)))
1200 ((string= key
"TEXINFO") value
)
1201 ((string= key
"CINDEX") (format "@cindex %s" value
))
1202 ((string= key
"FINDEX") (format "@findex %s" value
))
1203 ((string= key
"KINDEX") (format "@kindex %s" value
))
1204 ((string= key
"PINDEX") (format "@pindex %s" value
))
1205 ((string= key
"TINDEX") (format "@tindex %s" value
))
1206 ((string= key
"VINDEX") (format "@vindex %s" value
)))))
1210 (defun org-texinfo-line-break (line-break contents info
)
1211 "Transcode a LINE-BREAK object from Org to Texinfo.
1212 CONTENTS is nil. INFO is a plist holding contextual information."
1217 (defun org-texinfo-link (link desc info
)
1218 "Transcode a LINK object from Org to Texinfo.
1220 DESC is the description part of the link, or the empty string.
1221 INFO is a plist holding contextual information. See
1223 (let* ((type (org-element-property :type link
))
1224 (raw-path (org-element-property :path link
))
1225 ;; Ensure DESC really exists, or set it to nil.
1226 (desc (and (not (string= desc
"")) desc
))
1228 ((member type
'("http" "https" "ftp"))
1229 (concat type
":" raw-path
))
1230 ((and (string= type
"file") (file-name-absolute-p raw-path
))
1231 (concat "file:" raw-path
))
1233 (email (if (string= type
"mailto")
1234 (let ((text (replace-regexp-in-string
1235 "@" "@@" raw-path
)))
1236 (concat text
(if desc
(concat "," desc
))))))
1239 ;; Links pointing to a headline: Find destination and build
1240 ;; appropriate referencing command.
1241 ((member type
'("custom-id" "id"))
1242 (let ((destination (org-export-resolve-id-link link info
)))
1243 (case (org-element-type destination
)
1244 ;; Id link points to an external file.
1246 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1247 (format "@uref{file://%s}" destination
)))
1248 ;; LINK points to a headline. Use the headline as the NODE target
1250 (format "@ref{%s,%s}"
1251 (org-texinfo--get-node destination info
)
1254 (let ((path (org-export-solidify-link-text path
)))
1255 (if (not desc
) (format "@ref{%s}" path
)
1256 (format "@ref{%s,,%s}" path desc
)))))))
1257 ((member type
'("info"))
1258 (let* ((info-path (split-string path
"[:#]"))
1259 (info-manual (car info-path
))
1260 (info-node (or (cadr info-path
) "top"))
1261 (title (or desc
"")))
1262 (format "@ref{%s,%s,,%s,}" info-node title info-manual
)))
1263 ((member type
'("fuzzy"))
1264 (let ((destination (org-export-resolve-fuzzy-link link info
)))
1265 (case (org-element-type destination
)
1266 ;; Id link points to an external file.
1268 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1269 (format "@uref{file://%s}" destination
)))
1270 ;; LINK points to a headline. Use the headline as the NODE target
1272 (format "@ref{%s,%s}"
1273 (org-texinfo--get-node destination info
)
1276 (let ((path (org-export-solidify-link-text path
)))
1277 (if (not desc
) (format "@ref{%s}" path
)
1278 (format "@ref{%s,,%s}" path desc
)))))))
1279 ;; Special case for email addresses
1281 (format "@email{%s}" email
))
1282 ;; External link with a description part.
1283 ((and path desc
) (format "@uref{%s,%s}" path desc
))
1284 ;; External link without a description part.
1285 (path (format "@uref{%s}" path
))
1286 ;; No path, only description. Try to do something useful.
1287 (t (format org-texinfo-link-with-unknown-path-format desc
)))))
1292 (defun org-texinfo-make-menu (info level
)
1293 "Create the menu for inclusion in the texifo document.
1295 INFO is the parsed buffer that contains the headlines. LEVEL
1296 determines whether to make the main menu, or the detailed menu.
1298 This is only used for generating the primary menu. In-Node menus
1299 are generated directly."
1300 (let ((parse (plist-get info
:parse-tree
)))
1302 ;; Generate the main menu
1303 ((eq level
'main
) (org-texinfo--build-menu parse
1 info
))
1304 ;; Generate the detailed (recursive) menu
1305 ((eq level
'detailed
)
1306 ;; Requires recursion
1307 ;;(org-texinfo--build-detailed-menu parse top info)
1308 (org-texinfo--build-menu parse
1 info
'detailed
)))))
1312 (defun org-texinfo-node-property (node-property contents info
)
1313 "Transcode a NODE-PROPERTY element from Org to Texinfo.
1314 CONTENTS is nil. INFO is a plist holding contextual
1317 (org-element-property :key node-property
)
1318 (let ((value (org-element-property :value node-property
)))
1319 (if value
(concat " " value
) ""))))
1323 (defun org-texinfo-paragraph (paragraph contents info
)
1324 "Transcode a PARAGRAPH element from Org to Texinfo.
1325 CONTENTS is the contents of the paragraph, as a string. INFO is
1326 the plist used as a communication channel."
1331 (defun org-texinfo-plain-list (plain-list contents info
)
1332 "Transcode a PLAIN-LIST element from Org to Texinfo.
1333 CONTENTS is the contents of the list. INFO is a plist holding
1334 contextual information."
1335 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1336 (indic (or (plist-get attr
:indic
)
1337 org-texinfo-def-table-markup
))
1338 (type (org-element-property :type plain-list
))
1339 (table-type (plist-get attr
:table-type
))
1340 ;; Ensure valid texinfo table type.
1341 (table-type (if (member table-type
'("ftable" "vtable")) table-type
1344 ((eq type
'ordered
) "enumerate")
1345 ((eq type
'unordered
) "itemize")
1346 ((eq type
'descriptive
) table-type
))))
1347 (format "@%s%s\n@end %s"
1348 (if (eq type
'descriptive
)
1349 (concat list-type
" " indic
)
1356 (defun org-texinfo-plain-text (text info
)
1357 "Transcode a TEXT string from Org to Texinfo.
1358 TEXT is the string to transcode. INFO is a plist holding
1359 contextual information."
1360 ;; First protect @, { and }.
1361 (let ((output (org-texinfo--sanitize-content text
)))
1362 ;; Activate smart quotes. Be sure to provide original TEXT string
1363 ;; since OUTPUT may have been modified.
1364 (when (plist-get info
:with-smart-quotes
)
1366 (org-export-activate-smart-quotes output
:texinfo info text
)))
1367 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1368 (let ((case-fold-search nil
)
1370 (while (string-match "\\(\\(?:La\\)?TeX\\)" output start
)
1371 (setq output
(replace-match
1372 (format "@%s{}" (match-string 1 output
)) nil t output
)
1373 start
(match-end 0))))
1374 ;; Convert special strings.
1375 (when (plist-get info
:with-special-strings
)
1376 (while (string-match (regexp-quote "...") output
)
1377 (setq output
(replace-match "@dots{}" nil t output
))))
1378 ;; Handle break preservation if required.
1379 (when (plist-get info
:preserve-breaks
)
1380 (setq output
(replace-regexp-in-string
1381 "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output
)))
1387 (defun org-texinfo-planning (planning contents info
)
1388 "Transcode a PLANNING element from Org to Texinfo.
1389 CONTENTS is nil. INFO is a plist holding contextual
1397 (let ((closed (org-element-property :closed planning
)))
1400 (format "@strong{%s} " org-closed-string
)
1401 (format org-texinfo-inactive-timestamp-format
1403 (org-element-property :raw-value closed
))))))
1404 (let ((deadline (org-element-property :deadline planning
)))
1407 (format "@strong{%s} " org-deadline-string
)
1408 (format org-texinfo-active-timestamp-format
1410 (org-element-property :raw-value deadline
))))))
1411 (let ((scheduled (org-element-property :scheduled planning
)))
1414 (format "@strong{%s} " org-scheduled-string
)
1415 (format org-texinfo-active-timestamp-format
1417 (org-element-property :raw-value scheduled
))))))))
1423 (defun org-texinfo-property-drawer (property-drawer contents info
)
1424 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1425 CONTENTS holds the contents of the drawer. INFO is a plist
1426 holding contextual information."
1427 (and (org-string-nw-p contents
)
1428 (format "@verbatim\n%s@end verbatim" contents
)))
1432 (defun org-texinfo-quote-block (quote-block contents info
)
1433 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1434 CONTENTS holds the contents of the block. INFO is a plist
1435 holding contextual information."
1436 (let* ((title (org-element-property :name quote-block
))
1437 (start-quote (concat "@quotation"
1439 (format " %s" title
)))))
1440 (format "%s\n%s@end quotation" start-quote contents
)))
1444 (defun org-texinfo-radio-target (radio-target text info
)
1445 "Transcode a RADIO-TARGET object from Org to Texinfo.
1446 TEXT is the text of the target. INFO is a plist holding
1447 contextual information."
1448 (format "@anchor{%s}%s"
1449 (org-export-solidify-link-text
1450 (org-element-property :value radio-target
))
1455 (defun org-texinfo-section (section contents info
)
1456 "Transcode a SECTION element from Org to Texinfo.
1457 CONTENTS holds the contents of the section. INFO is a plist
1458 holding contextual information."
1463 (defun org-texinfo-special-block (special-block contents info
)
1464 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1465 CONTENTS holds the contents of the block. INFO is a plist used
1466 as a communication channel."
1467 (if (org-export-raw-special-block-p special-block info
)
1468 (org-remove-indentation (org-element-property :raw-value special-block
))
1473 (defun org-texinfo-src-block (src-block contents info
)
1474 "Transcode a SRC-BLOCK element from Org to Texinfo.
1475 CONTENTS holds the contents of the item. INFO is a plist holding
1476 contextual information."
1477 (let* ((lang (org-element-property :language src-block
))
1478 (lisp-p (string-match-p "lisp" lang
))
1479 (src-contents (org-texinfo--sanitize-content
1480 (org-export-format-code-default src-block info
))))
1482 ;; Case 1. Lisp Block
1484 (format "@lisp\n%s@end lisp"
1486 ;; Case 2. Other blocks
1488 (format "@example\n%s@end example"
1491 ;;; Statistics Cookie
1493 (defun org-texinfo-statistics-cookie (statistics-cookie contents info
)
1494 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1495 CONTENTS is nil. INFO is a plist holding contextual information."
1496 (org-element-property :value statistics-cookie
))
1500 (defun org-texinfo-subscript (subscript contents info
)
1501 "Transcode a SUBSCRIPT object from Org to Texinfo.
1502 CONTENTS is the contents of the object. INFO is a plist holding
1503 contextual information."
1504 (format "@math{_%s}" contents
))
1508 (defun org-texinfo-superscript (superscript contents info
)
1509 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1510 CONTENTS is the contents of the object. INFO is a plist holding
1511 contextual information."
1512 (format "@math{^%s}" contents
))
1516 ;; `org-texinfo-table' is the entry point for table transcoding. It
1517 ;; takes care of tables with a "verbatim" attribute. Otherwise, it
1518 ;; delegates the job to either `org-texinfo-table--table.el-table' or
1519 ;; `org-texinfo-table--org-table' functions, depending of the type of
1522 ;; `org-texinfo-table--align-string' is a subroutine used to build
1523 ;; alignment string for Org tables.
1525 (defun org-texinfo-table (table contents info
)
1526 "Transcode a TABLE element from Org to Texinfo.
1527 CONTENTS is the contents of the table. INFO is a plist holding
1528 contextual information."
1530 ;; Case 1: verbatim table.
1531 ((or org-texinfo-tables-verbatim
1532 (let ((attr (mapconcat 'identity
1533 (org-element-property :attr_latex table
)
1535 (and attr
(string-match "\\<verbatim\\>" attr
))))
1536 (format "@verbatim \n%s\n@end verbatim"
1537 ;; Re-create table, without affiliated keywords.
1539 (org-element-interpret-data
1540 `(table nil
,@(org-element-contents table
))))))
1541 ;; Case 2: table.el table. Convert it using appropriate tools.
1542 ((eq (org-element-property :type table
) 'table.el
)
1543 (org-texinfo-table--table.el-table table contents info
))
1544 ;; Case 3: Standard table.
1545 (t (org-texinfo-table--org-table table contents info
))))
1547 (defun org-texinfo-table-column-widths (table info
)
1548 "Determine the largest table cell in each column to process alignment.
1550 TABLE is the table element to transcode. INFO is a plist used as
1551 a communication channel."
1552 (let* ((rows (org-element-map table
'table-row
'identity info
))
1553 (collected (loop for row in rows collect
1554 (org-element-map row
'table-cell
'identity info
)))
1555 (number-cells (length (car collected
)))
1557 (loop for row in collected do
1558 (push (mapcar (lambda (ref)
1559 (let* ((start (org-element-property :contents-begin ref
))
1560 (end (org-element-property :contents-end ref
))
1561 (length (- end start
)))
1562 length
)) row
) cells
))
1563 (setq cells
(org-remove-if 'null cells
))
1564 (push (loop for count from
0 to
(- number-cells
1) collect
1565 (loop for item in cells collect
1566 (nth count item
))) counts
)
1567 (mapconcat (lambda (size)
1568 (make-string size ?a
)) (mapcar (lambda (ref)
1569 (apply 'max
`(,@ref
))) (car counts
))
1572 (defun org-texinfo-table--org-table (table contents info
)
1573 "Return appropriate Texinfo code for an Org table.
1575 TABLE is the table type element to transcode. CONTENTS is its
1576 contents, as a string. INFO is a plist used as a communication
1579 This function assumes TABLE has `org' as its `:type' attribute."
1580 (let* ((attr (org-export-read-attribute :attr_texinfo table
))
1581 (col-width (plist-get attr
:columns
))
1582 (columns (if col-width
1583 (format "@columnfractions %s"
1586 (org-texinfo-table-column-widths
1588 ;; Prepare the final format string for the table.
1593 (format "@multitable %s\n%s@end multitable"
1597 (defun org-texinfo-table--table.el-table
(table contents info
)
1600 Rather than return an invalid table, nothing is returned."
1605 (defun org-texinfo-table-cell (table-cell contents info
)
1606 "Transcode a TABLE-CELL element from Org to Texinfo.
1607 CONTENTS is the cell contents. INFO is a plist used as
1608 a communication channel."
1609 (concat (if (and contents
1610 org-texinfo-table-scientific-notation
1611 (string-match orgtbl-exp-regexp contents
))
1612 ;; Use appropriate format string for scientific
1614 (format org-texinfo-table-scientific-notation
1615 (match-string 1 contents
)
1616 (match-string 2 contents
))
1618 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1622 (defun org-texinfo-table-row (table-row contents info
)
1623 "Transcode a TABLE-ROW element from Org to Texinfo.
1624 CONTENTS is the contents of the row. INFO is a plist used as
1625 a communication channel."
1626 ;; Rules are ignored since table separators are deduced from
1627 ;; borders of the current row.
1628 (when (eq (org-element-property :type table-row
) 'standard
)
1631 ;; Case 1: Belongs to second or subsequent rowgroup.
1632 ((not (= 1 (org-export-table-row-group table-row info
)))
1634 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
1635 ((org-export-table-has-header-p
1636 (org-export-get-parent-table table-row
) info
)
1638 ;; Case 3: Row is from first and only row group.
1640 (when (eq (org-element-property :type table-row
) 'standard
)
1641 (concat rowgroup-tag contents
"\n")))))
1645 (defun org-texinfo-target (target contents info
)
1646 "Transcode a TARGET object from Org to Texinfo.
1647 CONTENTS is nil. INFO is a plist holding contextual
1649 (format "@anchor{%s}"
1650 (org-export-solidify-link-text (org-element-property :value target
))))
1654 (defun org-texinfo-timestamp (timestamp contents info
)
1655 "Transcode a TIMESTAMP object from Org to Texinfo.
1656 CONTENTS is nil. INFO is a plist holding contextual
1658 (let ((value (org-texinfo-plain-text
1659 (org-timestamp-translate timestamp
) info
)))
1660 (case (org-element-property :type timestamp
)
1661 ((active active-range
)
1662 (format org-texinfo-active-timestamp-format value
))
1663 ((inactive inactive-range
)
1664 (format org-texinfo-inactive-timestamp-format value
))
1665 (t (format org-texinfo-diary-timestamp-format value
)))))
1669 (defun org-texinfo-verbatim (verbatim contents info
)
1670 "Transcode a VERBATIM object from Org to Texinfo.
1671 CONTENTS is nil. INFO is a plist used as a communication
1673 (org-texinfo--text-markup (org-element-property :value verbatim
) 'verbatim
))
1677 (defun org-texinfo-verse-block (verse-block contents info
)
1678 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1679 CONTENTS is verse block contents. INFO is a plist holding
1680 contextual information."
1681 ;; In a verse environment, add a line break to each newline
1682 ;; character and change each white space at beginning of a line
1683 ;; into a space of 1 em. Also change each blank line with
1684 ;; a vertical space of 1 em.
1686 (setq contents
(replace-regexp-in-string
1687 "^ *\\\\\\\\$" "\\\\vspace*{1em}"
1688 (replace-regexp-in-string
1689 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" contents
)))
1690 (while (string-match "^[ \t]+" contents
)
1691 (let ((new-str (format "\\hspace*{%dem}"
1692 (length (match-string 0 contents
)))))
1693 (setq contents
(replace-match new-str nil t contents
))))
1694 (format "\\begin{verse}\n%s\\end{verse}" contents
)))
1697 ;;; Interactive functions
1699 (defun org-texinfo-export-to-texinfo
1700 (&optional async subtreep visible-only body-only ext-plist
)
1701 "Export current buffer to a Texinfo file.
1703 If narrowing is active in the current buffer, only export its
1706 If a region is active, export that region.
1708 A non-nil optional argument ASYNC means the process should happen
1709 asynchronously. The resulting file should be accessible through
1710 the `org-export-stack' interface.
1712 When optional argument SUBTREEP is non-nil, export the sub-tree
1713 at point, extracting information from the headline properties
1716 When optional argument VISIBLE-ONLY is non-nil, don't export
1717 contents of hidden elements.
1719 When optional argument BODY-ONLY is non-nil, only write code
1720 between \"\\begin{document}\" and \"\\end{document}\".
1722 EXT-PLIST, when provided, is a property list with external
1723 parameters overriding Org default settings, but still inferior to
1724 file-local settings.
1726 Return output file's name."
1728 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1729 (org-export-coding-system org-texinfo-coding-system
))
1730 (org-export-to-file 'texinfo outfile
1731 async subtreep visible-only body-only ext-plist
)))
1733 (defun org-texinfo-export-to-info
1734 (&optional async subtreep visible-only body-only ext-plist
)
1735 "Export current buffer to Texinfo then process through to INFO.
1737 If narrowing is active in the current buffer, only export its
1740 If a region is active, export that region.
1742 A non-nil optional argument ASYNC means the process should happen
1743 asynchronously. The resulting file should be accessible through
1744 the `org-export-stack' interface.
1746 When optional argument SUBTREEP is non-nil, export the sub-tree
1747 at point, extracting information from the headline properties
1750 When optional argument VISIBLE-ONLY is non-nil, don't export
1751 contents of hidden elements.
1753 When optional argument BODY-ONLY is non-nil, only write code
1754 between \"\\begin{document}\" and \"\\end{document}\".
1756 EXT-PLIST, when provided, is a property list with external
1757 parameters overriding Org default settings, but still inferior to
1758 file-local settings.
1760 When optional argument PUB-DIR is set, use it as the publishing
1763 Return INFO file's name."
1765 (let ((outfile (org-export-output-file-name ".texi" subtreep
))
1766 (org-export-coding-system org-texinfo-coding-system
))
1767 (org-export-to-file 'texinfo outfile
1768 async subtreep visible-only body-only ext-plist
1769 (lambda (file) (org-texinfo-compile file
)))))
1772 (defun org-texinfo-publish-to-texinfo (plist filename pub-dir
)
1773 "Publish an org file to Texinfo.
1775 FILENAME is the filename of the Org file to be published. PLIST
1776 is the property list for the given project. PUB-DIR is the
1777 publishing directory.
1779 Return output file name."
1780 (org-publish-org-to 'texinfo filename
".texi" plist pub-dir
))
1783 (defun org-texinfo-convert-region-to-texinfo ()
1784 "Assume the current region has org-mode syntax, and convert it to Texinfo.
1785 This can be used in any buffer. For example, you can write an
1786 itemized list in org-mode syntax in an Texinfo buffer and use
1787 this command to convert it."
1789 (org-export-replace-region-by 'texinfo
))
1791 (defun org-texinfo-compile (file)
1792 "Compile a texinfo file.
1794 FILE is the name of the file being compiled. Processing is
1795 done through the command specified in `org-texinfo-info-process'.
1797 Return INFO file name or an error if it couldn't be produced."
1798 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file
)))
1799 (full-name (file-truename file
))
1800 (out-dir (file-name-directory file
))
1801 ;; Properly set working directory for compilation.
1802 (default-directory (if (file-name-absolute-p file
)
1803 (file-name-directory full-name
)
1806 (message (format "Processing Texinfo file %s..." file
))
1807 (save-window-excursion
1809 ;; A function is provided: Apply it.
1810 ((functionp org-texinfo-info-process
)
1811 (funcall org-texinfo-info-process
(shell-quote-argument file
)))
1812 ;; A list is provided: Replace %b, %f and %o with appropriate
1813 ;; values in each command before applying it. Output is
1814 ;; redirected to "*Org INFO Texinfo Output*" buffer.
1815 ((consp org-texinfo-info-process
)
1816 (let ((outbuf (get-buffer-create "*Org INFO Texinfo Output*")))
1820 (replace-regexp-in-string
1821 "%b" (shell-quote-argument base-name
)
1822 (replace-regexp-in-string
1823 "%f" (shell-quote-argument full-name
)
1824 (replace-regexp-in-string
1825 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
1827 org-texinfo-info-process
)
1828 ;; Collect standard errors from output buffer.
1829 (setq errors
(org-texinfo-collect-errors outbuf
))))
1830 (t (error "No valid command to process to Info")))
1831 (let ((infofile (concat out-dir base-name
".info")))
1832 ;; Check for process failure. Provide collected errors if
1834 (if (not (file-exists-p infofile
))
1835 (error (concat (format "INFO file %s wasn't produced" infofile
)
1836 (when errors
(concat ": " errors
))))
1837 ;; Else remove log files, when specified, and signal end of
1838 ;; process to user, along with any error encountered.
1839 (when org-texinfo-remove-logfiles
1840 (dolist (ext org-texinfo-logfiles-extensions
)
1841 (let ((file (concat out-dir base-name
"." ext
)))
1842 (when (file-exists-p file
) (delete-file file
)))))
1843 (message (concat "Process completed"
1844 (if (not errors
) "."
1845 (concat " with errors: " errors
)))))
1846 ;; Return output file name.
1849 (defun org-texinfo-collect-errors (buffer)
1850 "Collect some kind of errors from \"makeinfo\" command output.
1852 BUFFER is the buffer containing output.
1854 Return collected error types as a string, or nil if there was
1856 (with-current-buffer buffer
1858 (goto-char (point-min))
1859 ;; Find final "makeinfo" run.
1861 (let ((case-fold-search t
)
1863 (when (save-excursion
1864 (re-search-forward "perhaps incorrect sectioning?" nil t
))
1865 (setq errors
(concat errors
" [incorrect sectioning]")))
1866 (when (save-excursion
1867 (re-search-forward "missing close brace" nil t
))
1868 (setq errors
(concat errors
" [syntax error]")))
1869 (when (save-excursion
1870 (re-search-forward "Unknown command" nil t
))
1871 (setq errors
(concat errors
" [undefined @command]")))
1872 (when (save-excursion
1873 (re-search-forward "No matching @end" nil t
))
1874 (setq errors
(concat errors
" [block incomplete]")))
1875 (when (save-excursion
1876 (re-search-forward "requires a sectioning" nil t
))
1877 (setq errors
(concat errors
" [invalid section command]")))
1878 (when (save-excursion
1879 (re-search-forward "\\[unexpected\]" nil t
))
1880 (setq errors
(concat errors
" [unexpected error]")))
1881 (when (save-excursion
1882 (re-search-forward "misplaced " nil t
))
1883 (setq errors
(concat errors
" [syntax error]")))
1884 (and (org-string-nw-p errors
) (org-trim errors
)))))))
1887 (provide 'ox-texinfo
)
1890 ;; generated-autoload-file: "org-loaddefs.el"
1893 ;;; ox-texinfo.el ends here