Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,9 @@ t/complex/figure_dual_caption.xml
t/complex/figure_mixed_content.pdf
t/complex/figure_mixed_content.tex
t/complex/figure_mixed_content.xml
t/complex/graphicxalt.pdf
t/complex/graphicxalt.tex
t/complex/graphicxalt.xml
t/complex/hyperchars.pdf
t/complex/hyperchars.tex
t/complex/hyperchars.xml
Expand Down
27 changes: 20 additions & 7 deletions lib/LaTeXML/Package/graphicx.sty.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ DefKeyVal('Gin', 'keepaspectratio', '', 'true');
DefKeyVal('Gin', 'clip', '', 'true');
DefKeyVal('Gin', 'scale', '');
DefKeyVal('Gin', 'angle', '');
DefKeyVal('Gin', 'actualtext', '');
DefKeyVal('Gin', 'alt', '');
DefKeyVal('Gin', 'artifact', '', 'true');
DefKeyVal('Gin', 'trim', 'GraphixDimensions');
DefKeyVal('Gin', 'viewport', 'GraphixDimensions');
# NOTE: graphicx defines @angle to actually carry out the rotation (on \box\z@) w/\Gin@erotate
Expand All @@ -56,19 +58,30 @@ DefConstructor('\@includegraphicx OptionalMatch:* OptionalKeyVals:Gin Semiverbat
scope => 'global',
afterConstruct => sub {
my ($document, $whatsit) = @_;
my $alt = $whatsit->getProperty('alt');
# Trickery to set @description EVEN IF empty string (constructor shorthand omits it)
if (defined $alt) {
$document->getNode->lastChild->setAttribute(description => ToString($alt)); } },
my $actualtext = $whatsit->getProperty('actualtext');
my $alt = $whatsit->getProperty('alt');
my $artifact = $whatsit->getProperty('artifact');
$artifact = 1 if defined $artifact && ToString($artifact) ne 'false';
if ($artifact || defined $actualtext || defined $alt) {
my $node = $document->getNode->lastChild;
# Trickery to set @description EVEN IF empty string (constructor shorthand omits it)
$node->setAttribute(description => ToString($actualtext // $alt // ''));
# when both actualtext and alt are specified, use aria-description for alt
$document->setAttribute($node, 'aria:description', ToString($alt)) if defined $alt && defined $actualtext;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be aria:label?
Perhaps you were thrown by the awkward naming of ltx:graphics@description (as I was), which is a stand-in for html's img@alt, whose specification seems to shift over time.
The graphics keywords alt and actualtext are apparently only very subtly different; there's not (yet) a key for a detailed description, which is what aria:description should be (as I understand it).

$document->setAttribute($node, 'aria:hidden', 'true') if $artifact; } },
properties => sub {
my ($stomach, $starred, $kv, $graphic) = @_;
my $options = graphicX_options($starred, $kv);
my ($path, @candidates) = image_candidates(ToString($graphic));
my $alt = $kv && $kv->getValue('alt');
my $alt = $kv && $kv->getValue('alt');
my $actualtext = $kv && $kv->getValue('actualtext');
my $artifact = $kv && $kv->getValue('artifact');
(path => $path,
candidates => join(',', @candidates),
(defined $alt ? (alt => $alt) : ()),
options => $options); },
actualtext => $actualtext,
alt => $alt,
artifact => $artifact,
options => $options); },
mode => 'restricted_horizontal', enterHorizontal => 1);

#**********************************************************************
Expand Down
Binary file added t/complex/graphicxalt.pdf
Binary file not shown.
12 changes: 12 additions & 0 deletions t/complex/graphicxalt.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{sunset}
\includegraphics[alt={alt text}]{sunset}
\includegraphics[actualtext={actual text}]{sunset}
\includegraphics[actualtext={actual text},alt={alt text}]{sunset}
\includegraphics[artifact]{sunset}
\includegraphics[artifact,alt={alt text}]{sunset}
\includegraphics[artifact,actualtext={actual text}]{sunset}
\includegraphics[artifact,actualtext={actual text},alt={alt text}]{sunset}
\end{document}
18 changes: 18 additions & 0 deletions t/complex/graphicxalt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<?latexml class="article"?>
<?latexml package="graphicx"?>
<?latexml RelaxNGSchema="LaTeXML"?>
<document xmlns="http://dlmf.nist.gov/LaTeXML" xmlns:aria="http://www.w3.org/ns/wai-aria">
<resource src="LaTeXML.css" type="text/css"/>
<resource src="ltx-article.css" type="text/css"/>
<para xml:id="p1">
<graphics candidates="sunset.jpg" graphic="sunset" xml:id="p1.g1"/>
<graphics candidates="sunset.jpg" description="alt text" graphic="sunset" options="alt=alt text" xml:id="p1.g2"/>
<graphics candidates="sunset.jpg" description="actual text" graphic="sunset" options="actualtext=actual text" xml:id="p1.g3"/>
<graphics aria:description="alt text" candidates="sunset.jpg" description="actual text" graphic="sunset" options="actualtext=actual text,alt=alt text" xml:id="p1.g4"/>
<graphics aria:hidden="true" candidates="sunset.jpg" description="" graphic="sunset" options="artifact=true" xml:id="p1.g5"/>
<graphics aria:hidden="true" candidates="sunset.jpg" description="alt text" graphic="sunset" options="artifact=true,alt=alt text" xml:id="p1.g6"/>
<graphics aria:hidden="true" candidates="sunset.jpg" description="actual text" graphic="sunset" options="artifact=true,actualtext=actual text" xml:id="p1.g7"/>
<graphics aria:description="alt text" aria:hidden="true" candidates="sunset.jpg" description="actual text" graphic="sunset" options="artifact=true,actualtext=actual text,alt=alt text" xml:id="p1.g8"/>
</para>
</document>