这个错误让我抓狂,因为我找不到解决办法。包术语表工作正常,除了当条目中包含瑞典语字符 (åäö) 时。我找到了根本原因,这是因为makeglossaries
输出文件时使用的是 ISO-8859-1 而不是 UTF-8,而当 LaTeX 尝试读取词汇表文件时,它会假定它们是 UTF-8,这就是问题所在。
最小示例main.tex
:
\documentclass[12pt,a4paper,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage[swedish]{babel}
\usepackage[T1]{fontenc}
\usepackage[nonumberlist]{glossaries}
\makeglossaries
\loadglsentries{ordlista}
\begin{document}
\glsaddall
\printglossaries
\end{document}
ordlista.tex
:
\newglossaryentry{This works}
{
name=This works,
description={This works fine}
}
\newglossaryentry{Swedish åäö}
{
name=Swedish åäö,
description={Swedish characters in the entry breaks things}
}
我使用 编译该文档pdflatex main
。然后运行,输出makeglossaries main
结果如下:
$ makeglossaries main
makeglossaries version 2.20 (2016-12-16)
added glossary type 'main' (glg,gls,glo)
makeindex -s "main.ist" -t "main.glg" -o "main.gls" "main.glo"
This is makeindex, version 2.15 [TeX Live 2016] (kpathsea + Thai support).
Scanning style file ./main.ist.............................done (29 attributes redefined, 0 ignored).
Scanning input file main.glo....done (2 entries accepted, 0 rejected).
Sorting entries....done (2 comparisons).
Generating output file main.gls....done (9 lines written, 0 warnings).
Output written in main.gls.
Transcript written in main.glg.
然后pdflatex main
再次运行时,出现一大堆错误:
l.4 \glossentry{Swedish }
{\glossaryentrynumbers{\relax
! Missing ) inserted for expression.
<to be read again>
(snip)
l.5 ...etentrycounter[]{page}\glsnumberformat{1}}}
\glsgroupskip
Package glossaries Warning: Glossary entry `Swedish \GenericError {(inputenc)
}{Package inputenc Error: Unicode char (U+5)
(glossaries) not set up for use with LaTeX}{See the inputenc pac
kage documentation for explanation.}{Your command was ignored.
(glossaries) Type I <command> <return> to replace it with anot
her command,
(glossaries) or <return> to continue without it.}' has not bee
n defined on input line 5.
因此,词汇表文件:
$ file main.g*
main.glg: Makeindex log file, ASCII text
main.glo: LaTeX raw glossary, ISO-8859 text
main.gls: LaTeX document, ISO-8859 text
main.glo
看起来是这样的:
\glossaryentry{This works?\glossentry{This works}|setentrycounter[]{page}\glsnumberformat}{1}
\glossaryentry{Swedish åäö?\glossentry{Swedish åäö}|setentrycounter[]{page}\glsnumberformat}{1}
这就是根本原因。现在,如果我手动编辑main.glo
以删除垃圾并输入正确的字符并将其保存为 UTF-8,那么问题就会消失。我猜这是makeglossaries
根本原因,因为它将 *.gl* 文件保存为 ISO-8859 而不是 UTF-8。
问题:如何强制makeglossaries
始终以 UTF-8 输出文本文件?
或者:我如何告诉glossaries
包 *.glo 文件是用 ISO-8859 编码的而不是 UTF-8 (它假定)?
答案1
您有一个相当旧的 texlive(2016),其 makeglossaries 版本为 2.20。
在过去的几年中,对 utf8 的支持得到了很大的改进,在当前的 texlive 2021/2022(预测试)中它运行良好。
考虑升级。