Text FormattingCreating a list of item names from a list with details

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Kit
Posts: 4
Joined: Mon Nov 15, 2010 6:34 pm

Creating a list of item names from a list with details

Post by Kit »

I am trying to figure out how to create a list of item names from a list of items that contain names and details. I thought about using glossaries, but I don't want page numbers. Here is what I have so far:

Code: Select all

\documentclass{article}
% Available from CTAN
\usepackage{paralist}
\usepackage{hyperref}
\usepackage{nameref}
% I copied this from 
% http://tex.stackexchange.com/questions/1230/reference-name-of-description-list-item-in-latex%
\makeatletter
\let\orgdescriptionlabel\descriptionlabel
\renewcommand*{\descriptionlabel}[1]{%
  \let\orglabel\label
  \let\label\@gobble
  \phantomsection
  \edef\@currentlabel{#1}%
  %\edef\@currentlabelname{#1}%
  \let\label\orglabel
  \orgdescriptionlabel{#1}%
}
\makeatother
% Here is an example of what I can do right now
\begin{document}
% Ideally, I'd like this to be generated from the detail list
\section{List of Actions}
\begin{compactdesc}
\item \ref{itm:login}
\item \ref{itm:logout}
\item \ref{itm:update}
\end{compactdesc}

\section{Definitions}
\begin{compactdesc}
    \item [Log in\label{itm:login}] The user logs into the database.
    \item [Log out\label{itm:logout}] The user logs out of the database.
    \item [Update records\label{itm:update}] A user changes information in a record.  Requires \ref{itm:login}.
\end{compactdesc} 

% I'd also like to drop the red boxes
The item `\ref{itm:login}' is listed on page~\pageref{itm:login} in section~\nameref{itm:login}.
\end{document}
It works fine, but (as I noted in the example) I would like to at least drop the boxes from the references. It would be really great if I could generate the short list from the detail list, the idea being that then I only have to worry about the detail list.

Does anyone have a good idea about how to get the short list from the detail list? Do I need to use something like makeindex? And is there an easy way to get rid of those boxes? I looked for a parameter for nameref that would allow me to turn these off, but I didn't see anything obvious.

I would like this to work nicely with the paralist package, but I am willing to use something besides hyperref. I'm not sure if I'm taking the right approach.

This is by far the most complicated thing I've tried to do in LaTeX, but I would like to use it as an opportunity to learn some new things, so even suggesting which tool to use would be extremely helpful. Thank you.

**EDIT: Okay, I guess this should have occurred to me sooner, but I got rid of the boxes by turning the color links on and setting the link color to black.

Code: Select all

\usepackage[colorlinks, linkcolor=black]{hyperref}
I am still wondering about how to put together the simple list from the detail list though.
Last edited by Kit on Thu Nov 18, 2010 4:19 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

Creating a list of item names from a list with details

Post by nlct »

Kit wrote:I thought about using glossaries, but I don't want page numbers.
You can suppress the page numbers using the glossaries package option "nonumberlist".

Code: Select all

\documentclass{article}

\usepackage{paralist}
\usepackage[colorlinks]{hyperref}
\usepackage[nonumberlist,numberedsection]{glossaries}

\newglossaryentry{login}{name={Log in},description={The user logs
into the database}}

\newglossaryentry{logout}{name={Log out},description={The user logs
out of the database}}

\newglossaryentry{update}{name={Update records},description={A user
changes information in a record.  Requires \gls{login}}}

\makeglossaries

\glsaddall

\begin{document}

\section{List of Actions}

\begin{compactdesc}
\forglsentries{\thislabel}{\item \gls{\thislabel}}%
\end{compactdesc}

\renewcommand{\glossaryname}{Definitions}
\renewcommand{\glsgroupskip}{}
\renewenvironment{theglossary}%
 {\begin{compactdesc}}{\end{compactdesc}}%
\printglossaries
\end{document}
Regards
Nicola Talbot
User avatar
nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

Creating a list of item names from a list with details

Post by nlct »

It's just occurred to me that you can use datatool instead of glossaries, since you're not interested in the page numbers. This only requires one latex run and no external indexing application, but now you can't use \gls{login}.

Code: Select all

\documentclass{article}

\usepackage{paralist}
\usepackage[colorlinks]{hyperref}
\usepackage{datatool}

\begin{filecontents*}{test.csv}
Label,Name,Description
login,Log in,The user logs into the database.
logout,Log out,The user logs out of the database.
update,Update records,A user changes information in a record.  Requires \hyperlink{Log in}{login}.
\end{filecontents*}

\DTLloaddb{entries}{test.csv}

% The following line sorts the entries into alphabetical
% order. Remove if not required.
\DTLsort{Name}{entries}

\begin{document}

\section{List of Actions}

\begin{compactdesc}
\DTLforeach*{entries}{\thislabel=Label,\thisname=Name}{\item \hyperlink{\thisname}{\thislabel}}%
\end{compactdesc}

\begin{compactdesc}
\DTLforeach*{entries}{\thislabel=Label,\thisname=Name,\thisdesc=Description}{\item[\hypertarget{\thisname}{\thislabel}] \thisdesc}%
\end{compactdesc}
\end{document}
Regards
Nicola Talbot
Kit
Posts: 4
Joined: Mon Nov 15, 2010 6:34 pm

Re: Creating a list of item names from a list with details

Post by Kit »

Thanks, Nicola, that works great. I've never seen datatool before, and I'm excited to try it with some different things.

Also, I really liked your article about glossaries. I found it easy to understand and well-structured. That's what got me started trying to do this particular thing. So thanks for that too!
Post Reply