如何在 cite 中使用变量

如何在 cite 中使用变量

我在阅读的文本文件中有一些引用键,我能够成功读取这些键并将它们打印在文章中,但不能在里面打印\cite{\MyVariable}

具体来说,这就是我想要实现的\cite{\CitePointer}(从当前示例来看),并且\CitePointer具有我需要参考的 bib 键。

这里有一个我想要实现的完整工作示例:

\documentclass[journal]{IEEEtran}
\usepackage{catchfilebetweentags}

\begin{filecontents}{\jobname-tags.tex}
Hello world I have a tag inside this
\iffalse
%<*tag:citekey>
IEEEhowto
%</tag:citekey>
\fi
\end{filecontents}

\begin{document}

- This is working as expected\cite{IEEEhowto}

\edef\PaperCiteRef{IEEEhowto}
- This reference is working as expected we will call \PaperCiteRef \ in a cite\cite{\PaperCiteRef}

\edef\CitePointer{\ExecuteMetaData[\jobname-tags.tex]{tag:citekey}}
- This prints the reference key \CitePointer 

- The following is not working (uncomment it)
%- Why this \cite{\CitePointer} wont work?

\begin{thebibliography}{1}
        \bibitem{IEEEhowto}
        H.~Kopka and P.~W. Daly, \emph{A Guide to \LaTeX}, 3rd~ed.\hskip 1em plus
        0.5em minus 0.4em\relax Harlow, England: Addison-Wesley, 1999.
\end{thebibliography}
    
\end{document}

我猜测这\CitePointer是由于某些格式破坏了\cite命令,但我无法修复它,有什么想法吗?

在这种情况下\cite{\PaperCiteRef}有效但\cite{\CitePointer}实际上无效。

答案1

这样做\edef\CitePointer{\ExecuteMetaData[\jobname-tags.tex]{tag:citekey}}并不能定义\CitePointer你想要的字符串。事实上,如果我添加

\show\CitePointer

按照这个指令我得到了

> \CitePointer=macro:
->\ExecuteMetaData [camacho-tags.tex]{tag:citekey}.

(因为我将主文件命名为camacho.tex)。您应该使用\CatchFileBetweenTags

\documentclass[journal]{IEEEtran}
\usepackage{catchfilebetweentags}

\begin{filecontents}{\jobname-tags.tex}
Hello world I have a tag inside this
\iffalse
%<*tag:citekey>
IEEEhowto
%</tag:citekey>
\fi
\end{filecontents}

\begin{document}

-- This is working as expected~\cite{IEEEhowto}

\edef\PaperCiteRef{IEEEhowto}
-- This reference is working as expected we will call \PaperCiteRef \ in a 
   cite~\cite{\PaperCiteRef}

\CatchFileBetweenTags{\CitePointer}{\jobname-tags.tex}{tag:citekey}
-- This prints the reference key \CitePointer\ and the reference
   works~\cite{\CitePointer}

\begin{thebibliography}{1}

\bibitem{IEEEhowto}
  H.~Kopka and P.~W. Daly, \emph{A Guide to \LaTeX}, 3rd~ed.%
  \hspace{1em plus 0.5em minus 0.4em}Harlow, England: Addison-Wesley, 1999.

\end{thebibliography}
    
\end{document}

在此处输入图片描述

相关内容