带前缀标签的 Natbib-Multibib 问题

带前缀标签的 Natbib-Multibib 问题

natbib我在使用和 标签前缀时遇到了一个问题multibib。我想定义两个书目:一个用于其他人的文献,带有编号的参考文献,另一个用于我自己的文献,也带有编号的参考文献,但每个参考文献前面都有一个前缀“O”(选项multibib labeled)。不使用natbib(仅使用multibib),它可以正常工作。但与 一起使用时natbib,“O”前缀会在文本中消失。在书目中,它仍然存在。我需要使用natbibsort&compress功能。

工作最小示例:

\documentclass{scrbook}

\usepackage{filecontents}
\begin{filecontents}{main.bib}
@ARTICLE{travis,
  author = {Brehm, M. and Kirchner, B.},
  title = {TRAVIS - A free Analyzer and Visualizer for Monte Carlo and Molecular
    Dynamics Trajectories},
  journal = {J. Chem. Inf. Model.},
  year = {2011},
  volume = {51 (8)},
  pages = {2007-2023},
  owner = {Brehministrator},
  timestamp = {2011.11.27}
},
@ARTICLE{welton2001,
  author = {L. Cammarata and S. G. Kazarian and P. A. Salter and T. Welton},
  title = {Molecular states of water in room temperature ionic liquids},
  journal = {Phys. Chem. Chem. Phys.},
  year = {2001},
  volume = {3},
  pages = {5192-5200},
  owner = {Brehministrator},
  timestamp = {2011.12.11}
}
}
\end{filecontents}

\usepackage[square, sort&compress, super, comma]{natbib} 
\usepackage[labeled,resetlabels]{multibib}

\newcites{O}{Own Publications}

\begin{document}
\chapter{Introduction}

Citing my own literature\citeO{travis}.
Citing other people's literature\cite{welton2001}.

\appendix
\bibliographystyle{plain}
\bibliographystyleO{plain}
\bibliography{main}
\bibliographyO{main}

\end{document}

要编译这个,您需要在“main”和“O”上分别运行 bibtex。

答案1

这是实现结果的一种方法。 (我复制了您的参考资料以检​​查排序和压缩是否有效。)

你必须记住直到您生成并时,该natbib包才应该被注释。O.bbl<filename>.bbl也就是说,natbib一旦bbl使用 生成文件,就加载包bibtex。否则,\citation条目将只写入<filename>.aux,并且O.bbl将生成没有\bibitem{...}。稍后编辑文件时,您会记住这一点main.bib

\documentclass{scrbook}

