Makeindex 风格的首字母缩略词列表(词汇表)

Makeindex 风格的首字母缩略词列表(词汇表)

我是一个 LaTeX 新手,使用这个例子提供方汤姆·布赖恩将我的一些首字母缩略词与其词汇表条目合并。我想更改首字母缩略词列表的样式,使其看起来像这样: 在此处输入图片描述

我尝试使用此命令来更改样式:

\printglossary[type=\acronymtype,style=long3col]

现在我的列表如下所示: 在此处输入图片描述

以下是代码:

\documentclass{article}
\usepackage{hyperref}
\usepackage[acronym]{glossaries}
\makeglossaries


%%% The glossary entry the acronym links to   
\newglossaryentry{apig}{name={API},
    description={An Application Programming Interface (API) is a particular set
of rules and specifications that a software program can follow to access and
make use of the services and resources provided by another particular software
program that implements that API}}

%%% define the acronym and use the see= option
\newglossaryentry{api}{type=\acronymtype, name={API}, description={Application
Programming Interface}, first={Application
Programming Interface (API)\glsadd{apig}}, see=[Glossary:]{apig}}
\begin{document}
\noindent
First use \gls{api}\\
subsequent \gls{api}
\newpage

\printglossary[type=\acronymtype,style=long3col]
%%% \newpage just to demonstrate that links are correct
\newpage
\printglossary[type=main]

\end{document}

我需要在代码中做哪些改动才能让它看起来像上图那样?

答案1

关键see是始终将交叉引用放在位置列表的末尾,因此我认为最好将交叉引用移到描述的末尾,如下所示:

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage[acronym]{glossaries}
\makeglossaries

