Set alt attribute when publishing a figure
Mostra commenti meno recenti
I am using Publish to write some documentation that will be included in a larger website. I would like to be able to properly caption my figures:
function testAlt
figure(1);
x=0:.1:2*pi;
y=sin(x);
plot(x,y);
set(gcf,'Tag','Sine wave');
Produces:
<img vspace="5" hspace="5" src="testAlt_01.png" alt="">
What I want is:
<figure>
<img vspace="5" hspace="5" src="testAlt_01.png" alt="">
<figcaption>Sine wave</figcaption>
</figure>
Which would render as:

Looking at toolbox/matlab/codetools/private/mxdom2simplehtml.xsl, the <img> template contains:
<xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute>
I can modify this file to include:
<figure>
...
<figcaption><xsl:value-of select="@alt"/></figcaption>
</figure>
and I'll get my caption. Only problem is that there doesn't seem to be a way to propogate any property of gcf into the XML. @alt seems like the natural choice, and since someone wrote the code to consume it, perhaps someone could write the code to produce it.
My other suggestion on this is that embedding the css style sheet in an xsl file in a folder named "private" is painful. Why not provide a configuration parameter "cssfile" that would import the specified file into the document's head?
<link rel="stylesheet" type="text/css"><xsl:attribute name="href">u<xsl:value-of select="@cssfile"/></xsl:attribute></link>
Where I can put:
figure {
display: inline-block;
margin: 20px;
}
figure img {
vertical-align: top;
}
figure figcaption {
caption-side: bottom;
padding: 10px;
font-weight: bold;
font-size: 110%;
text-align: center;
}
1 Commento
Jeff Mandel
il 21 Feb 2025
Modificato: Jeff Mandel
il 22 Feb 2025
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Interactive Control and Callbacks in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!