我有几位作者为使用外部强加的方案编号的问题贡献解决方案,我通过环境处理该方案description
。我将每位作者的姓名包装在其中,\index{}
并需要打印的索引来显示外部方案中出现的问题编号。现在我正在使用报告文档类,但可以说服我进行更改。
我找到了一种方法来捕获外部编号,方法是使用\ref{}
来自这里,但无法显示除计数器值之外的其他索引。
例如:
\documentclass{report}
\usepackage{makeidx}
\makeindex
\usepackage{hyperref}
\newcounter{desccount}
\newcommand{\descitem}[1]{%
\item[#1] \refstepcounter{desccount}\label{#1}
}
\newcommand{\descref}[1]{\hyperref[#1]{#1}}
\begin{document}
\begin{description}
\descitem{1B.1} by \index{Smith}
\descitem{1B.3} by \index{Jones}
\descitem{1C.1} by \index{Smith}
\descitem{1E.11} by \index{Burton}
\end{description}
\printindex
\end{document}
我希望文档的最终索引是
Burton 1E.11
Jones 1B.3
Smith 1B.1, 1C.1
并hyperref
适当地填写超链接。我最接近的做法是使用memoir
文档类并包含一个\renewcommand{\index}[1]{\specialindex{\jobname}{desccount}{#1}}
,但这只会返回的值desccount
,而不是外部编号方案。在给出的示例中,我得到的输出是
Burton 4
Jones 2
Smith 1, 3
这不是我想要的。我怎样才能让索引返回 的参数\descitem
而不是 页码或 的值desccount
?
答案1
这是一个可能的解决方案,将glossaries
“任意”文本标签写入文件.aux
,然后使用\getrefnumber
(包refcount
)提供问题编号
底层desccount
计数器用于提供新词汇表的相关条目provider
。
可能有更好的设置\descitem
,但这是 OP 给出的,我对其进行了一点修改\descitem[provider name]{Number}
。
我\descitem
故意保留了旧的宏,但对其进行了评论!
\documentclass{report}
\usepackage{array}
\usepackage{refcount}
\usepackage{xparse}
\usepackage{hyperref}
\usepackage[nomain,savenumberlist=true]{glossaries}
\makeatletter
\newcommand{\writetextlabel}[1]{%
\immediate\write\@auxout{%
\string\newlabel{description::\number\value{desccount}}{{#1}{\thepage}{}{desccount.\number\value{desccount}}}%
}%
}
\makeatother
\newcounter{desccount}
% Here is the 'original' \descitem command.
%\newcommand{\descitem}[2][]{%
%\item[\protect\hypertarget{#1}{#1}]\refstepcounter{desccount}\writetextlabel{#1}
%}
\NewDocumentCommand{\descitem}{om}{%
\IfValueTF{#1}{%
\item[\protect\hypertarget{#2}{#2}]\refstepcounter{desccount}\writetextlabel{#2} by \gls{#1}%
}{%
\item[\protect\hypertarget{#2}{#2}]%
}%
}
\newglossary[prl]{provider}{pri}{pro}{Providers of solutions}[desccount]
\newglossaryentry{Smith}{%
type={provider},
name={Smith},
description={Smith has provided some of solutions},
}
\newglossaryentry{Jones}{%
type={provider},
name={Jones},
description={Jones has provided other solutions},
}
\newglossaryentry{Burton}{%
type={provider},
name={Burton},
description={Burton was a lazy guy}
}
\makeglossaries
\newglossarystyle{providerdesc}{%
\setglossarystyle{long3col}% base this style on the list style
\renewenvironment{theglossary}{% Change the table type --> 3 columns
\begin{longtable}{lp{0.6\glsdescwidth}>{\raggedleft\arraybackslash}p{5cm}}}%
{\end{longtable}}%
%
\renewcommand{\glsnumberformat}[1]{\protect\hyperlink{\getrefnumber{description::##1}}{\getrefnumber{description::##1}}}% Change to use the textlabel
\renewcommand*{\glossaryheader}{% Change the table header
\bfseries Author & \bfseries Description & \bfseries Solutions provided \\
\hline
\endhead}
\renewcommand*{\glossentry}[2]{% Change the displayed items
\glstarget{##1}{\glossentryname{##1}} %
& \glossentrydesc{##1}% Description
& \space ##2 \tabularnewline
}
}
\begin{document}
\begin{description}
\descitem[Smith]{1B.1}
\descitem[Jones]{1B.3}
\descitem[Smith]{1C.3}
\descitem[Burton]{A5.6}
\end{description}
\clearpage
\begin{description}
\descitem[Smith]{A.1}
\descitem[Jones]{A3}
\descitem[Smith]{45.B}
\descitem[Burton]{6.E}
\end{description}
\setglossarystyle{providerdesc}
\printglossaries
\end{document}