子节迷你索引

子节迷你索引

有如下代码:

\subsection{some subsection}
Some \mindex[mean=aaa]{sentence} with some \mindex[mean=bbb]{unknown} words.
\listminiindexfromsubsection

预期输出:

部分小节

有些句子含有一些未知的单词。

迷你索引:句子 - aaa 未知 - bbb

我想创建一个类似迷你索引的东西,它可以创建一个小词典。\mindex[mean=something]{word}应该收集特定子部分中作为参数的所有单词,并且当命令\listminiindexfromsubsection写入时,输出应该包含所有这些单词及其含义。

从某个小节中收集特定单词然后将其打印出来的方法是什么?

答案1

\documentclass[a4paper]{article}

\def\mindexlist{}
\makeatletter
\newcommand{\mindex}[2]{\g@addto@macro\mindexlist{\textbf{#1} --- #2\par}#2}
\newcommand{\printmindex}{\begin{flushleft}\mindexlist\end{flushleft}
  \gdef\mindexlist{}}
\makeatother

\begin{document}
\section{First}
Some \mindex{sentence}{aaa} with some \mindex{unknown}{bbb} words.

\printmindex

\section{Second}
Some \mindex{sentence}{ccc} with some \mindex{unknown}{ddd} words.

\printmindex
\end{document}

每个\printmindex命令都会重置列表。

答案2

也许没有你想象的那么简单,但也不是很难。你可以使用词汇表打包并为每个小节创建一个词汇表:

\documentclass{article}
\usepackage[nonumberlist,savewrites,xindy,nomain]{glossaries}

 % Define new glossaries
\newglossary[sco]{seco}{oin}{ofi}{Short Index}
\newglossary[sct]{sect}{tin}{tfi}{Short Index}

\makeglossaries

% declare the entries
\newglossaryentry{seco:unk}{type=seco, name={unknown}, description={Not known}}

\newglossaryentry{seco:sen}{type=seco,name={sentence},description={Some description}}

\newglossaryentry{sect:rin}{type=sect,name={ring},description={Not known}}

\newglossaryentry{sect:gro}{type=sect,name={group},description={Simple structure}}

\begin{document}

\section{Test section}

\subsection{First subsection}
This is a \gls{seco:sen} with some \gls{seco:unk} words.
\printglossary[type=seco]

\subsection{Second subsection}
A \gls{sect:rin} is an algebraic structure whose definition is not known; A \gls{sect:gro} is a simple algebraic structure.
\printglossary[type=sect]

\end{document}

test.tex可以使用以下命令编译该示例(我们称之为上述文档):

(pdf)latex test
makeglossaries test
(pdf)latex test
(pdf)latex test

结果:

相关内容