ox-texinfo.el 61 KB

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