# Troubleshooting a LaTeX Walkthrough Exercise

I'm currently going through Exercise 20 in section 9.4 on page 186 of Peter Flynn's Formatting Information and have come up with the following LaTeX source to complete it:

\documentclass[12pt,letterpaper]{article}

\usepackage[margin=0.65in]{geometry}
\usepackage{makeidx}

\makeindex

\newcommand{\person}[1]{#1\reindex #1\sentinel}
\def\reindex #1 #2\sentinel{\index{#2, #1}}

\begin{document}
\section{Names of Various Formats for Indexing}

Here are some random names given to me to typeset and add index entries for by Exercise 20 in \S{}9.4 of Peter Flynn's \textit{Formatting Information} that aren't in the standard First Last' format:

\begin{itemize}
\item \person{Blanca\space{}Maria\space{}Bartosova de\space{}Paul}
\item \person{Patricia\space{}Maria\space{}Soria de\space{}Miguel}
\item \person{Arnaud de\space{}la\space{}Vill\esbrunne}
\item \person{Prince}
\item \person{Pope\space{}John\space{}Paul\space{}II} % \textit{Why} doesn't this typeset correctly?  For \textit{some} reason, \LaTeX{} \textit{chokes} on it!
% How in the \textit{blazes} do I properly typeset actual Roman numerals\ldots?
\end{itemize}

\printindex
\end{document}


Note that my use of the geometry package here is just to get margins I won't cringe at for being too wide. In any case, when I run this through TeXShop — I'm using the MacTeX distribution of TeX Live 2017, by the way, if that helps diagnosing my problem any —, it doesn't typeset the last bullet item and its pdfLaTeX backend pelts me with the following logs:

This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./Exercise 20.tex
LaTeX2e <2017-04-15>
Babel <3.12> and hyphenation patterns for 84 language(s) loaded.
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/texlive/2017/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/ifvtex.sty)
(/usr/local/texlive/2017/texmf-dist/tex/generic/ifxetex/ifxetex.sty))
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/makeidx.sty)
Writing index file "Exercise 20".idx
(./Exercise 20.aux)
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/omscmr.fd)
Runaway argument?
\item \person {Pope\space {}John\space {}Paul\space {}II} \end {itemi\ETC.
./Exercise 20.tex:24: Paragraph ended before \reindex was complete.
\par
l.24

?
No file "Exercise 20".ind.

./Exercise 20.tex:26: LaTeX Error: \begin{itemize} on input line 16 ended by \e
nd{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.26 \end{document}

?
[1{/usr/local/texlive/2017/texmf-var/fonts/map/pdftex/updmap/pdftex.map
}]
(./Exercise 20.aux) )
(\end occurred inside a group at level 1)

### semi simple group (level 1) entered at line 16 (\begingroup)
### bottom level</usr/local/texlive/2017/texmf-dist/fonts/type1/public/amsfonts
/cm/cmbx12.pfb></usr/local/texlive/2017/texmf-dist/fonts/type1/public/amsfonts/
cm/cmr12.pfb></usr/local/texlive/2017/texmf-dist/fonts/type1/public/amsfonts/cm
/cmsy10.pfb></usr/local/texlive/2017/texmf-dist/fonts/type1/public/amsfonts/cm/
cmti12.pfb>
Output written on "Exercise 20.pdf" (1 page, 43759 bytes).
SyncTeX written on "Exercise 20.synctex.gz"
Transcript written on "Exercise 20.log".


Using TeXShop's 'TeX and DVI' script for typesetting gives similar results, as far as I can tell. A cursory inspection of my input LaTeX leads me to believe I've got all of my curly braces balanced properly, but perhaps I'm overlooking some crucial detail here? Or perhaps the macro provided by the tutorial for use in this example doesn't exactly play all that well with the itemize environment? What else could I try here, exactly, to stop pdfLaTeX from choking on the input I showed earlier?

• you are defining \reindex to require a literal space token between the arguments (not a normal latex definition) but you have used \space{} which will not work, – David Carlisle Aug 18 '17 at 20:02
• Ah, of course! It seems obvious now that you've pointed it out! I'm not sure if that should matter, though, as, given the second-to-last bullet item, the macro that's causing trouble here can take having one of its arguments omitted just fine. I'm only using \space{} for when I don't want anything to be split, like in the case of that last bullet item and in some other bullet items where name parts are also made up of multiple words (the last one seems to me like I could only logically treat it as a multi-word last name starting with a title that can't be split off from its front.) – RandomDSdevel Aug 18 '17 at 20:08

Two of your entries have no space, so you need to make the lookahead for space optional, something like

\documentclass[12pt,letterpaper]{article}

\usepackage[margin=0.65in]{geometry}% text too wide to read....
\usepackage{makeidx}

\makeindex

\newcommand{\person}[1]{#1\reindex #1 \sentinel}
%                                    ^
\def\reindex #1 #2\sentinel{\index{\ifx\\#2\\\else#2\unskip, \fi#1}}

\begin{document}
\section{Names of Various Formats for Indexing}

Here are some random names given to me to typeset and add index entries for by Exercise 20 in \S{}9.4 of Peter Flynn's \textit{Formatting Information} that aren't in the standard First Last' format:

\begin{itemize}
\item \person{Blanca\space{}Maria\space{}Bartosova de\space{}Paul}
\item \person{Patricia\space{}Maria\space{}Soria de\space{}Miguel}
\item \person{Arnaud de\space{}la\space{}Vill\esbrunne}
\item \person{Prince}
\item \person{Pope\space{}John\space{}Paul\space{}II} % \textit{Why} doesn't this typeset correctly?  For \textit{some} reason, \LaTeX{} \textit{chokes} on it!
% How in the \textit{blazes} do I properly typeset actual Roman numerals\ldots?
\end{itemize}

\printindex
\end{document}

• You're right, that should do the trick. I'm glad I didn't have to insert a regular expression there or something crazy like that, as I'm still quite a novice at using those. – RandomDSdevel Aug 18 '17 at 20:15
• I've just realized that your answer here almost, but not quite, answers my question: it works, but then the resulting index entries end up with extra commas and spaces in them. How might I get rid of those? – RandomDSdevel Aug 18 '17 at 21:20
• You don't need to modify the command to get most of them right. Just change the input to \person{Blanca Maria\space{}Bartosova\space{}de\space{}Paul} etc. But the \reindex command always inserts a hard comma in the index entry, so you will have to find another way to handle Prince. – alephzero Aug 19 '17 at 0:23
• @alephzero: Grouping middle names with last names instead of first names…just doesn't sit right with me, though I do admit I'm making (hopefully reasonable) assumptions about name partitioning. Isn't there any way to make the presence of the comma conditional on the existence of a second argument to \reindex, possibly using etoolbox or xparse? I looked earlier, but what I found didn't seem easily adaptable to my use case. I'd treat the extra space between last names and their succeeding commas, which sneaks in via \Person's definition, the same way, but that would fail parsing. – RandomDSdevel Aug 19 '17 at 1:14
• @RandomDSdevel I only answered the question asked, which was why the parsing gave a tex error, none of the code is robust enough for real world name parsing, but I assumed that wasn't an issue as it was just a tex tutorial example. See blog.jclark.com/2007/12/thai-personal-names.html for example – David Carlisle Aug 19 '17 at 6:16