5

I am trying to accomplish something like in this question and this question.

I have several authors contributing solutions to problems that are numbered using an externally imposed scheme, which I handle via the description environment. I wrap each author's name in \index{} and need the printed index to display the problem number as it appears in the external scheme. Right now I'm using the report document class, but could be persuaded to change.

I picked up a way to capture the external numbering using a modified \ref{} command from here, but have not been able to get the index to display other than just the counter value.

For example:

\documentclass{report}
\usepackage{makeidx}
\makeindex
\usepackage{hyperref}

\newcounter{desccount}
\newcommand{\descitem}[1]{%
\item[#1] \refstepcounter{desccount}\label{#1}
}
\newcommand{\descref}[1]{\hyperref[#1]{#1}}

\begin{document}
\begin{description}
\descitem{1B.1} by \index{Smith}
\descitem{1B.3} by \index{Jones}
\descitem{1C.1} by \index{Smith}
\descitem{1E.11} by \index{Burton}
\end{description}

\printindex

\end{document}

I would like the resulting index of the document to be

Burton   1E.11  
Jones    1B.3  
Smith    1B.1, 1C.1

with hyperref filling in the hyperlinks appropriately. The closest I've come is to use the memoir document class and include a \renewcommand{\index}[1]{\specialindex{\jobname}{desccount}{#1}} but this simply returns the value of desccount and not the external numbering scheme. In the example given, the output I would get is

Burton    4  
Jones     2  
Smith     1, 3

which is not quite what I want. How can I have the index return the argument of \descitem instead of the page number or the value of desccount?

3
  • This seems more like a glossary, than an index. I'd look into the glossaries package.
    – egreg
    Commented Feb 4, 2015 at 20:37
  • @egreg, you may be right, but I'm not sure how to do this using the glossaries package either. I tried using the xindy option with \GlsAddXdyLocation{descref} but still only got the results of desccount and not the external numbering system. Do you have any specific feedback on what to do with the glossaries package in this case?
    – Brian
    Commented Feb 5, 2015 at 16:25
  • @Brian: If you're still interested in a solution, see my possible answer
    – user31729
    Commented Dec 30, 2015 at 18:37

1 Answer 1

3

Here's a possible solution with glossaries and writing 'arbitrary' text labels to the .aux file which are used in turn to provide problem number using \getrefnumber (package refcount)

The underlying desccount counter was used to provided the relevant entries for the new glossary provider.

There might be better setups for \descitem, but this was given by the O.P. I changed it a little bit to \descitem[provider name]{Number}.

I kept the old \descitem macro on purpose, but commented it!

\documentclass{report}
\usepackage{array}
\usepackage{refcount}
\usepackage{xparse}
\usepackage{hyperref}

\usepackage[nomain,savenumberlist=true]{glossaries}

\makeatletter
\newcommand{\writetextlabel}[1]{%
  \immediate\write\@auxout{%
    \string\newlabel{description::\number\value{desccount}}{{#1}{\thepage}{}{desccount.\number\value{desccount}}}% 
  }%
}
\makeatother

\newcounter{desccount}
% Here is the 'original' \descitem command. 
%\newcommand{\descitem}[2][]{%
%\item[\protect\hypertarget{#1}{#1}]\refstepcounter{desccount}\writetextlabel{#1}
%}

\NewDocumentCommand{\descitem}{om}{%
  \IfValueTF{#1}{%
  \item[\protect\hypertarget{#2}{#2}]\refstepcounter{desccount}\writetextlabel{#2} by \gls{#1}%
  }{%   
  \item[\protect\hypertarget{#2}{#2}]%
  }%
}


\newglossary[prl]{provider}{pri}{pro}{Providers of solutions}[desccount]
\newglossaryentry{Smith}{%
  type={provider},
  name={Smith},
  description={Smith has provided some of solutions},
}

\newglossaryentry{Jones}{%
  type={provider},
  name={Jones},
  description={Jones has provided other solutions},
}

\newglossaryentry{Burton}{%
  type={provider},
  name={Burton},
  description={Burton was a lazy guy}
}



\makeglossaries


\newglossarystyle{providerdesc}{%
\setglossarystyle{long3col}% base this style on the list style
\renewenvironment{theglossary}{% Change the table type --> 3 columns
  \begin{longtable}{lp{0.6\glsdescwidth}>{\raggedleft\arraybackslash}p{5cm}}}%
  {\end{longtable}}%
%
\renewcommand{\glsnumberformat}[1]{\protect\hyperlink{\getrefnumber{description::##1}}{\getrefnumber{description::##1}}}% Change to use the textlabel
\renewcommand*{\glossaryheader}{%  Change the table header
  \bfseries Author & \bfseries Description & \bfseries Solutions provided \\
  \hline
  \endhead}
\renewcommand*{\glossentry}[2]{%  Change the displayed items
  \glstarget{##1}{\glossentryname{##1}} %
  & \glossentrydesc{##1}% Description
  & \space ##2  \tabularnewline
}
}

\begin{document}
\begin{description}
\descitem[Smith]{1B.1}
\descitem[Jones]{1B.3} 
\descitem[Smith]{1C.3}
\descitem[Burton]{A5.6}
\end{description}

\clearpage

\begin{description}
\descitem[Smith]{A.1}
\descitem[Jones]{A3} 
\descitem[Smith]{45.B} 
\descitem[Burton]{6.E} 
\end{description}


\setglossarystyle{providerdesc}
\printglossaries

\end{document}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .