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