3

I am currently writing a report where I use hyperlink, as an example \href{run:./Annex/MyTestResult.pdf}{Annex 4}. It works pretty fine.

However, I would like to add a counter for Annex numbering. Is there a way to make this easier for example by using \newcommand? If so, how can I add a counter and use \href command?

Airthan
  • 145
  • 2
    \newcounter{annexcntr}\newcommand{\annexref}[1]{\refstepcounter{annexcntr}\href{#1}{Annex~ \theannexctr}, most likely? \annexref{run:./Annex/MyTestResult.pdf} should work then –  Feb 28 '19 at 13:41

1 Answers1

3

I'm no really sure what's the expected output. Following Christian Hupfer's lead, I reordered and cleaned up the code thus:

\documentclass{article}
\usepackage{hyperref}
\newcounter{annexcntr}

\newcommand*{\annexref}[1]{%
    \stepcounter{annexcntr}%
    \href{#1}{Annex~\arabic{annexcntr}}%
    }

\begin{document}
    \annexref{run:./Annex/MyTestResult.pdf}
    \annexref{run:./Annex/MyTestResult.pdf}
\end{document}

Which renders as:

enter image description here

NVaughan
  • 8,175
  • What does clean up and reorder mean in conjunction with my comment, apart from that it was a comment only, lacking display facilities and the fact that I've forgotten a closing } accidentally? –  Feb 28 '19 at 17:30
  • I took your comment and changed the \theannexctr to \arabic{annexctr}, and created a MWE. I also gave you credit for it. Feel free to post is as an answer, if you wish to. – NVaughan Mar 01 '19 at 14:52
  • 1
    \theannexcntr is the preferred way to display the counter value according to requested format. It falls back to \arabic{annexctr} if not specified otherwise... Taking comments of other users is not the way to start, actually. –  Mar 03 '19 at 16:36