LaTeX forum ⇒ Page Layoutnewb question

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Genteel
Posts: 1
Joined: Mon May 13, 2024 10:40 am

newb question

Postby Genteel » Tue Jun 04, 2024 8:05 am

Hi, I'm typesetting a recipes book (for hobby), in this book every recipe is a section, I have and index containing the ingredients of every recipe in this form:

water, 4-7
salt, 4, 6, 8
sugar, 5, ,8-10

I want the name of the recipe (section) near every appearance:

water,
home made pasta, 4
something else, 5
another recipe, 6
salt,
very ugly cake, 4
not edible yogurt, 6

and so on.

Recommended reading 2021:

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

Exclusive June 2024 offer: All LaTeX eBooks (PDF, EPBUB) for $9.99 or €8.99

LaTeX books

User avatar
Stefan Kottwitz
Site Admin
Posts: 10191
Joined: Mon Mar 10, 2008 9:44 pm

newb question

Postby Stefan Kottwitz » Tue Jun 04, 2024 9:16 am

Hi Genteel,

welcome to the forum!

Here is a quick example, using the imakeidx package and the nameref package for referencing the section names. I made a custom command to index with section names.

\documentclass{article}
\usepackage{imakeidx}
\usepackage{nameref}
\makeindex
\newcommand{\secindex}[1]{#1\index{#1!\nameref{sec:\thesection}}}
\begin{document}
\section{home made pasta}\label{sec:\thesection}
We need \secindex{salt} here.
\clearpage
\section{something else}\label{sec:\thesection}
Use \secindex{water} and more.
\clearpage
\section{another recipe}\label{sec:\thesection}
Use \secindex{water}.
\clearpage
\section{very ugly cake}\label{sec:\thesection}
Take \secindex{salt} and \secindex{water}.
\clearpage
\printindex
\end{document}


index.png
index.png (13.25 KiB) Viewed 389 times


Stefan
LaTeX.org admin


Return to “Page Layout”

Who is online

Users browsing this forum: No registered users and 26 guests