Function: org-texinfo-template
org-texinfo-template is a byte-compiled function defined in
ox-texinfo.el.gz.
Signature
(org-texinfo-template CONTENTS INFO)
Documentation
Return complete document string after Texinfo conversion.
CONTENTS is the transcoded contents string. INFO is a plist holding export options.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ox-texinfo.el.gz
;;; Template
(defun org-texinfo-template (contents info)
"Return complete document string after Texinfo conversion.
CONTENTS is the transcoded contents string. INFO is a plist
holding export options."
(let ((title (org-export-data (plist-get info :title) info))
;; Copying data is the contents of the first headline in
;; parse tree with a non-nil copying property.
(copying (org-element-map (plist-get info :parse-tree) 'headline
(lambda (hl)
(and (org-not-nil (org-element-property :COPYING hl))
(org-element-contents hl)))
info t)))
(concat
"\\input texinfo @c -*- texinfo -*-\n"
"@c %**start of header\n"
(let ((file (or (org-strip-quotes (plist-get info :texinfo-filename))
(let ((f (plist-get info :output-file)))
(and f (concat (file-name-sans-extension f) ".info"))))))
(and file (format "@setfilename %s\n" file)))
(format "@settitle %s\n" title)
;; Insert class-defined header.
(org-element-normalize-string
(let ((header (nth 1 (assoc (plist-get info :texinfo-class)
org-texinfo-classes)))
(coding
(catch 'coding-system
(let ((case-fold-search t)
(name (symbol-name (or org-texinfo-coding-system
buffer-file-coding-system))))
(dolist (system org-texinfo-supported-coding-systems "UTF-8")
(when (string-match-p (regexp-quote system) name)
(throw 'coding-system system))))))
(language (plist-get info :language))
(case-fold-search nil))
;; Auto coding system.
(replace-regexp-in-string
"^@documentencoding \\(AUTO\\)$"
coding
(replace-regexp-in-string
"^@documentlanguage \\(AUTO\\)$" language header t nil 1)
t nil 1)))
;; Additional header options set by #+TEXINFO_HEADER.
(let ((texinfo-header (plist-get info :texinfo-header)))
(and texinfo-header (org-element-normalize-string texinfo-header)))
"@c %**end of header\n\n"
;; Additional options set by #+TEXINFO_POST_HEADER.
(let ((texinfo-post-header (plist-get info :texinfo-post-header)))
(and texinfo-post-header
(org-element-normalize-string texinfo-post-header)))
;; Copying.
(and copying
(format "@copying\n%s@end copying\n\n"
(org-element-normalize-string
(org-export-data copying info))))
(let* ((dircat (or (plist-get info :texinfo-dircat) "Misc"))
(file (or (org-strip-quotes (plist-get info :texinfo-filename))
(plist-get info :output-file)))
(file (if file (file-name-sans-extension file)))
(dn (or (plist-get info :texinfo-dirname)
(plist-get info :texinfo-dirtitle))) ;Obsolete name.
;; Strip any terminating `.' from `dn'.
(dn (if (and dn (string-match "\\.\\'" dn)) (substring dn 0 -1) dn))
;; The direntry we need to produce has the shape:
;; * DIRNAME: NODE. DESCRIPTION.
;; where NODE is usually just `(FILENAME)', and where
;; `* FILENAME.' is a shorthand for `* FILENAME: (FILENAME).'
(dirname
(cond
((and dn (string-match
(eval-when-compile
(concat "\\`\\(?:"
"\\* \\(?1:.*\\)" ;Starts with `* ' or
"\\|\\(?1:.*(.*).*\\)" ;contains parens.
"\\)\\'"))
dn))
;; When users provide a `dn' that looks like a complete
;; `* DIRNAME: (FILENAME).' thingy, we just trust them to
;; provide something valid (just making sure it starts
;; with `* ' and ends with `.').
(format "* %s." (match-string 1 dn)))
;; `dn' is presumed to be just the DIRNAME part, so generate
;; either `* DIRNAME: (FILENAME).' or `* FILENAME.', whichever
;; is shortest.
(dn
(format "* %s: (%s)." dn (or file dn)))
(t (format "* (%s)." file)))))
(concat "@dircategory " dircat "\n"
"@direntry\n"
(let ((dirdesc
(let ((desc (or (plist-get info :texinfo-dirdesc)
title)))
(cond ((not desc) nil)
((string-suffix-p "." desc) desc)
(t (concat desc "."))))))
(if dirdesc (format "%-23s %s" dirname dirdesc) dirname))
"\n"
"@end direntry\n\n"))
;; Title
"@finalout\n"
"@titlepage\n"
(when (plist-get info :with-title)
(concat
(format "@title %s\n"
(or (plist-get info :texinfo-printed-title) title ""))
(let ((subtitle (plist-get info :subtitle)))
(when subtitle
(format "@subtitle %s\n"
(org-export-data subtitle info))))))
(when (plist-get info :with-author)
(concat
;; Primary author.
(let ((author (org-string-nw-p
(org-export-data (plist-get info :author) info)))
(email (and (plist-get info :with-email)
(org-string-nw-p
(org-export-data (plist-get info :email) info)))))
(cond ((and author email)
(format "@author %s (@email{%s})\n" author email))
(author (format "@author %s\n" author))
(email (format "@author @email{%s}\n" email))))
;; Other authors.
(let ((subauthor (plist-get info :subauthor)))
(and subauthor
(org-element-normalize-string
(replace-regexp-in-string "^" "@author " subauthor))))))
(and copying "@page\n@vskip 0pt plus 1filll\n@insertcopying\n")
"@end titlepage\n\n"
;; Table of contents.
(and (plist-get info :with-toc) "@contents\n\n")
;; Configure Top Node when not for TeX. Also include contents
;; from the first section of the document.
"@ifnottex\n"
"@node Top\n"
(format "@top %s\n" title)
(let* ((first-section
(org-element-map (plist-get info :parse-tree) 'section
#'identity info t '(headline)))
(top-contents
(org-export-data (org-element-contents first-section) info)))
(and (org-string-nw-p top-contents) (concat "\n" top-contents)))
"@end ifnottex\n\n"
;; Menu.
(org-texinfo-make-menu (plist-get info :parse-tree) info 'master)
"\n"
;; Document's body.
contents "\n"
;; Creator.
(and (plist-get info :with-creator)
(concat (plist-get info :creator) "\n"))
;; Document end.
"@bye")))