Browse Source

ox-texinfo: Handle @image

* lisp/ox-texinfo.el (org-texinfo-inline-image-rules): New variable.
(org-texinfo--inline-image): New function.
(org-texinfo-link): Use new function.

* doc/org.texi (Texinfo specific attributes):
* etc/ORG-NEWS:  Document new feature.
Nicolas Goaziou 9 years ago
parent
commit
bc3cf21659
3 changed files with 66 additions and 3 deletions
  1. 15 3
      doc/org.texi
  2. 2 0
      etc/ORG-NEWS
  3. 49 0
      lisp/ox-texinfo.el

+ 15 - 3
doc/org.texi

@@ -13618,9 +13618,9 @@ This paragraph is preceded by...
 @subsection Texinfo specific attributes
 
 @cindex #+ATTR_TEXINFO
-@samp{texinfo} back-end understands several attributes in plain lists and
-tables.  They must be specified using an @code{#+ATTR_TEXINFO} keyword,
-written just above the list or table.
+@samp{texinfo} back-end understands several attributes in plain lists, tables
+and images.  They must be specified using an @code{#+ATTR_TEXINFO} keyword,
+written just above the list, table or table.
 
 @subsubheading Plain lists
 
@@ -13651,6 +13651,18 @@ length, using @code{:columns} attribute.
 | a cell | another cell |
 @end example
 
+@subsubheading Images
+
+Images are links to files with a supported image extension and no
+description.  Image scaling is set with @code{:width} and @code{:height}
+attributes.  You can also use @code{:alt} to specify alternate text, as
+Texinfo code.
+
+@example
+#+ATTR_TEXINFO: :width 1in :alt Alternate @@i@{text@}
+[[ridt.pdf]]
+@end example
+
 @node An example
 @subsection An example
 

+ 2 - 0
etc/ORG-NEWS

@@ -379,6 +379,8 @@ a dedicated buffer.  It works even if buffer is currently narrowed.
 *** New function ~org-delete-indentation~ bound to ~M-^~
 Work as ~delete-indentation~ unless at heading, in which case text is
 added to headline text.
+*** Support for images in Texinfo back-end
+~Texinfo~ back-end now handles images.  See manual for details.
 ** Miscellaneous
 *** Strip all meta data from ITEM special property
 ITEM special property does not contain TODO, priority or tags anymore.

+ 49 - 0
lisp/ox-texinfo.el

@@ -385,6 +385,11 @@ Specified coding system will be matched against these strings.
 If two strings share the same prefix (e.g. \"ISO-8859-1\" and
 \"ISO-8859-15\"), the most specific one has to be listed first.")
 
+(defconst org-texinfo-inline-image-rules
+  (list (cons "file"
+	      (regexp-opt '("eps" "pdf" "png" "jpg" "jpeg" "gif" "svg"))))
+  "Rules characterizing image files that can be inlined.")
+
 
 ;;; Internal Functions
 
@@ -917,6 +922,8 @@ INFO is a plist holding contextual information.  See
 		(t raw-path))))
     (cond
      ((org-export-custom-protocol-maybe link desc 'texinfo))
+     ((org-export-inline-image-p link org-texinfo-inline-image-rules)
+      (org-texinfo--inline-image link info))
      ((equal type "radio")
       (let ((destination (org-export-resolve-radio-link link info)))
 	(if (not destination) desc
@@ -983,6 +990,48 @@ INFO is a plist holding contextual information.  See
      (t
       (format (plist-get info :texinfo-link-with-unknown-path-format) desc)))))
 
+(defun org-texinfo--inline-image (link info)
+  "Return Texinfo code for an inline image.
+LINK is the link pointing to the inline image.  INFO is the
+current state of the export, as a plist."
+  (let* ((parent (org-export-get-parent-element link))
+	 (caption (org-export-get-caption parent))
+	 (shortcaption (org-export-get-caption parent t))
+	 (filename
+	  (file-name-sans-extension
+	   (let ((raw-path (org-element-property :path link)))
+	     (if (not (file-name-absolute-p raw-path)) raw-path
+	       (expand-file-name raw-path)))))
+	 (attributes (org-export-read-attribute :attr_texinfo parent))
+	 (height (or (plist-get attributes :height) ""))
+	 (width (or (plist-get attributes :width) ""))
+	 (alt (or (plist-get attributes :alt) ""))
+	 (image (format "@image{%s,%s,%s,%s}" filename width height alt)))
+    (if (not (or caption shortcaption)) image
+      (let ((label (org-element-property :name parent))
+	    (b (org-export-create-backend
+		:parent 'texinfo
+		:transcoders '((footnote-reference . ignore)
+			       (inline-src-block . ignore)
+			       (link . (lambda (object c i) c))
+			       (radio-target . (lambda (object c i) c))
+			       (target . ignore)
+			       (verbatim . ignore)))))
+	(format "@float %s%s\n%s\n%s%s@end float"
+		(org-export-translate "Figure" :utf-8 info)
+		(if label (concat "," label) "")
+		image
+		(if caption
+		    (concat "@caption{"
+			    (org-export-data-with-backend caption b info)
+			    "}\n")
+		  "")
+		(if shortcaption
+		    (concat "@shortcaption{"
+			    (org-export-data-with-backend shortcaption b info)
+			    "}\n")
+		  ""))))))
+
 
 ;;;; Menu