Inserting images with alt text to compile for epub/html?

Hi, AmberV,
Thanks for this post and the sample Scrivener file. Am I understanding your solution correctly:

  1. Inside Scrivener project, create a style called “Raw HTML Block” The stock Ebook compile Format comes with a matching style for the output.
  2. Select the image tag within my Scrivener project and apply the new style.
    OR
    Select the image itself?
  3. Fill in the alt text for that image.
  4. Compile the epub.

I also wondered: is it difficult for the next version of Scrivener to add a new style in the stock Ebook compile format called “ALTTEXT”?

And the corresponding metatag to the Inspector?

(Just thinking how nice it would be for you all if all the authors using Scrivener don’t show up and ask the same question about alt text. :blush: )

Regards and thanks,
Laurel

So with this approach you can’t use an image directly, because then that will cause Scrivener to create the full HTML itself, instead of how we’re doing it here, creating the HTML ourselves (with styles), so that we can insert the text we want into the right places.

The examples where I show an image in the editor are either in an inline annotation (so it stripped out), or inside the text area of the section that is using a Type that will not export the text area at all. In both cases this is meant to demonstrate how we can show the image for our reference, in writing around it, but not use it.

As for us adding an alt field to the software, while that in and of itself wouldn’t be difficult, it’s the conversion that would require a different approach to how we are making ebooks (at least on Mac). Your work is converted to Markdown, and we use the MultiMarkdown engine in Scrivener to generate the HTML from that. So we don’t actually have direct control over how the image HTML is created. It would be a little easier on Windows. Overall though, I do certainly agree it would be a nice improvement to the software—but given how it would take a bit of a change in thinking, it might be better to think of for a future major upgrade.

Those who do wish to use Markdown to generate ebooks, rather than rich text conventions, could use Pandoc, which Scrivener has integration with and even has extensive front end for, in the compiler. Pandoc has a way of supplying alt text, like so:

![Here is the caption of the image](images/filename.png){alt="Alt text goes here"}

So in a way it’s not too different than one of the examples I gave, but of course this method depends upon using a different ePub generator, with its own way of doing things. One is required to know CSS well enough to design a book with it, rather than use a GUI to generate that CSS for them.

1 Like

What am I missing? I’ve worked on replicating this for 3 or 4 long evening sessions, but I’m not getting it to work. Just now, I tried dragging my sample texts into the binder of Amber’s scriv project, but even that didn’t compile. I’ve learned how to add this in Sigil, but that means every time I re-compile an epub, I have to re-edit the files. Would really prefer not to do that. I tried all three methods.

In this project, I’m trying to add alt tags to images that are in the Backmatter folder (Research folder). I don’t know if that makes any difference. I couldn’t get it to work inside the main project either.

“Image Sections” method

I got the alt text and the caption to show, but the image is missing:
I tried pasting the image in, insert image linked to document, adding and dropping the .jpg in the binder name. How exactly do I tell Scrivener where the image is?


Thanks in advance for your help!
Laurel

“Raw html method”
I didn’t get this method to work at all, because I can’t seem to tell Scrivener that this is html. I’m wondering if I deleted the original compile styles I need. Maybe I missed settings when I created new ones for Raw html block and character style Raw html?




Styles Method
I added the metadata in the Inspector and created the image name and figure styles.



This method gave me an error in the epub and the image and alt text were both missing.


Any tips are welcome! I’d really like to figure this out without too many more long evenings. There are books to write :slight_smile:

A post was split to a new topic: Does Scrivener use accessible section breaks in ePub?

I deleted this post and added images above.

I don’t think it is a problem with the styles in this case. Note how the <figure> part disappears from the visible text, meaning it worked at least to some degree. I think the main problem is that after that point, this isn’t valid HTML, you have typographic characters in here for quotes. You need <img src="this"...> not <img src=“this”...>.

For this one, an HTML code snippet would be a lot more useful to see than the error message. It’s hard to tell from the screenshot as they fields are tiny, but if you copied and pasted your HTML into the style prefix/suffix fields from the other example, it likely has the same problem of fancy typography in a code environment.

Here’s a snippet of HTML from the epub in Sigil:

Thanks for the tip about the curly quotes. Once I fixed them, I still have a missing image and alt text here too:

I figured out the error message by looking at the invisibles in the Scrivener editor. I had to delete a blank line that I think was centered and hit return.

I still can’t get image and alt text to appear.


I can’t really help too much with missing images. That’s going to be something you need to back-trace from the result, see what is going wrong in the ePub, and then fixing in Scrivener. I can maybe help if you know more, and can relay where you are stuck, but I’m just looking at a picture of an error over here.

General non-Scrivener missing image troubleshooting starts with looking for the image name you’re referencing, in the ePub. They’ll be sorted into an Images subfolder. If you don’t see a file with precisely the name you gave, capitals and punctuation and extension all matter, then it will break. Finding the actual file name, copying it, and pasting it into the HTML to replace the incorrect reference should reconnect it. Then of course if that works, you want to fix Scrivener by pasting the same filename into your blue style here.

1 Like

The image compiles perfectly until I add the new options to add the caption and alt text.

I thought I might need to add the file suffix .jpg but I tried it with and without. It didn’t compile either way. I also tried turning on Treat as markup for the Image Name and Alt Text styles, but that wasn’t it either.

I uploaded HTML code. I don’t know how else to show you where it isn’t working.

Hmm, I guess my point of confusion is that the most recent HTML snippets you posted look fine to me. I see the alt text in them, and the image is referenced correctly.[1] The only thing I can’t know from these snippets is whether an image by that name is in the ePub, which is why I went down that train of thought, before.

I guess what does it mean when you say the alt text does not appear? Just to get the basics out of the way, we wouldn’t actually expect it to appear, in the literal sense, anywhere other than in the HTML code itself. It would be read aloud, when using a screen reader, and maybe at most in some other tools it might be presented somehow, like in a tooltip, but with Sigil anyway you’re not going to see it anywhere in the preview panel.

So again I can only say that I see nothing wrong in the HTML you’ve posted. Myself I would add a line in Sigil below the figure Scrivener added, and use Insert ▸ File... to insert this image, selecting the same one that should be showing, in the dialogue box. Then compare the two <img...> lines and look for typos, capitalisation differences, that sort of thing. If you copy and paste what Sigil created from between the src="..." quotes, into the one Scrivener created, does it suddenly work? If so, then try pasting that (sans the ‘images/’ prefix) into the styled text in Scrivener, and seeing if compiling with that is better.

I don’t know how else to show you where it isn’t working.

Well if the above doesn’t help, if it is not too difficult for you, sharing a sample project with a line of text like you’ve shown in the screenshot, with an image and caption, and the compile settings you are using, might help me more easily see what is going wrong. Or if that’s too much trouble, feel free to send a copy of the working project privately, either by clicking on my avatar and sending a Message, or to official tech support, where they will alert me.


  1. My only hesitation there is that it is being referred to as in the “Images” folder, when I believe Scrivener would be creating an “images” folder, which is different. ↩︎

2 Likes