通过运行下面的代码我得到了这个结果:
但我想要类似下图的效果。换句话说,我需要extendeddiscription
在命令中有一个额外的选项\newglossaryentry
,这样我就可以向某些条目添加“扩展描述”。我该怎么做?
\documentclass[a4paper]{book}
\usepackage{lipsum}
\usepackage[xindy,nonumberlist,toc]{glossaries}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
%\renewcommand{\glossarymark}[1]{\markboth{#1}{#1}}
\newglossarystyle{mylist}{%
\glossarystyle{treegroup}
\renewenvironment{theglossary}%
{\setlength{\parindent}{0pt}%
\setlength{\parskip}{0pt}
}%
{}%
\renewcommand*{\glossaryheader}{}%
\renewcommand*{\glsgroupheading}[1]{\noindent\textbf{\glsgetgrouptitle{##1}}\par\nopagebreak}
\renewcommand{\glossaryentryfield}[5]{%
\hangindent0pt\relax
\parindent0pt\relax
\glsentryitem{##1}\glstarget{##1}{##2}%
{\dotfill}\ifx\relax##4\relax
\else
\space(##4)%
\fi
\space ##3\glspostdescription \space ##5\par}%
\renewcommand{\glossarysubentryfield}[6]{%
% \hangindent##1\glstreeindent\relax
\parindent##1\glstreeindent\relax
\ifnum##1=1\relax
\glssubentryitem{##2}%
\fi
\glstarget{##2}{##3}%
\ifx\relax##5\relax
\else
\space(##5)%
\fi
{\dotfill}
##4\indent\glspostdescription\space##6\par}%
\renewcommand*{\glsgroupskip}{\indexspace}
\renewcommand*{\glspostdescription}{}
}
\makeatother
\setlength{\glstreeindent}{20pt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newglossaryentry{latinalph}
{
name={Alfabeto latino},
description={Latin Alphabet},
}
\newglossaryentry{exlatinalph}
{
name={Esteso alfabeto latino},
description={Extended Latin Alphabet},
parent={latinalph}
%extendeddescription={\lipsum[1]}
}
\newglossaryentry{set}
{
name={Impostato},
description={Set},
parent={latinalph}
}
\newglossaryentry{diamatrix}
{
name={Matrice diagonale},
description={Diagonal matrix},
%extendeddescription={\lipsum[2]}
}
\makeglossaries
\glossarystyle{mylist}
\begin{document}
In this chapter we introduce \gls{latinalph}, \gls{exlatinalph},\gls{set}, and \gls{diamatrix}.
\printglossary[title=Glossario]
\end{document}
答案1
您使用了一些已弃用的命令,所以我猜您使用的是旧版本的glossaries
。如果您更新到较新的版本(至少 4.16),则可以使用\glsaddstoragekey
添加新密钥。例如:
\glsaddstoragekey{extendeddescription}{}{\extendeddesc}
这定义了一个新键extendeddescription
,现在可以在 中使用\newglossaryentry
。第二个参数是键不存在时的默认值。我把它留空了。第三个参数是新命令的名称,您可以使用它来访问此值(类似于 之类的命令\glsentrytext
)。例如,我在这里使用了,所以我可以使用 来访问条目\extendedesc
的扩展描述。latinalph
\extendeddesc{latinalph}
我建议您也关闭此字段的扩展,以防您有任何脆弱的命令:
\glssetnoexpandfield{extendeddescription}
我已更新您的词汇表样式以使用较新的样式命令,并添加了\extendeddesc{##1}
扩展描述:
\documentclass[a4paper]{book}
\usepackage{lipsum}
\usepackage[xindy,nonumberlist,toc]{glossaries}
\makeglossaries
\glsaddstoragekey{extendeddescription}{}{\extendeddesc}
\glssetnoexpandfield{extendeddescription}
\newglossarystyle{mylist}{%
\setglossarystyle{treegroup}
\renewenvironment{theglossary}%
{\setlength{\parindent}{0pt}%
\setlength{\parskip}{0pt}
}%
{}%
\renewcommand*{\glossaryheader}{}%
\renewcommand*{\glsgroupheading}[1]{%
\noindent\textbf{\glsgetgrouptitle{##1}}\par\nopagebreak
}
\renewcommand{\glossentry}[2]{%
\hangindent0pt\relax
\parindent0pt\relax
\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}}%
{\dotfill}\ifglshassymbol{##1}{\space(\glossentrysymbol{##1})}{}%
\space \glossentrydesc{##1}\glspostdescription \space ##2\par
\extendeddesc{##1}\par}%
\renewcommand{\subglossentry}[3]{%
\parindent##1\glstreeindent\relax
\ifnum##1=1\relax
\glssubentryitem{##2}%
\fi
\glstarget{##2}{\glossentryname{##2}}%
\ifglshassymbol{##2}{\space(\glossentrysymbol{##2})}{}%
{\dotfill}
\glossentrydesc{##2}\indent\glspostdescription\space##3\par
\extendeddesc{##2}\par}%
\renewcommand*{\glsgroupskip}{\indexspace}
\renewcommand*{\glspostdescription}{}
}
\setlength{\glstreeindent}{20pt}
\newglossaryentry{latinalph}
{
name={Alfabeto latino},
description={Latin Alphabet},
}
\newglossaryentry{exlatinalph}
{
name={Esteso alfabeto latino},
description={Extended Latin Alphabet},
parent={latinalph},
extendeddescription={\lipsum[1]}
}
\newglossaryentry{set}
{
name={Impostato},
description={Set},
parent={latinalph}
}
\newglossaryentry{diamatrix}
{
name={Matrice diagonale},
description={Diagonal matrix},
extendeddescription={\lipsum[2]}
}
\setglossarystyle{mylist}
\begin{document}
In this chapter we introduce \gls{latinalph}, \gls{exlatinalph},\gls{set}, and \gls{diamatrix}.
\printglossary[title=Glossario]
\end{document}
词汇表现在如下所示: