Set alt attribute when publishing a figure

조회 수: 3 (최근 30일)
Jeff Mandel
Jeff Mandel 2025년 2월 20일
편집: Jeff Mandel 2025년 2월 22일
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
Jeff Mandel
Jeff Mandel 2025년 2월 21일
편집: Jeff Mandel 2025년 2월 22일
A bit of a kludge, but until @alt is available, change the xsl to:
<figcaption>Figure <xsl:value-of select="substring(@src,string-length($title)+2,2)"/></figcaption>
This takes the name of the image file (myfunction-xx.png) and pulls out the xx, so the first figure will be "Figure 01". Yes, I could probably figure out how to suppress the leading zero.
What would be a nice feature would be the ability to define an XML variable in the script, so you could cross reference to the figure, something like:
setXMLtag('fignum', 1);
setXMLtag('caption', 'Money as a function of time');
%%
% As can be seen in Figure @fignum, time is money
plot(time,money)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by