词汇表的数字标签如何使用手动定义的章节数(或其他章节单位)?

词汇表的数字标签如何使用手动定义的章节数(或其他章节单位)?

我使用“词汇表”来为我的书制作索引,我将数字列表设置为部分,因此部分的编号将在数字标签中。例如:

                               INDEX
Unix, a multitasking, multi-user computer operating system  1
Unix-like, operating system is one that behaves in a manner similar to a Unix system 2  

这意味着单词 Unix 在第 1 部分中,单词 Unix-like 在第 2 部分中。

但是现在我有一些部分的名称不是默认生成的,它们是通过以下命令手动定义的:

\section*{2a Linux}

最卑鄙的代码如下:

\documentclass{book}
\renewcommand\thesection{\arabic{section}}
\usepackage[counter=section]{glossaries}
\makeglossaries


\newglossaryentry{Unix}{
name={Unix},
description={a multitasking, multi-user computer operating system}
}
\newglossaryentry{Unix-like}{
name={Unix-like},
description={operating system is one that behaves in a manner similar to a Unix system}
}
\newglossaryentry{Linux}{
name={Linux},
description={Linux was originally developed as a free operating system}
}
\newglossaryentry{FreeBSD}{
name={FreeBSD},
description={a free Unix-like operating system, an operating system}
}
\newglossaryentry{Windows}{
name={Windows},
description={a series of graphical interface operating systems}
}
\newglossaryentry{Mobile Operating System}{
name={Mobile Operating System},
description={the operating system that operates a smartphone...}
}


\begin{document}
\section{Unix}
Unix \glsadd{Unix} (officially trademarked as UNIX, sometimes also written as Unix) is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT\&T employees at Bell Labs.

