1

I'm writing a report and I'd like to use superscript references (like I'm already using for the bibliography) to link to a section withing an \appendix so it appears as a superscript with brackets like [A.1] or [A.2] (to match the section I'm pointing).

All I've been able to do is the following:

\documentclass[12pt,a4paper]{article}
\usepackage[hidelinks]{hyperref}
%a million other packages

\begin{document}

Text see annex 1\ref{ref:a}

\appendix
\section{title of annex}
information\label{ref:a}

\end{document}

This works well enough, except it only displays an A without brackets with the same size as the text. Any ideas?

  • Welcome to TeX.SE. See https://tex.stackexchange.com/a/397724/31729, for example, but the term superscript is misleading, here. –  Oct 25 '17 at 11:11
  • 1
    @ChristianHupfer Why do say "superscript" is misleading, if the OP wants superscripts? – Torbjørn T. Oct 26 '17 at 20:25
  • @TorbjørnT.: Superscript is something like x^{2} for me ... –  Oct 26 '17 at 20:31
  • @ChristianHupfer Indeed I'd like them also to be superscripted, I've updated the question to make it more clear. Anyway thanks for the brackets, that's already a step in the right direction. – jackhammer Oct 27 '17 at 09:01
  • @salhelder: It was a waste of time for me to answer a question that was posted and changed afterwards :-( –  Oct 27 '17 at 09:06
  • @ChristianHupfer I just made it more clear, but I figured it out, you have my eternal gratitude, granted it ain't much. I just had to change the line to: \textsuperscript{[A.\thesection]}}% – jackhammer Oct 27 '17 at 09:09

1 Answers1

1

The cross -reference format is stored for a counter, named, say foo, as as \p@foo\csname thefoo\endcsname, basically always \p@foo is empty, and \thefoo comes into action. The storage occurs in \refstepcounter as \@currentlabel.

Defining \p@foo as [] will only print [] before \thefoo, but not enclose it. \csname thefoo\endcsname has to 'gobbled' (captured with a special macro using it as delimiter, then [A.\thefoo] can be used.

In order to limit this effect to the appendix only, I've added it to the definition of \appendix with \g@addto@macro{\appendix}.

In my explanations replace foo with section, however.

\documentclass[12pt,a4paper]{article}
\usepackage[hidelinks]{hyperref}
%a million other packages

\makeatletter
\g@addto@macro\appendix{%
  \renewcommand{\thesection}{\arabic{section}}%
  \def\@gobblerefstuff#1\csname thesection\endcsname{%
    [A.\thesection]}%
  \renewcommand{\p@section}{\@gobblerefstuff}
}
\makeatother

\begin{document}

Text see annex \ref{ref:a} or \ref{Completelydifferent}



\appendix
\section{title of annex}
information\label{ref:a}

\section{And now for something completely different} \label{Completelydifferent}

\end{document}

enter image description here