ox-texinfo.el 60 KB

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