ox-texinfo.el 61 KB

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