\usepackage{filecontents}
\begin{filecontents}{main.bib}
@ARTICLE{travis,
  author = {Brehm, M. and Kirchner, B.},
  title = {TRAVIS - A free Analyzer and Visualizer for Monte Carlo and Molecular
    Dynamics Trajectories},
  journal = {J. Chem. Inf. Model.},
  year = {2011},
  volume = {51 (8)},
  pages = {2007-2023},
  owner = {Brehministrator},
  timestamp = {2011.11.27}
},
@ARTICLE{travis1,
  author = {Brehm, M. and Kirchner, B.},
  title = {TRAVIS - A free Analyzer and Visualizer for Monte Carlo and Molecular
    Dynamics Trajectories},
  journal = {J. Chem. Inf. Model.},
  year = {2011},
  volume = {51 (8)},
  pages = {2007-2023},
  owner = {Brehministrator},
  timestamp = {2011.11.27}
},
@ARTICLE{travis2,
  author = {Brehm, M. and Kirchner, B.},
  title = {TRAVIS - A free Analyzer and Visualizer for Monte Carlo and Molecular
    Dynamics Trajectories},
  journal = {J. Chem. Inf. Model.},
  year = {2011},
  volume = {51 (8)},
  pages = {2007-2023},
  owner = {Brehministrator},
  timestamp = {2011.11.27}
},
@ARTICLE{travis3,
  author = {Brehm, M. and Kirchner, B.},
  title = {TRAVIS - A free Analyzer and Visualizer for Monte Carlo and Molecular
    Dynamics Trajectories},
  journal = {J. Chem. Inf. Model.},
  year = {2011},
  volume = {51 (8)},
  pages = {2007-2023},
  owner = {Brehministrator},
  timestamp = {2011.11.27}
},
@ARTICLE{welton2001,
  author = {L. Cammarata and S. G. Kazarian and P. A. Salter and T. Welton},
  title = {Molecular states of water in room temperature ionic liquids},
  journal = {Phys. Chem. Chem. Phys.},
  year = {2001},
  volume = {3},
  pages = {5192-5200},
  owner = {Brehministrator},
  timestamp = {2011.12.11}
}
@ARTICLE{welton20011,
  author = {L. Cammarata and S. G. Kazarian and P. A. Salter and T. Welton},
  title = {Molecular states of water in room temperature ionic liquids},
  journal = {Phys. Chem. Chem. Phys.},
  year = {2001},
  volume = {3},
  pages = {5192-5200},
  owner = {Brehministrator},
  timestamp = {2011.12.11}
}
@ARTICLE{welton20012,
  author = {L. Cammarata and S. G. Kazarian and P. A. Salter and T. Welton},
  title = {Molecular states of water in room temperature ionic liquids},
  journal = {Phys. Chem. Chem. Phys.},
  year = {2001},
  volume = {3},
  pages = {5192-5200},
  owner = {Brehministrator},
  timestamp = {2011.12.11}
}
@ARTICLE{welton20013,
  author = {L. Cammarata and S. G. Kazarian and P. A. Salter and T. Welton},
  title = {Molecular states of water in room temperature ionic liquids},
  journal = {Phys. Chem. Chem. Phys.},
  year = {2001},
  volume = {3},
  pages = {5192-5200},
  owner = {Brehministrator},
  timestamp = {2011.12.11}
}
}
\end{filecontents}

\usepackage[square,sort&compress,super,comma]{natbib} %%Comment on first run

\usepackage[labeled,resetlabels]{multibib}

\newcites{O}{Own Publications}

