\datetime 在 \index 中不起作用

\datetime 在 \index 中不起作用

我正在构建一个复杂的日期索引,并使用了很多 home 命令。除了使用\datetime带参数的命令(例如)之外,其他都很好

\newcommand*{\qd}[1]{\ordinalnum{#1}~siècle\index{\ordinalnum{#1}~siècle}}
\qd{8}

它没有被编入索引。我向你展示了我的所有文件:

% !TEX encoding = UTF-8 Unicode
\documentclass{scrbook}
\usepackage[frenchb]{babel} 
\usepackage[quiet]{fontspec}                    
\usepackage[automark,headsepline]{scrpage2}         
\usepackage[babel,french=guillemets*]{csquotes}
\usepackage{etoolbox}
\usepackage{ifthen}
\usepackage{ifmtarg}
\usepackage{fp}
\usepackage[dayofweek]{datetime} 
\usepackage[xindy={language=french, codepage=utf8}, style=altlist]{glossaries}
\usepackage[xindy, splitindex]{imakeidx}
\usepackage[itemlayout=singlepar]{idxlayout}
\setmainfont[Mapping=tex-text, Ligatures={Common, Rare}, Numbers={OldStyle}]{Adobe Garamond Pro}
\addtokomafont{disposition}{\normalfont}

\renewcommand{\fmtord}[1]{\up{#1}}
\makeatletter\patchcmd{\@ordinalMfrench}{eme}{ème}{}{}\makeatother

\makeglossaries
\def\xindylangopt{-M lang/french/utf8-lang -M style1.xdy}
\makeindex[name=can, title=Index des dates, options=\xindylangopt, intoc]

\newglossaryentry{Test 1}{name = Test 1, description = {Test 1 glossaire}}
\newglossaryentry{Test 2}{name = Test 2, description = {Test 2 glossaire}}

\newcommand*{\qds}[1]{\ordinalnum{#1}~siècle\index[can]{\ordinalnum{#1}~siècle}}
\newcommand*{\qdo}[1]{\ordinalnum{#1}~siècle\index[can]{{#1}~siècle}}

\begin{document}
\gls{Test 1}, \gls{Test 2}, 
\qds{8}, \qdo{9}, Test index\index[can]{Test index}
\printindex[can]
\printglossary
\end{document}

我编译了该内容:

% xelatex Date.tex
% makeglossaries Date
% xelatex -shell-escape Date.tex
% xelatex Date.tex

有什么想法吗?如何找到解决方案?谢谢

答案1

它要么是一个错误,要么是一个功能,但是在命令\ordinalnum内部以某种方式失败了,由于某些我不知道的原因,\index[can]{...}它不喜欢。[]

解决方法是使用\ordinal计数器。我定义了一个虚拟计数器,它以世纪数(第一个参数)作为输入,然后\ordinal在命令qds和中使用qdo

\documentclass{scrbook}
\usepackage[frenchb]{babel} 
\usepackage[quiet]{fontspec}                    
\usepackage[automark,headsepline]{scrpage2}         
\usepackage[babel,french=guillemets*]{csquotes}
\usepackage{etoolbox}
\usepackage{ifthen}
\usepackage{ifmtarg}
\usepackage{fp}
\usepackage[dayofweek]{datetime} 
\usepackage[xindy={language=french, codepage=utf8}, style=altlist]{glossaries}
\usepackage[xindy, splitindex]{imakeidx}

\usepackage[itemlayout=singlepar]{idxlayout}
%%%% Commented out since font is not installed on my computer
%\setmainfont[Mapping=tex-text, Ligatures={Common, Rare}, Numbers={OldStyle}]{Adobe Garamond Pro}
\addtokomafont{disposition}{\normalfont}

\renewcommand{\fmtord}[1]{\up{#1}}%
\makeatletter\patchcmd{\@ordinalMfrench}{eme}{ème}{}{}\makeatother

\makeglossaries
\def\xindylangopt{-M lang/french/utf8-lang -M style1.xdy}
\makeindex[name=can, title={Index des dates}, options={\xindylangopt}, intoc]
\makeindex[name=can,title={Index des dates}]


\newglossaryentry{Test 1}{name = Test 1, description = {Test 1 glossaire}}
\newglossaryentry{Test 2}{name = Test 2, description = {Test 2 glossaire}}


%%%%%% My additions and workaround ---> instead of using the number directly
%%%%%% store the number to a dummy counter and use \ordinal instead of \ordinalnum


\newrobustcmd{\ProvideOrdinalCounter}[1]{%
\ifltxcounter{#1}{%
}{%
\newcounter{#1}%
}%
}% End Of \ProvideOrdinalCounter


\newcommand{\qds}[1]{%
\setcounter{CenturyCounter}{#1}%
\ordinal{CenturyCounter}~siècle\index[can]{\ordinal{CenturyCounter}~siècle}%
}%

\newcommand{\qdo}[1]{%
  \setcounter{CenturyCounter}{#1}%
  \ordinal{CenturyCounter}~siècle\index[can]{\ordinal{CenturyCounter}~siècle}%
}%

\AtBeginDocument{%
 \ProvideOrdinalCounter{CenturyCounter}%
}%



\begin{document}
\gls{Test 1}, \gls{Test 2}, 
\qds{8}, \qdo{9}, Test index\index[can]{Test index}
\printindex[can]
\printglossary
\end{document}

在此处输入图片描述

答案2

修复方法很简单:

\newcommand*{\qds}[1]{%
  \ordinalnum{#1}~siècle%
  \index[can]{\protect\ordinalnum{#1}~siècle}%
}

这是索引(style1当然,我删除了,还有调用调用\qdo{8})。

在此处输入图片描述

这是.ind文件

\begin{theindex}
  \providecommand*\lettergroupDefault[1]{}
  \providecommand*\lettergroup[1]{%
      \par\textbf{#1}\par
      \nopagebreak
  }

  \lettergroupDefault{default}
  \item \ordinalnum {8}~siècle, 1

  \indexspace

  \lettergroup{T}
  \item Test index, 1

\end{theindex}

相关内容