解决 LaTeX 演练练习中的问题

解决 LaTeX 演练练习中的问题

     我目前正在学习第 186 页第 9.4 节中的练习 20彼得·弗林的格式化信息并提出了以下 LaTeX 源来完成它:

\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}

请注意,我在这里使用该geometry包只是为了获得不会因太宽而感到尴尬的边距。在任何在这种情况下,当我通过 TeXShop 运行它时 — — 顺便说一下,我正在使用 TeX Live 2017 的 MacTeX 发行版,如果这有助于诊断我的问题 — —,它不会排版最后一项,并且它的 pdfLaTeX 后端向我发送了以下日志:

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.
<to be read again> 
                   \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".

据我所知,使用 TeXShop 的“TeX 和 DVI”脚本进行排版可以得到类似的结果。粗略检查我的输入 LaTeX 后,我相信我的所有花括号都已正确平衡,但也许我忽略了一些关键细节?或者本教程提供的用于此示例的宏可能与环境不太兼容itemize?我还能在这里尝试什么,以阻止 pdfLaTeX 阻塞我之前显示的输入?

答案1

您的两个条目没有空间,因此您需要将空间前瞻设为可选,例如

\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}

相关内容