我有一份包含三个部分且编号不同的文档:小写罗马数字、阿拉伯数字和大写罗马数字。打印首字母缩略词列表时,条目的页面顺序始终是小写罗马数字、大写罗马数字、阿拉伯数字,尽管大写罗马数字的页面是最后一页。我该如何修复此问题?
\glshyperlink
不是一个选项,因为我仍然希望显示页码。
\documentclass{article}
\usepackage[acronym,shortcuts,toc,hyperfirst=true,numberedsection=nolabel]{glossaries}
\setacronymstyle{long-short}
\makeglossaries
\newacronym{ABC}{ABC}{a blue cherry}
\newacronym{DEF}{DEF}{dry eggplant fruit}
\newacronym{GHI}{GHI}{green humongous iceberg lettuce}
\newacronym{JKL}{JKL}{jelly kiwi lentils}
\begin{document}
\pagenumbering{roman}
Today, I ate not only \ac{ABC}, but also \acp{DEF}.
\clearpage
\pagenumbering{arabic}
\Ac{ABC} is sweeter than a \ac{DEF}. And I ate a bit of \ac{GHI}.
The only thing I did not eat were \ac{JKL}.
\clearpage
\pagenumbering{Roman}
~
\clearpage
\ac{JKL} are even worse than \acp{DEF}.
\clearpage
\printglossary[type=\acronymtype,title={List of Abbreviations}]
\end{document}
编辑:正如指出的那样,问题归结为“我该如何教导以makeindex
不同的方式行事,或者是否有其他选择makeindex
?”,对两种情况都有答案。
答案1
如果makeindex
使用 而不是xindy
,则还需要做更多的事情。
makeindex
使用.ist
(索引样式文件),其中的精确设置是 即时glossaries
写入的,除非给出了明确的不同文件。glossaries
这是为 jobname 生成的文件glossariespageorder.tex
:
% makeindex style file created by the glossaries package
% for document 'glossariespageorder' on 2016-3-29
actual '?'
encap '|'
level '!'
quote '"'
keyword "\\glossaryentry"
preamble "\\glossarysection[\\glossarytoctitle]{\\glossarytitle}\\glossarypreamble\n\\begin{theglossary}\\glossaryheader\n"
postamble "\%\n\\end{theglossary}\\glossarypostamble\n"
group_skip "\\glsgroupskip\n"
item_0 "\%\n"
item_1 "\%\n"
item_2 "\%\n"
item_01 "\%\n"
item_x1 "\\relax \\glsresetentrylist\n"
item_12 "\%\n"
item_x2 "\\relax \\glsresetentrylist\n"
delim_0 "\{\\glossaryentrynumbers\{\\relax "
delim_1 "\{\\glossaryentrynumbers\{\\relax "
delim_2 "\{\\glossaryentrynumbers\{\\relax "
delim_t "\}\}"
delim_n "\\delimN "
delim_r "\\delimR "
headings_flag 1
heading_prefix "\\glsgroupheading\{"
heading_suffix "\}\\relax \\glsresetentrylist "
symhead_positive "glssymbols"
numhead_positive "glsnumbers"
page_compositor "."
suffix_2p ""
suffix_3p ""
关于页面顺序的问题的关键点是page_precedence
键,默认情况下它是“rRnaA”,而不是 OP 要求的“rnR”
据我所知,没有简单的方法可以glossaries
将用户定义的设置写入此\jobname.ist
文件。
这里有一个技巧,将 \glswrite` 文件设置page_precedence
为“rnRAa”,即小写罗马数字、阿拉伯数字、大写罗马数字、大写字母和小写字母by writing into the
。
改良版
\documentclass{article}
\usepackage{xpatch}
\usepackage[nomain,acronym,shortcuts,toc,hyperfirst=true,numberedsection=nolabel]{glossaries}
\newcommand{\glspageprecedence}{rnRaA}
\newcommand{\glswritehookextra}{%
\write\glswrite{page_precedence \string"\glspageprecedence\string"}
}
\xpatchcmd{\writeist}{%
\fi
\closeout\glswrite
\let\writeist\relax
}{%
\fi
\glswritehookextra
\closeout\glswrite
\let\writeist\relax
}{}{\typeout{Error: patching \string\writeist failed}}
\setacronymstyle{long-short}
\makeglossaries
\newacronym{ABC}{ABC}{a blue cherry}
\newacronym{DEF}{DEF}{dry eggplant fruit}
\newacronym{GHI}{GHI}{green humongous iceberg lettuce}
\newacronym{JKL}{JKL}{jelly kiwi lentils}
\begin{document}
\pagenumbering{roman}
Today, I ate not only \ac{ABC}, but also \acp{DEF}.
\clearpage
\pagenumbering{arabic}
\Ac{ABC} is sweeter than a \ac{DEF}. And I ate a bit of \ac{GHI}.
The only thing I did not eat were \ac{JKL}.
\clearpage
\pagenumbering{Roman}
~
\clearpage
\ac{JKL} are even worse than \acp{DEF}.
\clearpage
\printglossary[type=\acronymtype,title={List of Abbreviations}]
\end{document}
答案2
从默认值更改makeindex
为xindy
解决问题:添加包选项xindy
:
\documentclass{article}
\usepackage[xindy,acronym,shortcuts,toc,hyperfirst=true,numberedsection=nolabel]{glossaries}
\setacronymstyle{long-short}
\makeglossaries
\newacronym{ABC}{ABC}{a blue cherry}
\newacronym{DEF}{DEF}{dry eggplant fruit}
\newacronym{GHI}{GHI}{green humongous iceberg lettuce}
\newacronym{JKL}{JKL}{jelly kiwi lentils}
\begin{document}
\pagenumbering{roman}
Today, I ate not only \ac{ABC}, but also \acp{DEF}.
\clearpage
\pagenumbering{arabic}
\Ac{ABC} is sweeter than a \ac{DEF}. And I ate a bit of \ac{GHI}.
The only thing I did not eat were \ac{JKL}.
\clearpage
\pagenumbering{Roman}
~
\clearpage
\ac{JKL} are even worse than \acp{DEF}.
\clearpage
\printglossary[type=\acronymtype,title={List of Abbreviations}]
\end{document}
答案3
从glossaries
v4.24 (2016-05-27) 开始,您可以使用
\GlsSetWriteIstHook{\write\glswrite{page_precedence "rnR"}}
前\makeglossaries
:
\documentclass{article}
\usepackage[acronym,shortcuts,toc,hyperfirst=true,numberedsection=nolabel]{glossaries}
\setacronymstyle{long-short}
\GlsSetWriteIstHook{\write\glswrite{page_precedence "rnR"}}
\makeglossaries
\newacronym{ABC}{ABC}{a blue cherry}
\newacronym{DEF}{DEF}{dry eggplant fruit}
\newacronym{GHI}{GHI}{green humongous iceberg lettuce}
\newacronym{JKL}{JKL}{jelly kiwi lentils}
\begin{document}
\pagenumbering{roman}
Today, I ate not only \ac{ABC}, but also \acp{DEF}.
\clearpage
\pagenumbering{arabic}
\Ac{ABC} is sweeter than a \ac{DEF}. And I ate a bit of \ac{GHI}.
The only thing I did not eat were \ac{JKL}.
\clearpage
\pagenumbering{Roman}
~
\clearpage
\ac{JKL} are even worse than \acp{DEF}.
\clearpage
\printglossary[type=\acronymtype,title={List of Abbreviations}]
\end{document}
但是,这要求您了解文档中的页面顺序。如果您想即时解决此问题,可以调整的行为\pagenumbering
并构建排序列表。由于 ist 文件是由 生成的\makeglossaries
,这是一个仅包含前导的命令,因此必须将信息保存在外部文件中并在下次运行时读入,或者需要将 ist 文件的创建推迟到文档末尾。
下面是第一种方法的示例,该方法创建一个带有扩展名的临时文件.tmp
。 (.aux
在这种情况下无法使用该文件,因为直到文档开始后才会读取它。)
% arara: pdflatex
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{article}
\usepackage{etoolbox}
\usepackage[acronym,shortcuts,toc,hyperfirst=true,numberedsection=nolabel]{glossaries}
\setacronymstyle{long-short}
\def\pageordering{rnaRA}% makeindex's default
\InputIfFileExists{\jobname.tmp}
{%
\GlsSetWriteIstHook{\write\glswrite{page_precedence "\pageordering"}}
}
{%
}
\def\thispageordering{}%
\newwrite\tmpfile
\openout\tmpfile=\jobname.tmp
\AtEndDocument{%
\immediate\write\tmpfile{\string\def\string\pageordering{\thispageordering}}
\closeout\tmpfile
}
\let\orgpagenumbering\pagenumbering
\renewcommand{\pagenumbering}[1]{%
\orgpagenumbering{#1}%
\ifstrequal{#1}{arabic}%
{%
\appto\thispageordering{n}%
}%
{%
\addpageordering#1\endaddpageordering
}%
}
\def\addpageordering#1#2\endaddpageordering{%
\appto\thispageordering{#1}%
}
\makeglossaries
\newacronym{ABC}{ABC}{a blue cherry}
\newacronym{DEF}{DEF}{dry eggplant fruit}
\newacronym{GHI}{GHI}{green humongous iceberg lettuce}
\newacronym{JKL}{JKL}{jelly kiwi lentils}
\begin{document}
\pagenumbering{roman}
Today, I ate not only \ac{ABC}, but also \acp{DEF}.
\clearpage
\pagenumbering{arabic}
\Ac{ABC} is sweeter than a \ac{DEF}. And I ate a bit of \ac{GHI}.
The only thing I did not eat were \ac{JKL}.
\clearpage
\pagenumbering{Roman}
~
\clearpage
\ac{JKL} are even worse than \acp{DEF}.
\clearpage
\printglossary[type=\acronymtype,title={List of Abbreviations}]
\end{document}
这需要两次 LaTeX 运行才能makeindex
运行。
现在介绍第二种方法。为此,首先防止\makeglossaries
使用 写入 ist 文件\noist
。由于\writeist
和\GlsSetWriteIstHook
是仅前导命令,因此在禁用它们之前需要保存它们的原始定义。
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{article}
\usepackage{etoolbox}
\usepackage[acronym,shortcuts,toc,hyperfirst=true,numberedsection=nolabel]{glossaries}
\setacronymstyle{long-short}
\newcommand\pageordering{}
\let\orgwriteist\writeist
\let\orgGlsSetWriteIstHook\GlsSetWriteIstHook
\noist
\AtEndDocument{%
\orgGlsSetWriteIstHook{\write\glswrite{page_precedence "\pageordering"}}
\orgwriteist
}
\let\orgpagenumbering\pagenumbering
\renewcommand{\pagenumbering}[1]{%
\orgpagenumbering{#1}%
\ifstrequal{#1}{arabic}%
{%
\appto\pageordering{n}%
}%
{%
\addpageordering#1\endaddpageordering
}%
}
\def\addpageordering#1#2\endaddpageordering{%
\appto\pageordering{#1}%
}
\makeglossaries
\newacronym{ABC}{ABC}{a blue cherry}
\newacronym{DEF}{DEF}{dry eggplant fruit}
\newacronym{GHI}{GHI}{green humongous iceberg lettuce}
\newacronym{JKL}{JKL}{jelly kiwi lentils}
\begin{document}
\pagenumbering{roman}
Today, I ate not only \ac{ABC}, but also \acp{DEF}.
\clearpage
\pagenumbering{arabic}
\Ac{ABC} is sweeter than a \ac{DEF}. And I ate a bit of \ac{GHI}.
The only thing I did not eat were \ac{JKL}.
\clearpage
\pagenumbering{Roman}
~
\clearpage
\ac{JKL} are even worse than \acp{DEF}.
\clearpage
\printglossary[type=\acronymtype,title={List of Abbreviations}]
\end{document}