我想index
按越南语字母顺序使用。顺序必须是 a、b、c、d、đ、e、ê。但在以下代码中。该顺序是错误的。第一个是“Ê”,而不是“A”,第二个是“Đ”,而不是“B”。如何安排该顺序?
这是我的代码
\documentclass{book}
\usepackage{imakeidx}
\makeindex[columns=3]
\usepackage[utf8]{vietnam}
\begin{document}
\chapter{Hello}
Some text.\index{Apple}\index{Apricot}\index{Avocado}\index{Banana}
\index{Bilberry}\index{Blackberry}\index{Blackcurrant}\index{Blueberry}
\index{Currant}\index{Cherry}\index{Cherimoya}\index{Clementine}
\index{Date}\index{Damson}\index{Dragonfruit}\index{Durian}
\index{Eggplant}\index{Elderberry}\index{Feijoa}\index{Gooseberry}
\index{Grape}\index{Grapefruit}\index{Guava}\index{Huckleberry}
\index{Jackfruit}\index{Jambul}\index{Kiwi fruit}\index{Kumquat}
\index{Legume}\index{Lemon}\index{Lime}\index{Lychee}\index{Mandarine}
\index{Mango}\index{Melon}\index{Nectarine}\index{Orange}\index{Peach}
\index{Pear}\index{Pitaya}\index{Physalis}\index{Plum}\index{Pineapple}
\index{Pomegranate}\index{Purple Mangosteen}\index{Raisin}\index{Raspberry}
\index{Rambutan}\index{Redcurrant}\index{Salal berry}\index{Satsuma}
\index{Star fruit}\index{Strawberry}\index{Tangerine}\index{Tomato}
\index{Ugli fruit}\index{Watermelon}\index{Ziziphus mauritiana}
\index{Đồng biến}
\index{Nghịch biến}
\index{Dao động điều hòa}
\index{Ếch}
\printindex
\end{document}
答案1
正如 Egreg 所说,默认情况下用于imakeidx
生成索引的 makeindex 不支持 unicode。另一个索引处理器支持越南语xindy
。不幸的是,pdflatex、越南语和 xindy 存在一些问题,因为索引条目以 TeX 序列而不是 utf-8 代码的形式编写,而 xindy 无法正确对它们进行排序。其他语言不会发生这种情况,所以这可能是一个错误。不过,您可以切换到xelatex
,这对亚洲语言来说是个好主意,我希望索引可以正确处理。
修改后的序言:
\documentclass{book}
\usepackage{polyglossia}
\setmainlanguage{vietnamese}
\usepackage[xindy]{imakeidx}
\makeindex[columns=3,options={-M lang/vietnamese/utf8-lang}]
对于 xelatex,使用polyglossia
包而不是vietnam
,我们使用xindy
选项来imakeidx
避免makeindex
使用并将options={-M lang/vietnamese/utf8-lang}
使用越南语排序。
用 编译xelatex -shell-escape filename
。该-shell-escape
选项允许在编译文档时直接编译索引。如果您不使用命令行来编译文档,则必须配置编辑器以使用此选项。
结果:
编辑:
作为 pdflatex 的解决方法,我编写了简单的过滤器,将使用inputenc
选项生成的控制序列转换utf8
为utf8
字符。
iec2utf.lua:
kpse.set_program_name("luatex")
local cmd_arg = [[
iec2utf.lua - Script for converting LaTeX LICR codes to utf8 characters
Usage: cat filename | texlua iec2utf.lua > newfilename
Parameters:
comma separated list of LaTeX font encodings used in the document
]]
local enc = {}
local licrs = {}
local codepoint2utf = unicode.utf8.char
function load_encodings(f)
local file= io.open(f,"r")
local encodings = file:read("*all")
file:close()
for codepoint, licr in encodings:gmatch('DeclareUnicodeCharacter(%b{})(%b{})') do
local codepoint = codepoint2utf(tonumber(codepoint:sub(2,-2),16))
local licr= licr:sub(2,-2):gsub('@tabacckludge','')
licrs[licr] = codepoint
end
end
function sanitize_licr(l)
return l:gsub(" (.)",function(s) if s:match("[%a]") then return " "..s else return s end end):sub(2,-2)
end
if arg[1] == nil then
enc = {"T1"}
else
for _,n in pairs(arg) do
enc[#enc+1] = n
end
end
for _,e in pairs(enc) do
local filename = e:lower() .. "enc.dfu"
local dfufile = kpse.find_file(filename)
if dfufile then
load_encodings(dfufile)
end
end
local input = io.read("*all")
local cache = {}
local output = input:gsub('\\IeC[%s]*(%b{})',function(iec)
local code = cache[iec] or licrs[sanitize_licr(iec)] or '\\IeC '..iec
-- print(iec, code)
cache[iec] = code
return code
end)
io.write(output)
将此脚本保存到与 tex 文件相同的目录中。此脚本将使用的字体编码作为参数,对于越南语,该编码为 T5。
如果您使用的是 Windows,则可以创建批处理脚本来使用此过滤器:
越南语.bat:
@echo of
type %~n1.idx | texlua iec2utf.lua T5 | texindy -i -M lang/vietnamese/utf8-lang -o %~n1.ind
对于 Linux,创建 shell 脚本vietxindy
:
#!/usr/bin/env sh
texlua iec2utf.lua T5 < `basename $1 .tex`.idx | texindy -i -M lang/vietnamese/utf8-lang -o `basename $1 .tex`.ind
然后使用以下命令编译该文档:
pdflatex filename
vietxindy filename
pdflatex filename
从命令行
答案2
这是另一种可能的解决方案,使用glossaries
反而:
\documentclass{book}
\usepackage[utf8]{vietnam}
\usepackage[xindy={codepage=utf8,language=vietnamese},nopostdot]{glossaries}
\usepackage{glossary-mcols}
\glossarystyle{mcolindex}
\renewcommand{\glsmcols}{3}
\makeatletter
\newcommand*{\glsindex}[1]{%
\def\theglslabel{#1}%
\def\theglsname{#1}%
\@onelevel@sanitize\theglslabel
\ifglsentryexists{\theglslabel}%
{%
}%
{%
\newglossaryentry{\theglslabel}%
{name={#1},text={\expandonce\theglsname},description={}}%
}%
\glsadd{\theglslabel}%
}
\makeatother
\makeglossaries
\begin{document}
\chapter{Hello}
Some text.\glsindex{Apple}\glsindex{Apricot}\glsindex{Avocado}\glsindex{Banana}
\glsindex{Bilberry}\glsindex{Blackberry}\glsindex{Blackcurrant}\glsindex{Blueberry}
\glsindex{Currant}\glsindex{Cherry}\glsindex{Cherimoya}\glsindex{Clementine}
\glsindex{Date}\glsindex{Damson}\glsindex{Dragonfruit}\glsindex{Durian}
\glsindex{Eggplant}\glsindex{Elderberry}\glsindex{Feijoa}\glsindex{Gooseberry}
\glsindex{Grape}\glsindex{Grapefruit}\glsindex{Guava}\glsindex{Huckleberry}
\glsindex{Jackfruit}\glsindex{Jambul}\glsindex{Kiwi fruit}\glsindex{Kumquat}
\glsindex{Legume}\glsindex{Lemon}\glsindex{Lime}\glsindex{Lychee}\glsindex{Mandarine}
\glsindex{Mango}\glsindex{Melon}\glsindex{Nectarine}\glsindex{Orange}\glsindex{Peach}
\glsindex{Pear}\glsindex{Pitaya}\glsindex{Physalis}\glsindex{Plum}\glsindex{Pineapple}
\glsindex{Pomegranate}\glsindex{Purple Mangosteen}\glsindex{Raisin}\glsindex{Raspberry}
\glsindex{Rambutan}\glsindex{Redcurrant}\glsindex{Salal berry}\glsindex{Satsuma}
\glsindex{Star fruit}\glsindex{Strawberry}\glsindex{Tangerine}\glsindex{Tomato}
\glsindex{Ugli fruit}\glsindex{Watermelon}\glsindex{Ziziphus mauritiana}
\glsindex{Đồng biến}
\glsindex{Nghịch biến}
\glsindex{Dao động điều hòa}
\glsindex{Ếch}
\printglossary[title=\indexname]
\end{document}
结果:
需要 (pdf)latex、makeglossaries、(pdf)latex
编辑:
有关使用该glossaries
包的更多信息:
答案3
这是我的方式,例如,如果我想对ếch进行排序,我输入\index{eesch@ếch}
\documentclass{book}
\usepackage{imakeidx}
\makeindex[columns=2]
\usepackage[utf8]{vietnam}
\begin{document}
\chapter{Hello}
\index{Uwsnd dujng@Ứng dụng}
\index{ddoofng bieesn@đồng biến}
\index{nghijch bieesn@nghịch biến}
\index{Dao ddoojng ddieefu hoaf@Dao động điều hòa}
\index{eesch@ếch}
\printindex
\end{document}