每当文档中的单词表后面使用“Varicer”、“Lobuli”、“Haptocytter”、“Fibrose”等单词时,它们都应该采用斜体字体,有没有办法创建一个以此为起点的函数:
\nomenclature{Varicer}{explanation}
\nomenclature{Lobuli}{explanation}
\nomenclature{Haptocytter}{explanation}
\nomenclature{Fibrose}{explanation}
哪个会遍历上述列表并检查整个文本中的单词并使其成为斜体字体?
我的项目结构包含更多文件,下面是一个最简单的示例:
主文本
\documentclass[10pt,a4paper]{article}
\usepackage[a4paper,top=2cm, bottom=3cm, left=3cm, right=3cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{subfiles}
\usepackage{graphicx}
\graphicspath{{images/}{../images/}}
\usepackage[danish]{babel}
%---Wordlist---%
\usepackage[danish]{nomencl} %package to make wordlist
\usepackage{xpatch}
\patchcmd{\thenomenclature} %makes indent in front of all entries
{\leftmargin\labelwidth}
{\leftmargin\labelwidth\itemindent 1em }
{}{}
\makenomenclature %Makes the word list
\setlength\nomlabelwidth{3cm} %distance to explanation text
\renewcommand{\nomname}{Wordlist} %Title of wordlist
\renewcommand{\nompreamble}{Introduction text}
%---Wordlist---%
\begin{document}
\subfile{01}
\subfile{02}
\end{document}
01.tex
\documentclass[main.tex]{subfiles}
\graphicspath{{./img/}{../img}}
\begin{document}
\nomenclature{Varicer}{explanation}
\nomenclature{Lobuli}{explanation}
\nomenclature{Haptocytter}{explanation}
\nomenclature{Fibrose}{explanation}
\printnomenclature
\section{Test1}
Som text Varicer blabla Lobuli.
\end{document}
02.tex
\documentclass[main.tex]{subfiles}
\graphicspath{{./img/}{../img}}
\begin{document}
\section{Test 2}
blablabla Varicer blabla Lobuli bla.
\end{document}
注意:从主文件编译
答案1
由于原帖作者无法利用我在根据字典自动突出显示文本,我在下面展示它。
我修改了对的调用,\nomenclature
将每个单词添加到\thewordlist
,然后将其用作参数\setsepchar
,以引用问题的方式设置搜索listofitems
。我还根据 OP 的问题将突出显示从颜色更改为斜体。我这样做是为了如果列表中的单词作为其自己的单词出现或作为较大单词的一部分出现,它将被斜体化。
我调用 tokencycle后定义命名法,因为命名法用于构建单词列表。因此,我修改后的调用\nomenclature
还将参数作为传递\textit
,以便以斜体形式获取命名法条目本身。
\documentclass[10pt,a4paper]{article}
\usepackage[a4paper,top=2cm, bottom=3cm, left=3cm, right=3cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{subfiles}
\usepackage{graphicx}
\graphicspath{{images/}{../images/}}
\usepackage[danish]{babel}
%---Wordlist---%
\usepackage[danish]{nomencl} %package to make wordlist
\usepackage{xpatch}
\patchcmd{\thenomenclature} %makes indent in front of all entries
{\leftmargin\labelwidth}
{\leftmargin\labelwidth\itemindent 1em }
{}{}
\makenomenclature %Makes the word list
\setlength\nomlabelwidth{3cm} %distance to explanation text
\renewcommand{\nomname}{Wordlist} %Title of wordlist
\renewcommand{\nompreamble}{Introduction text}
%---Wordlist---%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tokcycle,listofitems}
\let\svnomenclature\nomenclature
\renewcommand\nomenclature[2]{\addtowordlist{#1}\svnomenclature{\textit{#1}}{#2}}
\def\thewordlist{}
\newcommand\addtowordlist[1]{\ifx\thewordlist\empty\def\thewordlist{#1}
\else\edef\thewordlist{\thewordlist||#1}\fi}
\newcommand\testdict{%
\if\relax\detokenize\expandafter{\currentword}\relax\else
{\ignoreemptyitems
\greadlist\dictcompA{\currentword}}%
\readlist\dictcompB{\currentword}%
\ifnum\listlen\dictcompA[]=0\relax
\addcytoks[1]{\autohighlightStyleA}%
\addcytoks[1]{\expandafter{\currentword}}
\else
\ifnum\listlen\dictcompB[]>1\relax
\addcytoks[1]{\autohighlightStyleB}%
\addcytoks[1]{\expandafter{\currentword}}
\else
\addcytoks[1]{\currentword}%
\fi
\fi
\fi
\gdef\currentword{}%
}
\makeatletter
\Characterdirective{\tctestifcatnx A#1{\g@addto@macro\currentword{#1}}
{\testdict\addcytoks{#1}}}
\stripgroupingtrue
\Groupdirective{\testdict\groupedcytoks{\processtoks{#1}\testdict}}
\Macrodirective{\g@addto@macro\currentword{#1}}
\Spacedirective{\testdict\addcytoks{#1}}
\makeatother
\newcommand\autohighlightStyleA{\textit}
\newcommand\autohighlightStyleB{\textit}
\begin{document}
\nomenclature{Varicer}{explanation}
\nomenclature{Lobuli}{explanation}
\nomenclature{Haptocytter}{explanation}
\nomenclature{Fibrose}{explanation}
\printnomenclature
\expandafter\setsepchar\expandafter{\thewordlist}
\def\currentword{}\tokencyclexpress
\section{Test1}
Som text Varicer blabla Lobuli.
\section{Test 2}
blablabla Varicer blabla Lobuli bla.
\endtokencyclexpress
\end{document}
ps 警告:该过程依赖于大小写,因此如果单词在文档中以小写形式出现,则不会在列表中拾取它们。