\newglossarystyle{longdotted}{%
 \setglossarystyle{long}%
  \renewcommand{\glossentry}[2]{%
    \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
    \glossentrydesc{##1}\glspostdescription\dotfill ##2\tabularnewline
  }%
}

\setlength{\glsdescwidth}{0.85\hsize}

%%% The glossary entry the acronym links to   
\newglossaryentry{apig}{name={API},
    description={An Application Programming Interface (API) is a particular set
of rules and specifications that a software program can follow to access and
make use of the services and resources provided by another particular software
program that implements that API}}

%%% define the acronym and use the see= option
\newglossaryentry{api}{type=\acronymtype, name={API}, description={Application
Programming Interface \emph{Glossary:} \glsname{apig}}, first={Application
Programming Interface (API)\glsadd{apig}}}
\begin{document}
\noindent
First use \gls{api}\\
subsequent \gls{api}
\newpage

\printglossary[type=\acronymtype,style=longdotted]
%%% \newpage just to demonstrate that links are correct
\newpage
\printglossary[type=main]

\end{document}

这看起来像:

带虚线引线的词汇表图像

您可能需要更改 的值\glsdescwidth

另一种可能性是使用扩展包glossaries-extra,它存储密钥的值see。(基础glossaries包不执行此操作。密钥see只是触发\glssee。)see可以使用以下方式访问该值\glsxtrusesee{标签},这样就可以调整词汇表样式,以便将交叉引用放在所需的位置。例如:

\newglossarystyle{longdotted}{%
 \setglossarystyle{long}%
  \renewcommand{\glossentry}[2]{%
    \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
    \glossentrydesc{##1}\glspostdescription
     \space\glsxtrusesee{##1}% add cross-reference
     \dotfill ##2\tabularnewline
  }%
}

现在唯一的问题是防止在定义条目\glssee时检测到字段时发生的自动see检测。有两种方法可以做到这一点。

第一种方法需要glossaries-extrav1.16,这是新版本,因此可能不可用。此版本提供了autoseeindex包选项,用于控制 的自动使用\glssee。该选项autoseeindex=false的副作用是不会打开该indexcrossrefs选项,因此需要明确执行:

\usepackage[acronym,
 autoseeindex=false,% store see key but don't automatically add to location list
 indexcrossrefs% index the cross-referenced terms
]{glossaries-extra}

完整示例:

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage[acronym,
 autoseeindex=false,% store see key but don't automatically add to location list
 indexcrossrefs% index the cross-referenced terms
]{glossaries-extra}
\makeglossaries

\newglossarystyle{longdotted}{%
 \setglossarystyle{long}%
  \renewcommand{\glossentry}[2]{%
    \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
    \glossentrydesc{##1}\glspostdescription
     \space\glsxtrusesee{##1}% add cross-reference
     \dotfill ##2\tabularnewline
  }%
}

\setlength{\glsdescwidth}{0.85\hsize}

%%% The glossary entry the acronym links to   
\newglossaryentry{apig}{name={API},
    description={An Application Programming Interface (API) is a particular set
of rules and specifications that a software program can follow to access and
make use of the services and resources provided by another particular software
program that implements that API}}

%%% define the acronym and use the see= option
\newglossaryentry{api}{type=\acronymtype, 
 name={API},
 see=[Glossary:]{apig},
 description={Application Programming Interface},
 first={Application Programming Interface (API)}}

\begin{document}
\noindent
First use \gls{api}\\
subsequent \gls{api}
\newpage

\printglossary[type=\acronymtype,style=longdotted]
%%% \newpage just to demonstrate that links are correct
\newpage
\printglossary[type=main]

\end{document}

第二种方法是将其放在\makeglossaries条目定义之后。此命令打开外部词汇表文件以备索引。由于未打开相应文件,因此无法实现该命令之前发生的任何索引。由于通常不希望出现这种情况,因此如果在之前使用,则glossaries包将产生错误。可以使用包选项将此错误转换为警告,或者使用简单地忽略它。(此选项是v4.24 的新增选项):see\makeglossariesseenoindex=warnseenoindex=ignoreglossaries

完整示例:

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage[acronym,
 seenoindex=ignore% ignore 'see' key occurring before \makeglossaries
]{glossaries-extra}


\newglossarystyle{longdotted}{%
 \setglossarystyle{long}%
  \renewcommand{\glossentry}[2]{%
    \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
    \glossentrydesc{##1}\glspostdescription
     \space\glsxtrusesee{##1}% add cross-reference
     \dotfill ##2\tabularnewline
  }%
}

\setlength{\glsdescwidth}{0.85\hsize}

%%% The glossary entry the acronym links to   
\newglossaryentry{apig}{name={API},
    description={An Application Programming Interface (API) is a particular set
of rules and specifications that a software program can follow to access and
make use of the services and resources provided by another particular software
program that implements that API}}

%%% define the acronym and use the see= option
\newglossaryentry{api}{type=\acronymtype, 
 name={API},
 see=[Glossary:]{apig},
 description={Application Programming Interface},
 first={Application Programming Interface (API)}}

\makeglossaries % open external files for indexing

\begin{document}
\noindent
First use \gls{api}\\
subsequent \gls{api}
\newpage

\printglossary[type=\acronymtype,style=longdotted]
%%% \newpage just to demonstrate that links are correct
\newpage
\printglossary[type=main]

\end{document}

可以进行进一步的修改。目前,Glossary:需要将标签添加到see键的每个实例(如see=[Glossary:]{apig})。如果需要对acronym词汇表中的每个条目都执行此操作,那么以交叉引用格式设置此标签会更方便。使用基础glossaries包,有两种方法可以做到这一点:重新定义\seename或重新定义\glsseeformat。我不推荐前者,因为如果文档还需要索引,这会导致问题。

\glsseeformat有一个可选参数,即标签,定义为:

\DeclareRobustCommand*{\glsseeformat}[3][\seename]{%
  \emph{#1} \glsseelist{#2}}

它很少在没有可选参数的情况下使用,并且see={apig}最终会变成\glsseeformat[\seename]{apig}{},因此改变的版本将需要在定义中明确使用标签:

\renewrobustcmd*{\glsseeformat}[3][\seename]{%
  \emph{Glossary:} \glsseelist{#2}}

\seename(或者添加对as 的测试#1)。

如果您使用的是glossaries-extrav1.16,还有另一种选择,那就是使用 keyseealso而不是seekey。keyseealso不允许在交叉引用标签列表的开头使用可选的标签部分。相关格式\glsxtruseseealsoformat定义为:

\newcommand*{\glsxtruseseealsoformat}[1]{%
  \glsseeformat[\seealsoname]{#1}{}%
}

这可以重新定义为使用您的自定义标签:

\renewcommand*{\glsxtruseseealsoformat}[1]{%
  \glsseeformat[Glossary:]{#1}{}%
}

任何其他不应具有此标签的交叉引用均可使用该see键正常执行。

相关内容