# Autoref with optional argument text *in generated link*

Related to Autoref with optional argument, I would like to define an (optional) argument to \autoref that appears after the regular autoref printout, but within the actual link that is generated by \autoref.

I.e., the command

\autoref[(left inset)]{fig:somefigure}


should produce a hyperref link with the complete text being active

... Figure 1 (left inset) ...

Is that possible in a generic way?

The trick is to always use a non-link reference and then separately adding the hyperlink: (example copied from Christian Hupfers answer to the original question)

\documentclass{article}

\usepackage{hyperref}
\usepackage{letltxmacro}
\usepackage{xparse}

\AtBeginDocument{%
\LetLtxMacro\autoreforig\autoref
\RenewDocumentCommand{\autoref}{som}{%
\IfBooleanF{#1}{%
\hyperref[#3]%
}%
{%
\autoreforig*{#3}\IfValueT{#2}{#2}%
}%
}
}

\begin{document}

See \autoref[ is very nice]{section:foo} or \autoref*[ is nice too]{section:foobar}

\section{Foo section}\label{section:foo}

\section{Foo bar section}\label{section:foobar}

\end{document}


• Great – thank you Marcel! For completeness, I've added an \xspace to automatically get the space between regular and optional argument –> \autoreforig*{#3}\xspace\IfValueT{#2}{#2} – yogik Apr 24 '18 at 18:39