diff --git a/src/latex/generator.ml b/src/latex/generator.ml
index da3b93242e..2cbbe8c208 100644
--- a/src/latex/generator.ml
+++ b/src/latex/generator.ml
@@ -97,7 +97,7 @@ let elt_size (x : elt) =
| Code_fragment _ | Tag _ | Break _ | Ligaturable _ ->
Small
| List _ | Section _ | Verbatim _ | Raw _ | Code_block _ | Indented _
- | Description _ ->
+ | Description _ | Image _ ->
Large
| Table _ | Layout_table _ -> Huge
@@ -169,6 +169,7 @@ let rec pp_elt ppf = function
| Indented x -> Raw.indent pp ppf x
| Ligaturable s -> Fmt.string ppf s
| Tag (s, t) -> tag s ppf t
+ | Image target -> Raw.includegraphics Fpath.pp ppf target
and pp ppf = function
| [] -> ()
@@ -283,9 +284,24 @@ let rec block ~in_source (l : Block.t) =
let one (t : Block.one) =
match t.desc with
| Inline i -> inline ~verbatim:false ~in_source:false i
- | Audio (_, content) | Video (_, content) | Image (_, content) ->
- txt ~verbatim:false ~in_source:false [ content ]
+ | Image (Internal (Resolved x), alt) ->
+ let dir, file = Link.get_dir_and_file x.page in
+ begin match Fpath.(get_ext @@ v file) with
+ | "" | ".jpeg" | ".png" | ".pdf" ->
+ let fpath = Fpath.v (String.concat Fpath.dir_sep (dir @ [file])) in
+ [ Image fpath ]
+ | _ ->
+ txt ~verbatim:false ~in_source:false [ alt ]
@ if in_source then [] else [ Break Paragraph ]
+ end
+ | Image (Internal Unresolved, c) | Audio(Internal _, c) | Video (Internal _, c) ->
+ txt ~verbatim:false ~in_source:false [ c ]
+ @ if in_source then [] else [ Break Paragraph ]
+ | Audio (External l, content) | Video (External l, content)
+ | Image (External l, content) ->
+ let text = txt ~verbatim:false ~in_source:false [ content ] in
+ let break = if in_source then [] else [ Break Paragraph ] in
+ [ External_ref (l, Some text)] @ break
| Paragraph i ->
inline ~in_source:false ~verbatim:false i
@ if in_source then [] else [ Break Paragraph ]
diff --git a/src/latex/raw.ml b/src/latex/raw.ml
index ac6816d1b3..4c6d0078ca 100644
--- a/src/latex/raw.ml
+++ b/src/latex/raw.ml
@@ -127,6 +127,8 @@ let code_block pp ppf x =
Fmt.cut ppf ();
mend ppf name
+let includegraphics pp = create "includegraphics" pp
+
let section pp = create "section" pp
let subsection pp = create "subsection" pp
diff --git a/src/latex/raw.mli b/src/latex/raw.mli
index c6c2196d26..c247ab4b9c 100644
--- a/src/latex/raw.mli
+++ b/src/latex/raw.mli
@@ -67,6 +67,8 @@ val small_table : ('a, Types.alignment list option * 'a list list) tr
val input : Fpath.t Fmt.t
+val includegraphics: 'a t
+
(** {1 Required OCaml-specific primitives }
All the macro should be implemented as "ocaml"-suffixed macro
in the latex preamble
diff --git a/src/latex/types.ml b/src/latex/types.ml
index 3ac77cf730..72b07cc2a9 100644
--- a/src/latex/types.ml
+++ b/src/latex/types.ml
@@ -26,6 +26,7 @@ type elt =
| Layout_table of layout_table
| Table of table
| Ligaturable of string
+ | Image of Fpath.t
and section = { level : int; label : string option; content : t }
diff --git a/test/pages/medias.t/index.mld b/test/pages/medias.t/index.mld
index 6ee04f217f..947a00bffb 100644
--- a/test/pages/medias.t/index.mld
+++ b/test/pages/medias.t/index.mld
@@ -7,7 +7,7 @@
Some image:
- Without alt text:{image!caml.gif}
-- With an alt text: {{image!caml.gif}With alt text and {b emphasis}}
+- With an alt text: {{image!caml.png}With alt text and {b emphasis}}
- Unresolved without alt text: {image!caqzdqzdml.gif}
- Unresolved with alt text: {{image!camezfzeffl.gif}With alt text and {b emphasis}}
diff --git a/test/pages/medias.t/run.t b/test/pages/medias.t/run.t
index 841abe232d..480ed1d00b 100644
--- a/test/pages/medias.t/run.t
+++ b/test/pages/medias.t/run.t
@@ -3,6 +3,7 @@ We need to odoc-compile the package mld file, listing its children
$ odoc compile index.mld --parent-id pkg1/ --output-dir _odoc
$ odoc compile-asset --parent-id pkg1/ --output-dir _odoc --name caml.gif
+ $ odoc compile-asset --parent-id pkg1/ --output-dir _odoc --name caml.png
$ odoc compile-asset --parent-id pkg1/ --output-dir _odoc --name Cri_du_chameau.ogg
$ odoc compile-asset --parent-id pkg1/ --output-dir _odoc --name flower.webm
@@ -28,8 +29,8 @@ Testing the working references:
$ cat html/pkg1/index.html | grep img
-
-
+
+
@@ -72,6 +73,9 @@ Testing latex and manpages
caml.gif
./caqzdqzdml.gif
+ $ cat latex/pkg1/index.tex | grep png
+ \includegraphics{pkg1/caml.png}}%
+
$ odoc man-generate -o man _odoc/pkg1/page-index.odocl
$ cat man/pkg1/index.3o | grep gif
caml\.gif