Auto generate List of \url usages within document describes a method for generating an index of URLs that are used in the document, including page number. However, the URLs are sorted alphanumerically. I'd like to make a URL index that sorts them per page, in the order in which the links appear on the page. Furthermore, my links are actually in \hrefs and I would like to include the link text in the index:
p. 1
Wikipedia... http://wikipedia.org
SXE... http://stackexchange.com
p. 2
Google... http://google.com
I've created a MWE following the instructions from Heiko Oberdiek in the post I linked to above (compile with xelatex links.tex, makeindex links-url, xelatex links.tex). Note, the output I currently get is, as expected (but not desired) in alphabetical order rather than page order:
\documentclass[12pt,article]{memoir}
\settrimmedsize{11in}{8.5in}{*}
\settrims{0in}{0in}
\settypeblocksize{9in}{6.5in}{*}
\setlrmargins{1in}{*}{*}
\setulmargins{1in}{*}{*}
\setheadfoot{\onelineskip}{2\onelineskip}
\setheaderspaces{*}{1.5\onelineskip}{*}
\checkandfixthelayout
\PassOptionsToPackage{hyphens}{url}
\usepackage[linktoc=all,frenchlinks,pdfborderstyle={/S/U/W .5},citebordercolor={1 1 1},linkbordercolor={1 1 1},urlbordercolor={1 1 1}]{hyperref}
\makeatletter
\g@addto@macro{\UrlBreaks}{\UrlOrds}
\makeatother
\usepackage{filecontents}
\begin{filecontents*}{\jobname-url.mst}
% Input style specifiers
keyword "\\urlentry"
% Output style specifiers
preamble "\\begin{theurls}"
postamble "\\end{theurls}\n"
group_skip ""
headings_flag 0
item_0 "\n\\urlitem{"
delim_0 "}{"
delim_t "}"
line_max 500
\end{filecontents*}
\usepackage{pdfescape}
\makeatletter
\newwrite\file@url
\openout\file@url=\jobname-url.idx\relax
\def\instring#1#2{TT\fi\begingroup
\edef\x{\endgroup\noexpand\in@{#1}{#2}}\x\ifin@}
\newcommand*{\write@url}[1]{%
\begingroup
\EdefEscapeHex\@tmp{#1}%
\protected@write\file@url{}{%
\protect\urlentry{\@tmp}{\thepage}%
}%
\endgroup
}
\let\saved@hyper@linkurl\hyper@linkurl
\renewcommand*{\hyper@linkurl}[2]{%
\write@url{#2}%
\saved@hyper@linkurl{#1}{#2}%
}
\newcommand*{\listurlname}{List of URLs}
\newcommand*{\printurls}{%
\InputIfFileExists{\jobname-url.ind}{}{}%
}
\newenvironment{theurls}{%
\begin{center}{\Huge \listurlname}%
\vspace{.7in}\\ \end{center}
{All of these links were active as of \today.} \\
\quad \\ \noindent
%\section*{\listurlname}%
\@mkboth{\listurlname}{\listurlname}%
\let\write@url\@gobble
\ttfamily\footnotesize
\raggedright
\hspace{-1.4em}
}{%
\par
}
\newcommand*{\urlitem}[2]{%
\hangindent=1em
\hangafter=1
\begingroup
\urlpages{#2}%
\EdefUnescapeHex\@tmp{#1}%
\expandafter\url\expandafter{\@tmp}%
\endgroup
\newline
}
\newcommand*{\urlpages}[1]{%
{%
\normalfont
\space(\if\instring{,}{#1}{pp.\space#1}\else{p.\space\hyperlink{page.#1}{#1}}\fi)}
}
\makeatother
\begin{document}
\href{http://wikipedia.org}{Wikipedia} \href{http://stackexchange.com}{SXE}
\newpage
\href{http://google.com}{Google}
\section*{Index of URLs}
\printurls
\end{document}


\urlis not defined anymore. Logic because there is no key-text for the index list. But often it may be usefull to display the url in the text and listed the url also in the index with key-information. Is there a way to make\urlcommand working with two arguments (url + key-text) also to display url in the document and the same listing as\hrefin the index ? – Piroooh Apr 21 '20 at 15:05