ox-texinfo.el 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706
  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 <http://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")
  128. ("@section %s" . "@unnumberedsec %s")
  129. ("@subsection %s" . "@unnumberedsubsec %s")
  130. ("@subsubsection %s" . "@unnumberedsubsubsec %s")))
  131. "Alist of Texinfo classes and associated header and structure.
  132. If #+TEXINFO_CLASS is set in the buffer, use its value and the
  133. associated information. Here is the structure of each cell:
  134. (class-name
  135. header-string
  136. (numbered-section . unnumbered-section)
  137. ...)
  138. The header string
  139. -----------------
  140. The header string is inserted in the header of the generated
  141. document, right after \"@setfilename\" and \"@settitle\"
  142. commands.
  143. If it contains the special string
  144. \"@documentencoding AUTO\"
  145. \"AUTO\" will be replaced with an appropriate coding system. See
  146. `org-texinfo-coding-system' for more information. Likewise, if
  147. the string contains the special string
  148. \"@documentlanguage AUTO\"
  149. \"AUTO\" will be replaced with the language defined in the
  150. buffer, through #+LANGUAGE keyword, or globally, with
  151. `org-export-default-language', which see.
  152. The sectioning structure
  153. ------------------------
  154. The sectioning structure of the class is given by the elements
  155. following the header string. For each sectioning level, a number
  156. of strings is specified. A %s formatter is mandatory in each
  157. section string and will be replaced by the title of the section.
  158. Instead of a list of sectioning commands, you can also specify
  159. a function name. That function will be called with two
  160. parameters, the reduced) level of the headline, and a predicate
  161. non-nil when the headline should be numbered. It must return
  162. a format string in which the section title will be added."
  163. :group 'org-export-texinfo
  164. :version "24.4"
  165. :package-version '(Org . "8.2")
  166. :type '(repeat
  167. (list (string :tag "Texinfo class")
  168. (string :tag "Texinfo header")
  169. (repeat :tag "Levels" :inline t
  170. (choice
  171. (cons :tag "Heading"
  172. (string :tag " numbered")
  173. (string :tag "unnumbered"))
  174. (function :tag "Hook computing sectioning"))))))
  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 %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. :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--filter-section-blank-lines (headline _backend _info)
  330. "Filter controlling number of blank lines after a section."
  331. (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" "\n\n" headline))
  332. (defun org-texinfo--normalize-headlines (tree _backend info)
  333. "Normalize headlines in TREE.
  334. BACK-END is the symbol specifying back-end used for export. INFO
  335. is a plist used as a communication channel.
  336. Make sure every headline in TREE contains a section, since those
  337. are required to install a menu. Also put exactly one blank line
  338. at the end of each section.
  339. Return new tree."
  340. (org-element-map tree 'headline
  341. (lambda (hl)
  342. (org-element-put-property hl :post-blank 1)
  343. (let ((contents (org-element-contents hl)))
  344. (when contents
  345. (let ((first (org-element-map contents '(headline section)
  346. #'identity info t)))
  347. (unless (eq (org-element-type first) 'section)
  348. (apply #'org-element-set-contents
  349. hl
  350. (cons `(section (:parent ,hl)) contents)))))))
  351. info)
  352. tree)
  353. (defun org-texinfo--find-verb-separator (s)
  354. "Return a character not used in string S.
  355. This is used to choose a separator for constructs like \\verb."
  356. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  357. (cl-loop for c across ll
  358. when (not (string-match (regexp-quote (char-to-string c)) s))
  359. return (char-to-string c))))
  360. (defun org-texinfo--text-markup (text markup _info)
  361. "Format TEXT depending on MARKUP text markup.
  362. INFO is a plist used as a communication channel. See
  363. `org-texinfo-text-markup-alist' for details."
  364. (pcase (cdr (assq markup org-texinfo-text-markup-alist))
  365. (`nil text) ;no markup: return raw text
  366. (`code (format "@code{%s}" (org-texinfo--sanitize-content text)))
  367. (`samp (format "@samp{%s}" (org-texinfo--sanitize-content text)))
  368. (`verb
  369. (let ((separator (org-texinfo--find-verb-separator text)))
  370. (format "@verb{%s%s%s}" separator text separator)))
  371. ;; Else use format string.
  372. (fmt (format fmt text))))
  373. (defun org-texinfo--get-node (datum info)
  374. "Return node or anchor associated to DATUM.
  375. DATUM is an element or object. INFO is a plist used as
  376. a communication channel. The function guarantees the node or
  377. anchor name is unique."
  378. (let ((cache (plist-get info :texinfo-node-cache)))
  379. (or (cdr (assq datum cache))
  380. (let* ((salt 0)
  381. (basename
  382. (org-texinfo--sanitize-node
  383. (if (eq (org-element-type datum) 'headline)
  384. (org-texinfo--sanitize-title
  385. (org-export-get-alt-title datum info) info)
  386. (org-export-get-reference datum info))))
  387. (name basename))
  388. ;; Ensure NAME is unique and not reserved node name "Top".
  389. (while (or (equal name "Top") (rassoc name cache))
  390. (setq name (concat basename (format " %d" (cl-incf salt)))))
  391. (plist-put info :texinfo-node-cache (cons (cons datum name) cache))
  392. name))))
  393. (defun org-texinfo--sanitize-node (title)
  394. "Bend string TITLE to node line requirements.
  395. Trim string and collapse multiple whitespace characters as they
  396. are not significant. Replace leading left parenthesis, when
  397. followed by a right parenthesis, with a square bracket. Remove
  398. periods, commas and colons."
  399. (org-trim
  400. (replace-regexp-in-string
  401. "[ \t]+" " "
  402. (replace-regexp-in-string
  403. "[:,.]" ""
  404. (replace-regexp-in-string "\\`(\\(.*?)\\)" "[\\1" title)))))
  405. (defun org-texinfo--sanitize-title (title info)
  406. "Make TITLE suitable as a section name.
  407. TITLE is a string or a secondary string. INFO is the current
  408. export state, as a plist."
  409. (org-export-data-with-backend
  410. title
  411. (org-export-create-backend
  412. :parent 'texinfo
  413. :transcoders '((footnote-reference . ignore)
  414. (link . (lambda (object c i) c))
  415. (radio-target . (lambda (object c i) c))
  416. (target . ignore)))
  417. info))
  418. (defun org-texinfo--sanitize-content (text)
  419. "Escape special characters in string TEXT.
  420. Special characters are: @ { }"
  421. (replace-regexp-in-string "[@{}]" "@\\&" text))
  422. (defun org-texinfo--wrap-float (value info &optional type label caption short)
  423. "Wrap string VALUE within a @float command.
  424. INFO is the current export state, as a plist. TYPE is float
  425. type, as a string. LABEL is the cross reference label for the
  426. float, as a string. CAPTION and SHORT are, respectively, the
  427. caption and shortcaption used for the float, as secondary
  428. strings (e.g., returned by `org-export-get-caption')."
  429. (let* ((backend
  430. (org-export-create-backend
  431. :parent 'texinfo
  432. :transcoders '((link . (lambda (object c i) c))
  433. (radio-target . (lambda (object c i) c))
  434. (target . ignore))))
  435. (short-backend
  436. (org-export-create-backend
  437. :parent 'texinfo
  438. :transcoders '((footnote-reference . ignore)
  439. (inline-src-block . ignore)
  440. (link . (lambda (object c i) c))
  441. (radio-target . (lambda (object c i) c))
  442. (target . ignore)
  443. (verbatim . ignore))))
  444. (short-str
  445. (if (and short caption)
  446. (format "@shortcaption{%s}\n"
  447. (org-export-data-with-backend short short-backend info))
  448. ""))
  449. (caption-str
  450. (if (or short caption)
  451. (format "@caption{%s}\n"
  452. (org-export-data-with-backend
  453. (or caption short)
  454. (if (equal short-str "") short-backend backend)
  455. info))
  456. "")))
  457. (format "@float %s%s\n%s\n%s%s@end float"
  458. type (if label (concat "," label) "") value caption-str short-str)))
  459. ;;; Template
  460. (defun org-texinfo-template (contents info)
  461. "Return complete document string after Texinfo conversion.
  462. CONTENTS is the transcoded contents string. INFO is a plist
  463. holding export options."
  464. (let ((title (org-export-data (plist-get info :title) info))
  465. ;; Copying data is the contents of the first headline in
  466. ;; parse tree with a non-nil copying property.
  467. (copying (org-element-map (plist-get info :parse-tree) 'headline
  468. (lambda (hl)
  469. (and (org-not-nil (org-element-property :COPYING hl))
  470. (org-element-contents hl)))
  471. info t)))
  472. (concat
  473. "\\input texinfo @c -*- texinfo -*-\n"
  474. "@c %**start of header\n"
  475. (let ((file (or (plist-get info :texinfo-filename)
  476. (let ((f (plist-get info :output-file)))
  477. (and f (concat (file-name-sans-extension f) ".info"))))))
  478. (and file (format "@setfilename %s\n" file)))
  479. (format "@settitle %s\n" title)
  480. ;; Insert class-defined header.
  481. (org-element-normalize-string
  482. (let ((header (nth 1 (assoc (plist-get info :texinfo-class)
  483. org-texinfo-classes)))
  484. (coding
  485. (catch 'coding-system
  486. (let ((case-fold-search t)
  487. (name (symbol-name (or org-texinfo-coding-system
  488. buffer-file-coding-system))))
  489. (dolist (system org-texinfo-supported-coding-systems "UTF-8")
  490. (when (string-match-p (regexp-quote system) name)
  491. (throw 'coding-system system))))))
  492. (language (plist-get info :language))
  493. (case-fold-search nil))
  494. ;; Auto coding system.
  495. (replace-regexp-in-string
  496. "^@documentencoding \\(AUTO\\)$"
  497. coding
  498. (replace-regexp-in-string
  499. "^@documentlanguage \\(AUTO\\)$" language header t nil 1) t nil 1)))
  500. ;; Additional header options set by #+TEXINFO_HEADER.
  501. (let ((texinfo-header (plist-get info :texinfo-header)))
  502. (and texinfo-header (org-element-normalize-string texinfo-header)))
  503. "@c %**end of header\n\n"
  504. ;; Additional options set by #+TEXINFO_POST_HEADER.
  505. (let ((texinfo-post-header (plist-get info :texinfo-post-header)))
  506. (and texinfo-post-header
  507. (org-element-normalize-string texinfo-post-header)))
  508. ;; Copying.
  509. (and copying
  510. (format "@copying\n%s@end copying\n\n"
  511. (org-element-normalize-string
  512. (org-export-data copying info))))
  513. ;; Info directory information. Only supply if both title and
  514. ;; category are provided.
  515. (let ((dircat (plist-get info :texinfo-dircat))
  516. (dirtitle
  517. (let ((title (plist-get info :texinfo-dirtitle)))
  518. (and title
  519. (string-match "^\\(?:\\* \\)?\\(.*?\\)\\(\\.\\)?$" title)
  520. (format "* %s." (match-string 1 title))))))
  521. (when (and dircat dirtitle)
  522. (concat "@dircategory " dircat "\n"
  523. "@direntry\n"
  524. (let ((dirdesc
  525. (let ((desc (plist-get info :texinfo-dirdesc)))
  526. (cond ((not desc) nil)
  527. ((string-suffix-p "." desc) desc)
  528. (t (concat desc "."))))))
  529. (if dirdesc (format "%-23s %s" dirtitle dirdesc) dirtitle))
  530. "\n"
  531. "@end direntry\n\n")))
  532. ;; Title
  533. "@finalout\n"
  534. "@titlepage\n"
  535. (when (plist-get info :with-title)
  536. (concat
  537. (format "@title %s\n" (or (plist-get info :texinfo-printed-title) title ""))
  538. (let ((subtitle (plist-get info :subtitle)))
  539. (when subtitle
  540. (format "@subtitle %s\n"
  541. (org-export-data subtitle info))))))
  542. (when (plist-get info :with-author)
  543. (concat
  544. ;; Primary author.
  545. (let ((author (org-string-nw-p
  546. (org-export-data (plist-get info :author) info)))
  547. (email (and (plist-get info :with-email)
  548. (org-string-nw-p
  549. (org-export-data (plist-get info :email) info)))))
  550. (cond ((and author email)
  551. (format "@author %s (@email{%s})\n" author email))
  552. (author (format "@author %s\n" author))
  553. (email (format "@author @email{%s}\n" email))))
  554. ;; Other authors.
  555. (let ((subauthor (plist-get info :subauthor)))
  556. (and subauthor
  557. (org-element-normalize-string
  558. (replace-regexp-in-string "^" "@author " subauthor))))))
  559. (and copying "@page\n@vskip 0pt plus 1filll\n@insertcopying\n")
  560. "@end titlepage\n\n"
  561. ;; Table of contents.
  562. (and (plist-get info :with-toc) "@contents\n\n")
  563. ;; Configure Top Node when not for Tex
  564. "@ifnottex\n"
  565. "@node Top\n"
  566. (format "@top %s\n" title)
  567. (and copying "@insertcopying\n")
  568. "@end ifnottex\n\n"
  569. ;; Menu.
  570. (org-texinfo-make-menu (plist-get info :parse-tree) info 'master)
  571. "\n"
  572. ;; Document's body.
  573. contents "\n"
  574. ;; Creator.
  575. (and (plist-get info :with-creator)
  576. (concat (plist-get info :creator) "\n"))
  577. ;; Document end.
  578. "@bye")))
  579. ;;; Transcode Functions
  580. ;;;; Bold
  581. (defun org-texinfo-bold (_bold contents info)
  582. "Transcode BOLD from Org to Texinfo.
  583. CONTENTS is the text with bold markup. INFO is a plist holding
  584. contextual information."
  585. (org-texinfo--text-markup contents 'bold info))
  586. ;;;; Center Block
  587. (defun org-texinfo-center-block (_center-block contents _info)
  588. "Transcode a CENTER-BLOCK element from Org to Texinfo.
  589. CONTENTS holds the contents of the block. INFO is a plist used
  590. as a communication channel."
  591. contents)
  592. ;;;; Clock
  593. (defun org-texinfo-clock (clock _contents info)
  594. "Transcode a CLOCK element from Org to Texinfo.
  595. CONTENTS is nil. INFO is a plist holding contextual
  596. information."
  597. (concat
  598. "@noindent"
  599. (format "@strong{%s} " org-clock-string)
  600. (format (plist-get info :texinfo-inactive-timestamp-format)
  601. (concat (org-timestamp-translate (org-element-property :value clock))
  602. (let ((time (org-element-property :duration clock)))
  603. (and time (format " (%s)" time)))))
  604. "@*"))
  605. ;;;; Code
  606. (defun org-texinfo-code (code _contents info)
  607. "Transcode a CODE object from Org to Texinfo.
  608. CONTENTS is nil. INFO is a plist used as a communication
  609. channel."
  610. (org-texinfo--text-markup (org-element-property :value code) 'code info))
  611. ;;;; Drawer
  612. (defun org-texinfo-drawer (drawer contents info)
  613. "Transcode a DRAWER element from Org to Texinfo.
  614. CONTENTS holds the contents of the block. INFO is a plist
  615. holding contextual information."
  616. (let* ((name (org-element-property :drawer-name drawer))
  617. (output (funcall (plist-get info :texinfo-format-drawer-function)
  618. name contents)))
  619. output))
  620. ;;;; Dynamic Block
  621. (defun org-texinfo-dynamic-block (_dynamic-block contents _info)
  622. "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
  623. CONTENTS holds the contents of the block. INFO is a plist
  624. holding contextual information."
  625. contents)
  626. ;;;; Entity
  627. (defun org-texinfo-entity (entity _contents _info)
  628. "Transcode an ENTITY object from Org to Texinfo."
  629. ;; Since there is not specific Texinfo entry in entities, use
  630. ;; Texinfo-specific commands whenever possible, and fallback to
  631. ;; UTF-8 otherwise.
  632. (pcase (org-element-property :name entity)
  633. ("AElig" "@AE{}")
  634. ("aelig" "@ae{}")
  635. ((or "bull" "bullet") "@bullet{}")
  636. ("copy" "@copyright{}")
  637. ("deg" "@textdegree{}")
  638. ((or "dots" "hellip") "@dots{}")
  639. ("equiv" "@equiv{}")
  640. ((or "euro" "EUR") "@euro{}")
  641. ((or "ge" "geq") "@geq{}")
  642. ("laquo" "@guillemetleft{}")
  643. ("iexcl" "@exclamdown{}")
  644. ("imath" "@dotless{i}")
  645. ("iquest" "@questiondown{}")
  646. ("jmath" "@dotless{j}")
  647. ((or "le" "leq") "@leq{}")
  648. ("lsaquo" "@guilsinglleft{}")
  649. ("mdash" "---")
  650. ("minus" "@minus{}")
  651. ("nbsp" "@tie{}")
  652. ("ndash" "--")
  653. ("OElig" "@OE{}")
  654. ("oelig" "@oe{}")
  655. ("ordf" "@ordf{}")
  656. ("ordm" "@ordm{}")
  657. ("pound" "@pound{}")
  658. ("raquo" "@guillemetright{}")
  659. ((or "rArr" "Rightarrow") "@result{}")
  660. ("reg" "@registeredsymbol{}")
  661. ((or "rightarrow" "to" "rarr") "@arrow{}")
  662. ("rsaquo" "@guilsinglright{}")
  663. ("thorn" "@th{}")
  664. ("THORN" "@TH{}")
  665. ((and (pred (string-prefix-p "_")) name) ;spacing entities
  666. (format "@w{%s}" (substring name 1)))
  667. (_ (org-element-property :utf-8 entity))))
  668. ;;;; Example Block
  669. (defun org-texinfo-example-block (example-block _contents info)
  670. "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
  671. CONTENTS is nil. INFO is a plist holding contextual
  672. information."
  673. (format "@example\n%s@end example"
  674. (org-texinfo--sanitize-content
  675. (org-export-format-code-default example-block info))))
  676. ;;; Export Block
  677. (defun org-texinfo-export-block (export-block _contents _info)
  678. "Transcode a EXPORT-BLOCK element from Org to Texinfo.
  679. CONTENTS is nil. INFO is a plist holding contextual information."
  680. (when (string= (org-element-property :type export-block) "TEXINFO")
  681. (org-remove-indentation (org-element-property :value export-block))))
  682. ;;; Export Snippet
  683. (defun org-texinfo-export-snippet (export-snippet _contents _info)
  684. "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
  685. CONTENTS is nil. INFO is a plist holding contextual information."
  686. (when (eq (org-export-snippet-backend export-snippet) 'texinfo)
  687. (org-element-property :value export-snippet)))
  688. ;;;; Fixed Width
  689. (defun org-texinfo-fixed-width (fixed-width _contents _info)
  690. "Transcode a FIXED-WIDTH element from Org to Texinfo.
  691. CONTENTS is nil. INFO is a plist holding contextual information."
  692. (format "@example\n%s@end example"
  693. (org-remove-indentation
  694. (org-texinfo--sanitize-content
  695. (org-element-property :value fixed-width)))))
  696. ;;;; Footnote Reference
  697. (defun org-texinfo-footnote-reference (footnote _contents info)
  698. "Create a footnote reference for FOOTNOTE.
  699. FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
  700. plist holding contextual information."
  701. (let ((def (org-export-get-footnote-definition footnote info)))
  702. (format "@footnote{%s}"
  703. (org-trim (org-export-data def info)))))
  704. ;;;; Headline
  705. (defun org-texinfo-headline (headline contents info)
  706. "Transcode a HEADLINE element from Org to Texinfo.
  707. CONTENTS holds the contents of the headline. INFO is a plist
  708. holding contextual information."
  709. (let* ((class (plist-get info :texinfo-class))
  710. (level (org-export-get-relative-level headline info))
  711. (numberedp (org-export-numbered-headline-p headline info))
  712. (class-sectioning (assoc class (plist-get info :texinfo-classes)))
  713. ;; Find the index type, if any.
  714. (index (org-element-property :INDEX headline))
  715. ;; Create node info, to insert it before section formatting.
  716. ;; Use custom menu title if present.
  717. (node (format "@node %s\n" (org-texinfo--get-node headline info)))
  718. ;; Section formatting will set two placeholders: one for the
  719. ;; title and the other for the contents.
  720. (section-fmt
  721. (if (org-not-nil (org-element-property :APPENDIX headline))
  722. "@appendix %s\n%s"
  723. (let ((sec (if (and (symbolp (nth 2 class-sectioning))
  724. (fboundp (nth 2 class-sectioning)))
  725. (funcall (nth 2 class-sectioning) level numberedp)
  726. (nth (1+ level) class-sectioning))))
  727. (cond
  728. ;; No section available for that LEVEL.
  729. ((not sec) nil)
  730. ;; Section format directly returned by a function.
  731. ((stringp sec) sec)
  732. ;; (numbered-section . unnumbered-section)
  733. ((not (consp (cdr sec)))
  734. (concat (if (or index (not numberedp)) (cdr sec) (car sec))
  735. "\n%s"))))))
  736. (todo
  737. (and (plist-get info :with-todo-keywords)
  738. (let ((todo (org-element-property :todo-keyword headline)))
  739. (and todo (org-export-data todo info)))))
  740. (todo-type (and todo (org-element-property :todo-type headline)))
  741. (tags (and (plist-get info :with-tags)
  742. (org-export-get-tags headline info)))
  743. (priority (and (plist-get info :with-priority)
  744. (org-element-property :priority headline)))
  745. (text (org-texinfo--sanitize-title
  746. (org-element-property :title headline) info))
  747. (full-text (funcall (plist-get info :texinfo-format-headline-function)
  748. todo todo-type priority text tags))
  749. (contents (if (org-string-nw-p contents) (concat "\n" contents) "")))
  750. (cond
  751. ;; Case 1: This is a footnote section: ignore it.
  752. ((org-element-property :footnote-section-p headline) nil)
  753. ;; Case 2: This is the `copying' section: ignore it
  754. ;; This is used elsewhere.
  755. ((org-not-nil (org-element-property :COPYING headline)) nil)
  756. ;; Case 3: An index. If it matches one of the known indexes,
  757. ;; print it as such following the contents, otherwise
  758. ;; print the contents and leave the index up to the user.
  759. (index
  760. (concat node
  761. (format
  762. section-fmt
  763. full-text
  764. (concat contents
  765. (and (member index '("cp" "fn" "ky" "pg" "tp" "vr"))
  766. (concat "\n@printindex " index))))))
  767. ;; Case 4: This is a deep sub-tree: export it as a list item.
  768. ;; Also export as items headlines for which no section
  769. ;; format has been found.
  770. ((or (not section-fmt) (org-export-low-level-p headline info))
  771. ;; Build the real contents of the sub-tree.
  772. (concat (and (org-export-first-sibling-p headline info)
  773. (format "@%s\n" (if numberedp 'enumerate 'itemize)))
  774. "@item\n" full-text "\n"
  775. contents
  776. (if (org-export-last-sibling-p headline info)
  777. (format "@end %s" (if numberedp 'enumerate 'itemize))
  778. "\n")))
  779. ;; Case 5: Standard headline. Export it as a section.
  780. (t (concat node (format section-fmt full-text contents))))))
  781. (defun org-texinfo-format-headline-default-function
  782. (todo _todo-type priority text tags)
  783. "Default format function for a headline.
  784. See `org-texinfo-format-headline-function' for details."
  785. (concat (when todo (format "@strong{%s} " todo))
  786. (when priority (format "@emph{#%s} " priority))
  787. text
  788. (when tags (format " :%s:" (mapconcat 'identity tags ":")))))
  789. ;;;; Inline Src Block
  790. (defun org-texinfo-inline-src-block (inline-src-block _contents _info)
  791. "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
  792. CONTENTS holds the contents of the item. INFO is a plist holding
  793. contextual information."
  794. (format "@code{%s}"
  795. (org-texinfo--sanitize-content
  796. (org-element-property :value inline-src-block))))
  797. ;;;; Inlinetask
  798. (defun org-texinfo-inlinetask (inlinetask contents info)
  799. "Transcode an INLINETASK element from Org to Texinfo.
  800. CONTENTS holds the contents of the block. INFO is a plist
  801. holding contextual information."
  802. (let ((title (org-export-data (org-element-property :title inlinetask) info))
  803. (todo (and (plist-get info :with-todo-keywords)
  804. (let ((todo (org-element-property :todo-keyword inlinetask)))
  805. (and todo (org-export-data todo info)))))
  806. (todo-type (org-element-property :todo-type inlinetask))
  807. (tags (and (plist-get info :with-tags)
  808. (org-export-get-tags inlinetask info)))
  809. (priority (and (plist-get info :with-priority)
  810. (org-element-property :priority inlinetask))))
  811. (funcall (plist-get info :texinfo-format-inlinetask-function)
  812. todo todo-type priority title tags contents)))
  813. (defun org-texinfo-format-inlinetask-default-function
  814. (todo _todo-type priority title tags contents)
  815. "Default format function for a inlinetasks.
  816. See `org-texinfo-format-inlinetask-function' for details."
  817. (let ((full-title
  818. (concat (when todo (format "@strong{%s} " todo))
  819. (when priority (format "#%c " priority))
  820. title
  821. (when tags (format ":%s:" (mapconcat #'identity tags ":"))))))
  822. (format "@center %s\n\n%s\n" full-title contents)))
  823. ;;;; Italic
  824. (defun org-texinfo-italic (_italic contents info)
  825. "Transcode ITALIC from Org to Texinfo.
  826. CONTENTS is the text with italic markup. INFO is a plist holding
  827. contextual information."
  828. (org-texinfo--text-markup contents 'italic info))
  829. ;;;; Item
  830. (defun org-texinfo-item (item contents info)
  831. "Transcode an ITEM element from Org to Texinfo.
  832. CONTENTS holds the contents of the item. INFO is a plist holding
  833. contextual information."
  834. (let* ((tag (org-element-property :tag item))
  835. (split (org-string-nw-p
  836. (org-export-read-attribute :attr_texinfo
  837. (org-element-property :parent item)
  838. :sep)))
  839. (items (and tag
  840. (let ((tag (org-export-data tag info)))
  841. (if split
  842. (split-string tag (regexp-quote split) t "[ \t\n]+")
  843. (list tag))))))
  844. (format "%s\n%s"
  845. (pcase items
  846. (`nil "@item")
  847. (`(,item) (concat "@item " item))
  848. (`(,item . ,items)
  849. (concat "@item " item "\n"
  850. (mapconcat (lambda (i) (concat "@itemx " i))
  851. items
  852. "\n"))))
  853. (or contents ""))))
  854. ;;;; Keyword
  855. (defun org-texinfo-keyword (keyword _contents info)
  856. "Transcode a KEYWORD element from Org to Texinfo.
  857. CONTENTS is nil. INFO is a plist holding contextual information."
  858. (let* ((raw-value (org-element-property :value keyword))
  859. (value (org-texinfo--sanitize-content raw-value)))
  860. (pcase (org-element-property :key keyword)
  861. ("TEXINFO" raw-value)
  862. ("CINDEX" (format "@cindex %s" value))
  863. ("FINDEX" (format "@findex %s" value))
  864. ("KINDEX" (format "@kindex %s" value))
  865. ("PINDEX" (format "@pindex %s" value))
  866. ("TINDEX" (format "@tindex %s" value))
  867. ("VINDEX" (format "@vindex %s" value))
  868. ("TOC"
  869. (cond ((string-match-p "\\<tables\\>" value)
  870. (concat "@listoffloats "
  871. (org-export-translate "Table" :utf-8 info)))
  872. ((string-match-p "\\<listings\\>" value)
  873. (concat "@listoffloats "
  874. (org-export-translate "Listing" :utf-8 info))))))))
  875. ;;;; Line Break
  876. (defun org-texinfo-line-break (_line-break _contents _info)
  877. "Transcode a LINE-BREAK object from Org to Texinfo.
  878. CONTENTS is nil. INFO is a plist holding contextual information."
  879. "@*\n")
  880. ;;;; Link
  881. (defun org-texinfo--@ref (datum description info)
  882. "Return @ref command for element or object DATUM.
  883. DESCRIPTION is the name of the section to print, as a string."
  884. (let ((node-name (org-texinfo--get-node datum info))
  885. ;; Sanitize DESCRIPTION for cross-reference use. In
  886. ;; particular, remove colons as they seem to cause (even
  887. ;; within @asis{...} to the Texinfo reader.
  888. (title (replace-regexp-in-string
  889. "[ \t]*:+" ""
  890. (replace-regexp-in-string "," "@comma{}" description))))
  891. (if (equal title node-name)
  892. (format "@ref{%s}" node-name)
  893. (format "@ref{%s, , %s}" node-name title))))
  894. (defun org-texinfo-link (link desc info)
  895. "Transcode a LINK object from Org to Texinfo.
  896. DESC is the description part of the link, or the empty string.
  897. INFO is a plist holding contextual information. See
  898. `org-export-data'."
  899. (let* ((type (org-element-property :type link))
  900. (raw-path (org-element-property :path link))
  901. ;; Ensure DESC really exists, or set it to nil.
  902. (desc (and (not (string= desc "")) desc))
  903. (path (cond
  904. ((member type '("http" "https" "ftp"))
  905. (concat type ":" raw-path))
  906. ((string= type "file") (org-export-file-uri raw-path))
  907. (t raw-path))))
  908. (cond
  909. ((org-export-custom-protocol-maybe link desc 'texinfo))
  910. ((org-export-inline-image-p link org-texinfo-inline-image-rules)
  911. (org-texinfo--inline-image link info))
  912. ((equal type "radio")
  913. (let ((destination (org-export-resolve-radio-link link info)))
  914. (if (not destination) desc
  915. (org-texinfo--@ref destination desc info))))
  916. ((member type '("custom-id" "id" "fuzzy"))
  917. (let ((destination
  918. (if (equal type "fuzzy")
  919. (org-export-resolve-fuzzy-link link info)
  920. (org-export-resolve-id-link link info))))
  921. (pcase (org-element-type destination)
  922. (`nil
  923. (format org-texinfo-link-with-unknown-path-format
  924. (org-texinfo--sanitize-content path)))
  925. ;; Id link points to an external file.
  926. (`plain-text
  927. (if desc (format "@uref{file://%s,%s}" destination desc)
  928. (format "@uref{file://%s}" destination)))
  929. ((or `headline
  930. ;; Targets within headlines cannot be turned into
  931. ;; @anchor{}, so we refer to the headline parent
  932. ;; directly.
  933. (and `target
  934. (guard (eq 'headline
  935. (org-element-type
  936. (org-element-property :parent destination))))))
  937. (let ((headline (org-element-lineage destination '(headline) t)))
  938. (org-texinfo--@ref
  939. headline
  940. (or desc (org-texinfo--sanitize-title
  941. (org-element-property :title headline) info))
  942. info)))
  943. (_
  944. (org-texinfo--@ref
  945. destination
  946. (or desc
  947. (pcase (org-export-get-ordinal destination info)
  948. ((and (pred integerp) n) (number-to-string n))
  949. ((and (pred consp) n) (mapconcat #'number-to-string n "."))
  950. (_ "???"))) ;cannot guess the description
  951. info)))))
  952. ((string= type "mailto")
  953. (format "@email{%s}"
  954. (concat (org-texinfo--sanitize-content path)
  955. (and desc (concat ", " desc)))))
  956. ;; External link with a description part.
  957. ((and path desc) (format "@uref{%s, %s}" path desc))
  958. ;; External link without a description part.
  959. (path (format "@uref{%s}" path))
  960. ;; No path, only description. Try to do something useful.
  961. (t
  962. (format (plist-get info :texinfo-link-with-unknown-path-format) desc)))))
  963. (defun org-texinfo--inline-image (link info)
  964. "Return Texinfo code for an inline image.
  965. LINK is the link pointing to the inline image. INFO is the
  966. current state of the export, as a plist."
  967. (let* ((parent (org-export-get-parent-element link))
  968. (label (and (org-element-property :name parent)
  969. (org-texinfo--get-node parent info)))
  970. (caption (org-export-get-caption parent))
  971. (shortcaption (org-export-get-caption parent t))
  972. (path (org-element-property :path link))
  973. (filename
  974. (file-name-sans-extension
  975. (if (file-name-absolute-p path) (expand-file-name path) path)))
  976. (extension (file-name-extension path))
  977. (attributes (org-export-read-attribute :attr_texinfo parent))
  978. (height (or (plist-get attributes :height) ""))
  979. (width (or (plist-get attributes :width) ""))
  980. (alt (or (plist-get attributes :alt) ""))
  981. (image (format "@image{%s,%s,%s,%s,%s}"
  982. filename width height alt extension)))
  983. (cond ((or caption shortcaption)
  984. (org-texinfo--wrap-float image
  985. info
  986. (org-export-translate "Figure" :utf-8 info)
  987. label
  988. caption
  989. shortcaption))
  990. (label (concat "@anchor{" label "}\n" image))
  991. (t image))))
  992. ;;;; Menu
  993. (defun org-texinfo-make-menu (scope info &optional master)
  994. "Create the menu for inclusion in the Texinfo document.
  995. SCOPE is a headline or a full parse tree. INFO is the
  996. communication channel, as a plist.
  997. When optional argument MASTER is non-nil, generate a master menu,
  998. including detailed node listing."
  999. (let ((menu (org-texinfo--build-menu scope info)))
  1000. (when (org-string-nw-p menu)
  1001. (org-element-normalize-string
  1002. (format
  1003. "@menu\n%s@end menu"
  1004. (concat menu
  1005. (when master
  1006. (let ((detailmenu
  1007. (org-texinfo--build-menu
  1008. scope info
  1009. (let ((toc-depth (plist-get info :with-toc)))
  1010. (if (wholenump toc-depth) toc-depth
  1011. org-texinfo-max-toc-depth)))))
  1012. (when (org-string-nw-p detailmenu)
  1013. (concat "\n@detailmenu\n"
  1014. "--- The Detailed Node Listing ---\n\n"
  1015. detailmenu
  1016. "@end detailmenu\n"))))))))))
  1017. (defun org-texinfo--build-menu (scope info &optional level)
  1018. "Build menu for entries within SCOPE.
  1019. SCOPE is a headline or a full parse tree. INFO is a plist
  1020. containing contextual information. When optional argument LEVEL
  1021. is an integer, build the menu recursively, down to this depth."
  1022. (cond
  1023. ((not level)
  1024. (org-texinfo--format-entries (org-texinfo--menu-entries scope info) info))
  1025. ((zerop level) nil)
  1026. (t
  1027. (org-element-normalize-string
  1028. (mapconcat
  1029. (lambda (h)
  1030. (let ((entries (org-texinfo--menu-entries h info)))
  1031. (when entries
  1032. (concat
  1033. (format "%s\n\n%s\n"
  1034. (org-export-data (org-export-get-alt-title h info) info)
  1035. (org-texinfo--format-entries entries info))
  1036. (org-texinfo--build-menu h info (1- level))))))
  1037. (org-texinfo--menu-entries scope info) "\n")))))
  1038. (defun org-texinfo--format-entries (entries info)
  1039. "Format all direct menu entries in SCOPE, as a string.
  1040. SCOPE is either a headline or a full Org document. INFO is
  1041. a plist containing contextual information."
  1042. (org-element-normalize-string
  1043. (mapconcat
  1044. (lambda (h)
  1045. (let* ((title
  1046. ;; Colons are used as a separator between title and node
  1047. ;; name. Remove them.
  1048. (replace-regexp-in-string
  1049. "[ \t]+:+" ""
  1050. (org-texinfo--sanitize-title
  1051. (org-export-get-alt-title h info) info)))
  1052. (node (org-texinfo--get-node h info))
  1053. (entry (concat "* " title ":"
  1054. (if (string= title node) ":"
  1055. (concat " " node ". "))))
  1056. (desc (org-element-property :DESCRIPTION h)))
  1057. (if (not desc) entry
  1058. (format (format "%%-%ds %%s" org-texinfo-node-description-column)
  1059. entry desc))))
  1060. entries "\n")))
  1061. (defun org-texinfo--menu-entries (scope info)
  1062. "List direct children in SCOPE needing a menu entry.
  1063. SCOPE is a headline or a full parse tree. INFO is a plist
  1064. holding contextual information."
  1065. (let* ((cache (or (plist-get info :texinfo-entries-cache)
  1066. (plist-get (plist-put info :texinfo-entries-cache
  1067. (make-hash-table :test #'eq))
  1068. :texinfo-entries-cache)))
  1069. (cached-entries (gethash scope cache 'no-cache)))
  1070. (if (not (eq cached-entries 'no-cache)) cached-entries
  1071. (puthash scope
  1072. (org-element-map (org-element-contents scope) 'headline
  1073. (lambda (h)
  1074. (and (not (org-not-nil (org-element-property :COPYING h)))
  1075. (not (org-element-property :footnote-section-p h))
  1076. (not (org-export-low-level-p h info))
  1077. h))
  1078. info nil 'headline)
  1079. cache))))
  1080. ;;;; Node Property
  1081. (defun org-texinfo-node-property (node-property _contents _info)
  1082. "Transcode a NODE-PROPERTY element from Org to Texinfo.
  1083. CONTENTS is nil. INFO is a plist holding contextual
  1084. information."
  1085. (format "%s:%s"
  1086. (org-element-property :key node-property)
  1087. (let ((value (org-element-property :value node-property)))
  1088. (if value (concat " " value) ""))))
  1089. ;;;; Paragraph
  1090. (defun org-texinfo-paragraph (_paragraph contents _info)
  1091. "Transcode a PARAGRAPH element from Org to Texinfo.
  1092. CONTENTS is the contents of the paragraph, as a string. INFO is
  1093. the plist used as a communication channel."
  1094. contents)
  1095. ;;;; Plain List
  1096. (defun org-texinfo-plain-list (plain-list contents info)
  1097. "Transcode a PLAIN-LIST element from Org to Texinfo.
  1098. CONTENTS is the contents of the list. INFO is a plist holding
  1099. contextual information."
  1100. (let* ((attr (org-export-read-attribute :attr_texinfo plain-list))
  1101. (indic (let ((i (or (plist-get attr :indic)
  1102. (plist-get info :texinfo-table-default-markup))))
  1103. ;; Allow indicating commands with missing @ sign.
  1104. (if (string-prefix-p "@" i) i (concat "@" i))))
  1105. (table-type (plist-get attr :table-type))
  1106. (type (org-element-property :type plain-list))
  1107. (list-type (cond
  1108. ((eq type 'ordered) "enumerate")
  1109. ((eq type 'unordered) "itemize")
  1110. ((member table-type '("ftable" "vtable")) table-type)
  1111. (t "table"))))
  1112. (format "@%s\n%s@end %s"
  1113. (if (eq type 'descriptive) (concat list-type " " indic) list-type)
  1114. contents
  1115. list-type)))
  1116. ;;;; Plain Text
  1117. (defun org-texinfo-plain-text (text info)
  1118. "Transcode a TEXT string from Org to Texinfo.
  1119. TEXT is the string to transcode. INFO is a plist holding
  1120. contextual information."
  1121. ;; First protect @, { and }.
  1122. (let ((output (org-texinfo--sanitize-content text)))
  1123. ;; Activate smart quotes. Be sure to provide original TEXT string
  1124. ;; since OUTPUT may have been modified.
  1125. (when (plist-get info :with-smart-quotes)
  1126. (setq output
  1127. (org-export-activate-smart-quotes output :texinfo info text)))
  1128. ;; LaTeX into @LaTeX{} and TeX into @TeX{}
  1129. (let ((case-fold-search nil))
  1130. (setq output (replace-regexp-in-string "\\(?:La\\)?TeX" "@\\&{}" output)))
  1131. ;; Convert special strings.
  1132. (when (plist-get info :with-special-strings)
  1133. (setq output
  1134. (replace-regexp-in-string
  1135. "\\.\\.\\." "@dots{}"
  1136. (replace-regexp-in-string "\\\\-" "@-" output))))
  1137. ;; Handle break preservation if required.
  1138. (when (plist-get info :preserve-breaks)
  1139. (setq output (replace-regexp-in-string
  1140. "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output)))
  1141. ;; Return value.
  1142. output))
  1143. ;;;; Planning
  1144. (defun org-texinfo-planning (planning _contents info)
  1145. "Transcode a PLANNING element from Org to Texinfo.
  1146. CONTENTS is nil. INFO is a plist holding contextual
  1147. information."
  1148. (concat
  1149. "@noindent"
  1150. (mapconcat
  1151. 'identity
  1152. (delq nil
  1153. (list
  1154. (let ((closed (org-element-property :closed planning)))
  1155. (when closed
  1156. (concat
  1157. (format "@strong{%s} " org-closed-string)
  1158. (format (plist-get info :texinfo-inactive-timestamp-format)
  1159. (org-timestamp-translate closed)))))
  1160. (let ((deadline (org-element-property :deadline planning)))
  1161. (when deadline
  1162. (concat
  1163. (format "@strong{%s} " org-deadline-string)
  1164. (format (plist-get info :texinfo-active-timestamp-format)
  1165. (org-timestamp-translate deadline)))))
  1166. (let ((scheduled (org-element-property :scheduled planning)))
  1167. (when scheduled
  1168. (concat
  1169. (format "@strong{%s} " org-scheduled-string)
  1170. (format (plist-get info :texinfo-active-timestamp-format)
  1171. (org-timestamp-translate scheduled)))))))
  1172. " ")
  1173. "@*"))
  1174. ;;;; Property Drawer
  1175. (defun org-texinfo-property-drawer (_property-drawer contents _info)
  1176. "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
  1177. CONTENTS holds the contents of the drawer. INFO is a plist
  1178. holding contextual information."
  1179. (and (org-string-nw-p contents)
  1180. (format "@verbatim\n%s@end verbatim" contents)))
  1181. ;;;; Quote Block
  1182. (defun org-texinfo-quote-block (quote-block contents _info)
  1183. "Transcode a QUOTE-BLOCK element from Org to Texinfo.
  1184. CONTENTS holds the contents of the block. INFO is a plist
  1185. holding contextual information."
  1186. (let* ((title (org-element-property :name quote-block))
  1187. (start-quote (concat "@quotation"
  1188. (if title
  1189. (format " %s" title)))))
  1190. (format "%s\n%s@end quotation" start-quote contents)))
  1191. ;;;; Radio Target
  1192. (defun org-texinfo-radio-target (radio-target text info)
  1193. "Transcode a RADIO-TARGET object from Org to Texinfo.
  1194. TEXT is the text of the target. INFO is a plist holding
  1195. contextual information."
  1196. (format "@anchor{%s}%s"
  1197. (org-texinfo--get-node radio-target info)
  1198. text))
  1199. ;;;; Section
  1200. (defun org-texinfo-section (section contents info)
  1201. "Transcode a SECTION element from Org to Texinfo.
  1202. CONTENTS holds the contents of the section. INFO is a plist
  1203. holding contextual information."
  1204. (org-trim
  1205. (concat contents
  1206. "\n"
  1207. (let ((parent (org-export-get-parent-headline section)))
  1208. (and parent (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. (defun org-texinfo-export-to-texinfo
  1383. (&optional async subtreep visible-only body-only ext-plist)
  1384. "Export current buffer to a Texinfo file.
  1385. If narrowing is active in the current buffer, only export its
  1386. narrowed part.
  1387. If a region is active, export that region.
  1388. A non-nil optional argument ASYNC means the process should happen
  1389. asynchronously. The resulting file should be accessible through
  1390. the `org-export-stack' interface.
  1391. When optional argument SUBTREEP is non-nil, export the sub-tree
  1392. at point, extracting information from the headline properties
  1393. first.
  1394. When optional argument VISIBLE-ONLY is non-nil, don't export
  1395. contents of hidden elements.
  1396. When optional argument BODY-ONLY is non-nil, only write code
  1397. between \"\\begin{document}\" and \"\\end{document}\".
  1398. EXT-PLIST, when provided, is a property list with external
  1399. parameters overriding Org default settings, but still inferior to
  1400. file-local settings.
  1401. Return output file's name."
  1402. (interactive)
  1403. (let ((outfile (org-export-output-file-name ".texi" subtreep))
  1404. (org-export-coding-system org-texinfo-coding-system))
  1405. (org-export-to-file 'texinfo outfile
  1406. async subtreep visible-only body-only ext-plist)))
  1407. (defun org-texinfo-export-to-info
  1408. (&optional async subtreep visible-only body-only ext-plist)
  1409. "Export current buffer to Texinfo then process through to INFO.
  1410. If narrowing is active in the current buffer, only export its
  1411. narrowed part.
  1412. If a region is active, export that region.
  1413. A non-nil optional argument ASYNC means the process should happen
  1414. asynchronously. The resulting file should be accessible through
  1415. the `org-export-stack' interface.
  1416. When optional argument SUBTREEP is non-nil, export the sub-tree
  1417. at point, extracting information from the headline properties
  1418. first.
  1419. When optional argument VISIBLE-ONLY is non-nil, don't export
  1420. contents of hidden elements.
  1421. When optional argument BODY-ONLY is non-nil, only write code
  1422. between \"\\begin{document}\" and \"\\end{document}\".
  1423. EXT-PLIST, when provided, is a property list with external
  1424. parameters overriding Org default settings, but still inferior to
  1425. file-local settings.
  1426. When optional argument PUB-DIR is set, use it as the publishing
  1427. directory.
  1428. Return INFO file's name."
  1429. (interactive)
  1430. (let ((outfile (org-export-output-file-name ".texi" subtreep))
  1431. (org-export-coding-system org-texinfo-coding-system))
  1432. (org-export-to-file 'texinfo outfile
  1433. async subtreep visible-only body-only ext-plist
  1434. (lambda (file) (org-texinfo-compile file)))))
  1435. ;;;###autoload
  1436. (defun org-texinfo-publish-to-texinfo (plist filename pub-dir)
  1437. "Publish an org file to Texinfo.
  1438. FILENAME is the filename of the Org file to be published. PLIST
  1439. is the property list for the given project. PUB-DIR is the
  1440. publishing directory.
  1441. Return output file name."
  1442. (org-publish-org-to 'texinfo filename ".texi" plist pub-dir))
  1443. ;;;###autoload
  1444. (defun org-texinfo-convert-region-to-texinfo ()
  1445. "Assume the current region has Org syntax, and convert it to Texinfo.
  1446. This can be used in any buffer. For example, you can write an
  1447. itemized list in Org syntax in an Texinfo buffer and use this
  1448. command to convert it."
  1449. (interactive)
  1450. (org-export-replace-region-by 'texinfo))
  1451. (defun org-texinfo-compile (file)
  1452. "Compile a texinfo file.
  1453. FILE is the name of the file being compiled. Processing is done
  1454. through the command specified in `org-texinfo-info-process',
  1455. which see. Output is redirected to \"*Org INFO Texinfo Output*\"
  1456. buffer.
  1457. Return INFO file name or an error if it couldn't be produced."
  1458. (message "Processing Texinfo file %s..." file)
  1459. (let* ((log-name "*Org INFO Texinfo Output*")
  1460. (log (get-buffer-create log-name))
  1461. (output
  1462. (org-compile-file file org-texinfo-info-process "info"
  1463. (format "See %S for details" log-name)
  1464. log)))
  1465. (when org-texinfo-remove-logfiles
  1466. (let ((base (file-name-sans-extension output)))
  1467. (dolist (ext org-texinfo-logfiles-extensions)
  1468. (let ((file (concat base "." ext)))
  1469. (when (file-exists-p file) (delete-file file))))))
  1470. (message "Process completed.")
  1471. output))
  1472. (provide 'ox-texinfo)
  1473. ;; Local variables:
  1474. ;; generated-autoload-file: "org-loaddefs.el"
  1475. ;; End:
  1476. ;;; ox-texinfo.el ends here