Skip to content

Concise command to wrap all \ac-like commands to ensure colorless links #274

@tplobo

Description

@tplobo

Hi there @cgnieder, thanks for the package, it is great!
I currently have a difficulty with the combination of acro and hyperref, but maybe I miss some particular instruction in the acro manual.
I am trying to have links colored as usual by hyperref, but avoid the coloring for acronyms, otherwise they become very distracting in the text. The best solution I have come up with is creating a custom wrapper to locally modify hypersetup to force links to be colored in black in a small environment, and apply it using \RenewAcroCommand. However, as you can see below, this forces me to renew each \ac-like command individually:

% Define BlackLink function to color local links black
\newcommand{\BlackLink}[1]{%
    \begingroup\hypersetup{linkcolor=black}#1\endgroup
}

% Renew ac-like commands to use the BlackLink wrapper
\RenewAcroCommand\ac{m}{\BlackLink{\UseAcroTemplate{first}{#1}}}
\RenewAcroCommand\Ac{m}{\BlackLink{\acroupper\UseAcroTemplate{first}{#1}}}
\RenewAcroCommand\acp{m}{\BlackLink{\acroplural\UseAcroTemplate{first}{#1}}}
\RenewAcroCommand\Acp{m}{\BlackLink{\acroupper\acroplural\UseAcroTemplate{first}{#1}}}
\RenewAcroCommand\iac{m}{\BlackLink{\acroindefinite\UseAcroTemplate{first}{#1}}}
\RenewAcroCommand\Iac{m}{\BlackLink{\acroupper\acroindefinite\UseAcroTemplate{first}{#1}}}

% Renew acs-like commands to use the BlackLink wrapper
\RenewAcroCommand\acs{m}{\BlackLink{\UseAcroTemplate{short}{#1}}}
\RenewAcroCommand\Acs{m}{\BlackLink{\acroupper\UseAcroTemplate{short}{#1}}}
\RenewAcroCommand\acsp{m}{\BlackLink{\acroplural\UseAcroTemplate{short}{#1}}}
\RenewAcroCommand\Acsp{m}{\BlackLink{\acroupper\acroplural\UseAcroTemplate{short}{#1}}}
\RenewAcroCommand\iacs{m}{\BlackLink{\acroindefinite\UseAcroTemplate{short}{#1}}}
\RenewAcroCommand\Iacs{m}{\BlackLink{\acroupper\acroindefinite\UseAcroTemplate{short}{#1}}}

% Renew acl-like commands to use the BlackLink wrapper
\RenewAcroCommand\acl{m}{\BlackLink{\UseAcroTemplate{long}{#1}}}
\RenewAcroCommand\Acl{m}{\BlackLink{\acroupper\UseAcroTemplate{long}{#1}}}
\RenewAcroCommand\aclp{m}{\BlackLink{\acroplural\UseAcroTemplate{long}{#1}}}
\RenewAcroCommand\Aclp{m}{\BlackLink{\acroupper\acroplural\UseAcroTemplate{long}{#1}}}
\RenewAcroCommand\iacl{m}{\BlackLink{\acroindefinite\UseAcroTemplate{long}{#1}}}
\RenewAcroCommand\Iacl{m}{\BlackLink{\acroupper\acroindefinite\UseAcroTemplate{long}{#1}}}

% Renew aca-like commands to use the BlackLink wrapper
\RenewAcroCommand\aca{m}{\BlackLink{\UseAcroTemplate{alt}{#1}}}
\RenewAcroCommand\Aca{m}{\BlackLink{\acroupper\UseAcroTemplate{alt}{#1}}}
\RenewAcroCommand\acap{m}{\BlackLink{\acroplural\UseAcroTemplate{alt}{#1}}}
\RenewAcroCommand\Acap{m}{\BlackLink{\acroupper\acroplural\UseAcroTemplate{alt}{#1}}}
\RenewAcroCommand\iaca{m}{\BlackLink{\acroindefinite\UseAcroTemplate{alt}{#1}}}
\RenewAcroCommand\Iaca{m}{\BlackLink{\acroupper\acroindefinite\UseAcroTemplate{alt}{#1}}}

% Renew acf-like commands to use the BlackLink wrapper
\RenewAcroCommand\acf{m}{\BlackLink{\acrofull\UseAcroTemplate{first}{#1}}}
\RenewAcroCommand\Acf{m}{\BlackLink{\acroupper\acrofull\UseAcroTemplate{first}{#1}}}
\RenewAcroCommand\acfp{m}{\BlackLink{\acrofull\acroplural\UseAcroTemplate{first}{#1}}}
\RenewAcroCommand\Acfp{m}{\BlackLink{\acroupper\acrofull\acroplural\UseAcroTemplate{first}{#1}}}
\RenewAcroCommand\iacf{m}{\BlackLink{\acroindefinite\acrofull\UseAcroTemplate{first}{#1}}}
\RenewAcroCommand\Iacf{m}{\BlackLink{\acroupper\acroindefinite\acrofull\UseAcroTemplate{first}{#1}}}

I can make it more concise by renewing the \UseAcroTemplate command directly, but that does not use \RenewAcroCommand:

\newcommand{\BlackLink}[1]{%
    \begingroup\hypersetup{linkcolor=black}#1\endgroup
}
\let\OriginalUseAcroTemplate\UseAcroTemplate
\renewcommand{\UseAcroTemplate}[2]{\BlackLink{\OriginalUseAcroTemplate{#1}{#2}}}`

and unfortunately it does not work if I just want colorless links:

\newcommand{\ColorlessLink}[1]{%
    \begingroup\hypersetup{colorlinks=false}#1\endgroup
}
\let\OriginalUseAcroTemplate\UseAcroTemplate
\renewcommand{\UseAcroTemplate}[2]{\ColorlessLink{\OriginalUseAcroTemplate{#1}{#2}}}`

Is there a correct way of doing this using acro commands? Is defining a new template required?

Thanks,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions