ox-texinfo.el 61 KB

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