ox-texinfo.el 60 KB

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