我正在尝试构建一个函数来扩展\cite{}
,以支持多点引用(仍然使用apacite
包)。我正在尝试制作一个 LaTeX 标记文档,它可以在 ShareLaTex 中呈现整洁的 PDF,也可以\citeNP
在文档中解析而不需要一堆命令
标准语法\cite{}
是:
\cite<preliminarytext>[pinpoint]{bibtexref1,bibtexref2,...}
我正在尝试创建这个命令:
\myapacite[pinpoint1,pinpoint2,...][additionaloptions]{bibtexref1,bibtexref2,...}
在哪里:
如果逗号分隔的“pinpoint”参数的数量
\myapacite
不等于逗号分隔的“bibtexref”参数的数量,则忽略这些参数并插入常规\cite{}
命令如果以逗号分隔的“pinpoint”和“bibtexref”参数的数量相同,则循环并插入这些参数:
(\citeNP[pinpoint1]{bibtexref1}; \citeNP[pinpoint2]{bibtexref2}; ...)
这是我想要实现的基本布局,尽管会存在多个 TeX 问题(与许多人一样,我有编程背景,只是在慢慢学习 TeX/LaTeX)。任何建议都将不胜感激。
\documentclass[apacite]{apa6}
\usepackage{xparse,expl3}
\NewDocumentCommand\myapacite{O{}O{}m}{%
\if\equals{\clist_count:n {#1}}{\clist_count:n {#3}}%
\cite[#1]{#3}%
\else%
\if\equals{1}{\clist_count:n {#3}}%
\cite[#1]{#3}%
\else%
\if\equals{2}{\clist_count:n {#3}}%
(\citeNP[\clist_item:Nn {1} {#2}]{\clist_item:Nn {1} {#3}}; \citeNP[\clist_item:Nn {2} {#2}]{\clist_item:Nn {2} {#3}})\fi\fi\fi%
}
\begin{document}
Single cite with no pinpoints: \myapacite{goossens93}
\\
\\
Double cite with both pinpoints: \myapacite[p.123,p.456]{greenwade93,goossens93}
\\
\\
Double cite with no pinpoints: \myapacite{greenwade93,goossens93}
\\
\\
\bibliography{ testbib }
\end{document}
这是testbib.bib
文件(我不知道如何在 ShareLaTeX 中使用文件内容):
@article{greenwade93,
author = "George D. Greenwade",
title = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
year = "1993",
journal = "TUGBoat",
volume = "14",
number = "3",
pages = "342--351"
}
@book{goossens93,
author = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
title = "The LaTeX Companion",
year = "1993",
publisher = "Addison-Wesley",
address = "Reading, Massachusetts"
}