ox-texinfo.el 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729
  1. ;;; ox-texinfo.el --- Texinfo Back-End for Org Export Engine -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2012-2020 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. ;;; Function Declarations
  23. (declare-function org-attach-link-expand "org-attach" (link &optional buffer-or-name))
  24. (defvar orgtbl-exp-regexp)
  25. ;;; Define Back-End
  26. (org-export-define-backend 'texinfo
  27. '((bold . org-texinfo-bold)
  28. (center-block . org-texinfo-center-block)
  29. (clock . org-texinfo-clock)
  30. (code . org-texinfo-code)
  31. (drawer . org-texinfo-drawer)
  32. (dynamic-block . org-texinfo-dynamic-block)
  33. (entity . org-texinfo-entity)
  34. (example-block . org-texinfo-example-block)
  35. (export-block . org-texinfo-export-block)
  36. (export-snippet . org-texinfo-export-snippet)
  37. (fixed-width . org-texinfo-fixed-width)
  38. (footnote-definition . org-texinfo-footnote-definition)
  39. (footnote-reference . org-texinfo-footnote-reference)
  40. (headline . org-texinfo-headline)
  41. (inline-src-block . org-texinfo-inline-src-block)
  42. (inlinetask . org-texinfo-inlinetask)
  43. (italic . org-texinfo-italic)
  44. (item . org-texinfo-item)
  45. (keyword . org-texinfo-keyword)
  46. (line-break . org-texinfo-line-break)
  47. (link . org-texinfo-link)
  48. (node-property . org-texinfo-node-property)
  49. (paragraph . org-texinfo-paragraph)
  50. (plain-list . org-texinfo-plain-list)
  51. (plain-text . org-texinfo-plain-text)
  52. (planning . org-texinfo-planning)
  53. (property-drawer . org-texinfo-property-drawer)
  54. (quote-block . org-texinfo-quote-block)
  55. (radio-target . org-texinfo-radio-target)
  56. (section . org-texinfo-section)
  57. (special-block . org-texinfo-special-block)
  58. (src-block . org-texinfo-src-block)
  59. (statistics-cookie . org-texinfo-statistics-cookie)
  60. (strike-through . org-texinfo-strike-through)
  61. (subscript . org-texinfo-subscript)
  62. (superscript . org-texinfo-superscript)
  63. (table . org-texinfo-table)
  64. (table-cell . org-texinfo-table-cell)
  65. (table-row . org-texinfo-table-row)
  66. (target . org-texinfo-target)
  67. (template . org-texinfo-template)
  68. (timestamp . org-texinfo-timestamp)
  69. (underline . org-texinfo-underline)
  70. (verbatim . org-texinfo-verbatim)
  71. (verse-block . org-texinfo-verse-block))
  72. :filters-alist
  73. '((:filter-headline . org-texinfo--filter-section-blank-lines)
  74. (:filter-parse-tree . org-texinfo--normalize-headlines)
  75. (:filter-section . org-texinfo--filter-section-blank-lines)
  76. (:filter-final-output . org-texinfo--untabify))
  77. :menu-entry
  78. '(?i "Export to Texinfo"
  79. ((?t "As TEXI file" org-texinfo-export-to-texinfo)
  80. (?i "As INFO file" org-texinfo-export-to-info)
  81. (?o "As INFO file and open"
  82. (lambda (a s v b)
  83. (if a (org-texinfo-export-to-info t s v b)
  84. (org-open-file (org-texinfo-export-to-info nil s v b)))))))
  85. :options-alist
  86. '((:texinfo-filename "TEXINFO_FILENAME" nil nil t)
  87. (:texinfo-class "TEXINFO_CLASS" nil org-texinfo-default-class t)
  88. (:texinfo-header "TEXINFO_HEADER" nil nil newline)
  89. (:texinfo-post-header "TEXINFO_POST_HEADER" nil nil newline)
  90. (:subtitle "SUBTITLE" nil nil parse)
  91. (:subauthor "SUBAUTHOR" nil nil newline)
  92. (:texinfo-dircat "TEXINFO_DIR_CATEGORY" nil nil t)
  93. (:texinfo-dirtitle "TEXINFO_DIR_TITLE" nil nil t)
  94. (:texinfo-dirdesc "TEXINFO_DIR_DESC" nil nil t)
  95. (:texinfo-printed-title "TEXINFO_PRINTED_TITLE" nil nil t)
  96. ;; Other variables.
  97. (:texinfo-classes nil nil org-texinfo-classes)
  98. (:texinfo-format-headline-function nil nil org-texinfo-format-headline-function)
  99. (:texinfo-node-description-column nil nil org-texinfo-node-description-column)
  100. (:texinfo-active-timestamp-format nil nil org-texinfo-active-timestamp-format)
  101. (:texinfo-inactive-timestamp-format nil nil org-texinfo-inactive-timestamp-format)
  102. (:texinfo-diary-timestamp-format nil nil org-texinfo-diary-timestamp-format)
  103. (:texinfo-link-with-unknown-path-format nil nil org-texinfo-link-with-unknown-path-format)
  104. (:texinfo-tables-verbatim nil nil org-texinfo-tables-verbatim)
  105. (:texinfo-table-scientific-notation nil nil org-texinfo-table-scientific-notation)
  106. (:texinfo-table-default-markup nil nil org-texinfo-table-default-markup)
  107. (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist)
  108. (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function)
  109. (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function)))
  110. ;;; User Configurable Variables
  111. (defgroup org-export-texinfo nil
  112. "Options for exporting Org mode files to Texinfo."
  113. :tag "Org Export Texinfo"
  114. :version "24.4"
  115. :package-version '(Org . "8.0")
  116. :group 'org-export)
  117. ;;;; Preamble
  118. (defcustom org-texinfo-coding-system nil
  119. "Default document encoding for Texinfo output.
  120. If nil it will default to `buffer-file-coding-system'."
  121. :group 'org-export-texinfo
  122. :type 'coding-system)
  123. (defcustom org-texinfo-default-class "info"
  124. "The default Texinfo class."
  125. :group 'org-export-texinfo
  126. :type '(string :tag "Texinfo class"))
  127. (defcustom org-texinfo-classes
  128. '(("info"
  129. "@documentencoding AUTO\n@documentlanguage AUTO"
  130. ("@chapter %s" "@unnumbered %s" "@chapheading %s" "@appendix %s")
  131. ("@section %s" "@unnumberedsec %s" "@heading %s" "@appendixsec %s")
  132. ("@subsection %s" "@unnumberedsubsec %s" "@subheading %s"
  133. "@appendixsubsec %s")
  134. ("@subsubsection %s" "@unnumberedsubsubsec %s" "@subsubheading %s"
  135. "@appendixsubsubsec %s")))
  136. "Alist of Texinfo classes and associated header and structure.
  137. If #+TEXINFO_CLASS is set in the buffer, use its value and the
  138. associated information. Here is the structure of a class
  139. definition:
  140. (class-name
  141. header-string
  142. (numbered-1 unnumbered-1 unnumbered-no-toc-1 appendix-1)
  143. (numbered-2 unnumbered-2 unnumbered-no-toc-2 appendix-2)
  144. ...)
  145. The header string
  146. -----------------
  147. The header string is inserted in the header of the generated
  148. document, right after \"@setfilename\" and \"@settitle\"
  149. commands.
  150. If it contains the special string
  151. \"@documentencoding AUTO\"
  152. \"AUTO\" will be replaced with an appropriate coding system. See
  153. `org-texinfo-coding-system' for more information. Likewise, if
  154. the string contains the special string
  155. \"@documentlanguage AUTO\"
  156. \"AUTO\" will be replaced with the language defined in the
  157. buffer, through #+LANGUAGE keyword, or globally, with
  158. `org-export-default-language', which see.
  159. The sectioning structure
  160. ------------------------
  161. The sectioning structure of the class is given by the elements
  162. following the header string. For each sectioning level, a number
  163. of strings is specified. A %s formatter is mandatory in each
  164. section string and will be replaced by the title of the section."
  165. :group 'org-export-texinfo
  166. :version "27.1"
  167. :package-version '(Org . "9.2")
  168. :type '(repeat
  169. (list (string :tag "Texinfo class")
  170. (string :tag "Texinfo header")
  171. (repeat :tag "Levels" :inline t
  172. (choice
  173. (list :tag "Heading"
  174. (string :tag " numbered")
  175. (string :tag " unnumbered")
  176. (string :tag "unnumbered-no-toc")
  177. (string :tag " appendix")))))))
  178. ;;;; Headline
  179. (defcustom org-texinfo-format-headline-function
  180. 'org-texinfo-format-headline-default-function
  181. "Function to format headline text.
  182. This function will be called with 5 arguments:
  183. TODO the todo keyword (string or nil).
  184. TODO-TYPE the type of todo (symbol: `todo', `done', nil)
  185. PRIORITY the priority of the headline (integer or nil)
  186. TEXT the main headline text (string).
  187. TAGS the tags as a list of strings (list of strings or nil).
  188. The function result will be used in the section format string."
  189. :group 'org-export-texinfo
  190. :type 'function
  191. :version "26.1"
  192. :package-version '(Org . "8.3"))
  193. ;;;; Node listing (menu)
  194. (defcustom org-texinfo-node-description-column 32
  195. "Column at which to start the description in the node listings.
  196. If a node title is greater than this length, the description will
  197. be placed after the end of the title."
  198. :group 'org-export-texinfo
  199. :type 'integer)
  200. ;;;; Timestamps
  201. (defcustom org-texinfo-active-timestamp-format "@emph{%s}"
  202. "A printf format string to be applied to active timestamps."
  203. :group 'org-export-texinfo
  204. :type 'string)
  205. (defcustom org-texinfo-inactive-timestamp-format "@emph{%s}"
  206. "A printf format string to be applied to inactive timestamps."
  207. :group 'org-export-texinfo
  208. :type 'string)
  209. (defcustom org-texinfo-diary-timestamp-format "@emph{%s}"
  210. "A printf format string to be applied to diary timestamps."
  211. :group 'org-export-texinfo
  212. :type 'string)
  213. ;;;; Links
  214. (defcustom org-texinfo-link-with-unknown-path-format "@indicateurl{%s}"
  215. "Format string for links with unknown path type."
  216. :group 'org-export-texinfo
  217. :type 'string)
  218. ;;;; Tables
  219. (defcustom org-texinfo-tables-verbatim nil
  220. "When non-nil, tables are exported verbatim."
  221. :group 'org-export-texinfo
  222. :type 'boolean)
  223. (defcustom org-texinfo-table-scientific-notation nil
  224. "Format string to display numbers in scientific notation.
  225. The format should have \"%s\" twice, for mantissa and exponent
  226. \(i.e. \"%s\\\\times10^{%s}\").
  227. When nil, no transformation is made."
  228. :group 'org-export-texinfo
  229. :type '(choice
  230. (string :tag "Format string")
  231. (const :tag "No formatting" nil)))
  232. (defcustom org-texinfo-table-default-markup "@asis"
  233. "Default markup for first column in two-column tables.
  234. This should an indicating command, e.g., \"@code\", \"@kbd\" or
  235. \"@samp\".
  236. It can be overridden locally using the \":indic\" attribute."
  237. :group 'org-export-texinfo
  238. :type 'string
  239. :version "26.1"
  240. :package-version '(Org . "9.1")
  241. :safe #'stringp)
  242. ;;;; Text markup
  243. (defcustom org-texinfo-text-markup-alist '((bold . "@strong{%s}")
  244. (code . code)
  245. (italic . "@emph{%s}")
  246. (verbatim . samp))
  247. "Alist of Texinfo expressions to convert text markup.
  248. The key must be a symbol among `bold', `code', `italic',
  249. `strike-through', `underscore' and `verbatim'. The value is
  250. a formatting string to wrap fontified text with.
  251. Value can also be set to the following symbols: `verb', `samp'
  252. and `code'. With the first one, Org uses \"@verb\" to create
  253. a format string and selects a delimiter character that isn't in
  254. the string. For the other two, Org uses \"@samp\" or \"@code\"
  255. to typeset and protects special characters.
  256. When no association is found for a given markup, text is returned
  257. as-is."
  258. :group 'org-export-texinfo
  259. :version "26.1"
  260. :package-version '(Org . "9.1")
  261. :type 'alist
  262. :options '(bold code italic strike-through underscore verbatim))
  263. ;;;; Drawers
  264. (defcustom org-texinfo-format-drawer-function (lambda (_name contents) contents)
  265. "Function called to format a drawer in Texinfo code.
  266. The function must accept two parameters:
  267. NAME the drawer name, like \"LOGBOOK\"
  268. CONTENTS the contents of the drawer.
  269. The function should return the string to be exported.
  270. The default function simply returns the value of CONTENTS."
  271. :group 'org-export-texinfo
  272. :version "24.4"
  273. :package-version '(Org . "8.2")
  274. :type 'function)
  275. ;;;; Inlinetasks
  276. (defcustom org-texinfo-format-inlinetask-function
  277. 'org-texinfo-format-inlinetask-default-function
  278. "Function called to format an inlinetask in Texinfo code.
  279. The function must accept six parameters:
  280. TODO the todo keyword, as a string
  281. TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
  282. PRIORITY the inlinetask priority, as a string
  283. NAME the inlinetask name, as a string.
  284. TAGS the inlinetask tags, as a list of strings.
  285. CONTENTS the contents of the inlinetask, as a string.
  286. The function should return the string to be exported."
  287. :group 'org-export-texinfo
  288. :type 'function)
  289. ;;;; Compilation
  290. (defcustom org-texinfo-info-process '("makeinfo --no-split %f")
  291. "Commands to process a Texinfo file to an INFO file.
  292. This is a list of strings, each of them will be given to the
  293. shell as a command. %f in the command will be replaced by the
  294. relative file name, %F by the absolute file name, %b by the file
  295. base name (i.e. without directory and extension parts), %o by the
  296. base directory of the file and %O by the absolute file name of
  297. the output file."
  298. :group 'org-export-texinfo
  299. :version "26.1"
  300. :package-version '(Org . "9.1")
  301. :type '(repeat :tag "Shell command sequence"
  302. (string :tag "Shell command")))
  303. (defcustom org-texinfo-logfiles-extensions
  304. '("aux" "toc" "cp" "fn" "ky" "pg" "tp" "vr")
  305. "The list of file extensions to consider as Texinfo logfiles.
  306. The logfiles will be remove if `org-texinfo-remove-logfiles' is
  307. non-nil."
  308. :group 'org-export-texinfo
  309. :type '(repeat (string :tag "Extension")))
  310. (defcustom org-texinfo-remove-logfiles t
  311. "Non-nil means remove the logfiles produced by compiling a Texinfo file.
  312. By default, logfiles are files with these extensions: .aux, .toc,
  313. .cp, .fn, .ky, .pg and .tp. To define the set of logfiles to remove,
  314. set `org-texinfo-logfiles-extensions'."
  315. :group 'org-export-latex
  316. :type 'boolean)
  317. ;;; Constants
  318. (defconst org-texinfo-max-toc-depth 4
  319. "Maximum depth for creation of detailed menu listings.
  320. Beyond this depth, Texinfo will not recognize the nodes and will
  321. cause errors. Left as a constant in case this value ever
  322. changes.")
  323. (defconst org-texinfo-supported-coding-systems
  324. '("US-ASCII" "UTF-8" "ISO-8859-15" "ISO-8859-1" "ISO-8859-2" "koi8-r" "koi8-u")
  325. "List of coding systems supported by Texinfo, as strings.
  326. Specified coding system will be matched against these strings.
  327. If two strings share the same prefix (e.g. \"ISO-8859-1\" and
  328. \"ISO-8859-15\"), the most specific one has to be listed first.")
  329. (defconst org-texinfo-inline-image-rules
  330. (list (cons "file"
  331. (regexp-opt '("eps" "pdf" "png" "jpg" "jpeg" "gif" "svg")))
  332. (cons "attachment"
  333. (regexp-opt '("eps" "pdf" "png" "jpg" "jpeg" "gif" "svg"))))
  334. "Rules characterizing image files that can be inlined.")
  335. ;;; Internal Functions
  336. (defun org-texinfo--untabify (s _backend _info)
  337. "Remove TAB characters in string S."
  338. (replace-regexp-in-string "\t" (make-string tab-width ?\s) s))
  339. (defun org-texinfo--filter-section-blank-lines (headline _backend _info)
  340. "Filter controlling number of blank lines after a section."
  341. (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" "\n\n" headline))
  342. (defun org-texinfo--normalize-headlines (tree _backend info)
  343. "Normalize headlines in TREE.
  344. BACK-END is the symbol specifying back-end used for export. INFO
  345. is a plist used as a communication channel.
  346. Make sure every headline in TREE contains a section, since those
  347. are required to install a menu. Also put exactly one blank line
  348. at the end of each section.
  349. Return new tree."
  350. (org-element-map tree 'headline
  351. (lambda (hl)
  352. (org-element-put-property hl :post-blank 1)
  353. (let ((contents (org-element-contents hl)))
  354. (when contents
  355. (let ((first (org-element-map contents '(headline section)
  356. #'identity info t)))
  357. (unless (eq (org-element-type first) 'section)
  358. (apply #'org-element-set-contents
  359. hl
  360. (cons `(section (:parent ,hl)) contents)))))))
  361. info)
  362. tree)
  363. (defun org-texinfo--find-verb-separator (s)
  364. "Return a character not used in string S.
  365. This is used to choose a separator for constructs like \\verb."
  366. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  367. (cl-loop for c across ll
  368. when (not (string-match (regexp-quote (char-to-string c)) s))
  369. return (char-to-string c))))
  370. (defun org-texinfo--text-markup (text markup _info)
  371. "Format TEXT depending on MARKUP text markup.
  372. INFO is a plist used as a communication channel. See
  373. `org-texinfo-text-markup-alist' for details."
  374. (pcase (cdr (assq markup org-texinfo-text-markup-alist))
  375. (`nil text) ;no markup: return raw text
  376. (`code (format "@code{%s}" (org-texinfo--sanitize-content text)))
  377. (`samp (format "@samp{%s}" (org-texinfo--sanitize-content text)))
  378. (`verb
  379. (let ((separator (org-texinfo--find-verb-separator text)))
  380. (format "@verb{%s%s%s}" separator text separator)))
  381. ;; Else use format string.
  382. (fmt (format fmt text))))
  383. (defun org-texinfo--get-node (datum info)
  384. "Return node or anchor associated to DATUM.
  385. DATUM is a headline, a radio-target or a target. INFO is a plist
  386. used as a communication channel. The function guarantees the
  387. node or anchor name is unique."
  388. (let ((cache (plist-get info :texinfo-node-cache)))
  389. (or (cdr (assq datum cache))
  390. (let* ((salt 0)
  391. (basename
  392. (org-texinfo--sanitize-node
  393. (pcase (org-element-type datum)
  394. (`headline
  395. (org-texinfo--sanitize-title
  396. (org-export-get-alt-title datum info) info))
  397. (`radio-target
  398. (org-export-data (org-element-contents datum) info))
  399. (`target
  400. (org-element-property :value datum))
  401. (_
  402. (or (org-element-property :name datum)
  403. (org-export-get-reference datum info))))))
  404. (name basename))
  405. ;; Org exports deeper elements before their parents. If two
  406. ;; node names collide -- e.g., they have the same title --
  407. ;; within the same hierarchy, the second one would get the
  408. ;; shorter node name. This is counter-intuitive.
  409. ;; Consequently, we ensure that every parent headline get
  410. ;; its node beforehand. As a recursive operation, this
  411. ;; achieves the desired effect.
  412. (let ((parent (org-element-lineage datum '(headline))))
  413. (when (and parent (not (assq parent cache)))
  414. (org-texinfo--get-node parent info)
  415. (setq cache (plist-get info :texinfo-node-cache))))
  416. ;; Ensure NAME is unique and not reserved node name "Top".
  417. (while (or (equal name "Top") (rassoc name cache))
  418. (setq name (concat basename (format " (%d)" (cl-incf salt)))))
  419. (plist-put info :texinfo-node-cache (cons (cons datum name) cache))
  420. name))))
  421. (defun org-texinfo--sanitize-node (title)
  422. "Bend string TITLE to node line requirements.
  423. Trim string and collapse multiple whitespace characters as they
  424. are not significant. Replace leading left parenthesis, when
  425. followed by a right parenthesis, with a square bracket. Remove
  426. periods, commas and colons."
  427. (org-trim
  428. (replace-regexp-in-string
  429. "[ \t]+" " "
  430. (replace-regexp-in-string
  431. "[:,.]" ""
  432. (replace-regexp-in-string "\\`(\\(.*?)\\)" "[\\1" title)))))
  433. (defun org-texinfo--sanitize-title (title info)
  434. "Make TITLE suitable as a section name.
  435. TITLE is a string or a secondary string. INFO is the current
  436. export state, as a plist."
  437. (org-export-data-with-backend
  438. title (org-export-toc-entry-backend 'texinfo) info))
  439. (defun org-texinfo--sanitize-content (text)
  440. "Escape special characters in string TEXT.
  441. Special characters are: @ { }"
  442. (replace-regexp-in-string "[@{}]" "@\\&" text))
  443. (defun org-texinfo--wrap-float (value info &optional type label caption short)
  444. "Wrap string VALUE within a @float command.
  445. INFO is the current export state, as a plist. TYPE is float
  446. type, as a string. LABEL is the cross reference label for the
  447. float, as a string. CAPTION and SHORT are, respectively, the
  448. caption and shortcaption used for the float, as secondary
  449. strings (e.g., returned by `org-export-get-caption')."
  450. (let* ((backend
  451. (org-export-toc-entry-backend 'texinfo
  452. (cons 'footnote-reference
  453. (lambda (f c i) (org-export-with-backend 'texinfo f c i)))))
  454. (short-backend
  455. (org-export-toc-entry-backend 'texinfo
  456. '(inline-src-block . ignore)
  457. '(verbatim . ignore)))
  458. (short-str
  459. (if (and short caption)
  460. (format "@shortcaption{%s}\n"
  461. (org-export-data-with-backend short short-backend info))
  462. ""))
  463. (caption-str
  464. (if (or short caption)
  465. (format "@caption{%s}\n"
  466. (org-export-data-with-backend
  467. (or caption short)
  468. (if (equal short-str "") short-backend backend)
  469. info))
  470. "")))
  471. (format "@float %s%s\n%s\n%s%s@end float"
  472. type (if label (concat "," label) "") value caption-str short-str)))
  473. ;;; Template
  474. (defun org-texinfo-template (contents info)
  475. "Return complete document string after Texinfo conversion.
  476. CONTENTS is the transcoded contents string. INFO is a plist
  477. holding export options."
  478. (let ((title (org-export-data (plist-get info :title) info))
  479. ;; Copying data is the contents of the first headline in
  480. ;; parse tree with a non-nil copying property.
  481. (copying (org-element-map (plist-get info :parse-tree) 'headline
  482. (lambda (hl)
  483. (and (org-not-nil (org-element-property :COPYING hl))
  484. (org-element-contents hl)))
  485. info t)))
  486. (concat
  487. "\\input texinfo @c -*- texinfo -*-\n"
  488. "@c %**start of header\n"
  489. (let ((file (or (org-strip-quotes (plist-get info :texinfo-filename))
  490. (let ((f (plist-get info :output-file)))
  491. (and f (concat (file-name-sans-extension f) ".info"))))))
  492. (and file (format "@setfilename %s\n" file)))
  493. (format "@settitle %s\n" title)
  494. ;; Insert class-defined header.
  495. (org-element-normalize-string
  496. (let ((header (nth 1 (assoc (plist-get info :texinfo-class)
  497. org-texinfo-classes)))
  498. (coding
  499. (catch 'coding-system
  500. (let ((case-fold-search t)
  501. (name (symbol-name (or org-texinfo-coding-system
  502. buffer-file-coding-system))))
  503. (dolist (system org-texinfo-supported-coding-systems "UTF-8")
  504. (when (string-match-p (regexp-quote system) name)
  505. (throw 'coding-system system))))))
  506. (language (plist-get info :language))
  507. (case-fold-search nil))
  508. ;; Auto coding system.
  509. (replace-regexp-in-string
  510. "^@documentencoding \\(AUTO\\)$"
  511. coding
  512. (replace-regexp-in-string
  513. "^@documentlanguage \\(AUTO\\)$" language header t nil 1)
  514. 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. (replace-regexp-in-string "\\(^\\).*?\\S-" "@center " contents nil nil 1))
  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\n@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. ;; Even if HEADLINE is using @subheading and al., leave an
  788. ;; anchor so cross-references in the Org document still work.
  789. (format (if notoc? "@anchor{%s}\n" "@node %s\n")
  790. (org-texinfo--get-node headline info))
  791. (format command full-text)
  792. contents))))))
  793. (defun org-texinfo-format-headline-default-function
  794. (todo _todo-type priority text tags)
  795. "Default format function for a headline.
  796. See `org-texinfo-format-headline-function' for details."
  797. (concat (and todo (format "@strong{%s} " todo))
  798. (and priority (format "@emph{#%s} " priority))
  799. text
  800. (and tags (concat " " (org-make-tag-string tags)))))
  801. ;;;; Inline Src Block
  802. (defun org-texinfo-inline-src-block (inline-src-block _contents _info)
  803. "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
  804. CONTENTS holds the contents of the item. INFO is a plist holding
  805. contextual information."
  806. (format "@code{%s}"
  807. (org-texinfo--sanitize-content
  808. (org-element-property :value inline-src-block))))
  809. ;;;; Inlinetask
  810. (defun org-texinfo-inlinetask (inlinetask contents info)
  811. "Transcode an INLINETASK element from Org to Texinfo.
  812. CONTENTS holds the contents of the block. INFO is a plist
  813. holding contextual information."
  814. (let ((title (org-export-data (org-element-property :title inlinetask) info))
  815. (todo (and (plist-get info :with-todo-keywords)
  816. (let ((todo (org-element-property :todo-keyword inlinetask)))
  817. (and todo (org-export-data todo info)))))
  818. (todo-type (org-element-property :todo-type inlinetask))
  819. (tags (and (plist-get info :with-tags)
  820. (org-export-get-tags inlinetask info)))
  821. (priority (and (plist-get info :with-priority)
  822. (org-element-property :priority inlinetask))))
  823. (funcall (plist-get info :texinfo-format-inlinetask-function)
  824. todo todo-type priority title tags contents)))
  825. (defun org-texinfo-format-inlinetask-default-function
  826. (todo _todo-type priority title tags contents)
  827. "Default format function for inlinetasks.
  828. See `org-texinfo-format-inlinetask-function' for details."
  829. (let ((full-title
  830. (concat (when todo (format "@strong{%s} " todo))
  831. (when priority (format "#%c " priority))
  832. title
  833. (when tags (org-make-tag-string tags)))))
  834. (format "@center %s\n\n%s\n" full-title contents)))
  835. ;;;; Italic
  836. (defun org-texinfo-italic (_italic contents info)
  837. "Transcode ITALIC from Org to Texinfo.
  838. CONTENTS is the text with italic markup. INFO is a plist holding
  839. contextual information."
  840. (org-texinfo--text-markup contents 'italic info))
  841. ;;;; Item
  842. (defun org-texinfo-item (item contents info)
  843. "Transcode an ITEM element from Org to Texinfo.
  844. CONTENTS holds the contents of the item. INFO is a plist holding
  845. contextual information."
  846. (let* ((tag (org-element-property :tag item))
  847. (split (org-string-nw-p
  848. (org-export-read-attribute :attr_texinfo
  849. (org-element-property :parent item)
  850. :sep)))
  851. (items (and tag
  852. (let ((tag (org-export-data tag info)))
  853. (if split
  854. (split-string tag (regexp-quote split) t "[ \t\n]+")
  855. (list tag))))))
  856. (format "%s\n%s"
  857. (pcase items
  858. (`nil "@item")
  859. (`(,item) (concat "@item " item))
  860. (`(,item . ,items)
  861. (concat "@item " item "\n"
  862. (mapconcat (lambda (i) (concat "@itemx " i))
  863. items
  864. "\n"))))
  865. (or contents ""))))
  866. ;;;; Keyword
  867. (defun org-texinfo-keyword (keyword _contents info)
  868. "Transcode a KEYWORD element from Org to Texinfo.
  869. CONTENTS is nil. INFO is a plist holding contextual information."
  870. (let ((value (org-element-property :value keyword)))
  871. (pcase (org-element-property :key keyword)
  872. ("TEXINFO" value)
  873. ("CINDEX" (format "@cindex %s" value))
  874. ("FINDEX" (format "@findex %s" value))
  875. ("KINDEX" (format "@kindex %s" value))
  876. ("PINDEX" (format "@pindex %s" value))
  877. ("TINDEX" (format "@tindex %s" value))
  878. ("VINDEX" (format "@vindex %s" value))
  879. ("TOC"
  880. (cond ((string-match-p "\\<tables\\>" value)
  881. (concat "@listoffloats "
  882. (org-export-translate "Table" :utf-8 info)))
  883. ((string-match-p "\\<listings\\>" value)
  884. (concat "@listoffloats "
  885. (org-export-translate "Listing" :utf-8 info))))))))
  886. ;;;; Line Break
  887. (defun org-texinfo-line-break (_line-break _contents _info)
  888. "Transcode a LINE-BREAK object from Org to Texinfo.
  889. CONTENTS is nil. INFO is a plist holding contextual information."
  890. "@*\n")
  891. ;;;; Link
  892. (defun org-texinfo--@ref (datum description info)
  893. "Return @ref command for element or object DATUM.
  894. DESCRIPTION is the printed name of the section, as a string, or
  895. nil."
  896. (let ((node-name (org-texinfo--get-node datum info))
  897. ;; Sanitize DESCRIPTION for cross-reference use. In
  898. ;; particular, remove colons as they seem to cause pain (even
  899. ;; within @asis{...}) to the Texinfo reader.
  900. (title (and description
  901. (replace-regexp-in-string
  902. "[ \t]*:+" ""
  903. (replace-regexp-in-string "," "@comma{}" description)))))
  904. (if (or (not title) (equal title node-name))
  905. (format "@ref{%s}" node-name)
  906. (format "@ref{%s, , %s}" node-name title))))
  907. (defun org-texinfo-link (link desc info)
  908. "Transcode a LINK object from Org to Texinfo.
  909. DESC is the description part of the link, or the empty string.
  910. INFO is a plist holding contextual information. See
  911. `org-export-data'."
  912. (let* ((type (org-element-property :type link))
  913. (raw-path (org-element-property :path link))
  914. ;; Ensure DESC really exists, or set it to nil.
  915. (desc (and (not (string= desc "")) desc))
  916. (path (cond
  917. ((member type '("http" "https" "ftp"))
  918. (concat type ":" raw-path))
  919. ((member type '("file" "attachment"))
  920. (when (string= type "attachment")
  921. (setq raw-path (org-attach-link-expand link)))
  922. (org-export-file-uri raw-path))
  923. (t raw-path))))
  924. (cond
  925. ((org-export-custom-protocol-maybe link desc 'texinfo))
  926. ((org-export-inline-image-p link org-texinfo-inline-image-rules)
  927. (org-texinfo--inline-image link info))
  928. ((equal type "radio")
  929. (let ((destination (org-export-resolve-radio-link link info)))
  930. (if (not destination) desc
  931. (org-texinfo--@ref destination desc info))))
  932. ((member type '("custom-id" "id" "fuzzy"))
  933. (let ((destination
  934. (if (equal type "fuzzy")
  935. (org-export-resolve-fuzzy-link link info)
  936. (org-export-resolve-id-link link info))))
  937. (pcase (org-element-type destination)
  938. (`nil
  939. (format org-texinfo-link-with-unknown-path-format
  940. (org-texinfo--sanitize-content path)))
  941. ;; Id link points to an external file.
  942. (`plain-text
  943. (if desc (format "@uref{file://%s,%s}" destination desc)
  944. (format "@uref{file://%s}" destination)))
  945. ((or `headline
  946. ;; Targets within headlines cannot be turned into
  947. ;; @anchor{}, so we refer to the headline parent
  948. ;; directly.
  949. (and `target
  950. (guard (eq 'headline
  951. (org-element-type
  952. (org-element-property :parent destination))))))
  953. (let ((headline (org-element-lineage destination '(headline) t)))
  954. (org-texinfo--@ref headline desc info)))
  955. (_ (org-texinfo--@ref destination desc info)))))
  956. ((string= type "mailto")
  957. (format "@email{%s}"
  958. (concat (org-texinfo--sanitize-content path)
  959. (and desc (concat ", " desc)))))
  960. ;; External link with a description part.
  961. ((and path desc) (format "@uref{%s, %s}" path desc))
  962. ;; External link without a description part.
  963. (path (format "@uref{%s}" path))
  964. ;; No path, only description. Try to do something useful.
  965. (t
  966. (format (plist-get info :texinfo-link-with-unknown-path-format) desc)))))
  967. (defun org-texinfo--inline-image (link info)
  968. "Return Texinfo code for an inline image.
  969. LINK is the link pointing to the inline image. INFO is the
  970. current state of the export, as a plist."
  971. (let* ((parent (org-export-get-parent-element link))
  972. (label (and (org-element-property :name parent)
  973. (org-texinfo--get-node parent info)))
  974. (caption (org-export-get-caption parent))
  975. (shortcaption (org-export-get-caption parent t))
  976. (path (org-element-property :path link))
  977. (filename
  978. (file-name-sans-extension
  979. (if (file-name-absolute-p path) (expand-file-name path) path)))
  980. (extension (file-name-extension path))
  981. (attributes (org-export-read-attribute :attr_texinfo parent))
  982. (height (or (plist-get attributes :height) ""))
  983. (width (or (plist-get attributes :width) ""))
  984. (alt (or (plist-get attributes :alt) ""))
  985. (image (format "@image{%s,%s,%s,%s,%s}"
  986. filename width height alt extension)))
  987. (cond ((or caption shortcaption)
  988. (org-texinfo--wrap-float image
  989. info
  990. (org-export-translate "Figure" :utf-8 info)
  991. label
  992. caption
  993. shortcaption))
  994. (label (concat "@anchor{" label "}\n" image))
  995. (t image))))
  996. ;;;; Menu
  997. (defun org-texinfo-make-menu (scope info &optional master)
  998. "Create the menu for inclusion in the Texinfo document.
  999. SCOPE is a headline or a full parse tree. INFO is the
  1000. communication channel, as a plist.
  1001. When optional argument MASTER is non-nil, generate a master menu,
  1002. including detailed node listing."
  1003. (let ((menu (org-texinfo--build-menu scope info)))
  1004. (when (org-string-nw-p menu)
  1005. (org-element-normalize-string
  1006. (format
  1007. "@menu\n%s@end menu"
  1008. (concat menu
  1009. (when master
  1010. (let ((detailmenu
  1011. (org-texinfo--build-menu
  1012. scope info
  1013. (let ((toc-depth (plist-get info :with-toc)))
  1014. (if (wholenump toc-depth) toc-depth
  1015. org-texinfo-max-toc-depth)))))
  1016. (when (org-string-nw-p detailmenu)
  1017. (concat "\n@detailmenu\n"
  1018. "--- The Detailed Node Listing ---\n\n"
  1019. detailmenu
  1020. "@end detailmenu\n"))))))))))
  1021. (defun org-texinfo--build-menu (scope info &optional level)
  1022. "Build menu for entries within SCOPE.
  1023. SCOPE is a headline or a full parse tree. INFO is a plist
  1024. containing contextual information. When optional argument LEVEL
  1025. is an integer, build the menu recursively, down to this depth."
  1026. (cond
  1027. ((not level)
  1028. (org-texinfo--format-entries (org-texinfo--menu-entries scope info) info))
  1029. ((zerop level) "\n")
  1030. (t
  1031. (mapconcat
  1032. (lambda (h)
  1033. (let ((entries (org-texinfo--menu-entries h info)))
  1034. (when entries
  1035. (concat
  1036. (format "%s\n\n%s\n"
  1037. (org-export-data (org-export-get-alt-title h info) info)
  1038. (org-texinfo--format-entries entries info))
  1039. (org-texinfo--build-menu h info (1- level))))))
  1040. (org-texinfo--menu-entries scope info)
  1041. ""))))
  1042. (defun org-texinfo--format-entries (entries info)
  1043. "Format all direct menu entries in SCOPE, as a string.
  1044. SCOPE is either a headline or a full Org document. INFO is
  1045. a plist containing contextual information."
  1046. (org-element-normalize-string
  1047. (mapconcat
  1048. (lambda (h)
  1049. (let* ((title
  1050. ;; Colons are used as a separator between title and node
  1051. ;; name. Remove them.
  1052. (replace-regexp-in-string
  1053. "[ \t]+:+" ""
  1054. (org-texinfo--sanitize-title
  1055. (org-export-get-alt-title h info) info)))
  1056. (node (org-texinfo--get-node h info))
  1057. (entry (concat "* " title ":"
  1058. (if (string= title node) ":"
  1059. (concat " " node ". "))))
  1060. (desc (org-element-property :DESCRIPTION h)))
  1061. (if (not desc) entry
  1062. (format (format "%%-%ds %%s" org-texinfo-node-description-column)
  1063. entry desc))))
  1064. entries "\n")))
  1065. (defun org-texinfo--menu-entries (scope info)
  1066. "List direct children in SCOPE needing a menu entry.
  1067. SCOPE is a headline or a full parse tree. INFO is a plist
  1068. holding contextual information."
  1069. (let* ((cache (or (plist-get info :texinfo-entries-cache)
  1070. (plist-get (plist-put info :texinfo-entries-cache
  1071. (make-hash-table :test #'eq))
  1072. :texinfo-entries-cache)))
  1073. (cached-entries (gethash scope cache 'no-cache)))
  1074. (if (not (eq cached-entries 'no-cache)) cached-entries
  1075. (puthash scope
  1076. (cl-remove-if
  1077. (lambda (h)
  1078. (org-not-nil (org-export-get-node-property :COPYING h t)))
  1079. (org-export-collect-headlines info 1 scope))
  1080. cache))))
  1081. ;;;; Node Property
  1082. (defun org-texinfo-node-property (node-property _contents _info)
  1083. "Transcode a NODE-PROPERTY element from Org to Texinfo.
  1084. CONTENTS is nil. INFO is a plist holding contextual
  1085. information."
  1086. (format "%s:%s"
  1087. (org-element-property :key node-property)
  1088. (let ((value (org-element-property :value node-property)))
  1089. (if value (concat " " value) ""))))
  1090. ;;;; Paragraph
  1091. (defun org-texinfo-paragraph (_paragraph contents _info)
  1092. "Transcode a PARAGRAPH element from Org to Texinfo.
  1093. CONTENTS is the contents of the paragraph, as a string. INFO is
  1094. the plist used as a communication channel."
  1095. contents)
  1096. ;;;; Plain List
  1097. (defun org-texinfo-plain-list (plain-list contents info)
  1098. "Transcode a PLAIN-LIST element from Org to Texinfo.
  1099. CONTENTS is the contents of the list. INFO is a plist holding
  1100. contextual information."
  1101. (let* ((attr (org-export-read-attribute :attr_texinfo plain-list))
  1102. (indic (let ((i (or (plist-get attr :indic)
  1103. (plist-get info :texinfo-table-default-markup))))
  1104. ;; Allow indicating commands with missing @ sign.
  1105. (if (string-prefix-p "@" i) i (concat "@" i))))
  1106. (table-type (plist-get attr :table-type))
  1107. (type (org-element-property :type plain-list))
  1108. (enum
  1109. (cond ((not (eq type 'ordered)) nil)
  1110. ((plist-member attr :enum) (plist-get attr :enum))
  1111. (t
  1112. ;; Texinfo only supports initial counters, i.e., it
  1113. ;; cannot change the numbering mid-list.
  1114. (let ((first-item (car (org-element-contents plain-list))))
  1115. (org-element-property :counter first-item)))))
  1116. (list-type (cond
  1117. ((eq type 'ordered) "enumerate")
  1118. ((eq type 'unordered) "itemize")
  1119. ((member table-type '("ftable" "vtable")) table-type)
  1120. (t "table"))))
  1121. (format "@%s\n%s@end %s"
  1122. (cond ((eq type 'descriptive) (concat list-type " " indic))
  1123. (enum (format "%s %s" list-type enum))
  1124. (t list-type))
  1125. contents
  1126. list-type)))
  1127. ;;;; Plain Text
  1128. (defun org-texinfo-plain-text (text info)
  1129. "Transcode a TEXT string from Org to Texinfo.
  1130. TEXT is the string to transcode. INFO is a plist holding
  1131. contextual information."
  1132. ;; First protect @, { and }.
  1133. (let ((output (org-texinfo--sanitize-content text)))
  1134. ;; Activate smart quotes. Be sure to provide original TEXT string
  1135. ;; since OUTPUT may have been modified.
  1136. (when (plist-get info :with-smart-quotes)
  1137. (setq output
  1138. (org-export-activate-smart-quotes output :texinfo info text)))
  1139. ;; LaTeX into @LaTeX{} and TeX into @TeX{}
  1140. (let ((case-fold-search nil))
  1141. (setq output (replace-regexp-in-string "\\(?:La\\)?TeX" "@\\&{}" output)))
  1142. ;; Convert special strings.
  1143. (when (plist-get info :with-special-strings)
  1144. (setq output
  1145. (replace-regexp-in-string
  1146. "\\.\\.\\." "@dots{}"
  1147. (replace-regexp-in-string "\\\\-" "@-" output))))
  1148. ;; Handle break preservation if required.
  1149. (when (plist-get info :preserve-breaks)
  1150. (setq output (replace-regexp-in-string
  1151. "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output)))
  1152. ;; Reverse sentence ending. A sentence can end with a capital
  1153. ;; letter. Use non-breaking space if it shouldn't.
  1154. (let ((case-fold-search nil))
  1155. (replace-regexp-in-string
  1156. "[A-Z]\\([.?!]\\)\\(?:[])]\\|'\\{1,2\\}\\)?\\(?: \\|$\\)"
  1157. "@\\1"
  1158. output nil nil 1))))
  1159. ;;;; Planning
  1160. (defun org-texinfo-planning (planning _contents info)
  1161. "Transcode a PLANNING element from Org to Texinfo.
  1162. CONTENTS is nil. INFO is a plist holding contextual
  1163. information."
  1164. (concat
  1165. "@noindent"
  1166. (mapconcat
  1167. 'identity
  1168. (delq nil
  1169. (list
  1170. (let ((closed (org-element-property :closed planning)))
  1171. (when closed
  1172. (concat
  1173. (format "@strong{%s} " org-closed-string)
  1174. (format (plist-get info :texinfo-inactive-timestamp-format)
  1175. (org-timestamp-translate closed)))))
  1176. (let ((deadline (org-element-property :deadline planning)))
  1177. (when deadline
  1178. (concat
  1179. (format "@strong{%s} " org-deadline-string)
  1180. (format (plist-get info :texinfo-active-timestamp-format)
  1181. (org-timestamp-translate deadline)))))
  1182. (let ((scheduled (org-element-property :scheduled planning)))
  1183. (when scheduled
  1184. (concat
  1185. (format "@strong{%s} " org-scheduled-string)
  1186. (format (plist-get info :texinfo-active-timestamp-format)
  1187. (org-timestamp-translate scheduled)))))))
  1188. " ")
  1189. "@*"))
  1190. ;;;; Property Drawer
  1191. (defun org-texinfo-property-drawer (_property-drawer contents _info)
  1192. "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
  1193. CONTENTS holds the contents of the drawer. INFO is a plist
  1194. holding contextual information."
  1195. (and (org-string-nw-p contents)
  1196. (format "@verbatim\n%s@end verbatim" contents)))
  1197. ;;;; Quote Block
  1198. (defun org-texinfo-quote-block (quote-block contents _info)
  1199. "Transcode a QUOTE-BLOCK element from Org to Texinfo.
  1200. CONTENTS holds the contents of the block. INFO is a plist
  1201. holding contextual information."
  1202. (let ((tag (org-export-read-attribute :attr_texinfo quote-block :tag))
  1203. (author (org-export-read-attribute :attr_texinfo quote-block :author)))
  1204. (format "@quotation%s\n%s%s\n@end quotation"
  1205. (if tag (concat " " tag) "")
  1206. contents
  1207. (if author (concat "\n@author " author) ""))))
  1208. ;;;; Radio Target
  1209. (defun org-texinfo-radio-target (radio-target text info)
  1210. "Transcode a RADIO-TARGET object from Org to Texinfo.
  1211. TEXT is the text of the target. INFO is a plist holding
  1212. contextual information."
  1213. (format "@anchor{%s}%s"
  1214. (org-texinfo--get-node radio-target info)
  1215. text))
  1216. ;;;; Section
  1217. (defun org-texinfo-section (section contents info)
  1218. "Transcode a SECTION element from Org to Texinfo.
  1219. CONTENTS holds the contents of the section. INFO is a plist
  1220. holding contextual information."
  1221. (let ((parent (org-export-get-parent-headline section)))
  1222. (when parent ;first section is handled in `org-texinfo-template'
  1223. (org-trim
  1224. (concat contents
  1225. "\n"
  1226. (and (not (org-export-excluded-from-toc-p parent info))
  1227. (org-texinfo-make-menu parent info)))))))
  1228. ;;;; Special Block
  1229. (defun org-texinfo-special-block (special-block contents _info)
  1230. "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
  1231. CONTENTS holds the contents of the block. INFO is a plist used
  1232. as a communication channel."
  1233. (let ((opt (org-export-read-attribute :attr_texinfo special-block :options))
  1234. (type (org-element-property :type special-block)))
  1235. (format "@%s%s\n%s@end %s"
  1236. type
  1237. (if opt (concat " " opt) "")
  1238. (or contents "")
  1239. type)))
  1240. ;;;; Src Block
  1241. (defun org-texinfo-src-block (src-block _contents info)
  1242. "Transcode a SRC-BLOCK element from Org to Texinfo.
  1243. CONTENTS holds the contents of the item. INFO is a plist holding
  1244. contextual information."
  1245. (let* ((lisp (string-match-p "lisp"
  1246. (org-element-property :language src-block)))
  1247. (code (org-texinfo--sanitize-content
  1248. (org-export-format-code-default src-block info)))
  1249. (value (format
  1250. (if lisp "@lisp\n%s@end lisp" "@example\n%s@end example")
  1251. code))
  1252. (caption (org-export-get-caption src-block))
  1253. (shortcaption (org-export-get-caption src-block t)))
  1254. (if (not (or caption shortcaption)) value
  1255. (org-texinfo--wrap-float value
  1256. info
  1257. (org-export-translate "Listing" :utf-8 info)
  1258. (org-texinfo--get-node src-block info)
  1259. caption
  1260. shortcaption))))
  1261. ;;;; Statistics Cookie
  1262. (defun org-texinfo-statistics-cookie (statistics-cookie _contents _info)
  1263. "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
  1264. CONTENTS is nil. INFO is a plist holding contextual information."
  1265. (org-element-property :value statistics-cookie))
  1266. ;;;; Strike-through
  1267. (defun org-texinfo-strike-through (_strike-through contents info)
  1268. "Transcode STRIKE-THROUGH from Org to Texinfo.
  1269. CONTENTS is the text with strike-through markup. INFO is a plist
  1270. holding contextual information."
  1271. (org-texinfo--text-markup contents 'strike-through info))
  1272. ;;;; Subscript
  1273. (defun org-texinfo-subscript (_subscript contents _info)
  1274. "Transcode a SUBSCRIPT object from Org to Texinfo.
  1275. CONTENTS is the contents of the object. INFO is a plist holding
  1276. contextual information."
  1277. (format "@math{_%s}" contents))
  1278. ;;;; Superscript
  1279. (defun org-texinfo-superscript (_superscript contents _info)
  1280. "Transcode a SUPERSCRIPT object from Org to Texinfo.
  1281. CONTENTS is the contents of the object. INFO is a plist holding
  1282. contextual information."
  1283. (format "@math{^%s}" contents))
  1284. ;;;; Table
  1285. (defun org-texinfo-table (table contents info)
  1286. "Transcode a TABLE element from Org to Texinfo.
  1287. CONTENTS is the contents of the table. INFO is a plist holding
  1288. contextual information."
  1289. (if (eq (org-element-property :type table) 'table.el)
  1290. (format "@verbatim\n%s@end verbatim"
  1291. (org-element-normalize-string
  1292. (org-element-property :value table)))
  1293. (let* ((col-width (org-export-read-attribute :attr_texinfo table :columns))
  1294. (columns
  1295. (if col-width (format "@columnfractions %s" col-width)
  1296. (org-texinfo-table-column-widths table info)))
  1297. (caption (org-export-get-caption table))
  1298. (shortcaption (org-export-get-caption table t))
  1299. (table-str (format "@multitable %s\n%s@end multitable"
  1300. columns
  1301. contents)))
  1302. (if (not (or caption shortcaption)) table-str
  1303. (org-texinfo--wrap-float table-str
  1304. info
  1305. (org-export-translate "Table" :utf-8 info)
  1306. (org-texinfo--get-node table info)
  1307. caption
  1308. shortcaption)))))
  1309. (defun org-texinfo-table-column-widths (table info)
  1310. "Determine the largest table cell in each column to process alignment.
  1311. TABLE is the table element to transcode. INFO is a plist used as
  1312. a communication channel."
  1313. (let ((widths (make-vector (cdr (org-export-table-dimensions table info)) 0)))
  1314. (org-element-map table 'table-row
  1315. (lambda (row)
  1316. (let ((idx 0))
  1317. (org-element-map row 'table-cell
  1318. (lambda (cell)
  1319. ;; Length of the cell in the original buffer is only an
  1320. ;; approximation of the length of the cell in the
  1321. ;; output. It can sometimes fail (e.g. it considers
  1322. ;; "/a/" being larger than "ab").
  1323. (let ((w (- (org-element-property :contents-end cell)
  1324. (org-element-property :contents-begin cell))))
  1325. (aset widths idx (max w (aref widths idx))))
  1326. (cl-incf idx))
  1327. info)))
  1328. info)
  1329. (format "{%s}" (mapconcat (lambda (w) (make-string w ?a)) widths "} {"))))
  1330. ;;;; Table Cell
  1331. (defun org-texinfo-table-cell (table-cell contents info)
  1332. "Transcode a TABLE-CELL element from Org to Texinfo.
  1333. CONTENTS is the cell contents. INFO is a plist used as
  1334. a communication channel."
  1335. (concat
  1336. (let ((scientific-notation
  1337. (plist-get info :texinfo-table-scientific-notation)))
  1338. (if (and contents
  1339. scientific-notation
  1340. (string-match orgtbl-exp-regexp contents))
  1341. ;; Use appropriate format string for scientific notation.
  1342. (format scientific-notation
  1343. (match-string 1 contents)
  1344. (match-string 2 contents))
  1345. contents))
  1346. (when (org-export-get-next-element table-cell info) "\n@tab ")))
  1347. ;;;; Table Row
  1348. (defun org-texinfo-table-row (table-row contents info)
  1349. "Transcode a TABLE-ROW element from Org to Texinfo.
  1350. CONTENTS is the contents of the row. INFO is a plist used as
  1351. a communication channel."
  1352. ;; Rules are ignored since table separators are deduced from
  1353. ;; borders of the current row.
  1354. (when (eq (org-element-property :type table-row) 'standard)
  1355. (let ((rowgroup-tag
  1356. (if (and (= 1 (org-export-table-row-group table-row info))
  1357. (org-export-table-has-header-p
  1358. (org-export-get-parent-table table-row) info))
  1359. "@headitem "
  1360. "@item ")))
  1361. (concat rowgroup-tag contents "\n"))))
  1362. ;;;; Target
  1363. (defun org-texinfo-target (target _contents info)
  1364. "Transcode a TARGET object from Org to Texinfo.
  1365. CONTENTS is nil. INFO is a plist holding contextual
  1366. information."
  1367. (format "@anchor{%s}" (org-texinfo--get-node target info)))
  1368. ;;;; Timestamp
  1369. (defun org-texinfo-timestamp (timestamp _contents info)
  1370. "Transcode a TIMESTAMP object from Org to Texinfo.
  1371. CONTENTS is nil. INFO is a plist holding contextual
  1372. information."
  1373. (let ((value (org-texinfo-plain-text
  1374. (org-timestamp-translate timestamp) info)))
  1375. (pcase (org-element-property :type timestamp)
  1376. ((or `active `active-range)
  1377. (format (plist-get info :texinfo-active-timestamp-format) value))
  1378. ((or `inactive `inactive-range)
  1379. (format (plist-get info :texinfo-inactive-timestamp-format) value))
  1380. (_ (format (plist-get info :texinfo-diary-timestamp-format) value)))))
  1381. ;;;; Underline
  1382. (defun org-texinfo-underline (_underline contents info)
  1383. "Transcode UNDERLINE from Org to Texinfo.
  1384. CONTENTS is the text with underline markup. INFO is a plist
  1385. holding contextual information."
  1386. (org-texinfo--text-markup contents 'underline info))
  1387. ;;;; Verbatim
  1388. (defun org-texinfo-verbatim (verbatim _contents info)
  1389. "Transcode a VERBATIM object from Org to Texinfo.
  1390. CONTENTS is nil. INFO is a plist used as a communication
  1391. channel."
  1392. (org-texinfo--text-markup
  1393. (org-element-property :value verbatim) 'verbatim info))
  1394. ;;;; Verse Block
  1395. (defun org-texinfo-verse-block (_verse-block contents _info)
  1396. "Transcode a VERSE-BLOCK element from Org to Texinfo.
  1397. CONTENTS is verse block contents. INFO is a plist holding
  1398. contextual information."
  1399. (format "@display\n%s@end display" contents))
  1400. ;;; Interactive functions
  1401. ;;;###autoload
  1402. (defun org-texinfo-export-to-texinfo
  1403. (&optional async subtreep visible-only body-only ext-plist)
  1404. "Export current buffer to a Texinfo file.
  1405. If narrowing is active in the current buffer, only export its
  1406. narrowed part.
  1407. If a region is active, export that region.
  1408. A non-nil optional argument ASYNC means the process should happen
  1409. asynchronously. The resulting file should be accessible through
  1410. the `org-export-stack' interface.
  1411. When optional argument SUBTREEP is non-nil, export the sub-tree
  1412. at point, extracting information from the headline properties
  1413. first.
  1414. When optional argument VISIBLE-ONLY is non-nil, don't export
  1415. contents of hidden elements.
  1416. When optional argument BODY-ONLY is non-nil, only write code
  1417. between \"\\begin{document}\" and \"\\end{document}\".
  1418. EXT-PLIST, when provided, is a property list with external
  1419. parameters overriding Org default settings, but still inferior to
  1420. file-local settings.
  1421. Return output file's name."
  1422. (interactive)
  1423. (let ((outfile (org-export-output-file-name ".texi" subtreep))
  1424. (org-export-coding-system org-texinfo-coding-system))
  1425. (org-export-to-file 'texinfo outfile
  1426. async subtreep visible-only body-only ext-plist)))
  1427. ;;;###autoload
  1428. (defun org-texinfo-export-to-info
  1429. (&optional async subtreep visible-only body-only ext-plist)
  1430. "Export current buffer to Texinfo then process through to INFO.
  1431. If narrowing is active in the current buffer, only export its
  1432. narrowed part.
  1433. If a region is active, export that region.
  1434. A non-nil optional argument ASYNC means the process should happen
  1435. asynchronously. The resulting file should be accessible through
  1436. the `org-export-stack' interface.
  1437. When optional argument SUBTREEP is non-nil, export the sub-tree
  1438. at point, extracting information from the headline properties
  1439. first.
  1440. When optional argument VISIBLE-ONLY is non-nil, don't export
  1441. contents of hidden elements.
  1442. When optional argument BODY-ONLY is non-nil, only write code
  1443. between \"\\begin{document}\" and \"\\end{document}\".
  1444. EXT-PLIST, when provided, is a property list with external
  1445. parameters overriding Org default settings, but still inferior to
  1446. file-local settings.
  1447. When optional argument PUB-DIR is set, use it as the publishing
  1448. directory.
  1449. Return INFO file's name."
  1450. (interactive)
  1451. (let ((outfile (org-export-output-file-name ".texi" subtreep))
  1452. (org-export-coding-system org-texinfo-coding-system))
  1453. (org-export-to-file 'texinfo outfile
  1454. async subtreep visible-only body-only ext-plist
  1455. (lambda (file) (org-texinfo-compile file)))))
  1456. ;;;###autoload
  1457. (defun org-texinfo-publish-to-texinfo (plist filename pub-dir)
  1458. "Publish an org file to Texinfo.
  1459. FILENAME is the filename of the Org file to be published. PLIST
  1460. is the property list for the given project. PUB-DIR is the
  1461. publishing directory.
  1462. Return output file name."
  1463. (org-publish-org-to 'texinfo filename ".texi" plist pub-dir))
  1464. ;;;###autoload
  1465. (defun org-texinfo-convert-region-to-texinfo ()
  1466. "Assume the current region has Org syntax, and convert it to Texinfo.
  1467. This can be used in any buffer. For example, you can write an
  1468. itemized list in Org syntax in an Texinfo buffer and use this
  1469. command to convert it."
  1470. (interactive)
  1471. (org-export-replace-region-by 'texinfo))
  1472. (defun org-texinfo-compile (file)
  1473. "Compile a texinfo file.
  1474. FILE is the name of the file being compiled. Processing is done
  1475. through the command specified in `org-texinfo-info-process',
  1476. which see. Output is redirected to \"*Org INFO Texinfo Output*\"
  1477. buffer.
  1478. Return INFO file name or an error if it couldn't be produced."
  1479. (message "Processing Texinfo file %s..." file)
  1480. (let* ((log-name "*Org INFO Texinfo Output*")
  1481. (log (get-buffer-create log-name))
  1482. (output
  1483. (org-compile-file file org-texinfo-info-process "info"
  1484. (format "See %S for details" log-name)
  1485. log)))
  1486. (when org-texinfo-remove-logfiles
  1487. (let ((base (file-name-sans-extension output)))
  1488. (dolist (ext org-texinfo-logfiles-extensions)
  1489. (let ((file (concat base "." ext)))
  1490. (when (file-exists-p file) (delete-file file))))))
  1491. (message "Process completed.")
  1492. output))
  1493. (provide 'ox-texinfo)
  1494. ;; Local variables:
  1495. ;; generated-autoload-file: "org-loaddefs.el"
  1496. ;; End:
  1497. ;;; ox-texinfo.el ends here