ox-texinfo.el 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
  1. ;;; ox-texinfo.el --- Texinfo Back-End for Org Export Engine -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2012-2017 Free Software Foundation, Inc.
  3. ;; Author: Jonathan Leech-Pepin <jonathan.leechpepin at gmail dot com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;
  18. ;; See Org manual for details.
  19. ;;; Code:
  20. (require 'cl-lib)
  21. (require 'ox)
  22. (defvar orgtbl-exp-regexp)
  23. ;;; Define Back-End
  24. (org-export-define-backend 'texinfo
  25. '((bold . org-texinfo-bold)
  26. (center-block . org-texinfo-center-block)
  27. (clock . org-texinfo-clock)
  28. (code . org-texinfo-code)
  29. (drawer . org-texinfo-drawer)
  30. (dynamic-block . org-texinfo-dynamic-block)
  31. (entity . org-texinfo-entity)
  32. (example-block . org-texinfo-example-block)
  33. (export-block . org-texinfo-export-block)
  34. (export-snippet . org-texinfo-export-snippet)
  35. (fixed-width . org-texinfo-fixed-width)
  36. (footnote-definition . org-texinfo-footnote-definition)
  37. (footnote-reference . org-texinfo-footnote-reference)
  38. (headline . org-texinfo-headline)
  39. (inline-src-block . org-texinfo-inline-src-block)
  40. (inlinetask . org-texinfo-inlinetask)
  41. (italic . org-texinfo-italic)
  42. (item . org-texinfo-item)
  43. (keyword . org-texinfo-keyword)
  44. (line-break . org-texinfo-line-break)
  45. (link . org-texinfo-link)
  46. (node-property . org-texinfo-node-property)
  47. (paragraph . org-texinfo-paragraph)
  48. (plain-list . org-texinfo-plain-list)
  49. (plain-text . org-texinfo-plain-text)
  50. (planning . org-texinfo-planning)
  51. (property-drawer . org-texinfo-property-drawer)
  52. (quote-block . org-texinfo-quote-block)
  53. (radio-target . org-texinfo-radio-target)
  54. (section . org-texinfo-section)
  55. (special-block . org-texinfo-special-block)
  56. (src-block . org-texinfo-src-block)
  57. (statistics-cookie . org-texinfo-statistics-cookie)
  58. (strike-through . org-texinfo-strike-through)
  59. (subscript . org-texinfo-subscript)
  60. (superscript . org-texinfo-superscript)
  61. (table . org-texinfo-table)
  62. (table-cell . org-texinfo-table-cell)
  63. (table-row . org-texinfo-table-row)
  64. (target . org-texinfo-target)
  65. (template . org-texinfo-template)
  66. (timestamp . org-texinfo-timestamp)
  67. (underline . org-texinfo-underline)
  68. (verbatim . org-texinfo-verbatim)
  69. (verse-block . org-texinfo-verse-block))
  70. :filters-alist
  71. '((:filter-headline . org-texinfo--filter-section-blank-lines)
  72. (:filter-parse-tree . org-texinfo--normalize-headlines)
  73. (:filter-section . org-texinfo--filter-section-blank-lines))
  74. :menu-entry
  75. '(?i "Export to Texinfo"
  76. ((?t "As TEXI file" org-texinfo-export-to-texinfo)
  77. (?i "As INFO file" org-texinfo-export-to-info)
  78. (?o "As INFO file and open"
  79. (lambda (a s v b)
  80. (if a (org-texinfo-export-to-info t s v b)
  81. (org-open-file (org-texinfo-export-to-info nil s v b)))))))
  82. :options-alist
  83. '((:texinfo-filename "TEXINFO_FILENAME" nil nil t)
  84. (:texinfo-class "TEXINFO_CLASS" nil org-texinfo-default-class t)
  85. (:texinfo-header "TEXINFO_HEADER" nil nil newline)
  86. (:texinfo-post-header "TEXINFO_POST_HEADER" nil nil newline)
  87. (:subtitle "SUBTITLE" nil nil parse)
  88. (:subauthor "SUBAUTHOR" nil nil newline)
  89. (:texinfo-dircat "TEXINFO_DIR_CATEGORY" nil nil t)
  90. (:texinfo-dirtitle "TEXINFO_DIR_TITLE" nil nil t)
  91. (:texinfo-dirdesc "TEXINFO_DIR_DESC" nil nil t)
  92. (:texinfo-printed-title "TEXINFO_PRINTED_TITLE" nil nil t)
  93. ;; Other variables.
  94. (:texinfo-classes nil nil org-texinfo-classes)
  95. (:texinfo-format-headline-function nil nil org-texinfo-format-headline-function)
  96. (:texinfo-node-description-column nil nil org-texinfo-node-description-column)
  97. (:texinfo-active-timestamp-format nil nil org-texinfo-active-timestamp-format)
  98. (:texinfo-inactive-timestamp-format nil nil org-texinfo-inactive-timestamp-format)
  99. (:texinfo-diary-timestamp-format nil nil org-texinfo-diary-timestamp-format)
  100. (:texinfo-link-with-unknown-path-format nil nil org-texinfo-link-with-unknown-path-format)
  101. (:texinfo-tables-verbatim nil nil org-texinfo-tables-verbatim)
  102. (:texinfo-table-scientific-notation nil nil org-texinfo-table-scientific-notation)
  103. (:texinfo-table-default-markup nil nil org-texinfo-table-default-markup)
  104. (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist)
  105. (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function)
  106. (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function)))
  107. ;;; User Configurable Variables
  108. (defgroup org-export-texinfo nil
  109. "Options for exporting Org mode files to Texinfo."
  110. :tag "Org Export Texinfo"
  111. :version "24.4"
  112. :package-version '(Org . "8.0")
  113. :group 'org-export)
  114. ;;;; Preamble
  115. (defcustom org-texinfo-coding-system nil
  116. "Default document encoding for Texinfo output.
  117. If nil it will default to `buffer-file-coding-system'."
  118. :group 'org-export-texinfo
  119. :type 'coding-system)
  120. (defcustom org-texinfo-default-class "info"
  121. "The default Texinfo class."
  122. :group 'org-export-texinfo
  123. :type '(string :tag "Texinfo class"))
  124. (defcustom org-texinfo-classes
  125. '(("info"
  126. "@documentencoding AUTO\n@documentlanguage AUTO"
  127. ("@chapter %s" "@unnumbered %s" "@chapheading %s" "@appendix %s")
  128. ("@section %s" "@unnumberedsec %s" "@heading %s" "@appendixsec %s")
  129. ("@subsection %s" "@unnumberedsubsec %s" "@subheading %s"
  130. "@appendixsubsec %s")
  131. ("@subsubsection %s" "@unnumberedsubsubsec %s" "@subsubheading %s"
  132. "@appendixsubsubsec %s")))
  133. "Alist of Texinfo classes and associated header and structure.
  134. If #+TEXINFO_CLASS is set in the buffer, use its value and the
  135. associated information. Here is the structure of a class
  136. definition:
  137. (class-name
  138. header-string
  139. (numbered-1 unnumbered-1 unnumbered-no-toc-1 appendix-1)
  140. (numbered-2 unnumbered-2 unnumbered-no-toc-2 appendix-2)
  141. ...)
  142. The header string
  143. -----------------
  144. The header string is inserted in the header of the generated
  145. document, right after \"@setfilename\" and \"@settitle\"
  146. commands.
  147. If it contains the special string
  148. \"@documentencoding AUTO\"
  149. \"AUTO\" will be replaced with an appropriate coding system. See
  150. `org-texinfo-coding-system' for more information. Likewise, if
  151. the string contains the special string
  152. \"@documentlanguage AUTO\"
  153. \"AUTO\" will be replaced with the language defined in the
  154. buffer, through #+LANGUAGE keyword, or globally, with
  155. `org-export-default-language', which see.
  156. The sectioning structure
  157. ------------------------
  158. The sectioning structure of the class is given by the elements
  159. following the header string. For each sectioning level, a number
  160. of strings is specified. A %s formatter is mandatory in each
  161. section string and will be replaced by the title of the section."
  162. :group 'org-export-texinfo
  163. :version "27.1"
  164. :package-version '(Org . "9.2")
  165. :type '(repeat
  166. (list (string :tag "Texinfo class")
  167. (string :tag "Texinfo header")
  168. (repeat :tag "Levels" :inline t
  169. (choice
  170. (list :tag "Heading"
  171. (string :tag " numbered")
  172. (string :tag " unnumbered")
  173. (string :tag "unnumbered-no-toc")
  174. (string :tag " appendix")))))))
  175. ;;;; Headline
  176. (defcustom org-texinfo-format-headline-function
  177. 'org-texinfo-format-headline-default-function
  178. "Function to format headline text.
  179. This function will be called with 5 arguments:
  180. TODO the todo keyword (string or nil).
  181. TODO-TYPE the type of todo (symbol: `todo', `done', nil)
  182. PRIORITY the priority of the headline (integer or nil)
  183. TEXT the main headline text (string).
  184. TAGS the tags as a list of strings (list of strings or nil).
  185. The function result will be used in the section format string."
  186. :group 'org-export-texinfo
  187. :type 'function
  188. :version "26.1"
  189. :package-version '(Org . "8.3"))
  190. ;;;; Node listing (menu)
  191. (defcustom org-texinfo-node-description-column 32
  192. "Column at which to start the description in the node listings.
  193. If a node title is greater than this length, the description will
  194. be placed after the end of the title."
  195. :group 'org-export-texinfo
  196. :type 'integer)
  197. ;;;; Timestamps
  198. (defcustom org-texinfo-active-timestamp-format "@emph{%s}"
  199. "A printf format string to be applied to active timestamps."
  200. :group 'org-export-texinfo
  201. :type 'string)
  202. (defcustom org-texinfo-inactive-timestamp-format "@emph{%s}"
  203. "A printf format string to be applied to inactive timestamps."
  204. :group 'org-export-texinfo
  205. :type 'string)
  206. (defcustom org-texinfo-diary-timestamp-format "@emph{%s}"
  207. "A printf format string to be applied to diary timestamps."
  208. :group 'org-export-texinfo
  209. :type 'string)
  210. ;;;; Links
  211. (defcustom org-texinfo-link-with-unknown-path-format "@indicateurl{%s}"
  212. "Format string for links with unknown path type."
  213. :group 'org-export-texinfo
  214. :type 'string)
  215. ;;;; Tables
  216. (defcustom org-texinfo-tables-verbatim nil
  217. "When non-nil, tables are exported verbatim."
  218. :group 'org-export-texinfo
  219. :type 'boolean)
  220. (defcustom org-texinfo-table-scientific-notation "%s\\,(%s)"
  221. "Format string to display numbers in scientific notation.
  222. The format should have \"%s\" twice, for mantissa and exponent
  223. \(i.e. \"%s\\\\times10^{%s}\").
  224. When nil, no transformation is made."
  225. :group 'org-export-texinfo
  226. :type '(choice
  227. (string :tag "Format string")
  228. (const :tag "No formatting" nil)))
  229. (defcustom org-texinfo-table-default-markup "@asis"
  230. "Default markup for first column in two-column tables.
  231. This should an indicating command, e.g., \"@code\", \"@kbd\" or
  232. \"@samp\".
  233. It can be overridden locally using the \":indic\" attribute."
  234. :group 'org-export-texinfo
  235. :type 'string
  236. :version "26.1"
  237. :package-version '(Org . "9.1")
  238. :safe #'stringp)
  239. ;;;; Text markup
  240. (defcustom org-texinfo-text-markup-alist '((bold . "@strong{%s}")
  241. (code . code)
  242. (italic . "@emph{%s}")
  243. (verbatim . samp))
  244. "Alist of Texinfo expressions to convert text markup.
  245. The key must be a symbol among `bold', `code', `italic',
  246. `strike-through', `underscore' and `verbatim'. The value is
  247. a formatting string to wrap fontified text with.
  248. Value can also be set to the following symbols: `verb', `samp'
  249. and `code'. With the first one, Org uses \"@verb\" to create
  250. a format string and selects a delimiter character that isn't in
  251. the string. For the other two, Org uses \"@samp\" or \"@code\"
  252. to typeset and protects special characters.
  253. When no association is found for a given markup, text is returned
  254. as-is."
  255. :group 'org-export-texinfo
  256. :version "26.1"
  257. :package-version '(Org . "9.1")
  258. :type 'alist
  259. :options '(bold code italic strike-through underscore verbatim))
  260. ;;;; Drawers
  261. (defcustom org-texinfo-format-drawer-function (lambda (_name contents) contents)
  262. "Function called to format a drawer in Texinfo code.
  263. The function must accept two parameters:
  264. NAME the drawer name, like \"LOGBOOK\"
  265. CONTENTS the contents of the drawer.
  266. The function should return the string to be exported.
  267. The default function simply returns the value of CONTENTS."
  268. :group 'org-export-texinfo
  269. :version "24.4"
  270. :package-version '(Org . "8.2")
  271. :type 'function)
  272. ;;;; Inlinetasks
  273. (defcustom org-texinfo-format-inlinetask-function
  274. 'org-texinfo-format-inlinetask-default-function
  275. "Function called to format an inlinetask in Texinfo code.
  276. The function must accept six parameters:
  277. TODO the todo keyword, as a string
  278. TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
  279. PRIORITY the inlinetask priority, as a string
  280. NAME the inlinetask name, as a string.
  281. TAGS the inlinetask tags, as a list of strings.
  282. CONTENTS the contents of the inlinetask, as a string.
  283. The function should return the string to be exported."
  284. :group 'org-export-texinfo
  285. :type 'function)
  286. ;;;; Compilation
  287. (defcustom org-texinfo-info-process '("makeinfo --no-split %f")
  288. "Commands to process a Texinfo file to an INFO file.
  289. This is a list of strings, each of them will be given to the
  290. shell as a command. %f in the command will be replaced by the
  291. relative file name, %F by the absolute file name, %b by the file
  292. base name (i.e. without directory and extension parts), %o by the
  293. base directory of the file and %O by the absolute file name of
  294. the output file."
  295. :group 'org-export-texinfo
  296. :version "26.1"
  297. :package-version '(Org . "9.1")
  298. :type '(repeat :tag "Shell command sequence"
  299. (string :tag "Shell command")))
  300. (defcustom org-texinfo-logfiles-extensions
  301. '("aux" "toc" "cp" "fn" "ky" "pg" "tp" "vr")
  302. "The list of file extensions to consider as Texinfo logfiles.
  303. The logfiles will be remove if `org-texinfo-remove-logfiles' is
  304. non-nil."
  305. :group 'org-export-texinfo
  306. :type '(repeat (string :tag "Extension")))
  307. (defcustom org-texinfo-remove-logfiles t
  308. "Non-nil means remove the logfiles produced by compiling a Texinfo file.
  309. By default, logfiles are files with these extensions: .aux, .toc,
  310. .cp, .fn, .ky, .pg and .tp. To define the set of logfiles to remove,
  311. set `org-texinfo-logfiles-extensions'."
  312. :group 'org-export-latex
  313. :type 'boolean)
  314. ;;; Constants
  315. (defconst org-texinfo-max-toc-depth 4
  316. "Maximum depth for creation of detailed menu listings.
  317. Beyond this depth, Texinfo will not recognize the nodes and will
  318. cause errors. Left as a constant in case this value ever
  319. changes.")
  320. (defconst org-texinfo-supported-coding-systems
  321. '("US-ASCII" "UTF-8" "ISO-8859-15" "ISO-8859-1" "ISO-8859-2" "koi8-r" "koi8-u")
  322. "List of coding systems supported by Texinfo, as strings.
  323. Specified coding system will be matched against these strings.
  324. If two strings share the same prefix (e.g. \"ISO-8859-1\" and
  325. \"ISO-8859-15\"), the most specific one has to be listed first.")
  326. (defconst org-texinfo-inline-image-rules
  327. (list (cons "file"
  328. (regexp-opt '("eps" "pdf" "png" "jpg" "jpeg" "gif" "svg"))))
  329. "Rules characterizing image files that can be inlined.")
  330. ;;; Internal Functions
  331. (defun org-texinfo--filter-section-blank-lines (headline _backend _info)
  332. "Filter controlling number of blank lines after a section."
  333. (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" "\n\n" headline))
  334. (defun org-texinfo--normalize-headlines (tree _backend info)
  335. "Normalize headlines in TREE.
  336. BACK-END is the symbol specifying back-end used for export. INFO
  337. is a plist used as a communication channel.
  338. Make sure every headline in TREE contains a section, since those
  339. are required to install a menu. Also put exactly one blank line
  340. at the end of each section.
  341. Return new tree."
  342. (org-element-map tree 'headline
  343. (lambda (hl)
  344. (org-element-put-property hl :post-blank 1)
  345. (let ((contents (org-element-contents hl)))
  346. (when contents
  347. (let ((first (org-element-map contents '(headline section)
  348. #'identity info t)))
  349. (unless (eq (org-element-type first) 'section)
  350. (apply #'org-element-set-contents
  351. hl
  352. (cons `(section (:parent ,hl)) contents)))))))
  353. info)
  354. tree)
  355. (defun org-texinfo--find-verb-separator (s)
  356. "Return a character not used in string S.
  357. This is used to choose a separator for constructs like \\verb."
  358. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  359. (cl-loop for c across ll
  360. when (not (string-match (regexp-quote (char-to-string c)) s))
  361. return (char-to-string c))))
  362. (defun org-texinfo--text-markup (text markup _info)
  363. "Format TEXT depending on MARKUP text markup.
  364. INFO is a plist used as a communication channel. See
  365. `org-texinfo-text-markup-alist' for details."
  366. (pcase (cdr (assq markup org-texinfo-text-markup-alist))
  367. (`nil text) ;no markup: return raw text
  368. (`code (format "@code{%s}" (org-texinfo--sanitize-content text)))
  369. (`samp (format "@samp{%s}" (org-texinfo--sanitize-content text)))
  370. (`verb
  371. (let ((separator (org-texinfo--find-verb-separator text)))
  372. (format "@verb{%s%s%s}" separator text separator)))
  373. ;; Else use format string.
  374. (fmt (format fmt text))))
  375. (defun org-texinfo--get-node (datum info)
  376. "Return node or anchor associated to DATUM.
  377. DATUM is an element or object. INFO is a plist used as
  378. a communication channel. The function guarantees the node or
  379. anchor name is unique."
  380. (let ((cache (plist-get info :texinfo-node-cache)))
  381. (or (cdr (assq datum cache))
  382. (let* ((salt 0)
  383. (basename
  384. (org-texinfo--sanitize-node
  385. (if (eq (org-element-type datum) 'headline)
  386. (org-texinfo--sanitize-title
  387. (org-export-get-alt-title datum info) info)
  388. (org-export-get-reference datum info))))
  389. (name basename))
  390. ;; Ensure NAME is unique and not reserved node name "Top".
  391. (while (or (equal name "Top") (rassoc name cache))
  392. (setq name (concat basename (format " %d" (cl-incf salt)))))
  393. (plist-put info :texinfo-node-cache (cons (cons datum name) cache))
  394. name))))
  395. (defun org-texinfo--sanitize-node (title)
  396. "Bend string TITLE to node line requirements.
  397. Trim string and collapse multiple whitespace characters as they
  398. are not significant. Replace leading left parenthesis, when
  399. followed by a right parenthesis, with a square bracket. Remove
  400. periods, commas and colons."
  401. (org-trim
  402. (replace-regexp-in-string
  403. "[ \t]+" " "
  404. (replace-regexp-in-string
  405. "[:,.]" ""
  406. (replace-regexp-in-string "\\`(\\(.*?)\\)" "[\\1" title)))))
  407. (defun org-texinfo--sanitize-title (title info)
  408. "Make TITLE suitable as a section name.
  409. TITLE is a string or a secondary string. INFO is the current
  410. export state, as a plist."
  411. (org-export-data-with-backend
  412. title
  413. (org-export-create-backend
  414. :parent 'texinfo
  415. :transcoders '((footnote-reference . ignore)
  416. (link . (lambda (l c i)
  417. (or c
  418. (org-export-data
  419. (org-element-property :raw-link l)
  420. i))))
  421. (radio-target . (lambda (_r c _i) c))
  422. (target . ignore)))
  423. info))
  424. (defun org-texinfo--sanitize-content (text)
  425. "Escape special characters in string TEXT.
  426. Special characters are: @ { }"
  427. (replace-regexp-in-string "[@{}]" "@\\&" text))
  428. (defun org-texinfo--wrap-float (value info &optional type label caption short)
  429. "Wrap string VALUE within a @float command.
  430. INFO is the current export state, as a plist. TYPE is float
  431. type, as a string. LABEL is the cross reference label for the
  432. float, as a string. CAPTION and SHORT are, respectively, the
  433. caption and shortcaption used for the float, as secondary
  434. strings (e.g., returned by `org-export-get-caption')."
  435. (let* ((backend
  436. (org-export-create-backend
  437. :parent 'texinfo
  438. :transcoders '((link . (lambda (l c i)
  439. (or c
  440. (org-export-data
  441. (org-element-property :raw-link l)
  442. i))))
  443. (radio-target . (lambda (_r c _i) c))
  444. (target . ignore))))
  445. (short-backend
  446. (org-export-create-backend
  447. :parent 'texinfo
  448. :transcoders
  449. '((footnote-reference . ignore)
  450. (inline-src-block . ignore)
  451. (link . (lambda (l c i)
  452. (or c
  453. (org-export-data
  454. (org-element-property :raw-link l)
  455. i))))
  456. (radio-target . (lambda (_r c _i) c))
  457. (target . ignore)
  458. (verbatim . ignore))))
  459. (short-str
  460. (if (and short caption)
  461. (format "@shortcaption{%s}\n"
  462. (org-export-data-with-backend short short-backend info))
  463. ""))
  464. (caption-str
  465. (if (or short caption)
  466. (format "@caption{%s}\n"
  467. (org-export-data-with-backend
  468. (or caption short)
  469. (if (equal short-str "") short-backend backend)
  470. info))
  471. "")))
  472. (format "@float %s%s\n%s\n%s%s@end float"
  473. type (if label (concat "," label) "") value caption-str short-str)))
  474. ;;; Template
  475. (defun org-texinfo-template (contents info)
  476. "Return complete document string after Texinfo conversion.
  477. CONTENTS is the transcoded contents string. INFO is a plist
  478. holding export options."
  479. (let ((title (org-export-data (plist-get info :title) info))
  480. ;; Copying data is the contents of the first headline in
  481. ;; parse tree with a non-nil copying property.
  482. (copying (org-element-map (plist-get info :parse-tree) 'headline
  483. (lambda (hl)
  484. (and (org-not-nil (org-element-property :COPYING hl))
  485. (org-element-contents hl)))
  486. info t)))
  487. (concat
  488. "\\input texinfo @c -*- texinfo -*-\n"
  489. "@c %**start of header\n"
  490. (let ((file (or (plist-get info :texinfo-filename)
  491. (let ((f (plist-get info :output-file)))
  492. (and f (concat (file-name-sans-extension f) ".info"))))))
  493. (and file (format "@setfilename %s\n" file)))
  494. (format "@settitle %s\n" title)
  495. ;; Insert class-defined header.
  496. (org-element-normalize-string
  497. (let ((header (nth 1 (assoc (plist-get info :texinfo-class)
  498. org-texinfo-classes)))
  499. (coding
  500. (catch 'coding-system
  501. (let ((case-fold-search t)
  502. (name (symbol-name (or org-texinfo-coding-system
  503. buffer-file-coding-system))))
  504. (dolist (system org-texinfo-supported-coding-systems "UTF-8")
  505. (when (string-match-p (regexp-quote system) name)
  506. (throw 'coding-system system))))))
  507. (language (plist-get info :language))
  508. (case-fold-search nil))
  509. ;; Auto coding system.
  510. (replace-regexp-in-string
  511. "^@documentencoding \\(AUTO\\)$"
  512. coding
  513. (replace-regexp-in-string
  514. "^@documentlanguage \\(AUTO\\)$" language header t nil 1) t nil 1)))
  515. ;; Additional header options set by #+TEXINFO_HEADER.
  516. (let ((texinfo-header (plist-get info :texinfo-header)))
  517. (and texinfo-header (org-element-normalize-string texinfo-header)))
  518. "@c %**end of header\n\n"
  519. ;; Additional options set by #+TEXINFO_POST_HEADER.
  520. (let ((texinfo-post-header (plist-get info :texinfo-post-header)))
  521. (and texinfo-post-header
  522. (org-element-normalize-string texinfo-post-header)))
  523. ;; Copying.
  524. (and copying
  525. (format "@copying\n%s@end copying\n\n"
  526. (org-element-normalize-string
  527. (org-export-data copying info))))
  528. ;; Info directory information. Only supply if both title and
  529. ;; category are provided.
  530. (let ((dircat (plist-get info :texinfo-dircat))
  531. (dirtitle
  532. (let ((title (plist-get info :texinfo-dirtitle)))
  533. (and title
  534. (string-match "^\\(?:\\* \\)?\\(.*?\\)\\(\\.\\)?$" title)
  535. (format "* %s." (match-string 1 title))))))
  536. (when (and dircat dirtitle)
  537. (concat "@dircategory " dircat "\n"
  538. "@direntry\n"
  539. (let ((dirdesc
  540. (let ((desc (plist-get info :texinfo-dirdesc)))
  541. (cond ((not desc) nil)
  542. ((string-suffix-p "." desc) desc)
  543. (t (concat desc "."))))))
  544. (if dirdesc (format "%-23s %s" dirtitle dirdesc) dirtitle))
  545. "\n"
  546. "@end direntry\n\n")))
  547. ;; Title
  548. "@finalout\n"
  549. "@titlepage\n"
  550. (when (plist-get info :with-title)
  551. (concat
  552. (format "@title %s\n"
  553. (or (plist-get info :texinfo-printed-title) title ""))
  554. (let ((subtitle (plist-get info :subtitle)))
  555. (when subtitle
  556. (format "@subtitle %s\n"
  557. (org-export-data subtitle info))))))
  558. (when (plist-get info :with-author)
  559. (concat
  560. ;; Primary author.
  561. (let ((author (org-string-nw-p
  562. (org-export-data (plist-get info :author) info)))
  563. (email (and (plist-get info :with-email)
  564. (org-string-nw-p
  565. (org-export-data (plist-get info :email) info)))))
  566. (cond ((and author email)
  567. (format "@author %s (@email{%s})\n" author email))
  568. (author (format "@author %s\n" author))
  569. (email (format "@author @email{%s}\n" email))))
  570. ;; Other authors.
  571. (let ((subauthor (plist-get info :subauthor)))
  572. (and subauthor
  573. (org-element-normalize-string
  574. (replace-regexp-in-string "^" "@author " subauthor))))))
  575. (and copying "@page\n@vskip 0pt plus 1filll\n@insertcopying\n")
  576. "@end titlepage\n\n"
  577. ;; Table of contents.
  578. (and (plist-get info :with-toc) "@contents\n\n")
  579. ;; Configure Top Node when not for TeX. Also include contents
  580. ;; from the first section of the document.
  581. "@ifnottex\n"
  582. "@node Top\n"
  583. (format "@top %s\n" title)
  584. (let* ((first-section
  585. (org-element-map (plist-get info :parse-tree) 'section
  586. #'identity info t '(headline)))
  587. (top-contents
  588. (org-export-data (org-element-contents first-section) info)))
  589. (and (org-string-nw-p top-contents) (concat "\n" top-contents)))
  590. "@end ifnottex\n\n"
  591. ;; Menu.
  592. (org-texinfo-make-menu (plist-get info :parse-tree) info 'master)
  593. "\n"
  594. ;; Document's body.
  595. contents "\n"
  596. ;; Creator.
  597. (and (plist-get info :with-creator)
  598. (concat (plist-get info :creator) "\n"))
  599. ;; Document end.
  600. "@bye")))
  601. ;;; Transcode Functions
  602. ;;;; Bold
  603. (defun org-texinfo-bold (_bold contents info)
  604. "Transcode BOLD from Org to Texinfo.
  605. CONTENTS is the text with bold markup. INFO is a plist holding
  606. contextual information."
  607. (org-texinfo--text-markup contents 'bold info))
  608. ;;;; Center Block
  609. (defun org-texinfo-center-block (_center-block contents _info)
  610. "Transcode a CENTER-BLOCK element from Org to Texinfo.
  611. CONTENTS holds the contents of the block. INFO is a plist used
  612. as a communication channel."
  613. contents)
  614. ;;;; Clock
  615. (defun org-texinfo-clock (clock _contents info)
  616. "Transcode a CLOCK element from Org to Texinfo.
  617. CONTENTS is nil. INFO is a plist holding contextual
  618. information."
  619. (concat
  620. "@noindent"
  621. (format "@strong{%s} " org-clock-string)
  622. (format (plist-get info :texinfo-inactive-timestamp-format)
  623. (concat (org-timestamp-translate (org-element-property :value clock))
  624. (let ((time (org-element-property :duration clock)))
  625. (and time (format " (%s)" time)))))
  626. "@*"))
  627. ;;;; Code
  628. (defun org-texinfo-code (code _contents info)
  629. "Transcode a CODE object from Org to Texinfo.
  630. CONTENTS is nil. INFO is a plist used as a communication
  631. channel."
  632. (org-texinfo--text-markup (org-element-property :value code) 'code info))
  633. ;;;; Drawer
  634. (defun org-texinfo-drawer (drawer contents info)
  635. "Transcode a DRAWER element from Org to Texinfo.
  636. CONTENTS holds the contents of the block. INFO is a plist
  637. holding contextual information."
  638. (let* ((name (org-element-property :drawer-name drawer))
  639. (output (funcall (plist-get info :texinfo-format-drawer-function)
  640. name contents)))
  641. output))
  642. ;;;; Dynamic Block
  643. (defun org-texinfo-dynamic-block (_dynamic-block contents _info)
  644. "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
  645. CONTENTS holds the contents of the block. INFO is a plist
  646. holding contextual information."
  647. contents)
  648. ;;;; Entity
  649. (defun org-texinfo-entity (entity _contents _info)
  650. "Transcode an ENTITY object from Org to Texinfo."
  651. ;; Since there is not specific Texinfo entry in entities, use
  652. ;; Texinfo-specific commands whenever possible, and fallback to
  653. ;; UTF-8 otherwise.
  654. (pcase (org-element-property :name entity)
  655. ("AElig" "@AE{}")
  656. ("aelig" "@ae{}")
  657. ((or "bull" "bullet") "@bullet{}")
  658. ("copy" "@copyright{}")
  659. ("deg" "@textdegree{}")
  660. ((or "dots" "hellip") "@dots{}")
  661. ("equiv" "@equiv{}")
  662. ((or "euro" "EUR") "@euro{}")
  663. ((or "ge" "geq") "@geq{}")
  664. ("laquo" "@guillemetleft{}")
  665. ("iexcl" "@exclamdown{}")
  666. ("imath" "@dotless{i}")
  667. ("iquest" "@questiondown{}")
  668. ("jmath" "@dotless{j}")
  669. ((or "le" "leq") "@leq{}")
  670. ("lsaquo" "@guilsinglleft{}")
  671. ("mdash" "---")
  672. ("minus" "@minus{}")
  673. ("nbsp" "@tie{}")
  674. ("ndash" "--")
  675. ("OElig" "@OE{}")
  676. ("oelig" "@oe{}")
  677. ("ordf" "@ordf{}")
  678. ("ordm" "@ordm{}")
  679. ("pound" "@pound{}")
  680. ("raquo" "@guillemetright{}")
  681. ((or "rArr" "Rightarrow") "@result{}")
  682. ("reg" "@registeredsymbol{}")
  683. ((or "rightarrow" "to" "rarr") "@arrow{}")
  684. ("rsaquo" "@guilsinglright{}")
  685. ("thorn" "@th{}")
  686. ("THORN" "@TH{}")
  687. ((and (pred (string-prefix-p "_")) name) ;spacing entities
  688. (format "@w{%s}" (substring name 1)))
  689. (_ (org-element-property :utf-8 entity))))
  690. ;;;; Example Block
  691. (defun org-texinfo-example-block (example-block _contents info)
  692. "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
  693. CONTENTS is nil. INFO is a plist holding contextual
  694. information."
  695. (format "@example\n%s@end example"
  696. (org-texinfo--sanitize-content
  697. (org-export-format-code-default example-block info))))
  698. ;;; Export Block
  699. (defun org-texinfo-export-block (export-block _contents _info)
  700. "Transcode a EXPORT-BLOCK element from Org to Texinfo.
  701. CONTENTS is nil. INFO is a plist holding contextual information."
  702. (when (string= (org-element-property :type export-block) "TEXINFO")
  703. (org-remove-indentation (org-element-property :value export-block))))
  704. ;;; Export Snippet
  705. (defun org-texinfo-export-snippet (export-snippet _contents _info)
  706. "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
  707. CONTENTS is nil. INFO is a plist holding contextual information."
  708. (when (eq (org-export-snippet-backend export-snippet) 'texinfo)
  709. (org-element-property :value export-snippet)))
  710. ;;;; Fixed Width
  711. (defun org-texinfo-fixed-width (fixed-width _contents _info)
  712. "Transcode a FIXED-WIDTH element from Org to Texinfo.
  713. CONTENTS is nil. INFO is a plist holding contextual information."
  714. (format "@example\n%s@end example"
  715. (org-remove-indentation
  716. (org-texinfo--sanitize-content
  717. (org-element-property :value fixed-width)))))
  718. ;;;; Footnote Reference
  719. (defun org-texinfo-footnote-reference (footnote _contents info)
  720. "Create a footnote reference for FOOTNOTE.
  721. FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
  722. plist holding contextual information."
  723. (let ((def (org-export-get-footnote-definition footnote info)))
  724. (format "@footnote{%s}"
  725. (org-trim (org-export-data def info)))))
  726. ;;;; Headline
  727. (defun org-texinfo-headline (headline contents info)
  728. "Transcode a HEADLINE element from Org to Texinfo.
  729. CONTENTS holds the contents of the headline. INFO is a plist
  730. holding contextual information."
  731. (cond
  732. ((org-element-property :footnote-section-p headline) nil)
  733. ((org-not-nil (org-export-get-node-property :COPYING headline t)) nil)
  734. (t
  735. (let* ((index (let ((i (org-export-get-node-property :INDEX headline t)))
  736. (and (member i '("cp" "fn" "ky" "pg" "tp" "vr")) i)))
  737. (numbered? (org-export-numbered-headline-p headline info))
  738. (notoc? (org-export-excluded-from-toc-p headline info))
  739. (command
  740. (and
  741. (not (org-export-low-level-p headline info))
  742. (let ((class (plist-get info :texinfo-class)))
  743. (pcase (assoc class (plist-get info :texinfo-classes))
  744. (`(,_ ,_ . ,sections)
  745. (pcase (nth (1- (org-export-get-relative-level headline info))
  746. sections)
  747. (`(,numbered ,unnumbered ,unnumbered-no-toc ,appendix)
  748. (cond
  749. ((org-not-nil
  750. (org-export-get-node-property :APPENDIX headline t))
  751. appendix)
  752. (numbered? numbered)
  753. (index unnumbered)
  754. (notoc? unnumbered-no-toc)
  755. (t unnumbered)))
  756. (`nil nil)
  757. (_ (user-error "Invalid Texinfo class specification: %S"
  758. class))))
  759. (_ (user-error "Unknown Texinfo class: %S" class))))))
  760. (todo
  761. (and (plist-get info :with-todo-keywords)
  762. (let ((todo (org-element-property :todo-keyword headline)))
  763. (and todo (org-export-data todo info)))))
  764. (todo-type (and todo (org-element-property :todo-type headline)))
  765. (tags (and (plist-get info :with-tags)
  766. (org-export-get-tags headline info)))
  767. (priority (and (plist-get info :with-priority)
  768. (org-element-property :priority headline)))
  769. (text (org-texinfo--sanitize-title
  770. (org-element-property :title headline) info))
  771. (full-text
  772. (funcall (plist-get info :texinfo-format-headline-function)
  773. todo todo-type priority text tags))
  774. (contents
  775. (concat "\n"
  776. (if (org-string-nw-p contents) (concat "\n" contents) "")
  777. (and index (format "\n@printindex %s\n" index)))))
  778. (if (not command)
  779. (concat (and (org-export-first-sibling-p headline info)
  780. (format "@%s\n" (if numbered? 'enumerate 'itemize)))
  781. "@item\n" full-text "\n"
  782. contents
  783. (if (org-export-last-sibling-p headline info)
  784. (format "@end %s" (if numbered? 'enumerate 'itemize))
  785. "\n"))
  786. (concat
  787. (and (not notoc?)
  788. (format "@node %s\n" (org-texinfo--get-node headline info)))
  789. (format command full-text)
  790. contents))))))
  791. (defun org-texinfo-format-headline-default-function
  792. (todo _todo-type priority text tags)
  793. "Default format function for a headline.
  794. See `org-texinfo-format-headline-function' for details."
  795. (concat (when todo (format "@strong{%s} " todo))
  796. (when priority (format "@emph{#%s} " priority))
  797. text
  798. (when tags (format " :%s:" (mapconcat 'identity tags ":")))))
  799. ;;;; Inline Src Block
  800. (defun org-texinfo-inline-src-block (inline-src-block _contents _info)
  801. "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
  802. CONTENTS holds the contents of the item. INFO is a plist holding
  803. contextual information."
  804. (format "@code{%s}"
  805. (org-texinfo--sanitize-content
  806. (org-element-property :value inline-src-block))))
  807. ;;;; Inlinetask
  808. (defun org-texinfo-inlinetask (inlinetask contents info)
  809. "Transcode an INLINETASK element from Org to Texinfo.
  810. CONTENTS holds the contents of the block. INFO is a plist
  811. holding contextual information."
  812. (let ((title (org-export-data (org-element-property :title inlinetask) info))
  813. (todo (and (plist-get info :with-todo-keywords)
  814. (let ((todo (org-element-property :todo-keyword inlinetask)))
  815. (and todo (org-export-data todo info)))))
  816. (todo-type (org-element-property :todo-type inlinetask))
  817. (tags (and (plist-get info :with-tags)
  818. (org-export-get-tags inlinetask info)))
  819. (priority (and (plist-get info :with-priority)
  820. (org-element-property :priority inlinetask))))
  821. (funcall (plist-get info :texinfo-format-inlinetask-function)
  822. todo todo-type priority title tags contents)))
  823. (defun org-texinfo-format-inlinetask-default-function
  824. (todo _todo-type priority title tags contents)
  825. "Default format function for a inlinetasks.
  826. See `org-texinfo-format-inlinetask-function' for details."
  827. (let ((full-title
  828. (concat (when todo (format "@strong{%s} " todo))
  829. (when priority (format "#%c " priority))
  830. title
  831. (when tags (format ":%s:" (mapconcat #'identity tags ":"))))))
  832. (format "@center %s\n\n%s\n" full-title contents)))
  833. ;;;; Italic
  834. (defun org-texinfo-italic (_italic contents info)
  835. "Transcode ITALIC from Org to Texinfo.
  836. CONTENTS is the text with italic markup. INFO is a plist holding
  837. contextual information."
  838. (org-texinfo--text-markup contents 'italic info))
  839. ;;;; Item
  840. (defun org-texinfo-item (item contents info)
  841. "Transcode an ITEM element from Org to Texinfo.
  842. CONTENTS holds the contents of the item. INFO is a plist holding
  843. contextual information."
  844. (let* ((tag (org-element-property :tag item))
  845. (split (org-string-nw-p
  846. (org-export-read-attribute :attr_texinfo
  847. (org-element-property :parent item)
  848. :sep)))
  849. (items (and tag
  850. (let ((tag (org-export-data tag info)))
  851. (if split
  852. (split-string tag (regexp-quote split) t "[ \t\n]+")
  853. (list tag))))))
  854. (format "%s\n%s"
  855. (pcase items
  856. (`nil "@item")
  857. (`(,item) (concat "@item " item))
  858. (`(,item . ,items)
  859. (concat "@item " item "\n"
  860. (mapconcat (lambda (i) (concat "@itemx " i))
  861. items
  862. "\n"))))
  863. (or contents ""))))
  864. ;;;; Keyword
  865. (defun org-texinfo-keyword (keyword _contents info)
  866. "Transcode a KEYWORD element from Org to Texinfo.
  867. CONTENTS is nil. INFO is a plist holding contextual information."
  868. (let ((value (org-element-property :value keyword)))
  869. (pcase (org-element-property :key keyword)
  870. ("TEXINFO" value)
  871. ("CINDEX" (format "@cindex %s" value))
  872. ("FINDEX" (format "@findex %s" value))
  873. ("KINDEX" (format "@kindex %s" value))
  874. ("PINDEX" (format "@pindex %s" value))
  875. ("TINDEX" (format "@tindex %s" value))
  876. ("VINDEX" (format "@vindex %s" value))
  877. ("TOC"
  878. (cond ((string-match-p "\\<tables\\>" value)
  879. (concat "@listoffloats "
  880. (org-export-translate "Table" :utf-8 info)))
  881. ((string-match-p "\\<listings\\>" value)
  882. (concat "@listoffloats "
  883. (org-export-translate "Listing" :utf-8 info))))))))
  884. ;;;; Line Break
  885. (defun org-texinfo-line-break (_line-break _contents _info)
  886. "Transcode a LINE-BREAK object from Org to Texinfo.
  887. CONTENTS is nil. INFO is a plist holding contextual information."
  888. "@*\n")
  889. ;;;; Link
  890. (defun org-texinfo--@ref (datum description info)
  891. "Return @ref command for element or object DATUM.
  892. DESCRIPTION is the name of the section to print, as a string."
  893. (let ((node-name (org-texinfo--get-node datum info))
  894. ;; Sanitize DESCRIPTION for cross-reference use. In
  895. ;; particular, remove colons as they seem to cause (even
  896. ;; within @asis{...} to the Texinfo reader.
  897. (title (replace-regexp-in-string
  898. "[ \t]*:+" ""
  899. (replace-regexp-in-string "," "@comma{}" description))))
  900. (if (equal title node-name)
  901. (format "@ref{%s}" node-name)
  902. (format "@ref{%s, , %s}" node-name title))))
  903. (defun org-texinfo-link (link desc info)
  904. "Transcode a LINK object from Org to Texinfo.
  905. DESC is the description part of the link, or the empty string.
  906. INFO is a plist holding contextual information. See
  907. `org-export-data'."
  908. (let* ((type (org-element-property :type link))
  909. (raw-path (org-element-property :path link))
  910. ;; Ensure DESC really exists, or set it to nil.
  911. (desc (and (not (string= desc "")) desc))
  912. (path (cond
  913. ((member type '("http" "https" "ftp"))
  914. (concat type ":" raw-path))
  915. ((string= type "file") (org-export-file-uri raw-path))
  916. (t raw-path))))
  917. (cond
  918. ((org-export-custom-protocol-maybe link desc 'texinfo))
  919. ((org-export-inline-image-p link org-texinfo-inline-image-rules)
  920. (org-texinfo--inline-image link info))
  921. ((equal type "radio")
  922. (let ((destination (org-export-resolve-radio-link link info)))
  923. (if (not destination) desc
  924. (org-texinfo--@ref destination desc info))))
  925. ((member type '("custom-id" "id" "fuzzy"))
  926. (let ((destination
  927. (if (equal type "fuzzy")
  928. (org-export-resolve-fuzzy-link link info)
  929. (org-export-resolve-id-link link info))))
  930. (pcase (org-element-type destination)
  931. (`nil
  932. (format org-texinfo-link-with-unknown-path-format
  933. (org-texinfo--sanitize-content path)))
  934. ;; Id link points to an external file.
  935. (`plain-text
  936. (if desc (format "@uref{file://%s,%s}" destination desc)
  937. (format "@uref{file://%s}" destination)))
  938. ((or `headline
  939. ;; Targets within headlines cannot be turned into
  940. ;; @anchor{}, so we refer to the headline parent
  941. ;; directly.
  942. (and `target
  943. (guard (eq 'headline
  944. (org-element-type
  945. (org-element-property :parent destination))))))
  946. (let ((headline (org-element-lineage destination '(headline) t)))
  947. (org-texinfo--@ref
  948. headline
  949. (or desc (org-texinfo--sanitize-title
  950. (org-element-property :title headline) info))
  951. info)))
  952. (_
  953. (org-texinfo--@ref
  954. destination
  955. (or desc
  956. (pcase (org-export-get-ordinal destination info)
  957. ((and (pred integerp) n) (number-to-string n))
  958. ((and (pred consp) n) (mapconcat #'number-to-string n "."))
  959. (_ "???"))) ;cannot guess the description
  960. info)))))
  961. ((string= type "mailto")
  962. (format "@email{%s}"
  963. (concat (org-texinfo--sanitize-content path)
  964. (and desc (concat ", " desc)))))
  965. ;; External link with a description part.
  966. ((and path desc) (format "@uref{%s, %s}" path desc))
  967. ;; External link without a description part.
  968. (path (format "@uref{%s}" path))
  969. ;; No path, only description. Try to do something useful.
  970. (t
  971. (format (plist-get info :texinfo-link-with-unknown-path-format) desc)))))
  972. (defun org-texinfo--inline-image (link info)
  973. "Return Texinfo code for an inline image.
  974. LINK is the link pointing to the inline image. INFO is the
  975. current state of the export, as a plist."
  976. (let* ((parent (org-export-get-parent-element link))
  977. (label (and (org-element-property :name parent)
  978. (org-texinfo--get-node parent info)))
  979. (caption (org-export-get-caption parent))
  980. (shortcaption (org-export-get-caption parent t))
  981. (path (org-element-property :path link))
  982. (filename
  983. (file-name-sans-extension
  984. (if (file-name-absolute-p path) (expand-file-name path) path)))
  985. (extension (file-name-extension path))
  986. (attributes (org-export-read-attribute :attr_texinfo parent))
  987. (height (or (plist-get attributes :height) ""))
  988. (width (or (plist-get attributes :width) ""))
  989. (alt (or (plist-get attributes :alt) ""))
  990. (image (format "@image{%s,%s,%s,%s,%s}"
  991. filename width height alt extension)))
  992. (cond ((or caption shortcaption)
  993. (org-texinfo--wrap-float image
  994. info
  995. (org-export-translate "Figure" :utf-8 info)
  996. label
  997. caption
  998. shortcaption))
  999. (label (concat "@anchor{" label "}\n" image))
  1000. (t image))))
  1001. ;;;; Menu
  1002. (defun org-texinfo-make-menu (scope info &optional master)
  1003. "Create the menu for inclusion in the Texinfo document.
  1004. SCOPE is a headline or a full parse tree. INFO is the
  1005. communication channel, as a plist.
  1006. When optional argument MASTER is non-nil, generate a master menu,
  1007. including detailed node listing."
  1008. (let ((menu (org-texinfo--build-menu scope info)))
  1009. (when (org-string-nw-p menu)
  1010. (org-element-normalize-string
  1011. (format
  1012. "@menu\n%s@end menu"
  1013. (concat menu
  1014. (when master
  1015. (let ((detailmenu
  1016. (org-texinfo--build-menu
  1017. scope info
  1018. (let ((toc-depth (plist-get info :with-toc)))
  1019. (if (wholenump toc-depth) toc-depth
  1020. org-texinfo-max-toc-depth)))))
  1021. (when (org-string-nw-p detailmenu)
  1022. (concat "\n@detailmenu\n"
  1023. "--- The Detailed Node Listing ---\n\n"
  1024. detailmenu
  1025. "@end detailmenu\n"))))))))))
  1026. (defun org-texinfo--build-menu (scope info &optional level)
  1027. "Build menu for entries within SCOPE.
  1028. SCOPE is a headline or a full parse tree. INFO is a plist
  1029. containing contextual information. When optional argument LEVEL
  1030. is an integer, build the menu recursively, down to this depth."
  1031. (cond
  1032. ((not level)
  1033. (org-texinfo--format-entries (org-texinfo--menu-entries scope info) info))
  1034. ((zerop level) nil)
  1035. (t
  1036. (org-element-normalize-string
  1037. (mapconcat
  1038. (lambda (h)
  1039. (let ((entries (org-texinfo--menu-entries h info)))
  1040. (when entries
  1041. (concat
  1042. (format "%s\n\n%s\n"
  1043. (org-export-data (org-export-get-alt-title h info) info)
  1044. (org-texinfo--format-entries entries info))
  1045. (org-texinfo--build-menu h info (1- level))))))
  1046. (org-texinfo--menu-entries scope info) "\n")))))
  1047. (defun org-texinfo--format-entries (entries info)
  1048. "Format all direct menu entries in SCOPE, as a string.
  1049. SCOPE is either a headline or a full Org document. INFO is
  1050. a plist containing contextual information."
  1051. (org-element-normalize-string
  1052. (mapconcat
  1053. (lambda (h)
  1054. (let* ((title
  1055. ;; Colons are used as a separator between title and node
  1056. ;; name. Remove them.
  1057. (replace-regexp-in-string
  1058. "[ \t]+:+" ""
  1059. (org-texinfo--sanitize-title
  1060. (org-export-get-alt-title h info) info)))
  1061. (node (org-texinfo--get-node h info))
  1062. (entry (concat "* " title ":"
  1063. (if (string= title node) ":"
  1064. (concat " " node ". "))))
  1065. (desc (org-element-property :DESCRIPTION h)))
  1066. (if (not desc) entry
  1067. (format (format "%%-%ds %%s" org-texinfo-node-description-column)
  1068. entry desc))))
  1069. entries "\n")))
  1070. (defun org-texinfo--menu-entries (scope info)
  1071. "List direct children in SCOPE needing a menu entry.
  1072. SCOPE is a headline or a full parse tree. INFO is a plist
  1073. holding contextual information."
  1074. (let* ((cache (or (plist-get info :texinfo-entries-cache)
  1075. (plist-get (plist-put info :texinfo-entries-cache
  1076. (make-hash-table :test #'eq))
  1077. :texinfo-entries-cache)))
  1078. (cached-entries (gethash scope cache 'no-cache)))
  1079. (if (not (eq cached-entries 'no-cache)) cached-entries
  1080. (puthash scope
  1081. (cl-remove-if
  1082. (lambda (h)
  1083. (org-not-nil (org-export-get-node-property :COPYING h t)))
  1084. (org-export-collect-headlines info 1 scope))
  1085. cache))))
  1086. ;;;; Node Property
  1087. (defun org-texinfo-node-property (node-property _contents _info)
  1088. "Transcode a NODE-PROPERTY element from Org to Texinfo.
  1089. CONTENTS is nil. INFO is a plist holding contextual
  1090. information."
  1091. (format "%s:%s"
  1092. (org-element-property :key node-property)
  1093. (let ((value (org-element-property :value node-property)))
  1094. (if value (concat " " value) ""))))
  1095. ;;;; Paragraph
  1096. (defun org-texinfo-paragraph (_paragraph contents _info)
  1097. "Transcode a PARAGRAPH element from Org to Texinfo.
  1098. CONTENTS is the contents of the paragraph, as a string. INFO is
  1099. the plist used as a communication channel."
  1100. contents)
  1101. ;;;; Plain List
  1102. (defun org-texinfo-plain-list (plain-list contents info)
  1103. "Transcode a PLAIN-LIST element from Org to Texinfo.
  1104. CONTENTS is the contents of the list. INFO is a plist holding
  1105. contextual information."
  1106. (let* ((attr (org-export-read-attribute :attr_texinfo plain-list))
  1107. (indic (let ((i (or (plist-get attr :indic)
  1108. (plist-get info :texinfo-table-default-markup))))
  1109. ;; Allow indicating commands with missing @ sign.
  1110. (if (string-prefix-p "@" i) i (concat "@" i))))
  1111. (table-type (plist-get attr :table-type))
  1112. (type (org-element-property :type plain-list))
  1113. (list-type (cond
  1114. ((eq type 'ordered) "enumerate")
  1115. ((eq type 'unordered) "itemize")
  1116. ((member table-type '("ftable" "vtable")) table-type)
  1117. (t "table"))))
  1118. (format "@%s\n%s@end %s"
  1119. (if (eq type 'descriptive) (concat list-type " " indic) list-type)
  1120. contents
  1121. list-type)))
  1122. ;;;; Plain Text
  1123. (defun org-texinfo-plain-text (text info)
  1124. "Transcode a TEXT string from Org to Texinfo.
  1125. TEXT is the string to transcode. INFO is a plist holding
  1126. contextual information."
  1127. ;; First protect @, { and }.
  1128. (let ((output (org-texinfo--sanitize-content text)))
  1129. ;; Activate smart quotes. Be sure to provide original TEXT string
  1130. ;; since OUTPUT may have been modified.
  1131. (when (plist-get info :with-smart-quotes)
  1132. (setq output
  1133. (org-export-activate-smart-quotes output :texinfo info text)))
  1134. ;; LaTeX into @LaTeX{} and TeX into @TeX{}
  1135. (let ((case-fold-search nil))
  1136. (setq output (replace-regexp-in-string "\\(?:La\\)?TeX" "@\\&{}" output)))
  1137. ;; Convert special strings.
  1138. (when (plist-get info :with-special-strings)
  1139. (setq output
  1140. (replace-regexp-in-string
  1141. "\\.\\.\\." "@dots{}"
  1142. (replace-regexp-in-string "\\\\-" "@-" output))))
  1143. ;; Handle break preservation if required.
  1144. (when (plist-get info :preserve-breaks)
  1145. (setq output (replace-regexp-in-string
  1146. "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output)))
  1147. ;; Return value.
  1148. output))
  1149. ;;;; Planning
  1150. (defun org-texinfo-planning (planning _contents info)
  1151. "Transcode a PLANNING element from Org to Texinfo.
  1152. CONTENTS is nil. INFO is a plist holding contextual
  1153. information."
  1154. (concat
  1155. "@noindent"
  1156. (mapconcat
  1157. 'identity
  1158. (delq nil
  1159. (list
  1160. (let ((closed (org-element-property :closed planning)))
  1161. (when closed
  1162. (concat
  1163. (format "@strong{%s} " org-closed-string)
  1164. (format (plist-get info :texinfo-inactive-timestamp-format)
  1165. (org-timestamp-translate closed)))))
  1166. (let ((deadline (org-element-property :deadline planning)))
  1167. (when deadline
  1168. (concat
  1169. (format "@strong{%s} " org-deadline-string)
  1170. (format (plist-get info :texinfo-active-timestamp-format)
  1171. (org-timestamp-translate deadline)))))
  1172. (let ((scheduled (org-element-property :scheduled planning)))
  1173. (when scheduled
  1174. (concat
  1175. (format "@strong{%s} " org-scheduled-string)
  1176. (format (plist-get info :texinfo-active-timestamp-format)
  1177. (org-timestamp-translate scheduled)))))))
  1178. " ")
  1179. "@*"))
  1180. ;;;; Property Drawer
  1181. (defun org-texinfo-property-drawer (_property-drawer contents _info)
  1182. "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
  1183. CONTENTS holds the contents of the drawer. INFO is a plist
  1184. holding contextual information."
  1185. (and (org-string-nw-p contents)
  1186. (format "@verbatim\n%s@end verbatim" contents)))
  1187. ;;;; Quote Block
  1188. (defun org-texinfo-quote-block (quote-block contents _info)
  1189. "Transcode a QUOTE-BLOCK element from Org to Texinfo.
  1190. CONTENTS holds the contents of the block. INFO is a plist
  1191. holding contextual information."
  1192. (let* ((title (org-element-property :name quote-block))
  1193. (start-quote (concat "@quotation"
  1194. (if title
  1195. (format " %s" title)))))
  1196. (format "%s\n%s@end quotation" start-quote contents)))
  1197. ;;;; Radio Target
  1198. (defun org-texinfo-radio-target (radio-target text info)
  1199. "Transcode a RADIO-TARGET object from Org to Texinfo.
  1200. TEXT is the text of the target. INFO is a plist holding
  1201. contextual information."
  1202. (format "@anchor{%s}%s"
  1203. (org-texinfo--get-node radio-target info)
  1204. text))
  1205. ;;;; Section
  1206. (defun org-texinfo-section (section contents info)
  1207. "Transcode a SECTION element from Org to Texinfo.
  1208. CONTENTS holds the contents of the section. INFO is a plist
  1209. holding contextual information."
  1210. (let ((parent (org-export-get-parent-headline section)))
  1211. (when (and parent (not (org-export-excluded-from-toc-p parent info)))
  1212. (org-trim (concat contents "\n" (org-texinfo-make-menu parent info))))))
  1213. ;;;; Special Block
  1214. (defun org-texinfo-special-block (special-block contents _info)
  1215. "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
  1216. CONTENTS holds the contents of the block. INFO is a plist used
  1217. as a communication channel."
  1218. (let ((opt (org-export-read-attribute :attr_texinfo special-block :options))
  1219. (type (org-element-property :type special-block)))
  1220. (format "@%s%s\n%s@end %s"
  1221. type
  1222. (if opt (concat " " opt) "")
  1223. (or contents "")
  1224. type)))
  1225. ;;;; Src Block
  1226. (defun org-texinfo-src-block (src-block _contents info)
  1227. "Transcode a SRC-BLOCK element from Org to Texinfo.
  1228. CONTENTS holds the contents of the item. INFO is a plist holding
  1229. contextual information."
  1230. (let* ((lisp (string-match-p "lisp"
  1231. (org-element-property :language src-block)))
  1232. (code (org-texinfo--sanitize-content
  1233. (org-export-format-code-default src-block info)))
  1234. (value (format
  1235. (if lisp "@lisp\n%s@end lisp" "@example\n%s@end example")
  1236. code))
  1237. (caption (org-export-get-caption src-block))
  1238. (shortcaption (org-export-get-caption src-block t)))
  1239. (if (not (or caption shortcaption)) value
  1240. (org-texinfo--wrap-float value
  1241. info
  1242. (org-export-translate "Listing" :utf-8 info)
  1243. (org-texinfo--get-node src-block info)
  1244. caption
  1245. shortcaption))))
  1246. ;;;; Statistics Cookie
  1247. (defun org-texinfo-statistics-cookie (statistics-cookie _contents _info)
  1248. "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
  1249. CONTENTS is nil. INFO is a plist holding contextual information."
  1250. (org-element-property :value statistics-cookie))
  1251. ;;;; Strike-through
  1252. (defun org-texinfo-strike-through (_strike-through contents info)
  1253. "Transcode STRIKE-THROUGH from Org to Texinfo.
  1254. CONTENTS is the text with strike-through markup. INFO is a plist
  1255. holding contextual information."
  1256. (org-texinfo--text-markup contents 'strike-through info))
  1257. ;;;; Subscript
  1258. (defun org-texinfo-subscript (_subscript contents _info)
  1259. "Transcode a SUBSCRIPT object from Org to Texinfo.
  1260. CONTENTS is the contents of the object. INFO is a plist holding
  1261. contextual information."
  1262. (format "@math{_%s}" contents))
  1263. ;;;; Superscript
  1264. (defun org-texinfo-superscript (_superscript contents _info)
  1265. "Transcode a SUPERSCRIPT object from Org to Texinfo.
  1266. CONTENTS is the contents of the object. INFO is a plist holding
  1267. contextual information."
  1268. (format "@math{^%s}" contents))
  1269. ;;;; Table
  1270. (defun org-texinfo-table (table contents info)
  1271. "Transcode a TABLE element from Org to Texinfo.
  1272. CONTENTS is the contents of the table. INFO is a plist holding
  1273. contextual information."
  1274. (if (eq (org-element-property :type table) 'table.el)
  1275. (format "@verbatim\n%s@end verbatim"
  1276. (org-element-normalize-string
  1277. (org-element-property :value table)))
  1278. (let* ((col-width (org-export-read-attribute :attr_texinfo table :columns))
  1279. (columns
  1280. (if col-width (format "@columnfractions %s" col-width)
  1281. (org-texinfo-table-column-widths table info)))
  1282. (caption (org-export-get-caption table))
  1283. (shortcaption (org-export-get-caption table t))
  1284. (table-str (format "@multitable %s\n%s@end multitable"
  1285. columns
  1286. contents)))
  1287. (if (not (or caption shortcaption)) table-str
  1288. (org-texinfo--wrap-float table-str
  1289. info
  1290. (org-export-translate "Table" :utf-8 info)
  1291. (org-texinfo--get-node table info)
  1292. caption
  1293. shortcaption)))))
  1294. (defun org-texinfo-table-column-widths (table info)
  1295. "Determine the largest table cell in each column to process alignment.
  1296. TABLE is the table element to transcode. INFO is a plist used as
  1297. a communication channel."
  1298. (let ((widths (make-vector (cdr (org-export-table-dimensions table info)) 0)))
  1299. (org-element-map table 'table-row
  1300. (lambda (row)
  1301. (let ((idx 0))
  1302. (org-element-map row 'table-cell
  1303. (lambda (cell)
  1304. ;; Length of the cell in the original buffer is only an
  1305. ;; approximation of the length of the cell in the
  1306. ;; output. It can sometimes fail (e.g. it considers
  1307. ;; "/a/" being larger than "ab").
  1308. (let ((w (- (org-element-property :contents-end cell)
  1309. (org-element-property :contents-begin cell))))
  1310. (aset widths idx (max w (aref widths idx))))
  1311. (cl-incf idx))
  1312. info)))
  1313. info)
  1314. (format "{%s}" (mapconcat (lambda (w) (make-string w ?a)) widths "} {"))))
  1315. ;;;; Table Cell
  1316. (defun org-texinfo-table-cell (table-cell contents info)
  1317. "Transcode a TABLE-CELL element from Org to Texinfo.
  1318. CONTENTS is the cell contents. INFO is a plist used as
  1319. a communication channel."
  1320. (concat
  1321. (let ((scientific-notation
  1322. (plist-get info :texinfo-table-scientific-notation)))
  1323. (if (and contents
  1324. scientific-notation
  1325. (string-match orgtbl-exp-regexp contents))
  1326. ;; Use appropriate format string for scientific notation.
  1327. (format scientific-notation
  1328. (match-string 1 contents)
  1329. (match-string 2 contents))
  1330. contents))
  1331. (when (org-export-get-next-element table-cell info) "\n@tab ")))
  1332. ;;;; Table Row
  1333. (defun org-texinfo-table-row (table-row contents info)
  1334. "Transcode a TABLE-ROW element from Org to Texinfo.
  1335. CONTENTS is the contents of the row. INFO is a plist used as
  1336. a communication channel."
  1337. ;; Rules are ignored since table separators are deduced from
  1338. ;; borders of the current row.
  1339. (when (eq (org-element-property :type table-row) 'standard)
  1340. (let ((rowgroup-tag
  1341. (if (and (= 1 (org-export-table-row-group table-row info))
  1342. (org-export-table-has-header-p
  1343. (org-export-get-parent-table table-row) info))
  1344. "@headitem "
  1345. "@item ")))
  1346. (concat rowgroup-tag contents "\n"))))
  1347. ;;;; Target
  1348. (defun org-texinfo-target (target _contents info)
  1349. "Transcode a TARGET object from Org to Texinfo.
  1350. CONTENTS is nil. INFO is a plist holding contextual
  1351. information."
  1352. (format "@anchor{%s}" (org-texinfo--get-node target info)))
  1353. ;;;; Timestamp
  1354. (defun org-texinfo-timestamp (timestamp _contents info)
  1355. "Transcode a TIMESTAMP object from Org to Texinfo.
  1356. CONTENTS is nil. INFO is a plist holding contextual
  1357. information."
  1358. (let ((value (org-texinfo-plain-text
  1359. (org-timestamp-translate timestamp) info)))
  1360. (pcase (org-element-property :type timestamp)
  1361. ((or `active `active-range)
  1362. (format (plist-get info :texinfo-active-timestamp-format) value))
  1363. ((or `inactive `inactive-range)
  1364. (format (plist-get info :texinfo-inactive-timestamp-format) value))
  1365. (_ (format (plist-get info :texinfo-diary-timestamp-format) value)))))
  1366. ;;;; Underline
  1367. (defun org-texinfo-underline (_underline contents info)
  1368. "Transcode UNDERLINE from Org to Texinfo.
  1369. CONTENTS is the text with underline markup. INFO is a plist
  1370. holding contextual information."
  1371. (org-texinfo--text-markup contents 'underline info))
  1372. ;;;; Verbatim
  1373. (defun org-texinfo-verbatim (verbatim _contents info)
  1374. "Transcode a VERBATIM object from Org to Texinfo.
  1375. CONTENTS is nil. INFO is a plist used as a communication
  1376. channel."
  1377. (org-texinfo--text-markup
  1378. (org-element-property :value verbatim) 'verbatim info))
  1379. ;;;; Verse Block
  1380. (defun org-texinfo-verse-block (_verse-block contents _info)
  1381. "Transcode a VERSE-BLOCK element from Org to Texinfo.
  1382. CONTENTS is verse block contents. INFO is a plist holding
  1383. contextual information."
  1384. (format "@display\n%s@end display" contents))
  1385. ;;; Interactive functions
  1386. ;;;###autoload
  1387. (defun org-texinfo-export-to-texinfo
  1388. (&optional async subtreep visible-only body-only ext-plist)
  1389. "Export current buffer to a Texinfo file.
  1390. If narrowing is active in the current buffer, only export its
  1391. narrowed part.
  1392. If a region is active, export that region.
  1393. A non-nil optional argument ASYNC means the process should happen
  1394. asynchronously. The resulting file should be accessible through
  1395. the `org-export-stack' interface.
  1396. When optional argument SUBTREEP is non-nil, export the sub-tree
  1397. at point, extracting information from the headline properties
  1398. first.
  1399. When optional argument VISIBLE-ONLY is non-nil, don't export
  1400. contents of hidden elements.
  1401. When optional argument BODY-ONLY is non-nil, only write code
  1402. between \"\\begin{document}\" and \"\\end{document}\".
  1403. EXT-PLIST, when provided, is a property list with external
  1404. parameters overriding Org default settings, but still inferior to
  1405. file-local settings.
  1406. Return output file's name."
  1407. (interactive)
  1408. (let ((outfile (org-export-output-file-name ".texi" subtreep))
  1409. (org-export-coding-system org-texinfo-coding-system))
  1410. (org-export-to-file 'texinfo outfile
  1411. async subtreep visible-only body-only ext-plist)))
  1412. ;;;###autoload
  1413. (defun org-texinfo-export-to-info
  1414. (&optional async subtreep visible-only body-only ext-plist)
  1415. "Export current buffer to Texinfo then process through to INFO.
  1416. If narrowing is active in the current buffer, only export its
  1417. narrowed part.
  1418. If a region is active, export that region.
  1419. A non-nil optional argument ASYNC means the process should happen
  1420. asynchronously. The resulting file should be accessible through
  1421. the `org-export-stack' interface.
  1422. When optional argument SUBTREEP is non-nil, export the sub-tree
  1423. at point, extracting information from the headline properties
  1424. first.
  1425. When optional argument VISIBLE-ONLY is non-nil, don't export
  1426. contents of hidden elements.
  1427. When optional argument BODY-ONLY is non-nil, only write code
  1428. between \"\\begin{document}\" and \"\\end{document}\".
  1429. EXT-PLIST, when provided, is a property list with external
  1430. parameters overriding Org default settings, but still inferior to
  1431. file-local settings.
  1432. When optional argument PUB-DIR is set, use it as the publishing
  1433. directory.
  1434. Return INFO file's name."
  1435. (interactive)
  1436. (let ((outfile (org-export-output-file-name ".texi" subtreep))
  1437. (org-export-coding-system org-texinfo-coding-system))
  1438. (org-export-to-file 'texinfo outfile
  1439. async subtreep visible-only body-only ext-plist
  1440. (lambda (file) (org-texinfo-compile file)))))
  1441. ;;;###autoload
  1442. (defun org-texinfo-publish-to-texinfo (plist filename pub-dir)
  1443. "Publish an org file to Texinfo.
  1444. FILENAME is the filename of the Org file to be published. PLIST
  1445. is the property list for the given project. PUB-DIR is the
  1446. publishing directory.
  1447. Return output file name."
  1448. (org-publish-org-to 'texinfo filename ".texi" plist pub-dir))
  1449. ;;;###autoload
  1450. (defun org-texinfo-convert-region-to-texinfo ()
  1451. "Assume the current region has Org syntax, and convert it to Texinfo.
  1452. This can be used in any buffer. For example, you can write an
  1453. itemized list in Org syntax in an Texinfo buffer and use this
  1454. command to convert it."
  1455. (interactive)
  1456. (org-export-replace-region-by 'texinfo))
  1457. (defun org-texinfo-compile (file)
  1458. "Compile a texinfo file.
  1459. FILE is the name of the file being compiled. Processing is done
  1460. through the command specified in `org-texinfo-info-process',
  1461. which see. Output is redirected to \"*Org INFO Texinfo Output*\"
  1462. buffer.
  1463. Return INFO file name or an error if it couldn't be produced."
  1464. (message "Processing Texinfo file %s..." file)
  1465. (let* ((log-name "*Org INFO Texinfo Output*")
  1466. (log (get-buffer-create log-name))
  1467. (output
  1468. (org-compile-file file org-texinfo-info-process "info"
  1469. (format "See %S for details" log-name)
  1470. log)))
  1471. (when org-texinfo-remove-logfiles
  1472. (let ((base (file-name-sans-extension output)))
  1473. (dolist (ext org-texinfo-logfiles-extensions)
  1474. (let ((file (concat base "." ext)))
  1475. (when (file-exists-p file) (delete-file file))))))
  1476. (message "Process completed.")
  1477. output))
  1478. (provide 'ox-texinfo)
  1479. ;; Local variables:
  1480. ;; generated-autoload-file: "org-loaddefs.el"
  1481. ;; End:
  1482. ;;; ox-texinfo.el ends here