ox-texinfo.el 62 KB

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