ox-texinfo.el 60 KB

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