\section{Unix-like}
A Unix-like \glsadd{Unix-like}(sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification.

\section*{2a \quad Linux}
Linux \glsadd{Linux}was originally developed as a free operating system for Intel x86-based personal computers. It has since been ported to more computer hardware platforms than any other operating system.

\section*{2alpha \quad FreeBSD}
FreeBSD \glsadd{FreeBSD} is a free Unix-like operating system descended from AT\&T UNIX via BSD UNIX.  Although for legal reasons FreeBSD cannot be called "UNIX".

\section{Windows}
Microsoft Windows \glsadd{Windows}is a series of graphical interface operating systems developed, marketed, and sold by Microsoft.

\section*{3delta \quad Mobile Operating System}
A mobile operating system \glsadd{Mobile Operating System}, also referred to as mobile OS, is the operating system that operates a smartphone, tablet, PDA, or other digital mobile devices.

\printglossary
\end{document}

因此,如果某些条目位于这些手动定义的部分中,则“词汇表”无法读取部分的数量,然后这些条目的数字列表将不起作用。现在它看起来像:

                            INDEX
Unix, a multitasking, multi-user computer operating system  1
Unix-like, operating system is one that behaves in a manner similar to a Unix system 2
Linux,Linux was originally developed as a free operating system 2
FreeBSD, a free Unix-like operating system, an operating system  2
Windows, a series of graphical interface operating systems 3
Mobile Operating System, the operating system that operates a smartphone... 3

其实,它应该是这样的:

                            INDEX
Unix, a multitasking, multi-user computer operating system  1
Unix-like, operating system is one that behaves in a manner similar to a Unix system 2
Linux,Linux was originally developed as a free operating system 2a
FreeBSD, a free Unix-like operating system, an operating system  2alpha
Windows, a series of graphical interface operating systems 3
Mobile Operating System, the operating system that operates a smartphone... 3delta

如何解决这些问题?如何让“词汇表”能够正确读取手动定义的部分数量?

答案1

glossaries包将位置写为分配给特定条目的计数器的值,因此您不能仅将特定位置指定为字符串。此外,makeindex仅能理解有限数量的位置样式(arabicromanalph),因此如果您有任何位置不符合该样式,则必须使用xindy。以下是一个可能的解决方案:

\documentclass{book}
\renewcommand\thesection{\arabic{section}}
\usepackage[counter=section,xindy]{glossaries}

\newcounter{sectionalph}
\newcounter{sectiongreek}

\renewcommand{\thesectionalph}{\thesection\alph{sectionalph}}
\renewcommand{\thesectiongreek}{\thesection\greekstring{sectiongreek}}

\newcommand{\greekstring}[1]{%
  \ifcase\value{#1}\relax
  \or
   alpha%
  \or
   beta%
  \or
   gamma%
  \or
   delta%
  \or
   epsilon%
  \or
   zeta%
  \or
   eta%
  \or
   theta%
  \or
   iota%
  \or
   kappa%
  \or
   lambda%
  \or
   mu%
  \or
   nu%
  \or
   omicron%
  \or
   pi%
  \or
   rho%
  \or
   sigma%
  \or
   tau%
  \or
   upsilon%
  \or
   phi%
  \or
   chi%
  \or
   xi%
  \or
   psi%
  \or
   omega%
  \fi
}

\GlsAddXdyCounters{sectionalph}
\GlsAddXdyCounters{sectiongreek}

\GlsAddXdyAlphabet{greek}{"alpha" "beta" "gamma" "delta"
"epsilon" "zeta" "eta" "theta" "iota" "kappa" "lambda" "mu"
"nu" "omicron" "pi" "rho" "sigma" "tau" "upsilon" "phi"
"chi" "xi" "psi" "omega"}

\GlsAddXdyLocation{sectiongreek}{
  "arabic-numbers" "greek"}

\makeglossaries

\newcommand{\sectionalph}[1]{%
  \refstepcounter{sectionalph}%
  \section*{\thesectionalph\quad #1}%
}

\newcommand{\sectiongreek}[1]{%
  \refstepcounter{sectiongreek}%
  \section*{\thesectiongreek\quad #1}%
}

\newglossaryentry{Unix}{
name={Unix},
description={a multitasking, multi-user computer operating system}
}
\newglossaryentry{Unix-like}{
name={Unix-like},
description={operating system is one that behaves in a manner
similar to a Unix system}
}
\newglossaryentry{Linux}{
name={Linux},
description={Linux was originally developed as a free operating
system}
}
\newglossaryentry{FreeBSD}{
name={FreeBSD},
description={a free Unix-like operating system, an operating system}
}
\newglossaryentry{Windows}{
name={Windows},
description={a series of graphical interface operating systems}
}
\newglossaryentry{Mobile Operating System}{
name={Mobile Operating System},
description={the operating system that operates a smartphone...}
}


\begin{document}
\section{Unix}
Unix \glsadd{Unix} (officially trademarked as UNIX, sometimes also
written as Unix) is a multitasking, multi-user computer operating
system originally developed in 1969 by a group of AT\&T employees at
Bell Labs.

\section{Unix-like}
A Unix-like \glsadd{Unix-like}(sometimes referred to as UN*X or
*nix) operating system is one that behaves in a manner similar to a
Unix system, while not necessarily conforming to or being certified
to any version of the Single UNIX Specification.

\sectionalph{Linux}
Linux \glsadd[counter=sectionalph]{Linux}was originally developed as a free operating
system for Intel x86-based personal computers. It has since been
ported to more computer hardware platforms than any other operating
system.

\sectiongreek{FreeBSD}
FreeBSD \glsadd[counter=sectiongreek]{FreeBSD} is a free Unix-like operating system
descended from AT\&T UNIX via BSD UNIX.  Although for legal reasons
FreeBSD cannot be called "UNIX".

\section{Windows}
Microsoft Windows \glsadd{Windows}is a series of graphical interface
operating systems developed, marketed, and sold by Microsoft.

\sectiongreek{Mobile Operating System}
A mobile operating system \glsadd[counter=sectiongreek]{Mobile Operating System}, also
referred to as mobile OS, is the operating system that operates a
smartphone, tablet, PDA, or other digital mobile devices.

\printglossary
\end{document}

答案2

我认为 Makeindex 或 Xindy 不必担心。这些条目不在未编号的 Sectional Units 中,它们在手动编号的 Section Units 中,例如 2a、2alpha、3delta 等。它们实际上是由作者定义的,例如

\section*{2a  Linux}

所以解决方案很简单,因为它们需要手动定义,那么我们可以添加一个参数来为词汇表提供这些部分的数量。如果此部分的编号为“2a”,则它可能看起来像序言中的那样:

\newcommand\mysection[2]{
    \section*{{#1}\quad{#2}}
    \addcontentsline{toc}{section}{{#1}\quad{#2}}
    \markright{{#1}\quad{#2}}
%----------------------
\addglodiynumberofsec{#1}

%----------------------
    }

参数 #1 是手动定义的节号,参数 #2 是其名称。我们只需在包 'glossaries' 中添加一个新函数 '\add-glo-diy-number-of-sec' 即可实现

词汇表可以读取#1,在文本中我们只需要

\mysection{2a}{Linux}

然后,词汇表可以使用位置 ---- 2a

只需添加一个新功能即可

 \addglodiynumberofsec

或词汇表中的其他名称。已解决。

但我不是程序员,我无法修改词汇表的代码,所以在这里寻求帮助。

相关内容