2

I feel like I should be able to figure this out but after poking around for hours at a time over several months, I'm at a loss. Essentially I want to do something like the following:

\documentclass{article}
\usepackage{imakeidx}

\newcommand{\bday}[3]{\index{#1!#2!#3}}

\makeindex
\begin{document}

\section{Birthday people}
Ted's birthday is March 20.\bday{March}{20}{Ted}\\
Bob's birthday is March 20.\bday{March}{20}{Bob}\\
Ann's birthday is April 30.\bday{April}{30}{Alice}\\
\printindex

\end{document}

And yet have the output of the index look like this, where they are sorted into headings (months, in calendar order rather than alphabetical) and combined by dates, and without page numbers:

enter image description here

Is there a reasonably straight-forward way to do this? Thanks.

2 Answers 2

3

Here is something that gets you started:

enter image description here

I used xstring to specify the sort order for the months. One can write a case statement without this pacakge if so desired.

To combine the items into a single line, use a semi-colon as the separator and eliminate the page number, I redfined \subsubitem.

\def\subsubitem#1,#2{#1;}

A less hackish method to eliminate the page number is given in Remove page number from index entries, but I was not able to ge that to work at this time. I know I have used that solution in the past so not sure why it is not working currently.

Code:

\documentclass{article}
\usepackage{imakeidx}
\usepackage{xstring}

\def\subsubitem#1,#2{#1;}% Combine into one line
\newcommand{\bday}[3]{%
    \IfStrEqCase{#1}{%
        {January}{\index{01@#1!#2!#3}}%
        {Feburary}{\index{02@#1!#2!#3}}%
        {March}{\index{03@#1!#2!#3}}%
        {April}{\index{04@#1!#2!#3}}%
        {March}{\index{05@#1!#2!#3}}%
        {June}{\index{06@#1!#2!#3}}%
        {July}{\index{07@#1!#2!#3}}%
        {August}{\index{08@#1!#2!#3}}%
        {September}{\index{09@#1!#2!#3}}%
        {October}{\index{10@#1!#2!#3}}%
        {November}{\index{11@#1!#2!#3}}%
        {December}{\index{12@#1!#2!#3}}%
    }%
}

\makeindex
\begin{document}

\section{Birthday people}
Ted's birthday is March 20.\bday{March}{20}{Ted}
Bob's birthday is March 20.\bday{March}{20}{Bob}
Ann's birthday is April 30.\bday{April}{30}{Alice}
\printindex

\end{document}
6
  • Thank you very much. This did get me started, now I'm struggling with the second part: the format of the index. I've tried making a .ist to center the top level items (Months) but with no luck. Maybe that's just not possible with items in an index, maybe that's only possible with headings?
    – Logan
    Nov 4, 2021 at 19:43
  • Glad it was helpful. As far as your follow up, it is always best to break down problems into their smallest pieces. The issue of centering the heading is not related to the other issues you posted here. Thus, I would recommend you post a followup question focused specifically on the centering of the index headings. But first, have a look at How can I center index headings?. If that does not work for you, please include what you tried in the question. Nov 4, 2021 at 21:27
  • Thanks Peter but unfortunately the two appear to be inextricably linked, at least given how I framed my initial attempt:
    – Logan
    Nov 5, 2021 at 11:03
  • My initial approach (and your solution based on that) made the months into items. I can format headings in a .ist but I don't have any headings. I've looked at Lamport, LaTeX Companion, Memoir manual, makeindex, and imakeidx documentation (and google of course) and kind of faked bold item_0 but not much else. I might have to scrap this approach and either come up with a way to make custom headings (months) or I've even thought about a separate index for each month (ugly, but should work). I do appreciate the help, I'll have to mull on this problem a bit more.
    – Logan
    Nov 5, 2021 at 11:13
  • @Logan: Not sure why you think the centering of the headings of an index is linked to this specfic problem. Imagine if you wanted a regular index but with centered headings. Nov 5, 2021 at 17:24
0

Thanks to @Peter above, I was able to get something working. I abandoned trying to include the month in the index and just built twelve separate indices. Not elegant but much more easily formatted and controlled. Essentially the following code and then format the chapter or section headers for the indices titles.

\documentclass{article}
\usepackage{imakeidx}

\def\subitem#1,#2{\, #1;}% Combine into one line
\newcommand{\bday}[3]{\index[#1]{#2!#3}}

\makeindex[name=January,title=January,columns=1]
\makeindex[name=February,title=February,columns=1]
\makeindex[name=March,title=March,columns=1]
\makeindex[name=April,title=April,columns=1]
\makeindex[name=May,title=May,columns=1]
\makeindex[name=June,title=June,columns=1]
\makeindex[name=July,title=July,columns=1]
\makeindex[name=August,title=August,columns=1]
\makeindex[name=September,title=September,columns=1]
\makeindex[name=October,title=October,columns=1]
\makeindex[name=November,title=November,columns=1]
\makeindex[name=December,title=December,columns=1]

\begin{document}

\section{Birthday people}
Ted's birthday is March 20.\bday{March}{20}{Ted}
Bob's birthday is March 20.\bday{March}{20}{Bob}
Ann's birthday is April 30.\bday{April}{30}{Alice}

\printindex[January]
\printindex[February]
\printindex[March]
\printindex[April]
\printindex[May]
\printindex[June]
\printindex[July]
\printindex[August]
\printindex[September]
\printindex[October]
\printindex[November]
\printindex[December]

\end{document}

You must log in to answer this question.

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