In my document, when referring to a certain section, I'm currently
using \ref and writing "§5.3" instead of "Section 5.3". Now I want to
use autoref to get the link on the entire "§5.3" and not just on
"5.3".
Therefore, I wrote the following command:
\def\sectionautorefname{\S{}}
It works good, except for one thing: it inserts a space after the
section symbol and before the section number. So the reference shown
above looks like "§ 5.3". I also tried "\def\sectionautorefname{\S\ }"
but that also doesn't work.
How do I get rid of this unwanted single space character? Thanks in
advance.
Best Regards,
Faraz Hussain.
Hello,
unfortunately this is hard-wired, so you have to do a bit of hacking:
\documentclass{article}
\usepackage{hyperref}
\makeatletter
\renewcommand*\sectionautorefname{\S\@gobble}
\makeatother
\begin{document}
\section{Foo}
\label{Foo}
\autoref{Foo}
\end{document}
The \@gobble removes the space that is inserted by hyperref.
--
Replace “READ-MY-SIG” by “tcalveu” to answer by mail.
> \def\sectionautorefname{\S{}}
hyperref automatically inserts a "~" (space without
line-break-permission) between the autorefname and
the number.
You could have removed that "~" by \@gobble.
Another possibility is using as the last token of your
autorefname a macro which does not take arguments
but whose parameter-text is delimited by a "~" .
In case something goes wrong, \@gobble would remove
just something which might lead to unpredictable
results and probably later on strange error-messages.
A macro with delimited parameter-text immediately
delivers a "does not match its definition"-error.
Ulrich
\documentclass{article}
\usepackage{hyperref}
\newcommand\myS[1]{}%<-launch error in case \myS is already defined.
\def\myS~{\S{}}
\renewcommand*\sectionautorefname{\myS}
On Mar 13, 3:13 pm, Ulrich D i e z <eu_angel...@web.de.invalid>
wrote:
>
> hyperref automatically inserts a "~" (space without
> line-break-permission) between the autorefname and
> the number.
>
> You could have removed that "~" by \@gobble.
>
> Another possibility is using as the last token of your
> autorefname a macro which does not take arguments
> but whose parameter-text is delimited by a "~" .
Are you talking about the ~ inside "\def\myS~{\S{}}"? Please tell me
what its for. I think the definition would be fine even without
it ...?
>
> In case something goes wrong, \@gobble would remove
> just something which might lead to unpredictable
> results and probably later on strange error-messages.
> A macro with delimited parameter-text immediately
> delivers a "does not match its definition"-error.
Okay. And I just tried your suggested method using my own macro and
its working great. Thanks!
This definition implies that every occurrence of \myS has to be followed
by ~.
\myS ~
will work, while
\myS 123
will give an error ("Usage of \myS doesn't match its definition"). Now
hyperref inserts the contents of \sectionautorefname, followed by a ~.
The \myS command checks if it is followed by this ~ and then removes it.
If hyperref was changed in a way so that \sectionautorefname would be
followed by \SomeImportantCommand, this definition of \myS would give an
error. The solution with \@gobble would silently remove
\SomeImportantCommand.
Ah, I get it now... thanks a lot again!