我正在写一份报告,其中包含常量列表和符号列表,均使用词汇表包。问题是第二个列表(在本例中为常量)不仅包含它应该包含的元素,还包含第一个列表中的元素(符号):
无论顺序如何,都会发生此问题(如果它们被调换,符号列表也会包含常量)。我想我必须在打印它们之间调用某种词汇表重置命令,但在任何地方都找不到它。有人知道是什么原因导致了这个问题吗?
我使用 Ubuntu 16.04 自带的 TeXLive-full 发行版。词汇表包版本根据\listfiles
:glossaries.sty 2017/01/19 v4.29
我准备了一个 MWE。请注意,我只包含 1 个词汇表样式,而实际上我会为常量和符号列表设置单独的样式。这只是为了保持 MWE 较小。单独的样式也会出现问题。这是 main.tex 文件:
\documentclass[12pt,a4paper]{article}
\usepackage{glossaries}
%%%%%%% Load the preamble that contains the glossary styles
\input{./Helpers/glspreamble}
%%%%%%% Define entries for the list of acronyms, constants and symbols
\newglossaryentry{con:g}
{
type=constants, % entry should be in the list of constants!
name={\ensuremath{g}}, % Put the symbol here in dollar signs
description={Local gravitational acceleration}, % A brief description of this entry (to appear in the glossary).
user1={\ensuremath{9.81}},
symbol={\ensuremath{\frac{m}{s^2}}}, % put the unit here
sort=g, % for correct sorting type the full name of the symbol here
parent=romanletter % for sorting purposes, use romanletter or greekletter
}
\newglossaryentry{sym:t}
{
type=symbol, % entry should be in the list of symbols!
name={\ensuremath{t}}, % Put the symbol here in dollar signs
description={Time}, % A brief description of this entry (to appear in the glossary).
user1={\ensuremath{-}},
symbol={\ensuremath{s}}, % put the unit here
sort=t, % for correct sorting type the full name of the symbol here
parent=romanletter % for sorting purposes, use romanletter or greekletter
}
\begin{document}
%%%%%%% Print the glossaries
\printnoidxglossary[type=symbol,nonumberlist,style=listoc]
%%%%%%% ----> What should I do here to reset the glossary entries?
\printnoidxglossary[type=constants,nonumberlist,style=listoc]
%%%%%%% Reference an element from every glossary
Reference symbol: \gls{sym:t} \gls{sym:t}\\
Reference constant: \gls{con:g} \gls{con:g}
\end{document}
这是定义词汇表样式的 glspreamble.tex 文件(通常它会包含一个单独的符号列表样式,因为它们没有值)
% Generate the glossary
% create a new glossary style for the list of constants
% Adapted from http://www.latex-community.org/forum/viewtopic.php?f=5&t=20797
\newglossarystyle{listoc}{%
% \glossarystyle{altlongragged4col}
\setlength{\glsdescwidth}{0.8\textwidth}
% allow line wrap in the description column
\renewenvironment{theglossary}%
{\begin{longtable}{lllp{\glsdescwidth}}}%
{\end{longtable}}%
\renewcommand{\glsgroupskip}{}% make nothing happen between groups
\renewcommand*{\glossaryheader}{%
\bfseries Symbol & \bfseries Value & \bfseries Unit & \bfseries Description \\\endhead}%
% No heading between groups:
\renewcommand*{\glsgroupheading}[1]{}%
% Main (level 0) entries displayed in a row optionally numbered:
\renewcommand*{\glossentry}[2]{%
\glsentryitem{##1}% Entry number if required
\glstarget{##1}{\glossentryname{##1}}% Name
& \glsentryuseri{##2}% Value
& \glossentrysymbol{##2}% Unit
& \glossentrydesc{##2}% Description
\tabularnewline % end of row
}%
% Similarly for sub-entries (no sub-entry numbers):
\renewcommand*{\subglossentry}[3]{%
% ignoring first argument (sub-level)
\glstarget{##2}{\glossentryname{##2}}% Name
& \glsentryuseri{##2}% Value
& \glossentrysymbol{##2}% Unit
& \glossentrydesc{##2}% Description
\tabularnewline % end of row
}%
% Nothing between groups:
\renewcommand*{\glsgroupskip}{}%
}
\newglossary[symbol-glg]{symbol}{symbol-gls}{symbol-glo}{List of Symbols}
\newglossary[constants-glg]{constants}{constants-gls}{constants-glo}{List of Constants}
\makenoidxglossaries
\newglossaryentry{romanletter}{type=symbol,name={},description={\nopostdesc},sort=a}
\newglossaryentry{greekletter}{type=symbol,name={},description={\nopostdesc},sort=b}
\newglossaryentry{romanletterc}{type=constants,name={},description={\nopostdesc},sort=a}
\newglossaryentry{greekletterc}{type=constants,name={},description={\nopostdesc},sort=b}
答案1
您已将一个词汇表中的条目分配给另一个词汇表中的父级。因此romanletter
(在symbol
词汇表中)在词汇表sym:t
中有一个子级,在词汇表中也symbol
有一个子级。子级导致其父级被添加到其自己的词汇表中,但这也导致父级的所有其他子条目(在本例中)被添加。con:g
constants
con:g
romanletter
sym:t
我怀疑这实际上只是一个打字错误, 的父级con:g
实际上应该是romanletterc
。
\newglossaryentry{con:g}
{
type=constants,
name={\ensuremath{g}},
description={Local gravitational acceleration},
user1={\ensuremath{9.81}},
symbol={\ensuremath{\frac{m}{s^2}}},
sort=g,
parent=romanletterc % <--- correction
}
经过此修正,产生了期望的结果。