Suppose I have the following in my dtx file (using ltxdoc):

%    \label{macro:mymacro}
%    Example text
%    \begin{macrocode}
\newcommand{\mymacro}[0]{An example macro}
%    \end{macrocode}
% ... blah blah \ref{macro:mymacro} ...

When I use \ref{macro:mymacro}, the result is empty. How can I make references to macros?

I'm using demopkg.dtx as a MWE

  • They are usually not numbered, right? Maybe try \nameref or something similar from hyperref or cleverref. – Johannes_B Jul 24 '16 at 6:58
  • @Johannes_B yes, they are not numbered (that explains why this doesn't work, thanks). Neither \nameref or cleveref seem to help though... – Keelan Jul 24 '16 at 9:06
  • Exactly, what would you want the result of \ref{macro:mymacro} to look like? For instance, should it typeset a reference to the line number? – GuM Jul 24 '16 at 12:12
  • @GustavoMezzetti ideally it would be the name of the macro defined (with a link, when using hyperref) --- a page reference can be made with \pageref. – Keelan Jul 24 '16 at 12:29
  • No, that was incorrect. \pageref would refer to the first section, subsection, ... or other labelable element before the macro. – Keelan Jul 24 '16 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.