1 ;;; org-e-texinfo.el --- Texinfo Back-End For Org Export Engine
3 ;; Copyright (C) 2012 Jonathan Leech-Pepin
4 ;; Author: Jonathan Leech-Pepin <jonathan.leechpepin at gmail dot com>
5 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; This file is not part of GNU Emacs.
9 ;; This program 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 ;; This program 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 this program. 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 'e-texinfo "*Test e-texinfo*") RET
31 ;; in an org-mode buffer then switch to the buffer to see the Texinfo
32 ;; export. See contrib/lisp/org-export.el for more details on how
33 ;; this exporter works.
35 ;; It introduces eight new buffer keywords: "TEXINFO_CLASS",
36 ;; "TEXINFO_FILENAME", "TEXINFO_HEADER", "TEXINFO_DIR_CATEGORY",
37 ;; "TEXINFO_DIR_TITLE", "TEXINFO_DIR_DESC" "SUBTITLE" and "SUBAUTHOR".
39 ;; It introduces 1 new headline property keywords:
40 ;; "TEXINFO_MENU_TITLE" for optional menu titles.
42 ;; To include inline code snippets (for example for generating @kbd{}
43 ;; and @key{} commands), the following export-snippet keys are
50 ;; You can add them for export snippets via any of the below:
52 ;; (add-to-list 'org-export-snippet-translation-alist
53 ;; '("e-info" . "e-texinfo"))
54 ;; (add-to-list 'org-export-snippet-translation-alist
55 ;; '("e-texinfo" . "e-texinfo"))
56 ;; (add-to-list 'org-export-snippet-translation-alist
57 ;; '("info" . "e-texinfo"))
62 (eval-when-compile (require 'cl
))
65 (defvar orgtbl-exp-regexp
)
71 (org-export-define-backend e-texinfo
72 ((bold . org-e-texinfo-bold
)
73 (center-block . org-e-texinfo-center-block
)
74 (clock . org-e-texinfo-clock
)
75 (code . org-e-texinfo-code
)
76 (comment . org-e-texinfo-comment
)
77 (comment-block . org-e-texinfo-comment-block
)
78 (drawer . org-e-texinfo-drawer
)
79 (dynamic-block . org-e-texinfo-dynamic-block
)
80 (entity . org-e-texinfo-entity
)
81 (example-block . org-e-texinfo-example-block
)
82 (export-block . org-e-texinfo-export-block
)
83 (export-snippet . org-e-texinfo-export-snippet
)
84 (fixed-width . org-e-texinfo-fixed-width
)
85 (footnote-definition . org-e-texinfo-footnote-definition
)
86 (footnote-reference . org-e-texinfo-footnote-reference
)
87 (headline . org-e-texinfo-headline
)
88 (inline-src-block . org-e-texinfo-inline-src-block
)
89 (inlinetask . org-e-texinfo-inlinetask
)
90 (italic . org-e-texinfo-italic
)
91 (item . org-e-texinfo-item
)
92 (keyword . org-e-texinfo-keyword
)
93 (line-break . org-e-texinfo-line-break
)
94 (link . org-e-texinfo-link
)
95 (paragraph . org-e-texinfo-paragraph
)
96 (plain-list . org-e-texinfo-plain-list
)
97 (plain-text . org-e-texinfo-plain-text
)
98 (planning . org-e-texinfo-planning
)
99 (property-drawer . org-e-texinfo-property-drawer
)
100 (quote-block . org-e-texinfo-quote-block
)
101 (quote-section . org-e-texinfo-quote-section
)
102 (radio-target . org-e-texinfo-radio-target
)
103 (section . org-e-texinfo-section
)
104 (special-block . org-e-texinfo-special-block
)
105 (src-block . org-e-texinfo-src-block
)
106 (statistics-cookie . org-e-texinfo-statistics-cookie
)
107 (subscript . org-e-texinfo-subscript
)
108 (superscript . org-e-texinfo-superscript
)
109 (table . org-e-texinfo-table
)
110 (table-cell . org-e-texinfo-table-cell
)
111 (table-row . org-e-texinfo-table-row
)
112 (target . org-e-texinfo-target
)
113 (template . org-e-texinfo-template
)
114 (timestamp . org-e-texinfo-timestamp
)
115 (verbatim . org-e-texinfo-verbatim
)
116 (verse-block . org-e-texinfo-verse-block
))
117 :export-block
"TEXINFO"
119 ((:filter-headline . org-e-texinfo-filter-section-blank-lines
)
120 (:filter-section . org-e-texinfo-filter-section-blank-lines
))
122 (?i
"Export to Texinfo"
123 ((?t
"As TEXI file" org-e-texinfo-export-to-texinfo
)
124 (?i
"As INFO file" org-e-texinfo-export-to-info
)))
126 ((:texinfo-filename
"TEXINFO_FILENAME" nil org-e-texinfo-filename t
)
127 (:texinfo-class
"TEXINFO_CLASS" nil org-e-texinfo-default-class t
)
128 (:texinfo-header
"TEXINFO_HEADER" nil nil newline
)
129 (:texinfo-post-header
"TEXINFO_POST_HEADER" nil nil newline
)
130 (:subtitle
"SUBTITLE" nil nil newline
)
131 (:subauthor
"SUBAUTHOR" nil nil newline
)
132 (:texinfo-dircat
"TEXINFO_DIR_CATEGORY" nil nil t
)
133 (:texinfo-dirtitle
"TEXINFO_DIR_TITLE" nil nil t
)
134 (:texinfo-dirdesc
"TEXINFO_DIR_DESC" nil nil t
)
135 (:texinfo-menu-title
"TEXINFO_MENU_TITLE" nil nil newline
)))
139 ;;; User Configurable Variables
141 (defgroup org-export-e-texinfo nil
142 "Options for exporting Org mode files to Texinfo."
143 :tag
"Org Export Texinfo"
148 (defcustom org-e-texinfo-filename nil
149 "Default filename for texinfo output."
150 :group
'org-export-e-texinfo
151 :type
'(string :tag
"Export Filename"))
153 (defcustom org-e-texinfo-default-class
"info"
154 "The default Texinfo class."
155 :group
'org-export-e-texinfo
156 :type
'(string :tag
"Texinfo class"))
158 (defcustom org-e-texinfo-classes
160 "\\input texinfo @c -*- texinfo -*-"
161 ("@chapter %s" .
"@unnumbered %s")
162 ("@section %s" .
"@unnumberedsec %s")
163 ("@subsection %s" .
"@unnumberedsubsec %s")
164 ("@subsubsection %s" .
"@unnumberedsubsubsec %s")))
165 "Alist of Texinfo classes and associated header and structure.
166 If #+Texinfo_CLASS is set in the buffer, use its value and the
167 associated information. Here is the structure of each cell:
171 \(numbered-section . unnumbered-section\)
174 The sectioning structure
175 ------------------------
177 The sectioning structure of the class is given by the elements
178 following the header string. For each sectioning level, a number
179 of strings is specified. A %s formatter is mandatory in each
180 section string and will be replaced by the title of the section.
182 Instead of a list of sectioning commands, you can also specify
183 a function name. That function will be called with two
184 parameters, the \(reduced) level of the headline, and a predicate
185 non-nil when the headline should be numbered. It must return
186 a format string in which the section title will be added."
187 :group
'org-export-e-texinfo
189 (list (string :tag
"Texinfo class")
190 (string :tag
"Texinfo header")
191 (repeat :tag
"Levels" :inline t
194 (string :tag
" numbered")
195 (string :tag
"unnumbered"))
196 (function :tag
"Hook computing sectioning"))))))
200 (defcustom org-e-texinfo-format-headline-function nil
201 "Function to format headline text.
203 This function will be called with 5 arguments:
204 TODO the todo keyword (string or nil).
205 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
206 PRIORITY the priority of the headline (integer or nil)
207 TEXT the main headline text (string).
208 TAGS the tags as a list of strings (list of strings or nil).
210 The function result will be used in the section format string.
212 As an example, one could set the variable to the following, in
213 order to reproduce the default set-up:
215 \(defun org-e-texinfo-format-headline (todo todo-type priority text tags)
216 \"Default format function for an headline.\"
218 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
220 \(format \"\\\\framebox{\\\\#%c} \" priority))
223 \(format \"\\\\hfill{}\\\\textsc{%s}\"
224 \(mapconcat 'identity tags \":\"))))"
225 :group
'org-export-e-texinfo
231 ;; Footnotes are inserted directly
235 (defcustom org-e-texinfo-active-timestamp-format
"@emph{%s}"
236 "A printf format string to be applied to active timestamps."
237 :group
'org-export-e-texinfo
240 (defcustom org-e-texinfo-inactive-timestamp-format
"@emph{%s}"
241 "A printf format string to be applied to inactive timestamps."
242 :group
'org-export-e-texinfo
245 (defcustom org-e-texinfo-diary-timestamp-format
"@emph{%s}"
246 "A printf format string to be applied to diary timestamps."
247 :group
'org-export-e-texinfo
252 (defcustom org-e-texinfo-link-with-unknown-path-format
"@indicateurl{%s}"
253 "Format string for links with unknown path type."
254 :group
'org-export-e-texinfo
259 (defcustom org-e-texinfo-tables-verbatim nil
260 "When non-nil, tables are exported verbatim."
261 :group
'org-export-e-texinfo
264 (defcustom org-e-texinfo-table-scientific-notation
"%s\\,(%s)"
265 "Format string to display numbers in scientific notation.
266 The format should have \"%s\" twice, for mantissa and exponent
267 \(i.e. \"%s\\\\times10^{%s}\").
269 When nil, no transformation is made."
270 :group
'org-export-e-texinfo
272 (string :tag
"Format string")
273 (const :tag
"No formatting")))
275 (defcustom org-e-texinfo-def-table-markup
"@samp"
276 "Default setting for @table environments.")
280 (defcustom org-e-texinfo-text-markup-alist
'((bold .
"@strong{%s}")
282 (italic .
"@emph{%s}")
285 "Alist of Texinfo expressions to convert text markup.
287 The key must be a symbol among `bold', `italic' and `comment'.
288 The value is a formatting string to wrap fontified text with.
290 Value can also be set to the following symbols: `verb' and
291 `code'. For the former, Org will use \"@verb\" to
292 create a format string and select a delimiter character that
293 isn't in the string. For the latter, Org will use \"@code\"
294 to typeset and try to protect special characters.
296 If no association can be found for a given markup, text will be
298 :group
'org-export-e-texinfo
300 :options
'(bold code italic verbatim comment
))
304 (defcustom org-e-texinfo-format-drawer-function nil
305 "Function called to format a drawer in Texinfo code.
307 The function must accept two parameters:
308 NAME the drawer name, like \"LOGBOOK\"
309 CONTENTS the contents of the drawer.
311 The function should return the string to be exported.
313 For example, the variable could be set to the following function
314 in order to mimic default behaviour:
316 \(defun org-e-texinfo-format-drawer-default \(name contents\)
317 \"Format a drawer element for Texinfo export.\"
319 :group
'org-export-e-texinfo
324 (defcustom org-e-texinfo-format-inlinetask-function nil
325 "Function called to format an inlinetask in Texinfo code.
327 The function must accept six parameters:
328 TODO the todo keyword, as a string
329 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
330 PRIORITY the inlinetask priority, as a string
331 NAME the inlinetask name, as a string.
332 TAGS the inlinetask tags, as a list of strings.
333 CONTENTS the contents of the inlinetask, as a string.
335 The function should return the string to be exported.
337 For example, the variable could be set to the following function
338 in order to mimic default behaviour:
340 \(defun org-e-texinfo-format-inlinetask \(todo type priority name tags contents\)
341 \"Format an inline task element for Texinfo export.\"
345 \(format \"@strong{%s} \" todo))
346 \(when priority (format \"#%c \" priority))
350 \(mapconcat 'identity tags \":\")))))
351 \(format (concat \"@center %s\n\n\"
354 full-title contents))"
355 :group
'org-export-e-texinfo
360 ;; Src Blocks are example blocks, except for LISP
364 (defcustom org-e-texinfo-info-process
366 "Commands to process a texinfo file to an INFO file.
367 This is list of strings, each of them will be given to the shell
368 as a command. %f in the command will be replaced by the full
369 file name, %b by the file base name \(i.e without extension) and
370 %o by the base directory of the file."
371 :group
'org-export-texinfo
372 :type
'(repeat :tag
"Shell command sequence"
373 (string :tag
"Shell command")))
376 ;;; Internal Functions
378 (defun org-e-texinfo-filter-section-blank-lines (headline back-end info
)
379 "Filter controlling number of blank lines after a section."
380 (let ((blanks (make-string 2 ?
\n)))
381 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline
)))
383 (defun org-e-texinfo--find-copying (info)
384 "Retrieve the headline identified by the property :copying:.
386 INFO is the plist containing the export options and tree. It is
387 used to find and extract the single desired headline. This
388 cannot be treated as a standard headline since it must be
389 inserted in a specific location."
391 (org-element-map (plist-get info
:parse-tree
) 'headline
393 (when (org-element-property :copying copy
)
394 (push copy copying
))) info t
)
395 ;; Retrieve the single entry
398 (defun org-e-texinfo--find-verb-separator (s)
399 "Return a character not used in string S.
400 This is used to choose a separator for constructs like \\verb."
401 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
402 (loop for c across ll
403 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
404 return
(char-to-string c
))))
406 (defun org-e-texinfo--make-option-string (options)
407 "Return a comma separated string of keywords and values.
408 OPTIONS is an alist where the key is the options keyword as
409 a string, and the value a list containing the keyword value, or
411 (mapconcat (lambda (pair)
413 (when (> (length (second pair
)) 0)
414 (concat "=" (second pair
)))))
418 (defun org-e-texinfo--text-markup (text markup
)
419 "Format TEXT depending on MARKUP text markup.
420 See `org-e-texinfo-text-markup-alist' for details."
421 (let ((fmt (cdr (assq markup org-e-texinfo-text-markup-alist
))))
423 ;; No format string: Return raw text.
426 (let ((separator (org-e-texinfo--find-verb-separator text
)))
427 (concat "@verb{" separator text separator
"}")))
432 (while (string-match "[@{}]" text
)
433 (setq char
(match-string 0 text
))
434 (if (> (match-beginning 0) 0)
435 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
436 (setq text
(substring text
(1+ (match-beginning 0))))
437 (setq char
(concat "@" char
)
438 rtn
(concat rtn char
)))
439 (setq text
(concat rtn text
)
442 ;; Else use format string.
443 (t (format fmt text
)))))
445 ;;; Headline sanitizing
447 (defun org-e-texinfo--sanitize-headline (headline info
)
448 "Remove all formatting from the text of a headline for use in
449 node and menu listing."
451 (org-e-texinfo--sanitize-headline-contents headline info
) " "))
453 (defun org-e-texinfo--sanitize-headline-contents (headline info
)
454 "Retrieve the content of the headline.
456 Any content that can contain further formatting is checked
457 recursively, to ensure that nested content is also properly
459 (loop for contents in headline append
463 (list (replace-regexp-in-string " $" "" contents
)))
464 ;; Is exported as-is (value)
465 ((org-element-map contents
'(verbatim code
)
467 (org-element-property :value value
)) info
))
468 ;; Has content and recurse into the content
469 ((org-element-contents contents
)
470 (org-e-texinfo--sanitize-headline-contents
471 (org-element-contents contents
) info
)))))
475 (defun org-e-texinfo--sanitize-menu (title)
476 "Remove invalid characters from TITLE for use in menus and
479 Based on TEXINFO specifications, the following must be removed:
481 (replace-regexp-in-string "[@{}():,.]" "" title
))
483 ;;; Content sanitizing
485 (defun org-e-texinfo--sanitize-content (text)
486 "Ensure characters are properly escaped when used in headlines or blocks.
488 Escape characters are: @ { }"
489 (replace-regexp-in-string "\\\([@{}]\\\)" "@\\1" text
))
493 (defun org-e-texinfo--build-menu (tree level info
&optional detailed
)
494 "Create the @menu/@end menu information from TREE at headline
497 TREE contains the parse-tree to work with, either of the entire
498 document or of a specific parent headline. LEVEL indicates what
499 level of headlines to look at when generating the menu. INFO is
500 a plist containing contextual information.
502 Detailed determines whether to build a single level of menu, or
503 recurse into all children as well."
504 (let ((menu (org-e-texinfo--generate-menu-list tree level info
))
508 ;; Looping is done within the menu generation.
509 (setq text-menu
(org-e-texinfo--generate-detailed menu level info
)))
511 (setq text-menu
(org-e-texinfo--generate-menu-items menu info
))))
513 (setq output
(org-e-texinfo--format-menu text-menu
))
514 (mapconcat 'identity output
"\n"))))
516 (defun org-e-texinfo--generate-detailed (menu level info
)
517 "Generate a detailed listing of all subheadings within MENU starting at LEVEL.
519 MENU is the parse-tree to work with. LEVEL is the starting level
520 for the menu headlines and from which recursion occurs. INFO is
521 a plist containing contextual information."
523 (let ((max-depth (plist-get info
:headline-levels
)))
524 (when (> max-depth level
)
525 (loop for headline in menu append
526 (let* ((title (org-e-texinfo--menu-headlines headline info
))
527 ;; Create list of menu entries for the next level
528 (sublist (org-e-texinfo--generate-menu-list
529 headline
(1+ level
) info
))
530 ;; Generate the menu items for that level. If
531 ;; there are none omit that heading completely,
532 ;; otherwise join the title to it's related entries.
533 (submenu (if (org-e-texinfo--generate-menu-items sublist info
)
535 (org-e-texinfo--generate-menu-items sublist info
))
537 ;; Start the process over the next level down.
538 (recursion (org-e-texinfo--generate-detailed sublist
(1+ level
) info
)))
539 (setq recursion
(append submenu recursion
))
542 (defun org-e-texinfo--generate-menu-list (tree level info
)
543 "Generate the list of headlines that are within a given level
544 of the tree for further formatting.
546 TREE is the parse-tree containing the headlines. LEVEL is the
547 headline level to generate a list of. INFO is a plist holding
548 contextual information."
550 (noexport (string= "noexport"
551 (and (plist-get info
:with-tags
)
552 (org-export-get-tags tree info
)))))
556 (when (org-element-property :level head
)
557 (if (and (eq level
(org-element-property :level head
))
558 ;; Do not take note of footnotes or copying
559 ;; headlines. Also ignore :noexport: headlines
561 (not (org-element-property :copying head
))
562 (not (org-element-property :footnote-section-p head
)))
565 ;; Return the list of headlines (reverse to have in actual order)
568 (defun org-e-texinfo--generate-menu-items (items info
)
569 "Generate a list of headline information from the listing ITEMS.
571 ITEMS is a list of the headlines to be converted into entries.
572 INFO is a plist containing contextual information.
574 Returns a list containing the following information from each
575 headline: length, title, description. This is used to format the
576 menu using `org-e-texinfo--format-menu'."
577 (loop for headline in items collect
578 (let* ((menu-title (org-e-texinfo--sanitize-menu
580 (org-element-property :texinfo-menu-title headline
)
582 (title (org-e-texinfo--sanitize-menu
583 (org-e-texinfo--sanitize-headline
584 (org-element-property :title headline
) info
)))
585 (descr (org-export-data
586 (org-element-property :description headline
)
588 (menu-entry (if (string= "" menu-title
) title menu-title
))
589 (len (length menu-entry
))
590 (output (list len menu-entry descr
)))
591 (message "%S" menu-title
)
592 ;; (message "%s" headline)
595 (defun org-e-texinfo--menu-headlines (headline info
)
596 "Retrieve the title from HEADLINE.
598 INFO is a plist holding contextual information.
600 Return the headline as a list of (length title description) with
601 length of -1 and nil description. This is used in
602 `org-e-texinfo--format-menu' to identify headlines as opposed to
604 (let ((title (org-export-data
605 (org-element-property :title headline
) info
)))
606 (list -
1 title
'nil
)))
608 (defun org-e-texinfo--format-menu (text-menu)
609 "Format the TEXT-MENU items to be properly printed in the menu.
611 Each entry in the menu should be provided as (length title
614 Headlines in the detailed menu are given length -1 to ensure they
615 are never confused with other entries. They also have no
618 Other menu items are output as:
621 With the spacing between :: and description based on the length
622 of the longest menu entry."
624 (let* ((lengths (mapcar 'car text-menu
))
625 (max-length (apply 'max lengths
))
628 (mapcar (lambda (name)
629 (let* ((title (nth 1 name
))
631 (length (nth 0 name
)))
633 (concat "* " title
":: "
635 (- (+ 3 max-length
) length
)
639 (concat "\n" title
"\n"))))
645 (defun org-e-texinfo-template (contents info
)
646 "Return complete document string after Texinfo conversion.
647 CONTENTS is the transcoded contents string. INFO is a plist
648 holding export options."
649 (let* ((title (org-export-data (plist-get info
:title
) info
))
650 (info-filename (or (plist-get info
:texinfo-filename
)
651 (file-name-nondirectory
652 (org-export-output-file-name ".info"))))
653 (author (org-export-data (plist-get info
:author
) info
))
654 (texinfo-header (plist-get info
:texinfo-header
))
655 (texinfo-post-header (plist-get info
:texinfo-post-header
))
656 (subtitle (plist-get info
:subtitle
))
657 (subauthor (plist-get info
:subauthor
))
658 (class (plist-get info
:texinfo-class
))
659 (header (nth 1 (assoc class org-e-texinfo-classes
)))
660 (copying (org-e-texinfo--find-copying info
))
661 (dircat (plist-get info
:texinfo-dircat
))
662 (dirtitle (plist-get info
:texinfo-dirtitle
))
663 (dirdesc (plist-get info
:texinfo-dirdesc
))
664 ;; Spacing to align description (column 32 - 3 for `* ' and
666 (dirspacing (- 29 (length dirtitle
)))
667 (menu (org-e-texinfo-make-menu info
'main
))
668 (detail-menu (org-e-texinfo-make-menu info
'detailed
)))
672 "@c %**start of header\n"
673 ;; Filename and Title
674 "@setfilename " info-filename
"\n"
675 "@settitle " title
"\n"
677 "@c Version and Contact Info\n"
678 "@set AUTHOR " author
"\n"
680 ;; Additional Header Options set by `#+TEXINFO_HEADER
686 "@c %**end of header\n"
690 ;; Additional Header Options set by #+TEXINFO_POST_HEADER
691 (if texinfo-post-header
698 ;; Only export the content of the headline, do not need the
700 (org-export-data (nth 2 copying
) info
)
704 ;; Info directory information
705 ;; Only supply if both title and category are provided
706 (if (and dircat dirtitle
)
707 (concat "@dircategory " dircat
"\n"
710 (make-string dirspacing ?\s
)
717 "@title " title
"\n\n"
719 (concat "@subtitle " subtitle
"\n"))
720 "@author " author
"\n"
722 (concat subauthor
"\n"))
724 "@c The following two commands start the copyright page.\n"
726 "@vskip 0pt plus 1filll\n"
729 "@c Output the table of contents at the beginning.\n"
732 ;; Configure Top Node when not for Tex
735 "@top " title
" Manual\n"
739 ;; Do not output menus if they are empty
747 (concat "@detailmenu\n"
748 " --- The Detailed Node Listing ---\n"
751 "@end detailmenu\n"))
759 (let ((creator-info (plist-get info
:with-creator
)))
761 ((not creator-info
) "")
762 ((eq creator-info
'comment
)
763 (format "@c %s\n" (plist-get info
:creator
)))
764 (t (concat (plist-get info
:creator
) "\n"))))
770 ;;; Transcode Functions
774 (defun org-e-texinfo-bold (bold contents info
)
775 "Transcode BOLD from Org to Texinfo.
776 CONTENTS is the text with bold markup. INFO is a plist holding
777 contextual information."
778 (org-e-texinfo--text-markup contents
'bold
))
782 (defun org-e-texinfo-center-block (center-block contents info
)
783 "Transcode a CENTER-BLOCK element from Org to Texinfo.
784 CONTENTS holds the contents of the block. INFO is a plist used
785 as a communication channel."
790 (defun org-e-texinfo-clock (clock contents info
)
791 "Transcode a CLOCK element from Org to Texinfo.
792 CONTENTS is nil. INFO is a plist holding contextual
796 (format "@strong{%s} " org-clock-string
)
797 (format org-e-texinfo-inactive-timestamp-format
798 (concat (org-translate-time
799 (org-element-property :raw-value
800 (org-element-property :value clock
)))
801 (let ((time (org-element-property :duration clock
)))
802 (and time
(format " (%s)" time
)))))
807 (defun org-e-texinfo-code (code contents info
)
808 "Transcode a CODE object from Org to Texinfo.
809 CONTENTS is nil. INFO is a plist used as a communication
811 (org-e-texinfo--text-markup (org-element-property :value code
) 'code
))
815 (defun org-e-texinfo-comment (comment contents info
)
816 "Transcode a COMMENT object from Org to Texinfo.
817 CONTENTS is the text in the comment. INFO is a plist holding
818 contextual information."
819 (org-e-texinfo--text-markup (org-element-property :value comment
) 'comment
))
823 (defun org-e-texinfo-comment-block (comment-block contents info
)
824 "Transcode a COMMENT-BLOCK object from Org to Texinfo.
825 CONTENTS is the text within the block. INFO is a plist holding
826 contextual information."
827 (format "@ignore\n%s@end ignore" (org-element-property :value comment-block
)))
831 (defun org-e-texinfo-drawer (drawer contents info
)
832 "Transcode a DRAWER element from Org to Texinfo.
833 CONTENTS holds the contents of the block. INFO is a plist
834 holding contextual information."
835 (let* ((name (org-element-property :drawer-name drawer
))
836 (output (if (functionp org-e-texinfo-format-drawer-function
)
837 (funcall org-e-texinfo-format-drawer-function
839 ;; If there's no user defined function: simply
840 ;; display contents of the drawer.
846 (defun org-e-texinfo-dynamic-block (dynamic-block contents info
)
847 "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
848 CONTENTS holds the contents of the block. INFO is a plist
849 holding contextual information. See `org-export-data'."
854 (defun org-e-texinfo-entity (entity contents info
)
855 "Transcode an ENTITY object from Org to Texinfo.
856 CONTENTS are the definition itself. INFO is a plist holding
857 contextual information."
858 (let ((ent (org-element-property :latex entity
)))
859 (if (org-element-property :latex-math-p entity
) (format "@math{%s}" ent
) ent
)))
863 (defun org-e-texinfo-example-block (example-block contents info
)
864 "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
865 CONTENTS is nil. INFO is a plist holding contextual
867 (format "@verbatim\n%s@end verbatim"
868 (org-export-format-code-default example-block info
)))
872 (defun org-e-texinfo-export-block (export-block contents info
)
873 "Transcode a EXPORT-BLOCK element from Org to Texinfo.
874 CONTENTS is nil. INFO is a plist holding contextual information."
875 (when (string= (org-element-property :type export-block
) "TEXINFO")
876 (org-remove-indentation (org-element-property :value export-block
))))
880 (defun org-e-texinfo-export-snippet (export-snippet contents info
)
881 "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
882 CONTENTS is nil. INFO is a plist holding contextual information."
883 (when (eq (org-export-snippet-backend export-snippet
) 'e-texinfo
)
884 (org-element-property :value export-snippet
)))
888 (defun org-e-texinfo-fixed-width (fixed-width contents info
)
889 "Transcode a FIXED-WIDTH element from Org to Texinfo.
890 CONTENTS is nil. INFO is a plist holding contextual information."
891 (format "@example\n%s\n@end example"
892 (org-remove-indentation
893 (org-e-texinfo--sanitize-content
894 (org-element-property :value fixed-width
)))))
896 ;;; Footnote Reference
899 (defun org-e-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-e-texinfo-headline (headline contents info
)
911 "Transcode an 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-sectionning (assoc class org-e-texinfo-classes
))
918 ;; Find the index type, if any
919 (index (org-element-property :index headline
))
920 ;; Retrieve custom menu title (if any)
921 (menu-title (org-e-texinfo--sanitize-menu
923 (org-element-property :texinfo-menu-title headline
)
925 ;; Retrieve headline text
926 (text (org-e-texinfo--sanitize-headline
927 (org-element-property :title headline
) info
))
928 ;; Create node info, to insert it before section formatting.
929 ;; Use custom menu title if present
930 (node (format "@node %s\n"
931 (org-e-texinfo--sanitize-menu
932 (replace-regexp-in-string "%" "%%"
933 (if (not (string= "" menu-title
))
936 ;; Menus must be generated with first child, otherwise they
937 ;; will not nest properly
938 (menu (let* ((first (org-export-first-sibling-p headline info
))
939 (parent (org-export-get-parent-headline headline
))
940 (title (org-e-texinfo--sanitize-headline
941 (org-element-property :title parent
) info
))
943 (tree (plist-get info
:parse-tree
)))
946 (plist-get info
:parse-tree
) 'headline
948 (if (member title
(org-element-property :title ref
))
951 (setq listing
(org-e-texinfo--build-menu
952 (car heading
) level info
))
954 (setq listing
(replace-regexp-in-string
957 "\n@menu\n%s\n@end menu\n\n" listing
))
959 ;; Section formatting will set two placeholders: one for the
960 ;; title and the other for the contents.
962 (let ((sec (if (and (symbolp (nth 2 class-sectionning
))
963 (fboundp (nth 2 class-sectionning
)))
964 (funcall (nth 2 class-sectionning
) level numberedp
)
965 (nth (1+ level
) class-sectionning
))))
967 ;; No section available for that LEVEL.
969 ;; Section format directly returned by a function.
971 ;; (numbered-section . unnumbered-section)
972 ((not (consp (cdr sec
)))
973 ;; If an index, always unnumbered
975 (concat menu node
(cdr sec
) "\n%s")
976 ;; Otherwise number as needed.
979 (if numberedp
#'car
#'cdr
) sec
) "\n%s"))))))
981 (and (plist-get info
:with-todo-keywords
)
982 (let ((todo (org-element-property :todo-keyword headline
)))
983 (and todo
(org-export-data todo info
)))))
984 (todo-type (and todo
(org-element-property :todo-type headline
)))
985 (tags (and (plist-get info
:with-tags
)
986 (org-export-get-tags headline info
)))
987 (priority (and (plist-get info
:with-priority
)
988 (org-element-property :priority headline
)))
989 ;; Create the headline text along with a no-tag version. The
990 ;; latter is required to remove tags from table of contents.
991 (full-text (org-e-texinfo--sanitize-content
992 (if (functionp org-e-texinfo-format-headline-function
)
993 ;; User-defined formatting function.
994 (funcall org-e-texinfo-format-headline-function
995 todo todo-type priority text tags
)
996 ;; Default formatting.
999 (format "@strong{%s} " todo
))
1000 (when priority
(format "@emph{#%s} " priority
))
1004 (mapconcat 'identity tags
":")))))))
1006 (org-e-texinfo--sanitize-content
1007 (if (functionp org-e-texinfo-format-headline-function
)
1008 ;; User-defined formatting function.
1009 (funcall org-e-texinfo-format-headline-function
1010 todo todo-type priority text nil
)
1011 ;; Default formatting.
1013 (when todo
(format "@strong{%s} " todo
))
1014 (when priority
(format "@emph{#%c} " priority
))
1017 (make-string (org-element-property :pre-blank headline
) 10)))
1019 ;; Case 1: This is a footnote section: ignore it.
1020 ((org-element-property :footnote-section-p headline
) nil
)
1021 ;; Case 2: This is the `copying' section: ignore it
1022 ;; This is used elsewhere.
1023 ((org-element-property :copying headline
) nil
)
1024 ;; Case 3: An index. If it matches one of the known indexes,
1025 ;; print it as such following the contents, otherwise
1026 ;; print the contents and leave the index up to the user.
1029 section-fmt full-text
1030 (concat pre-blanks contents
"\n"
1031 (if (member index
'("cp" "fn" "ky" "pg" "tp" "vr"))
1032 (concat "@printindex " index
)))))
1033 ;; Case 4: This is a deep sub-tree: export it as a list item.
1034 ;; Also export as items headlines for which no section
1035 ;; format has been found.
1036 ((or (not section-fmt
) (org-export-low-level-p headline info
))
1037 ;; Build the real contents of the sub-tree.
1038 (let ((low-level-body
1040 ;; If the headline is the first sibling, start a list.
1041 (when (org-export-first-sibling-p headline info
)
1042 (format "@%s\n" (if numberedp
'enumerate
'itemize
)))
1044 "@item\n" full-text
"\n" pre-blanks contents
)))
1045 ;; If headline is not the last sibling simply return
1046 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
1048 (if (not (org-export-last-sibling-p headline info
)) low-level-body
1049 (replace-regexp-in-string
1051 (format "\n@end %s" (if numberedp
'enumerate
'itemize
))
1053 ;; Case 5: Standard headline. Export it as a section.
1056 ((not (and tags
(eq (plist-get info
:with-tags
) 'not-in-toc
)))
1057 ;; Regular section. Use specified format string.
1058 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1059 (concat pre-blanks contents
)))
1060 ((string-match "\\`@\\(.*?\\){" section-fmt
)
1061 ;; If tags should be removed from table of contents, insert
1062 ;; title without tags as an alternative heading in sectioning
1064 (format (replace-match (concat (match-string 1 section-fmt
) "[%s]")
1065 nil nil section-fmt
1)
1066 ;; Replace square brackets with parenthesis since
1067 ;; square brackets are not supported in optional
1069 (replace-regexp-in-string
1071 (replace-regexp-in-string
1075 (concat pre-blanks contents
)))
1077 ;; Impossible to add an alternative heading. Fallback to
1078 ;; regular sectioning format string.
1079 (format (replace-regexp-in-string "%]" "%%]" section-fmt
) full-text
1080 (concat pre-blanks contents
))))))))
1082 ;;; Inline Src Block
1084 (defun org-e-texinfo-inline-src-block (inline-src-block contents info
)
1085 "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
1086 CONTENTS holds the contents of the item. INFO is a plist holding
1087 contextual information."
1088 (let* ((code (org-element-property :value inline-src-block
))
1089 (separator (org-e-texinfo--find-verb-separator code
)))
1090 (concat "@verb{" separator code separator
"}")))
1094 (defun org-e-texinfo-inlinetask (inlinetask contents info
)
1095 "Transcode an INLINETASK element from Org to Texinfo.
1096 CONTENTS holds the contents of the block. INFO is a plist
1097 holding contextual information."
1098 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
1099 (todo (and (plist-get info
:with-todo-keywords
)
1100 (let ((todo (org-element-property :todo-keyword inlinetask
)))
1101 (and todo
(org-export-data todo info
)))))
1102 (todo-type (org-element-property :todo-type inlinetask
))
1103 (tags (and (plist-get info
:with-tags
)
1104 (org-export-get-tags inlinetask info
)))
1105 (priority (and (plist-get info
:with-priority
)
1106 (org-element-property :priority inlinetask
))))
1107 ;; If `org-e-texinfo-format-inlinetask-function' is provided, call it
1108 ;; with appropriate arguments.
1109 (if (functionp org-e-texinfo-format-inlinetask-function
)
1110 (funcall org-e-texinfo-format-inlinetask-function
1111 todo todo-type priority title tags contents
)
1112 ;; Otherwise, use a default template.
1115 (when todo
(format "@strong{%s} " todo
))
1116 (when priority
(format "#%c " priority
))
1118 (when tags
(format ":%s:"
1119 (mapconcat 'identity tags
":"))))))
1120 (format (concat "@center %s\n\n"
1123 full-title contents
)))))
1127 (defun org-e-texinfo-italic (italic contents info
)
1128 "Transcode ITALIC from Org to Texinfo.
1129 CONTENTS is the text with italic markup. INFO is a plist holding
1130 contextual information."
1131 (org-e-texinfo--text-markup contents
'italic
))
1135 (defun org-e-texinfo-item (item contents info
)
1136 "Transcode an ITEM element from Org to Texinfo.
1137 CONTENTS holds the contents of the item. INFO is a plist holding
1138 contextual information."
1139 (let* ((tag (org-element-property :tag item
))
1140 (desc (org-export-data tag info
)))
1141 (concat "\n@item " (if tag desc
) "\n"
1142 (org-trim contents
) "\n")))
1146 (defun org-e-texinfo-keyword (keyword contents info
)
1147 "Transcode a KEYWORD element from Org to Texinfo.
1148 CONTENTS is nil. INFO is a plist holding contextual information."
1149 (let ((key (org-element-property :key keyword
))
1150 (value (org-element-property :value keyword
)))
1152 ((string= key
"TEXINFO") value
)
1153 ((string= key
"CINDEX") (format "@cindex %s" value
))
1154 ((string= key
"FINDEX") (format "@findex %s" value
))
1155 ((string= key
"KINDEX") (format "@kindex %s" value
))
1156 ((string= key
"PINDEX") (format "@pindex %s" value
))
1157 ((string= key
"TINDEX") (format "@tindex %s" value
))
1158 ((string= key
"VINDEX") (format "@vindex %s" value
)))))
1162 (defun org-e-texinfo-line-break (line-break contents info
)
1163 "Transcode a LINE-BREAK object from Org to Texinfo.
1164 CONTENTS is nil. INFO is a plist holding contextual information."
1169 (defun org-e-texinfo-link (link desc info
)
1170 "Transcode a LINK object from Org to Texinfo.
1172 DESC is the description part of the link, or the empty string.
1173 INFO is a plist holding contextual information. See
1175 (let* ((type (org-element-property :type link
))
1176 (raw-path (org-element-property :path link
))
1177 ;; Ensure DESC really exists, or set it to nil.
1178 (desc (and (not (string= desc
"")) desc
))
1180 ((member type
'("http" "https" "ftp"))
1181 (concat type
":" raw-path
))
1182 ((string= type
"file")
1183 (if (file-name-absolute-p raw-path
)
1184 (concat "file://" (expand-file-name raw-path
))
1185 (concat "file://" raw-path
)))
1187 (email (if (string= type
"mailto")
1188 (let ((text (replace-regexp-in-string
1189 "@" "@@" raw-path
)))
1190 (concat text
(if desc
(concat "," desc
))))))
1193 ;; Links pointing to an headline: Find destination and build
1194 ;; appropriate referencing command.
1195 ((member type
'("custom-id" "id"))
1196 (let ((destination (org-export-resolve-id-link link info
)))
1197 (case (org-element-type destination
)
1198 ;; Id link points to an external file.
1200 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1201 (format "@uref{file://%s}" destination
)))
1202 ;; LINK points to an headline. Use the headline as the NODE target
1206 (org-element-property :title destination
) info
)))
1208 (let ((path (org-export-solidify-link-text path
)))
1209 (if (not desc
) (format "@ref{%s}" path
)
1210 (format "@ref{%s,,%s}" path desc
)))))))
1211 ((member type
'("fuzzy"))
1212 (let ((destination (org-export-resolve-fuzzy-link link info
)))
1213 (case (org-element-type destination
)
1214 ;; Id link points to an external file.
1216 (if desc
(format "@uref{file://%s,%s}" destination desc
)
1217 (format "@uref{file://%s}" destination
)))
1218 ;; LINK points to an headline. Use the headline as the NODE target
1222 (org-element-property :title destination
) info
)))
1224 (let ((path (org-export-solidify-link-text path
)))
1225 (if (not desc
) (format "@ref{%s}" path
)
1226 (format "@ref{%s,,%s}" path desc
)))))))
1227 ;; Special case for email addresses
1229 (format "@email{%s}" email
))
1230 ;; External link with a description part.
1231 ((and path desc
) (format "@uref{%s,%s}" path desc
))
1232 ;; External link without a description part.
1233 (path (format "@uref{%s}" path
))
1234 ;; No path, only description. Try to do something useful.
1235 (t (format org-e-texinfo-link-with-unknown-path-format desc
)))))
1240 (defun org-e-texinfo-make-menu (info level
)
1241 "Create the menu for inclusion in the texifo document.
1243 INFO is the parsed buffer that contains the headlines. LEVEL
1244 determines whether to make the main menu, or the detailed menu.
1246 This is only used for generating the primary menu. In-Node menus
1247 are generated directly."
1248 (let* ((parse (plist-get info
:parse-tree
))
1249 ;; Top determines level to build menu from, it finds the
1250 ;; level of the first headline in the export.
1251 (top (org-element-map
1254 (org-element-property :level headline
)) info t
)))
1256 ;; Generate the main menu
1258 (org-e-texinfo--build-menu parse top info
))
1259 ;; Generate the detailed (recursive) menu
1260 ((eq level
'detailed
)
1261 ;; Requires recursion
1262 ;;(org-e-texinfo--build-detailed-menu parse top info)
1263 (org-e-texinfo--build-menu parse top info
'detailed
))
1264 ;; Otherwise do nothing
1269 (defun org-e-texinfo-paragraph (paragraph contents info
)
1270 "Transcode a PARAGRAPH element from Org to Texinfo.
1271 CONTENTS is the contents of the paragraph, as a string. INFO is
1272 the plist used as a communication channel."
1277 (defun org-e-texinfo-plain-list (plain-list contents info
)
1278 "Transcode a PLAIN-LIST element from Org to Texinfo.
1279 CONTENTS is the contents of the list. INFO is a plist holding
1280 contextual information."
1281 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list
))
1282 (indic (or (plist-get attr
:indic
)
1283 org-e-texinfo-def-table-markup
))
1284 (type (org-element-property :type plain-list
))
1285 (table-type (or (plist-get attr
:table-type
)
1287 ;; Ensure valid texinfo table type.
1288 (table-type (if (memq table-type
'("table" "ftable" "vtable"))
1292 ((eq type
'ordered
) "enumerate")
1293 ((eq type
'unordered
) "itemize")
1294 ((eq type
'descriptive
) table-type
))))
1295 (format "@%s%s\n@end %s"
1296 (if (eq type
'descriptive
)
1297 (concat list-type
" " indic
)
1304 (defun org-e-texinfo-plain-text (text info
)
1305 "Transcode a TEXT string from Org to Texinfo.
1306 TEXT is the string to transcode. INFO is a plist holding
1307 contextual information."
1308 ;; First protect @, { and }.
1309 (let ((output (org-e-texinfo--sanitize-content text
)))
1310 ;; Activate smart quotes. Be sure to provide original TEXT string
1311 ;; since OUTPUT may have been modified.
1312 (when (plist-get info
:with-smart-quotes
)
1314 (org-export-activate-smart-quotes output
:texinfo info text
)))
1315 ;; LaTeX into @LaTeX{} and TeX into @TeX{}
1316 (let ((case-fold-search nil
)
1318 (while (string-match "\\(\\(?:La\\)?TeX\\)" output start
)
1319 (setq output
(replace-match
1320 (format "@%s{}" (match-string 1 output
)) nil t output
)
1321 start
(match-end 0))))
1322 ;; Convert special strings.
1323 (when (plist-get info
:with-special-strings
)
1324 (while (string-match (regexp-quote "...") output
)
1325 (setq output
(replace-match "@dots{}" nil t output
))))
1326 ;; Handle break preservation if required.
1327 (when (plist-get info
:preserve-breaks
)
1328 (setq output
(replace-regexp-in-string
1329 "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output
)))
1335 (defun org-e-texinfo-planning (planning contents info
)
1336 "Transcode a PLANNING element from Org to Texinfo.
1337 CONTENTS is nil. INFO is a plist holding contextual
1345 (let ((closed (org-element-property :closed planning
)))
1348 (format "@strong{%s} " org-closed-string
)
1349 (format org-e-texinfo-inactive-timestamp-format
1351 (org-element-property :raw-value closed
))))))
1352 (let ((deadline (org-element-property :deadline planning
)))
1355 (format "@strong{%s} " org-deadline-string
)
1356 (format org-e-texinfo-active-timestamp-format
1358 (org-element-property :raw-value deadline
))))))
1359 (let ((scheduled (org-element-property :scheduled planning
)))
1362 (format "@strong{%s} " org-scheduled-string
)
1363 (format org-e-texinfo-active-timestamp-format
1365 (org-element-property :raw-value scheduled
))))))))
1371 (defun org-e-texinfo-property-drawer (property-drawer contents info
)
1372 "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
1373 CONTENTS is nil. INFO is a plist holding contextual
1375 ;; The property drawer isn't exported but we want separating blank
1376 ;; lines nonetheless.
1381 (defun org-e-texinfo-quote-block (quote-block contents info
)
1382 "Transcode a QUOTE-BLOCK element from Org to Texinfo.
1383 CONTENTS holds the contents of the block. INFO is a plist
1384 holding contextual information."
1385 (let* ((title (org-element-property :name quote-block
))
1386 (start-quote (concat "@quotation"
1388 (format " %s" title
)))))
1389 (format "%s\n%s@end quotation" start-quote contents
)))
1393 (defun org-e-texinfo-quote-section (quote-section contents info
)
1394 "Transcode a QUOTE-SECTION element from Org to Texinfo.
1395 CONTENTS is nil. INFO is a plist holding contextual information."
1396 (let ((value (org-remove-indentation
1397 (org-element-property :value quote-section
))))
1398 (when value
(format "@verbatim\n%s@end verbatim" value
))))
1402 (defun org-e-texinfo-radio-target (radio-target text info
)
1403 "Transcode a RADIO-TARGET object from Org to Texinfo.
1404 TEXT is the text of the target. INFO is a plist holding
1405 contextual information."
1406 (format "@anchor{%s}%s"
1407 (org-export-solidify-link-text
1408 (org-element-property :value radio-target
))
1413 (defun org-e-texinfo-section (section contents info
)
1414 "Transcode a SECTION element from Org to Texinfo.
1415 CONTENTS holds the contents of the section. INFO is a plist
1416 holding contextual information."
1421 (defun org-e-texinfo-special-block (special-block contents info
)
1422 "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
1423 CONTENTS holds the contents of the block. INFO is a plist used
1424 as a communication channel."
1429 (defun org-e-texinfo-src-block (src-block contents info
)
1430 "Transcode a SRC-BLOCK element from Org to Texinfo.
1431 CONTENTS holds the contents of the item. INFO is a plist holding
1432 contextual information."
1433 (let* ((lang (org-element-property :language src-block
))
1434 (lisp-p (string-match-p "lisp" lang
)))
1436 ;; Case 1. Lisp Block
1438 (format "@lisp\n%s\n@end lisp"
1439 (org-export-format-code-default src-block info
)))
1440 ;; Case 2. Other blocks
1442 (format "@example\n%s\n@end example"
1443 (org-export-format-code-default src-block info
))))))
1445 ;;; Statistics Cookie
1447 (defun org-e-texinfo-statistics-cookie (statistics-cookie contents info
)
1448 "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
1449 CONTENTS is nil. INFO is a plist holding contextual information."
1450 (org-element-property :value statistics-cookie
))
1454 (defun org-e-texinfo-subscript (subscript contents info
)
1455 "Transcode a SUBSCRIPT object from Org to Texinfo.
1456 CONTENTS is the contents of the object. INFO is a plist holding
1457 contextual information."
1458 (format "@math{_%s}" contents
))
1462 (defun org-e-texinfo-superscript (superscript contents info
)
1463 "Transcode a SUPERSCRIPT object from Org to Texinfo.
1464 CONTENTS is the contents of the object. INFO is a plist holding
1465 contextual information."
1466 (format "@math{^%s}" contents
))
1470 ;; `org-e-texinfo-table' is the entry point for table transcoding. It
1471 ;; takes care of tables with a "verbatim" attribute. Otherwise, it
1472 ;; delegates the job to either `org-e-texinfo-table--table.el-table' or
1473 ;; `org-e-texinfo-table--org-table' functions, depending of the type of
1476 ;; `org-e-texinfo-table--align-string' is a subroutine used to build
1477 ;; alignment string for Org tables.
1479 (defun org-e-texinfo-table (table contents info
)
1480 "Transcode a TABLE element from Org to Texinfo.
1481 CONTENTS is the contents of the table. INFO is a plist holding
1482 contextual information."
1484 ;; Case 1: verbatim table.
1485 ((or org-e-texinfo-tables-verbatim
1486 (let ((attr (mapconcat 'identity
1487 (org-element-property :attr_latex table
)
1489 (and attr
(string-match "\\<verbatim\\>" attr
))))
1490 (format "@verbatim \n%s\n@end verbatim"
1491 ;; Re-create table, without affiliated keywords.
1493 (org-element-interpret-data
1494 `(table nil
,@(org-element-contents table
))))))
1495 ;; Case 2: table.el table. Convert it using appropriate tools.
1496 ((eq (org-element-property :type table
) 'table.el
)
1497 (org-e-texinfo-table--table.el-table table contents info
))
1498 ;; Case 3: Standard table.
1499 (t (org-e-texinfo-table--org-table table contents info
))))
1501 (defun org-e-texinfo-table-column-widths (table info
)
1502 "Determine the largest table cell in each column to process alignment.
1504 TABLE is the table element to transcode. INFO is a plist used as
1505 a communication channel."
1506 (let* ((rows (org-element-map table
'table-row
'identity info
))
1507 (collected (loop for row in rows collect
1508 (org-element-map row
'table-cell
'identity info
)))
1509 (number-cells (length (car collected
)))
1511 (loop for row in collected do
1512 (push (mapcar (lambda (ref)
1513 (let* ((start (org-element-property :contents-begin ref
))
1514 (end (org-element-property :contents-end ref
))
1515 (length (- end start
)))
1516 length
)) row
) cells
))
1517 (setq cells
(org-remove-if 'null cells
))
1518 (push (loop for count from
0 to
(- number-cells
1) collect
1519 (loop for item in cells collect
1520 (nth count item
))) counts
)
1521 (mapconcat (lambda (size)
1522 (make-string size ?a
)) (mapcar (lambda (ref)
1523 (apply 'max
`,@ref
)) (car counts
))
1526 (defun org-e-texinfo-table--org-table (table contents info
)
1527 "Return appropriate Texinfo code for an Org table.
1529 TABLE is the table type element to transcode. CONTENTS is its
1530 contents, as a string. INFO is a plist used as a communication
1533 This function assumes TABLE has `org' as its `:type' attribute."
1534 (let* ((attr (org-export-read-attribute :attr_texinfo table
))
1535 (col-width (plist-get attr
:columns
))
1536 (columns (if col-width
1537 (format "@columnfractions %s"
1540 (org-e-texinfo-table-column-widths
1542 ;; Prepare the final format string for the table.
1547 (format "@multitable %s\n%s@end multitable"
1551 (defun org-e-texinfo-table--table.el-table
(table contents info
)
1554 Rather than return an invalid table, nothing is returned."
1559 (defun org-e-texinfo-table-cell (table-cell contents info
)
1560 "Transcode a TABLE-CELL element from Org to Texinfo.
1561 CONTENTS is the cell contents. INFO is a plist used as
1562 a communication channel."
1563 (concat (if (and contents
1564 org-e-texinfo-table-scientific-notation
1565 (string-match orgtbl-exp-regexp contents
))
1566 ;; Use appropriate format string for scientific
1568 (format org-e-texinfo-table-scientific-notation
1569 (match-string 1 contents
)
1570 (match-string 2 contents
))
1572 (when (org-export-get-next-element table-cell info
) "\n@tab ")))
1576 (defun org-e-texinfo-table-row (table-row contents info
)
1577 "Transcode a TABLE-ROW element from Org to Texinfo.
1578 CONTENTS is the contents of the row. INFO is a plist used as
1579 a communication channel."
1580 ;; Rules are ignored since table separators are deduced from
1581 ;; borders of the current row.
1582 (when (eq (org-element-property :type table-row
) 'standard
)
1585 ;; Case 1: Belongs to second or subsequent rowgroup.
1586 ((not (= 1 (org-export-table-row-group table-row info
)))
1588 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
1589 ((org-export-table-has-header-p
1590 (org-export-get-parent-table table-row
) info
)
1592 ;; Case 3: Row is from first and only row group.
1594 (when (eq (org-element-property :type table-row
) 'standard
)
1595 (concat rowgroup-tag contents
"\n")))))
1599 (defun org-e-texinfo-target (target contents info
)
1600 "Transcode a TARGET object from Org to Texinfo.
1601 CONTENTS is nil. INFO is a plist holding contextual
1603 (format "@anchor{%s}"
1604 (org-export-solidify-link-text (org-element-property :value target
))))
1608 (defun org-e-texinfo-timestamp (timestamp contents info
)
1609 "Transcode a TIMESTAMP object from Org to Texinfo.
1610 CONTENTS is nil. INFO is a plist holding contextual
1612 (let ((value (org-e-texinfo-plain-text
1613 (org-export-translate-timestamp timestamp
) info
)))
1614 (case (org-element-property :type timestamp
)
1615 ((active active-range
)
1616 (format org-e-texinfo-active-timestamp-format value
))
1617 ((inactive inactive-range
)
1618 (format org-e-texinfo-inactive-timestamp-format value
))
1619 (t (format org-e-texinfo-diary-timestamp-format value
)))))
1623 (defun org-e-texinfo-verbatim (verbatim contents info
)
1624 "Transcode a VERBATIM object from Org to Texinfo.
1625 CONTENTS is nil. INFO is a plist used as a communication
1627 (org-e-texinfo--text-markup (org-element-property :value verbatim
) 'verbatim
))
1631 (defun org-e-texinfo-verse-block (verse-block contents info
)
1632 "Transcode a VERSE-BLOCK element from Org to Texinfo.
1633 CONTENTS is verse block contents. INFO is a plist holding
1634 contextual information."
1635 ;; In a verse environment, add a line break to each newline
1636 ;; character and change each white space at beginning of a line
1637 ;; into a space of 1 em. Also change each blank line with
1638 ;; a vertical space of 1 em.
1640 (setq contents
(replace-regexp-in-string
1641 "^ *\\\\\\\\$" "\\\\vspace*{1em}"
1642 (replace-regexp-in-string
1643 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" contents
)))
1644 (while (string-match "^[ \t]+" contents
)
1645 (let ((new-str (format "\\hspace*{%dem}"
1646 (length (match-string 0 contents
)))))
1647 (setq contents
(replace-match new-str nil t contents
))))
1648 (format "\\begin{verse}\n%s\\end{verse}" contents
)))
1651 ;;; Interactive functions
1653 (defun org-e-texinfo-export-to-texinfo
1654 (&optional subtreep visible-only body-only ext-plist
)
1655 "Export current buffer to a Texinfo file.
1657 If narrowing is active in the current buffer, only export its
1660 If a region is active, export that region.
1662 When optional argument SUBTREEP is non-nil, export the sub-tree
1663 at point, extracting information from the headline properties
1666 When optional argument VISIBLE-ONLY is non-nil, don't export
1667 contents of hidden elements.
1669 When optional argument BODY-ONLY is non-nil, only write code
1670 between \"\\begin{document}\" and \"\\end{document}\".
1672 EXT-PLIST, when provided, is a property list with external
1673 parameters overriding Org default settings, but still inferior to
1674 file-local settings.
1676 Return output file's name."
1678 (let ((outfile (org-export-output-file-name ".texi" subtreep
)))
1680 'e-texinfo outfile subtreep visible-only body-only ext-plist
)))
1682 (defun org-e-texinfo-export-to-info
1683 (&optional subtreep visible-only body-only ext-plist
)
1684 "Export current buffer to Texinfo then process through to INFO.
1686 If narrowing is active in the current buffer, only export its
1689 If a region is active, export that region.
1691 When optional argument SUBTREEP is non-nil, export the sub-tree
1692 at point, extracting information from the headline properties
1695 When optional argument VISIBLE-ONLY is non-nil, don't export
1696 contents of hidden elements.
1698 When optional argument BODY-ONLY is non-nil, only write code
1699 between \"\\begin{document}\" and \"\\end{document}\".
1701 EXT-PLIST, when provided, is a property list with external
1702 parameters overriding Org default settings, but still inferior to
1703 file-local settings.
1705 When optional argument PUB-DIR is set, use it as the publishing
1708 Return INFO file's name."
1710 (org-e-texinfo-compile
1711 (org-e-texinfo-export-to-texinfo subtreep visible-only body-only ext-plist
)))
1713 (defun org-e-texinfo-compile (file)
1714 "Compile a texinfo file.
1716 FILE is the name of the file being compiled. Processing is
1717 done through the command specified in `org-e-texinfo-info-process'.
1719 Return INFO file name or an error if it couldn't be produced."
1720 (let* ((base-name (file-name-sans-extension (file-name-nondirectory file
)))
1721 (full-name (file-truename file
))
1722 (out-dir (file-name-directory file
))
1723 ;; Make sure `default-directory' is set to FILE directory,
1724 ;; not to whatever value the current buffer may have.
1725 (default-directory (file-name-directory full-name
))
1727 (message (format "Processing Texinfo file %s ..." file
))
1728 (save-window-excursion
1730 ;; A function is provided: Apply it.
1731 ((functionp org-e-texinfo-info-process
)
1732 (funcall org-e-texinfo-info-process
(shell-quote-argument file
)))
1733 ;; A list is provided: Replace %b, %f and %o with appropriate
1734 ;; values in each command before applying it. Output is
1735 ;; redirected to "*Org INFO Texinfo Output*" buffer.
1736 ((consp org-e-texinfo-info-process
)
1737 (let ((outbuf (get-buffer-create "*Org INFO Texinfo Output*")))
1741 (replace-regexp-in-string
1742 "%b" (shell-quote-argument base-name
)
1743 (replace-regexp-in-string
1744 "%f" (shell-quote-argument full-name
)
1745 (replace-regexp-in-string
1746 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
1748 org-e-texinfo-info-process
)
1749 ;; Collect standard errors from output buffer.
1750 (setq errors
(org-e-texinfo-collect-errors outbuf
))))
1751 (t (error "No valid command to process to Info")))
1752 (let ((infofile (concat out-dir base-name
".info")))
1753 ;; Check for process failure. Provide collected errors if
1755 (if (not (file-exists-p infofile
))
1756 (error (concat (format "INFO file %s wasn't produced" infofile
)
1757 (when errors
(concat ": " errors
))))
1758 ;; Else remove log files, when specified, and signal end of
1759 ;; process to user, along with any error encountered.
1760 (message (concat "Process completed"
1761 (if (not errors
) "."
1762 (concat " with errors: " errors
)))))
1763 ;; Return output file name.
1766 (defun org-e-texinfo-collect-errors (buffer)
1767 "Collect some kind of errors from \"makeinfo\" command output.
1769 BUFFER is the buffer containing output.
1771 Return collected error types as a string, or nil if there was
1773 (with-current-buffer buffer
1775 (goto-char (point-min))
1776 ;; Find final "makeinfo" run.
1778 (let ((case-fold-search t
)
1780 (when (save-excursion
1781 (re-search-forward "perhaps incorrect sectioning?" nil t
))
1782 (setq errors
(concat errors
" [incorrect sectioning]")))
1783 (when (save-excursion
1784 (re-search-forward "missing close brace" nil t
))
1785 (setq errors
(concat errors
" [syntax error]")))
1786 (when (save-excursion
1787 (re-search-forward "Unknown command" nil t
))
1788 (setq errors
(concat errors
" [undefined @command]")))
1789 (when (save-excursion
1790 (re-search-forward "No matching @end" nil t
))
1791 (setq errors
(concat errors
" [block incomplete]")))
1792 (when (save-excursion
1793 (re-search-forward "requires a sectioning" nil t
))
1794 (setq errors
(concat errors
" [invalid section command]")))
1795 (when (save-excursion
1796 (re-search-forward "\\[unexpected\]" nil t
))
1797 (setq errors
(concat errors
" [unexpected error]")))
1798 (when (save-excursion
1799 (re-search-forward "misplaced " nil t
))
1800 (setq errors
(concat errors
" [syntax error]")))
1801 (and (org-string-nw-p errors
) (org-trim errors
)))))))
1803 (provide 'org-e-texinfo
)
1804 ;;; org-e-texinfo.el ends here