Skip to content

Commit

Permalink
scoped \href arguments to avoid leaking color (#2433)
Browse files Browse the repository at this point in the history
* scoped \href arguments to avoid leaking color

* add new test for color containment in \href

* reorganize+optimize around "bounded"; reuse test
  • Loading branch information
dginev authored Dec 18, 2024
1 parent 116748f commit 1301850
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/LaTeXML/Engine/Base_Utility.pool.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,7 @@ DefPrimitive('\@add@frontmatter OptionalKeyVals {} OptionalKeyVals {}', sub {
$$entry[2] = Digest(Tokens(T_BEGIN, $tokens, T_END));
AssignValue(inPreamble => $inpreamble);
return; },
beforeDigest => sub {
$_[0]->bgroup; },
afterDigest => sub {
$_[0]->egroup; });
bounded => 1);

# Append a piece of data to an existing frontmatter item that is contained in <$tag>
# If $label is given, look for an item which has label=>$label,
Expand Down
2 changes: 2 additions & 0 deletions lib/LaTeXML/Package/hyperref.sty.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ DefMacro('\url', '\begingroup\lx@hyper@url\url', locked => 1);
DefConstructor('\lx@hyper@url@ Undigested {}{} Semiverbatim {}',
"?#isMath(<ltx:XMWrap class='#class' href='#href'>#5</ltx:XMWrap>)" # Allow this to work in Math!
. " (<ltx:ref href='#href' class='#class'>#5</ltx:ref>)",
bounded => 1,
properties => sub { (href => ComposeURL(LookupValue('BASE_URL'), $_[4]),
class => sub { my $c = ToString($_[1]); $c =~ s/^\\//; 'ltx_' . $c; }); },
sizer => '#5',
Expand All @@ -205,6 +206,7 @@ DefMacro('\hyperref', '\@ifnextchar[\hyperref@@ii\hyperref@@iv');
# 2 argument form
DefConstructor('\hyperref@@ii OptionalSemiverbatim {}',
"<ltx:ref labelref='#label'>#2</ltx:ref>",
bounded => 1,
properties => sub { (label => CleanLabel($_[1])); });
# 4 argument form
DefConstructor('\hyperref@@iv Semiverbatim Semiverbatim Semiverbatim Semiverbatim',
Expand Down
Binary file modified t/complex/hypertest.pdf
Binary file not shown.
13 changes: 13 additions & 0 deletions t/complex/hypertest.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
% Note also that older hyperxmp has fewer new options!
\usepackage{hyperxmp}
\usepackage[draft,pdftitle={Test Hyperref Metadata},backref]{hyperref}
\usepackage{xcolor}
\title{Test Hyperref Metadata}
\author{A..~Author}
\hypersetup{
Expand Down Expand Up @@ -39,4 +40,16 @@ \section{URL's}

And, you get this: \url{http://example.com/\~{}user}

\section{Bounded color}
A link: \href{https://example.com}{\color{blue}here}.

\subsection{Color should not leak into this heading}
This text should be black.

\def\simple#1#2{#1 and #2}
A simple macro: \simple{\color{blue}first}{second}.

\subsection{Color should leak into this heading}
This text should be blue.

\end{document}
40 changes: 40 additions & 0 deletions t/complex/hypertest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<?latexml class="article"?>
<?latexml package="hyperxmp"?>
<?latexml package="hyperref" options="draft,pdftitle=Test Hyperref Metadata,backref"?>
<?latexml package="xcolor"?>
<?latexml RelaxNGSchema="LaTeXML"?>
<document xmlns="http://dlmf.nist.gov/LaTeXML" class="ltx_authors_1line" prefix="cc: http://creativecommons.org/ns# dcterms: http://purl.org/dc/terms/">
<resource src="LaTeXML.css" type="text/css"/>
Expand Down Expand Up @@ -46,6 +47,45 @@
<p>And, you get this: <ref class="ltx_url" font="typewriter" href="http://example.com/~{}user">http://example.com/~{}user</ref></p>
</para>
</section>
<section inlist="toc" xml:id="S3">
<tags>
<tag>3</tag>
<tag role="autoref">section 3</tag>
<tag role="refnum">3</tag>
<tag role="typerefnum">§3</tag>
</tags>
<title><tag close=" ">3</tag>Bounded color</title>
<para xml:id="S3.p1">
<p>A link: <ref class="ltx_href" color="#0000FF" href="https://example.com">here</ref>.</p>
</para>
<subsection inlist="toc" xml:id="S3.SS1">
<tags>
<tag>3.1</tag>
<tag role="autoref">subsection 3.1</tag>
<tag role="refnum">3.1</tag>
<tag role="typerefnum">§3.1</tag>
</tags>
<title><tag close=" ">3.1</tag>Color should not leak into this heading</title>
<para xml:id="S3.SS1.p1">
<p>This text should be black.</p>
</para>
<para xml:id="S3.SS1.p2">
<p>A simple macro: <text color="#0000FF">first and second.</text></p>
</para>
</subsection>
<subsection inlist="toc" xml:id="S3.SS2">
<tags>
<tag>3.2</tag>
<tag role="autoref">subsection 3.2</tag>
<tag role="refnum">3.2</tag>
<tag role="typerefnum">§3.2</tag>
</tags>
<title color="#0000FF"><tag close=" ">3.2</tag>Color should leak into this heading</title>
<para xml:id="S3.SS2.p1">
<p><text color="#0000FF">This text should be blue.</text></p>
</para>
</subsection>
</section>
<rdf about="" content="An Author" property="dcterms:creator"/>
<rdf about="" content="Not subject to copyright" property="dcterms:rights"/>
<rdf about="" content="test,hyperref" property="dcterms:subject"/>
Expand Down

0 comments on commit 1301850

Please sign in to comment.