Page Layoutnewb question

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

newb question

Post by Genteel »

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 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

newb question

Post by Stefan Kottwitz »

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.

Code: Select all

\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 3646 times
Stefan
LaTeX.org admin
Post Reply