\makeatletter
\AtBeginDocument{\@ifpackageloaded{natbib}{%
\expandafter\DeclareRobustCommand\csname cite\@suffix\endcsname
    {\begingroup\let\NAT@ctype\z@\NAT@partrue\NAT@swatrue
      \@ifstar{\NAT@fulltrue\NAT@cites}{\NAT@fullfalse\csname NAT@cites\@suffix\endcsname}}
\expandafter\newcommand\csname NAT@cites\@suffix\endcsname{\@ifnextchar [{\csname NAT@@citetp\@suffix\endcsname}{%
     \ifNAT@numbers\else
     \NAT@swafalse
     \fi
    \csname NAT@@citetp\@suffix\endcsname[]}}
\expandafter\newcommand\csname NAT@citetp\@suffix\endcsname{\@ifnextchar[{\csname NAT@@citetp\@suffix\endcsname}{\csname NAT@@citetp\@suffix\endcsname[]}}
\expandafter\newcommand\csname NAT@@citetp\@suffix\endcsname{}
\expandafter\def\csname NAT@@citetp\@suffix\endcsname[#1]{\@ifnextchar[{\csname @citex\@suffix\endcsname[#1]}{\csname @citex\@suffix\endcsname[][#1]}}
\expandafter\newcommand\csname NAT@set@cites\@suffix\endcsname{%
  \ifNAT@numbers
    \ifNAT@super \let\@cite\NAT@citesuper
       \def\NAT@mbox##1{\unskip\nobreak\textsuperscript{##1}}%
       \let\citeyearpar=\citeyear
       \let\NAT@space\relax
       \def\NAT@super@kern{\kern\p@}%
    \else
       \let\NAT@mbox=\mbox
       \let\@cite\NAT@citenum
       \let\NAT@space\NAT@spacechar
       \let\NAT@super@kern\relax
    \fi
    \expandafter\let\csname @citex\@suffix\expandafter\endcsname\csname NAT@citexnum\@suffix\endcsname
    \let\@biblabel\NAT@biblabelnum
    \let\@bibsetup\NAT@bibsetnum
    \renewcommand\NAT@idxtxt{\NAT@name\NAT@spacechar\NAT@open\NAT@num\NAT@close}%
    \def\natexlab##1{}%
    \def\NAT@penalty{\penalty\@m}%
  \else
    \let\@cite\NAT@cite
    \let\@citex\NAT@citex
    \let\@biblabel\NAT@biblabel
    \let\@bibsetup\NAT@bibsetup
    \let\NAT@space\NAT@spacechar
    \let\NAT@penalty\@empty
    \renewcommand\NAT@idxtxt{\NAT@name\NAT@spacechar\NAT@open\NAT@date\NAT@close}%
    \def\natexlab##1{##1}%
  \fi}
\expandafter\newcommand\csname NAT@sep\@suffix\endcsname{,\@suffix}
\expandafter\def\csname NAT@separator\@suffix\endcsname{\csname NAT@sep\@suffix\endcsname\NAT@penalty}%
\expandafter\def\csname NAT@def@citea\@suffix\endcsname{\def\@citea{\csname NAT@separator\@suffix\endcsname\NAT@space}}%
\expandafter\def\csname NAT@def@citea@space\@suffix\endcsname{\def\@citea{\csname NAT@separator\@suffix\endcsname\NAT@spacechar}}%
\expandafter\def\csname NAT@def@citea@close\@suffix\endcsname{\def\@citea{\NAT@@close\csname NAT@separator\@suffix\endcsname\NAT@space}}%
\expandafter\def\csname NAT@def@citea@box\@suffix\endcsname{\def\@citea{\NAT@mbox{\NAT@@close}\csname NAT@separator\@suffix\endcsname\NAT@spacechar}}%
\expandafter\def\csname NAT@citexnum\@suffix\endcsname[#1][#2]#3{%
  \NAT@reset@parser
  \NAT@sort@cites{#3}%
  \NAT@reset@citea
  \@cite{\def\NAT@num{-1}\let\NAT@last@yr\relax\let\NAT@nm\@empty
    \@for\@citeb:=\NAT@cite@list\do
    {\@safe@activestrue
     \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
     \@safe@activesfalse
     \@ifundefined{b@\@citeb\@extra@b@citeb}{%
       {\reset@font\bfseries?}
        \NAT@citeundefined\PackageWarning{natbib}%
       {Citation `\@citeb' on page \thepage \space undefined}}%
     {\let\NAT@last@num\NAT@num\let\NAT@last@nm\NAT@nm
      \NAT@parse{\@citeb}%
      \ifNAT@longnames\@ifundefined{bv@\@citeb\@extra@b@citeb}{%
        \let\NAT@name=\NAT@all@names
        \global\@namedef{bv@\@citeb\@extra@b@citeb}{}}{}%
      \fi
      \ifNAT@full\let\NAT@nm\NAT@all@names\else
        \let\NAT@nm\NAT@name\fi
      \ifNAT@swa
       \@ifnum{\NAT@ctype>\@ne}{%
        \@citea
        \NAT@hyper@{\@ifnum{\NAT@ctype=\tw@}{\NAT@test{\NAT@ctype}}{\NAT@alias}}%
       }{%
        \@ifnum{\NAT@cmprs>\z@}{%
         \NAT@ifcat@num\NAT@num
          {\let\NAT@nm=\NAT@num}%
          {\def\NAT@nm{-2}}%
         \NAT@ifcat@num\NAT@last@num
          {\@tempcnta=\NAT@last@num\relax}%
          {\@suffix\@tempcnta\m@ne}%
         \@ifnum{\NAT@nm=\@tempcnta}{%
          \@ifnum{\NAT@merge>\@ne}{}{\NAT@last@yr@mbox}%
         }{%
           \advance\@tempcnta by\@ne
           \@ifnum{\NAT@nm=\@tempcnta}{%
             \ifx\NAT@last@yr\relax
               \def@NAT@last@yr{\@citea}%
             \else
               \def@NAT@last@yr{--\NAT@penalty\@suffix}%
             \fi
           }{%
             \NAT@last@yr@mbox
           }%
         }%
        }{%
         \@tempswatrue
         \@ifnum{\NAT@merge>\@ne}{\@ifnum{\NAT@last@num=\NAT@num\relax}{\@tempswafalse}{}}{}%
         \if@tempswa\NAT@citea@mbox\fi
        }%
       }%
       \csname NAT@def@citea\@suffix\endcsname
      \else
        \ifcase\NAT@ctype
          \ifx\NAT@last@nm\NAT@nm \NAT@yrsep\NAT@penalty\NAT@space\else
            \@citea \NAT@test{\@ne}\NAT@spacechar\NAT@mbox{\NAT@super@kern\NAT@@open}%
          \fi
          \if*#1*\else#1\NAT@spacechar\fi
          \NAT@mbox{\NAT@hyper@{{\citenumfont{\NAT@num}}}}%
          \csname NAT@def@citea@box\@suffix\endcsname
        \or
          \csname NAT@hyper@citea@space\@suffix\endcsname{\NAT@test{\NAT@ctype}}%
        \or
          \csname NAT@hyper@citea@space\@suffix\endcsname{\NAT@test{\NAT@ctype}}%
        \or
          \csname NAT@hyper@citea@space\@suffix\endcsname\NAT@alias
        \fi
      \fi
     }%
    }%
      \@ifnum{\NAT@cmprs>\z@}{\NAT@last@yr}{}%
      \ifNAT@swa\else
        \@ifnum{\NAT@ctype=\z@}{%
          \if*#2*\else\NAT@cmt#2\fi
        }{}%
        \NAT@mbox{\NAT@@close}%
      \fi
  }{#1}{#2}%
}%
\csname NAT@set@cites\@suffix\endcsname
}{}
\def\mycite{\csname cite\@suffix\endcsname}
}%
\makeatother

\begin{document}
\chapter{Introduction}

Citing my own literature\mycite{travis} and\mycite{travis,travis3} and\mycite[p.~1]{travis,travis3,travis2,travis1} and\mycite{travis,travis3,travis1}
Citing other people's literature\cite{welton2001} and\cite{welton2001,welton20013} and\cite[p.~1]{welton2001,welton20013,welton20012,welton20011} and\cite{welton2001,welton20013,welton20011}.

\appendix
\bibliographystyle{plain}
\bibliographystyleO{plain}
\bibliography{main}
\bibliographyO{main}

\end{document}

\makeatletter和之间定义的宏\makeatother取自natbib包。

输出将如下所示: 文本引用 其他人的文学作品 自己的文学作品

答案2

这是一个使用 的快速破解方法natbib\citenumfont但这意味着每个人\newcite都需要自己的补丁线。

\usepackage{xparse}
\let\oriCiteO\citeO

%% The O{} in this re-definition means "an optional argument
%% with an empty default value". It is not related to the
%% "O" prefix in the OP's example. 
\RenewDocumentCommand{\citeO}{O{} O{} m}{%
  %% The "O" here *is* the prefix as required by the OP's example
  \renewcommand{\citenumfont}[1]{O##1}%  
  \oriCiteO[#1][#2]{#3}%
  \renewcommand{\citenumfont}[1]{##1}%
}

我不完全确定这是否会破坏任何其他natbib行为,因此请小心尝试!

相关内容