如何检查密钥是否已在 aux 文件中

如何检查密钥是否已在 aux 文件中

尝试一些 LaTeX 命令,我想建立一个缩写列表,当定义时将首字母缩略词写入文件,如果已定义则不执行任何操作。到目前为止,它运行良好,添加\abvr{OpenCL}{Open Computing Language}会将一个条目添加到我的列表中。但如果我在报告中输入两次,则会有两个条目。

是否存在任何方法来检查密钥是否已存在于文件中.aux@loa或者使项目仅显示一次重复的项目?

\documentclass[10pt,conference]{IEEEtran}

\usepackage[utf8x]{inputenc}

\DeclareFontFamily{OT1}{pzc}{}
\DeclareFontShape{OT1}{pzc}{m}{it}{<-> s * [1.10] pzcmi7t}{}
\DeclareMathAlphabet{\mathpzc}{OT1}{pzc}{m}{it}

\usepackage{cite} %However, IEEEtran pre-defines some format control macros to facilitate easy use with Donald Arseneau’s cite.sty package [13]. So, all an author has to do is to call cite.sty:

\setlength{\parskip}{1.5mm}

\def\tm{\leavevmode\hbox{$\rm {}^{TM}$}}
\def\registered{{\ooalign{\hfil\raise .00ex\hbox{\scriptsize R}\hfil\crcr\mathhexbox20D}}} % $^\registered$
\def\trademark{$\rm {}^{\hbox{\tiny TM}}$} % then accessible in math mode

\newcommand{\vect}[1]{\boldsymbol{#1}} %If bold vectors.
%\newcommand{\vect}[1]{\vec{#1}}  %If arrow over vectors.

\title{Parallel Programming for Image Processing Algorithms}
\author{Poul~K.~Sørensen
\thanks{Thanks note.}
}
%\setlength{\columnsep}{distance}

\newif\ifabvrused
\abvrusedfalse

\makeatletter
\def\abvr#1#2{%
{#2 (\textbf{#1})}%
%\def\ArgI{{#1}}%
%\@ifundefined{r@\ArgI}{{#2 (\textbf{#1})\label{\ArgI}}}{#1}%   
\ifabvrused%
\else%
\newwrite\@loa%
\immediate\openout\@loa=\jobname.loa%
\abvrusedtrue%
\fi%
\immediate\write\@loa{\unexpanded{\item[#1]#2}}%
}

\newcommand\@startloa{%
  \immediate\closeout\@loa
  \section*{Abbreviations}
  \begin{listofabbrv}{SPMD}
  \InputIfFileExists{\jobname.loa}{}{\item[\null]}
  \end{listofabbrv}
}
\newcommand{\listofabbreviations}{\@startloa}


\newenvironment{listofabbrv}[1]{\begin{itemize}}{\end{itemize}}

\makeatother

\newcommand{\ie}{i.e.~\/}
\newcommand{\eg}{e.g.~\/}
\newcommand{\degree}{$^{\circ }$}

\usepackage{acronym}


\begin{document}
\maketitle
\begin{abstract}
\boldmath Learning \abvr{OpenCL}{Open C Laaaa} for Image Analysis.\abvr{OpenCL}{Open C Laaaa}
\end{abstract}

\listofabbreviations
\end{document}

答案1

以下 的定义\abrv针对每次使用缩写都会创建一个命令。然后,该命令用于检查缩写是否已被使用/创建,并随后确定是否将信息写入.loa辅助文件(通过\@ifundefined):

\def\abrv#1#2{%
  {#2 (\textbf{#1})}%
  \ifabrvused\else%
    \newwrite\@loa%
    \immediate\openout\@loa=\jobname.loa%
    \abrvusedtrue%
  \fi%
  \@ifundefined{abrv@#1}{%
    \expandafter\def\csname abrv@#1\endcsname{#2}%
    \immediate\write\@loa{\unexpanded{\item[#1]#2}}%
  }{}%
}

为每个缩写创建的宏<abrv>\abrv@<abrv>。这是一个完整的最小示例:

在此处输入图片描述

\documentclass[10pt,conference]{IEEEtran}

\title{Parallel Programming for Image Processing Algorithms}
\author{An Author%
\thanks{Thanks note.}
}

\newif\ifabrvused
\abrvusedfalse

\makeatletter
\def\abrv#1#2{%
  {#2 (\textbf{#1})}%
  \ifabrvused\else%
    \newwrite\@loa%
    \immediate\openout\@loa=\jobname.loa%
    \abrvusedtrue%
  \fi%
  \@ifundefined{abrv@#1}{%
    \expandafter\def\csname abrv@#1\endcsname{#2}%
    \immediate\write\@loa{\unexpanded{\item[#1]#2}}%
  }{}%
}

\newcommand\@startloa{%
  \immediate\closeout\@loa
  \section*{Abbreviations}
  \begin{listofabbrv}{SPMD}
  \InputIfFileExists{\jobname.loa}{}{\item[\null]}
  \end{listofabbrv}
}
\newcommand{\listofabbreviations}{\@startloa}
\newenvironment{listofabbrv}[1]{\begin{itemize}}{\end{itemize}}
\makeatother

\usepackage{acronym}% http://ctan.org/pkg/acronym


\begin{document}
\maketitle
\begin{abstract}
Learning \abrv{OpenCL}{Open C Laaaa} for Image Analysis.\abrv{OpenCL}{Open C Laaaa}
\end{abstract}

\listofabbreviations
\end{document}

相关内容