如何使用 BibTeX 强调一些作者姓名?

如何使用 BibTeX 强调一些作者姓名?

我想创建突出显示某些作者(例如,粗体)的参考书目。有几种类似的解决方案,但它们通常假设始终突出显示的是同一作者:

我希望有一个 BibTeX 解决方案这些线这样我就可以在文件中指出.bib哪些作者应该被突出显示,例如,

author = {J. Doe and J. Smith and J. Quincy}
usera = {1,3}

我的目标是将其用于我的简历,并突出学生作者。

答案1

我的解决方案是通过破解书目风格来实现的,类似于@Katuyci 提出的,但更符合您的示例。

  1. 复制你的样式文件。我plain.bst在这里使用,但它也适用于任何其他样式。
  2. 插入useraENTRY字段:

    ENTRY {
      ...
      year
      usera      %% added
    }
    
  3. 将以下函数添加到您的样式文件中,在从中获取多个 str.to.int` 函数之后FUNCTION {not}(或在获取FUNCTION {or} if using natbib). The多个str.to.int` 函数之后)and驯服野兽,修复了一个小错误。

    INTEGERS {length i a b}
    STRINGS {chr}
    
    FUNCTION {mult}
    {'a :=                  %% we store the first value
     'b :=                  %% we store the second value
     b #0 <                 %% We remember the sign of b, and
        {#-1 #0 b - 'b :=} %% then consider its absolute value.
        {#1}               %%
    if$                    %%
    #0                     %% Put 0 on the stack.
    {b #0 >}               %% While b is strictly positive,
    {                      %% we add a to the value on the stack
        a +                 %% and decrement b.
        b #1 - 'b :=        %%
    }                      %%
    while$                 %%
    swap$                  %% Last, we take the opposite
        'skip$              %% if b was negative.
        {#0 swap$ -}        %%
    if$                    %%
    }
    
    FUNCTION {chr.to.value}        %% The ASCII code of a character
    {
    chr.to.int$ #48 -            %% ASCII value of "0" -> 48
    duplicate$ duplicate$        %%                "1" -> 49
    #0 < swap$ #9 > or           %%                   ...
    {                            %%                "9" -> 57
        #48 + int.to.chr$
        " is not a number..." *
        warning$                %% Return 0 if it is not a number
        #0                      %% here we removed the pop$ before #0,
                                %% opposed to what is written in Tame The Beast
        }
    {}
    if$
    }
    FUNCTION {str.to.int.aux}      %% The auxiliary function
    {
    {duplicate$ empty$ not}      %% While the string is not empty
        {                         %% consider its first char
        swap$ #10 mult 'a :=    %% and ‘‘add’’ it at the end of
        duplicate$ #1 #1 substring$   %% the result.
        chr.to.value a +
        swap$
        #2 global.max$ substring$
        }
    while$
    pop$
    }
    FUNCTION {str.to.int}
    {                              %% Handling negative values
    duplicate$ #1 #1 substring$ "-" =
        {#1 swap$ #2 global.max$ substring$}  %% the first integer here indicates whether we have to
                                            %% multiply by -1, i.e., it is consumed by the following if$
        {#0 swap$}
    if$
                                %% Initialization, and then
    #0 swap$ str.to.int.aux      %% call to the aux. funtion
    swap$
        {#0 swap$ -}              %% And handle the sign.
        {}
    if$
    }
    
    %% takes a string literal from the stack and returns
    %% the position of the first " " (space) in the string;
    %% returns -1 if no space is contained
    FUNCTION {first.space}{
    duplicate$ text.length$ #1 + 'length :=
    #1 'i :=
    { 
        i length <
        { duplicate$ i #1 substring$ 'chr :=
          chr " " =
            { #0 }
            { #1 }
          if$
        }
        {
          #-1
        }
        if$
    }
    { #1 i + 'i := }
    while$
    i length =
        {
          #-1 'i :=
        }
        {}
    if$
    %% finally take the string from the stack
    pop$
    %% space position we identified
    i
    }
    
    %% takes a string literal from the stack,
    %% and returns the first number in the string, and the remaining string;
    %% returns -1 and the original string if no number is found
    STRINGS { tmpstr }
    FUNCTION {chop.number} {
    'tmpstr :=
    tmpstr first.space 'i :=
    i #0 >
        { tmpstr i #1 + global.max$ substring$ %% remaining string
          tmpstr #1 i #1 - substring$ str.to.int    %% number
          duplicate$ #0 =
            { pop$ #-1 }
            {}
          if$
        }
        { "" tmpstr str.to.int
          duplicate$ #0 =
            { pop$ #-1 }
            {}
          if$
        }
    if$
    }
    
  4. 现在找到FUNCTION {format.names}并放置

    INTEGERS { hlauthor hlauthorold }
    STRINGS { hlstr }
    

    在那之前。

  5. format.names必须修改。我标出了我添加的所有行。当您不使用时,您的函数可能看起来有点不同plain.bst,但非常相似。

    FUNCTION {format.names}
    { 
    's :=
    #1 'nameptr :=
    s num.names$ 'numnames :=
    numnames 'namesleft :=
    usera 'hlstr :=                                          %% added
    hlstr chop.number 'hlauthor := 'hlstr :=                 %% added
      { namesleft #0 > }
      { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
        nameptr hlauthor =                                   %% added
          {                                                  %% added
            "\hlauthor{" t * "}" * 't :=                     %% added
            hlauthor 'hlauthorold :=                         %% added
            hlstr chop.number 'hlauthor := 'hlstr :=         %% added
            hlauthor #0 >                                    %% added
              { hlauthor hlauthorold >                       %% added
                  {}                                         %% added
                  { "Highlighted authors not sorted for "    %% added
                    cite$ * ": " * hlauthorold int.to.str$ * %% added
                    " >= " * hlauthor int.to.str$ * warning$ %% added
                  }                                          %% added
                if$                                          %% added
              }                                              %% added
              {}                                             %% added
            if$                                              %% added
          }                                                  %% added
          {}                                                 %% added
        if$                                                  %% added
        nameptr #1 >
            { namesleft #1 >
                { ", " * t * }
                { numnames #2 >
                    { "," * }
                    'skip$
                if$
                t "others" =
                    { " et~al." * }
                    { " and " * t * }
                if$
                }
            if$
            }
            't
        if$
        nameptr #1 + 'nameptr :=
        namesleft #1 - 'namesleft :=
        }
    while$
    %% Sanity checks: hlstr should be empty,                 %% added
    %% and hlauthor should be -1                             %% added
    hlstr "" =                                               %% added
      {}                                                     %% added
      { "There are remaining authors to be highlighted for " %% added
        cite$ * ": " * hlstr * warning$                      %% added
      }                                                      %% added
    if$                                                      %% added
    hlauthor #-1 =                                           %% added
      {}                                                     %% added
      { "Unable to highlight author number " hlauthor        %% added
        int.to.str$ * " for " * cite$ * warning$             %% added
      }                                                      %% added
    if$                                                      %% added
    }
    
  6. 最后,我们为突出显示作者提供一种默认样式,这里我们使用粗体。这将注入到函数中begin.bib

    FUNCTION {begin.bib}
    { preamble$ empty$
        'skip$
        { preamble$ write$ newline$ }
      if$
      "\begin{thebibliography}{"  longest.label  * "}" * write$ newline$
      "\providecommand*{\hlauthor}[1]{\textbf{#1}}" write$ newline$   %% added
    }
    

就这样!让我们测试一下:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{hltest.bib}
@book{a,
  author = {A. First and B. Second and C. Third and D. Forth and E. Fifth and F. Sixth and G. Seventh},
  usera = {1 3 5 4},
  title = {My book title},
  year = 2013,
  publisher = {Inhouse}
}

@book{b,
  author = {A. One and B. Two and C. Three},
  usera = {1 4},
  title = {My book title},
  year = 2013,
  publisher = {Inhouse}
}

@book{c,
  author = {A. Uno and B. Due and C. Tre},
  usera = {4 5},
  title = {My book title},
  year = 2013,
  publisher = {Inhouse}
}

@book{d,
  author = {A. Eins and B. Zwei and C. Drei},
  usera = { 2},
  title = {My book title},
  year = 2013,
  publisher = {Inhouse}
}
\end{filecontents}


\begin{document}
\nocite{*}

% \providecommand{\hlauthor}[1]{\emph{#1}} % if you want to change the style of emphasis
\bibliographystyle{hlplain}
\bibliography{hltest}
\end{document}

示例输出

请注意,需要强调的作者应按升序排列,例如

usera = {10 13 15}, OK
usera = {9 1 2},    NOT OK

用空格隔开。否则,您将收到与测试代码中一样的警告。

答案2

这是l3regex软件包的一个应用程序,结合了先前的想法

\begin{filecontents*}{\jobname.bib}
@article{a,
 author={Studenta A. and Foo B.},
 title={Title},
 journal={Journal},
 year={2012},
}
@article{b,
 author={Studentb A. and Studentc B.},
 title={Title},
 journal={Journal},
 year={2012},
}
@article{c,
 author={Foo B. and Baz  B.},
 title={Title},
 journal={Journal},
 year={2012},
}
\end{filecontents*}
\documentclass{article}

\usepackage{xparse,l3regex}
\ExplSyntaxOn
\regex_new:N \g_hl_students_regex
\seq_new:N \l_hl_students_seq
\tl_new:N \l_hl_data_tl
\NewDocumentCommand{\studentslist}{m}
 {
  \seq_set_split:Nnn \l_hl_students_seq { , } { #1 }
  \regex_gset:Nx \g_hl_students_regex
   { ( \seq_use:Nnnn \l_hl_students_seq { | } { | } { | } ) }
 }
\cs_generate_variant:Nn \regex_gset:Nn { Nx }

\cs_set_eq:NN \hl_bibitem:w \bibitem
\cs_set:Npn \bibitem #1#2\par
 {
  \hl_bibitem:w { #1 }
  \tl_set:Nn \l_hl_data_tl { #2 }
  \regex_replace_all:NnN \g_hl_students_regex { \c{emph}\cB\{ \1 \cE\} } \l_hl_data_tl
  \tl_use:N \l_hl_data_tl \par
 }
\ExplSyntaxOff

\studentslist{Studenta, Studentb, Studentc}

\begin{document}
abc
\nocite{*}

\bibliographystyle{plain}
\bibliography{\jobname}
\end{document}

像往常一样,filecontents*仅用于使示例自洽,可以使用任何.bib文件。

序言中给出了以逗号分隔的学生姓名列表。

在此处输入图片描述

答案3

也许你可以尝试以前的想法邮政。我会建议你对方法和做法进行一些调整。

而不是使用数字在里面用户a = { ...}字段也许您可以使用作者姓名您想突出显示的内容。我相信这会像插入排名一样简单。确保如果你使用全名或简称你也这样做乌塞拉

宣布乌塞拉ENTRY {... usera ...}之前创建一个新函数FUNCTION{format.names}如下:

FUNCTION {student.author}  
{
  usera empty$  
    { "" }  
    { usera nameptr STYLE format.name$ }  
    if$  
}

笔记改变以上风格与您当前的 .bst 文件使用的任何样式。您可以在 中找到并复制它FUNCTION{format.names}。应该类似于"{ff~}{vv~}{ll}{, jj}"

创建要突出显示的函数:

FUNCTION {highlight}  
{ duplicate$ empty$  
      { pop$ "" }  
      { "\emph{" swap$ * "}" * }  
   if$  
}

每当被解析的作者是你的学生作者时,调用此函数:

FUNCTION {highlight.if.student.author}  
{ duplicate$ purify$ student.author purify$ =  
    { highlight }  
    'skip$  
  if$  
}

highlight.if.student.author最后调用format.name$如下FUNCTION{format.names)方法:

FUNCTION{format.names}  
{...  
format.names$ highlight.if.student.author  
...  
}

相关内容