自动将参考书目中的作者姓名加粗

自动将参考书目中的作者姓名加粗

我想在使用 生成的参考书目中自动将单个作者的条目加粗natbib。该bio.tex文件如下所示(所有内容均已虚构):

\documentclass{bio}

\updatebio{%
    name={Bob Digital},
    title={Prof.},
    dept={Department of Antics},
    uni={University of Fable},
    email={[email protected]},
    tel={(123) 456-7890},
    web={https://uof.edu/bobdigital}
}

\begin{document}

    \Products

\end{document}

\Products命令是主要感兴趣的命令,它会自动从 BibTeX 文件生成参考书目。该bio.cls文件如下所示:

\NeedsTeXFormat{LaTeX2e}

\ProvidesClass{bio}[2018/01/11 Stay classy.]

%% Declare article options
\DeclareOption{10pt}{\OptionNotUsed}
\DeclareOption{12pt}{\OptionNotUsed}
\DeclareOption{a4paper}{\OptionNotUsed}
\DeclareOption{a5paper}{\OptionNotUsed}
\DeclareOption{b5paper}{\OptionNotUsed}
\DeclareOption{executivepaper}{\OptionNotUsed}
\DeclareOption{legalpaper}{\OptionNotUsed}
\DeclareOption{draft}{\OptionNotUsed}
\DeclareOption{twocolumn}{\OptionNotUsed}
\DeclareOption{fleqn}{\OptionNotUsed}
\DeclareOption{leqno}{\OptionNotUsed}
\DeclareOption{landscape}{\OptionNotUsed}
\DeclareOption{titlepage}{\OptionNotUsed}
\DeclareOption{openright}{\OptionNotUsed}
\DeclareOption{openany}{\OptionNotUsed}

\DeclareOption{11pt}{
    \PassOptionsToClass{\CurrentOption}{article}
}

\DeclareOption{letterpaper}{
    \PassOptionsToClass{\CurrentOption}{article}
}

\DeclareOption*{%
    \ClassWarning{nsf}{Unknown option '\CurrentOption'}
}

\ExecuteOptions{11pt, letterpaper}

\ProcessOptions{\relax}

\LoadClassWithOptions{article}

%% Load packages
\RequirePackage[margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage{times}
\RequirePackage{calc}
\RequirePackage{lastpage}
\RequirePackage{fancyhdr}
\RequirePackage{xspace}
\RequirePackage[shortlabels]{enumitem}
\RequirePackage{graphicx}
\RequirePackage{varioref}
\RequirePackage[colorlinks=true,urlcolor=,pdfpagelabels=true,hypertexnames=true,plainpages=false,naturalnames=true,]{hyperref}
\RequirePackage{doi}
\RequirePackage{xifthen}
\RequirePackage[numbers]{natbib}
\RequirePackage{xparse}

%% Body of the class, most of the declarations appear here
\urlstyle{rm}

\renewcommand\thesection{(\alph{section})}
\renewcommand\thesubsection{(\alph{subsection})}

%\newcommand{\pageoflastpage}{Page {\thepage} of \pageref*{LastPage}}
%\newcommand{\pageoflastpage}{{\thepage} of \pageref*{LastPage}}
\newcommand{\pageoflastpage}{}

% Redefine the plain pagestyle for the title page
\makeatletter
\let\oldps@plain\ps@plain
\renewcommand{\ps@plain}{\oldps@plain%
\renewcommand{\@evenfoot}{\hfil\pageoflastpage\hfil}%
\renewcommand{\@oddfoot}{\@evenfoot}}
\makeatother

% Use fancy for non-title pages
\fancyhead{}
\fancyfoot{}
\cfoot{\pageoflastpage}
\pagestyle{fancy}

\newcommand{\ie}{i.e.,\xspace}
\newcommand{\eg}{e.g.,\xspace}

% Key-value property store for author
\ExplSyntaxOn

\NewDocumentCommand{\definename}{m}
 {
  \name_define:n { #1 }
 }

\NewDocumentCommand{\makebold}{m}
 {
  \name_makebold:n { #1 }
 }

\NewDocumentCommand{\updatebio}{+m}
 {
  \keys_set:nn {bio} {#1}
  \name_define:x { \prop_item:Nn \l_name_bio_prop { name } }
 }

\cs_new:Npn \getvalue#1
 {
  \prop_item:Nn \l_name_bio_prop {#1}
 }

\prop_new:N \l_name_bio_prop

\keys_define:nn {bio} {%
    name  .code:n={ \prop_put:Nnn \l_name_bio_prop {name}  {#1} },
    title .code:n={ \prop_put:Nnn \l_name_bio_prop {title} {#1} },
    dept  .code:n={ \prop_put:Nnn \l_name_bio_prop {dept}  {#1} },
    uni   .code:n={ \prop_put:Nnn \l_name_bio_prop {uni}   {#1} },
    email .code:n={ \prop_put:Nnn \l_name_bio_prop {email} {#1} },
    tel   .code:n={ \prop_put:Nnn \l_name_bio_prop {tel}   {#1} },
    web   .code:n={ \prop_put:Nnn \l_name_bio_prop {web}   {#1} },
}

\tl_new:N \l_name_full_tl
\tl_new:N \l_name_first_tl
\tl_new:N \l_name_last_tl
\tl_new:N \l_name_initials_tl
\tl_new:N \l__name_input_tl

\cs_new_protected:Nn \name_define:n
 {
  \tl_set:Nn \l_name_full_tl { #1 }
  \tl_set_eq:NN \l_name_first_tl \l_name_full_tl
  \tl_set_eq:NN \l_name_last_tl \l_name_full_tl
  \regex_replace_once:nnN { (.*)\s[^\s]*\Z } { \1 } \l_name_first_tl
  \regex_replace_once:nnN { .*\s([^\s]*)\Z } { \1 } \l_name_last_tl
  \tl_set_eq:NN \l_name_initials_tl \l_name_first_tl
  \regex_replace_all:nnN { ([[:alpha:]])[[:alpha:]]+ } { \1. } \l_name_initials_tl
 }

\cs_generate_variant:Nn \name_define:n { x }

\cs_new_protected:Nn \name_makebold:n
 {
  \tl_set:Nn \l__name_input_tl { #1 }
  % full name
  \regex_replace_all:nnN
   {
    (
     \u{l_name_full_tl}                              % name surname
     |
     \u{l_name_initials_tl} \s \u{l_name_last_tl}    % initials surname
     |
     \u{l_name_last_tl} , \s \u{l_name_first_tl}     % surname, name
     |
     \u{l_name_last_tl} , \s \u{l_name_initials_tl}  % surname, initials
    )
   }
   { \c{textbf} \cB\{ \1 \cE\} }
   \l__name_input_tl
  % print
  \tl_use:N \l__name_input_tl
 }

\ExplSyntaxOff

% Default variable values
%%%%%%%%%%%%%%%%%%%%%%%% FOR MODIFICATION %%%%%%%%%%%%%%%%%%%%%%%%
\updatebio{%
    name={Billy Zane}, 
    title={Dr.},
    dept={Department of Fiction},
    uni={University of Utopia},
    email={[email protected]},
    tel={(098) 765-4321},
    web={https://uo.edu/billyzane}
}
%%%%%%%%%%%%%%%%%%%%%%%% FOR MODIFICATION %%%%%%%%%%%%%%%%%%%%%%%%

% Modify hyperref PDF metadata settings
\hypersetup{%
    pdfsubject={A Biographical Sketch of \getvalue{title}.~\getvalue{name}},
    pdfauthor={\getvalue{title}.~\getvalue{name}},
    pdftitle={A Biographical Sketch of \getvalue{title}.~\getvalue{name}},
    pdfkeywords={}
}

\title{%
    \vspace{-2\baselineskip}
    \normalsize
    Biographical Sketch\\
    {\large\textbf{\getvalue{title}.~\getvalue{name}}}\\
    \vspace{0.5\baselineskip}
    \hrule
    \vspace{0.5\baselineskip}
    \getvalue{dept}, \getvalue{uni},
    e-mail: \href{mailto:\getvalue{email}}{\getvalue{email}},
    tel: \getvalue{tel},
    website: \url{\getvalue{web}}
    \vspace{-1.5ex}
}
\author{}
\date{}

\renewcommand{\refname}{}

\newcommand{\Products}{%
    \subsection{Products}
    \vspace{-1cm}
    \nocite{*}
    \bibliographystyle{bio}
    \bibliography{bio}
}

\newcommand{\product}[1]{\item{#1}}

% Change bibliography number
\renewcommand{\bibnumfmt}[1]{\textbf{{#1}.}}

% Bold font author by name
\let\originalbibitem\bibitem
\def\bibitem#1#2\par{%
    \noexpandarg%
    \originalbibitem{#1}%
    \makebold{#2}%
}

%% Macros to run after \begin{document}
\AtBeginDocument{%
    \maketitle
    \vspace{-4\baselineskip}
}

\endinput

最后,一个示例references.bib文件:

@article{Digital1968,
  author = {Bob Digital and Mister Roboto},
  doi = {https://doi.org/10.1016/0022-5193(68)90079-9},
  issn = {0022-5193},
  journal = {Journal of Theoretical Theory},
  number = {3},
  pages = {280--299},
  title = {{Some test title to use here just for fun}},
  url = {http://www.sciencedirect.com/science/article/pii/0022519368900799},
  volume = {18},
  year = {1968}
}

@article{Roboto1948,
  author = {Mister Roboto and Bob Digital},
  doi = {https://doi.org/10.1016/0022-5193(68)90079-9},
  issn = {002-52323},
  journal = {Utopiae},
  number = {2},
  pages = {1--19},
  title = {{Another title to use here just for fun!}},
  url = {http://www.sciencedirect.com/science/article/pii/0022519368900799},
  volume = {1},
  year = {1948}
}

我创建了一个自定义bio.bst文件,由于太大,无法在此分享。需要了解的是,它使用 AGU 格式,其中第一作者显示为LASTNAME, FI. MI.,后续作者显示为,FI. MI. LASTNAME后面跟着一个逗号以表示其他名称,其中FI == First InitialMI == Middle Initial。以下是相应的.bbl文件:

\begin{thebibliography}{10}

\bibitem{Digital1968}
Digital, B. and M.~Roboto.
\newblock {Some test title to use here just for fun}.
\newblock \emph{Journal of Theoretical Theory}, 18(3):280--299, 1968.
\newblock ISSN 022-5193
\newblock \doi{https://doi.org/10.1016/0022-5193(68)90079-9}.

\bibitem{Roboto1948}
Roboto, M. and B.~Digital.
\newblock {Another title to use here just for fun!}.
\newblock \emph{Utopiae}, 1(2):1--19, 1948.
\newblock ISSN 002-5232.
\newblock \doi{https://doi.org/10.1016/0022-5193(68)90079-9}.

\end{thebibliography}

在这个测试示例中,我希望Digital, B.B. Digital是粗体,无论它们在作者列表中的位置如何。我遇到的问题是,这种形式的引文FI. MI. LASTNAME没有被加粗。我相信这可能是由于间距的格式造成的......?

答案1

您可以立即从.bbl所使用的文件中看到~,这与空格不同。

只需将的定义更改\name_makebold:n

\cs_new_protected:Nn \name_makebold:n
 {
  \tl_set:Nn \l__name_input_tl { #1 }
  % full name
  \regex_replace_all:nnN
   {
    (
     \u{l_name_first_tl} (\s|\~) \u{l_name_last_tl}    % name surname
     |
     \u{l_name_initials_tl} (\s|\~) \u{l_name_last_tl} % initials surname
     |
     \u{l_name_last_tl} , (\s|\~) \u{l_name_first_tl}       % surname, name
     |
     \u{l_name_last_tl} , (\s|\~) \u{l_name_initials_tl}    % surname, initials
    )
   }
   { \c{textbf} \cB\{ \1 \cE\} }
   \l__name_input_tl
  % print
  \tl_use:N \l__name_input_tl
 }

删除\noexpandarg没有意义的(这是一个xstring命令)。

在此处输入图片描述

相关内容