ox-texinfo.el 60 KB

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