Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a problem with LyX and citation. I would like to use the option Natbib : Author-Year to display the citation like "(Gebel et al., 2009)" but I keep getting the error author-year not compatible with natbib package. I am using a custom ".bst" file. It works fine if I just want to show numbers as "[1]"

Can anyone help me solve this problem ? Would it work better with TeXmaker ?

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

The problem is that author-year in natbib requires to have bibitems with the following form:

\bibitem[Short(year)Long]{citekey} ...

Where Short is the short list of authors (e.g., Gebel et al in your case) and Long is the full list of authors. So the solution is to change the .bst. You can try to see if the bst file you use has a function output.bibitem, check that it is called in FUNCTION{book}, FUNCTION{article} and for the other BibTeX entry types, and then replace the output.bibitem function with:

FUNCTION {output.bibitem}
{ newline$
  "\bibitem[{" write$
  label write$
  ")" make.full.names duplicate$ short.list =
     { pop$ }
     { * }
   if$
  "}]{" * write$
  cite$ write$
  "}" write$
  newline$
  ""
  before.all 'output.state :=
}

Otherwise, you since in a previous question Make volume bold in custom bibliography style .bst you wrote you created your own bst using custom-bib. You can create it again specifying the right options for natbib and author-year.

share|improve this answer
    
I found the bibitem function and edited it but now I have a new error "Paragraph ended before Ibibitem was complete." –  esmitex Nov 13 '12 at 21:10
    
@esmitex Not knowing what the rest of the bst file is a bit hard. Can you give an example of a \bibitem produced by BibTeX? (look in the .bbl file) –  Guido Nov 14 '12 at 0:14
    
I created a new bst file using "author-year" but now I have to do it again, I have a colon instead of a comma after the volume. I don't know how to edit that in the bst file. This is driving me crazy. –  esmitex Nov 14 '12 at 11:22
add comment

For who might still be interested.. I had the same problem as esmitex with Guido's answer. I had to modify it, so I ended up with the following solution:

Replace FUNCTION {output.bibitem} with

    FUNCTION {output.bibitem}
    { newline$
      "\bibitem[{" write$ make.short.names "}(" * year empty$ {skip$} { year * } if$ "){" * make.full.names * "}]{" * write$
     cite$ write$
     "}" write$
     newline$
     ""
     before.all 'output.state :=
}

I also had to precede the above code with the following additional functions:

    FUNCTION {format.full.names}
{'s :=
 "" 't :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr
      "{vv~}{ll}" format.name$
      't :=
      nameptr #1 >
        {
          namesleft #1 >
            { ", " * t * }
            {
              s nameptr "{ll}" format.name$ duplicate$ "others" =
                { 't := }
                { pop$ }
              if$
              t "others" =
                {
                  " " * bbl.etal emphasize *
                }
                {
                  "\&"
                  space.word * t *
                }
              if$
            }
          if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

FUNCTION {format.short.names}
{'s := 
  s num.names$ 'numnames :=
    numnames #1 >  
    { s #1 "{vv~}{ll}" format.name$ " " * bbl.etal emphasize * } 
    { numnames #1 =  { s #1 "{vv~}{ll}" format.name$ } { "NN" } if$ }
    if$
 }

FUNCTION {author.editor.key.full}
{ author empty$
    { editor empty$
        { key empty$
            { cite$ #1 #3 substring$ }
            'key
          if$
        }
        { editor format.full.names }
      if$
    }
    { author format.full.names }
  if$
}

FUNCTION {author.editor.key.short}
{ author empty$
    { editor empty$
        { key empty$
            { cite$ #1 #3 substring$ }
            'key
          if$
        }
        { editor format.short.names }
      if$
    }
    { author format.short.names }
  if$
}

FUNCTION {author.key.full}
{ author empty$
    { key empty$
         { cite$ #1 #3 substring$ }
          'key
      if$
    }
    { author format.full.names }
  if$
}

FUNCTION {author.key.short}
{ author empty$
    { key empty$
         { cite$ #1 #3 substring$ }
          'key
      if$
    }
    { author format.short.names }
  if$
}

FUNCTION {editor.key.full}
{ editor empty$
    { key empty$
         { cite$ #1 #3 substring$ }
          'key
      if$
    }
    { editor format.full.names }
  if$
}

FUNCTION {editor.key.short}
{ editor empty$
    { key empty$
         { cite$ #1 #3 substring$ }
          'key
      if$
    }
    { editor format.short.names }
  if$
}

FUNCTION {make.full.names}
{ type$ "book" =
  type$ "inbook" =
  or
    'author.editor.key.full
    { type$ "proceedings" =
        'editor.key.full
        'author.key.full
      if$
    }
  if$
}

FUNCTION {make.short.names}
{ type$ "book" =
  type$ "inbook" =
  or
    'author.editor.key.short
    { type$ "proceedings" =
        'editor.key.short
        'author.key.short
      if$
    }
  if$
}

If you already have any of these functions defined, you might want to keep them or replace them.
The function make.short.names defines the author list to be displayed inline in text when using \citeauthor or \citet. This version shows John et al. [11] or just John [11] in case of a single author.

share|improve this answer
    
Welcome to TeX.sx! –  texenthusiast Apr 26 '13 at 14:34
add comment

You may need to add " extra.label *" to "year *" in FUNCTION {output.bibitem} if you use the author-year mode and get

FUNCTION {output.bibitem}
{ newline$
  "\bibitem[{" write$ make.short.names "}(" * year empty$ {skip$} { year * extra.label * } if$ "){" * make.full.names * "}]{" * write$
 cite$ write$
 "}" write$
 newline$
 ""
 before.all 'output.state :=
}

in case that the citations is the same author and the same year e.g. Titman et al. (2010a,b). Otherwise, it look like Titman et al. (2010,?)

share|improve this answer
    
Welcome to TeX.SX! You may have a look on our starter guide. –  texenthusiast May 11 '13 at 2:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.