ox-texinfo.el 62 KB

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