natbib author-year citation - fallback to editor possible when author missing? - latex

I'm having an issue with the natbib package. When the bib entry is missing an author I want to display the editor instead. However the second citation just takes the first three letters of the bib-key instead of the author.
Sample tex:
\documentclass{article}
\usepackage[authoryear,round]{natbib}
\bibliographystyle{abbrvnat}
\begin{document}
I need this \citet[S.~2]{Test1} to look like Surname (2022, S. 2).
and this \citep{Test1} like (Surname, 2022)
But also this \citet[S.~2]{Test2} to look like Editor (2022, S. 2).
and this \citep{Test2} like (Editor, 2022)
but it just prints (Tes, 2022)
\bibliography{refs}
\end{document}
The bib file could look like this:
#misc{Test1,
author={Surname, Name}
title = {Sometitle},
year = {2022}
}
#misc{Test2,
title = {Someothertitle},
editor={{Editor, Name}}
year = {2022}
}
Can anyone help with this? I'd also switch to another package than natbib, since I'm still early on the project. But at a first glance it seemed to meet my needs quite well.
Also I don't really know what I'm doing, it's been a while since I've been working with Latex. So sorry for that in advance!

Although the user posting the initial question here was able to switch to biblatex (which is good), not everyone has that freedom for some publishing venues. If this applies to you (that you have to stay with natbib and plainnat, you may be interested in a TeX Stack Exchange post that provides a description of how you can customize your BST file to modify your sorting, including configuring misc to sort by author then editor.
EDIT: A down-check for this answer being unhelpful inspired me to be more specific than my original answer above so the additional details specific to this case are below.
Since your provided code has natbib using abbrvnat (not plainnat as in the linked example that I initially provided), you can find abbrvnat.bst in your TeX repository and place a local copy with a different name (like abbrvnat-copy.bst) into your working directory. There are two steps in modifying your local copy of abbrvnat-copy.bst: First, update the calc.short.authors function to also look for an editor in the misc type. Second, have your TeX file use your newly customized BST file.
Note: I am using the 2007 version of abbrvnat.bst, which is the latest as of this posting in 2022.
In your local copy of abbrvnat-copy.bst, search for the calc.short.authors function. We'll need to add two lines of code to it:
type$ "misc" =
or
I show the new version here:
FUNCTION {calc.short.authors}
{ type$ "book" =
type$ "inbook" =
or
type$ "misc" =
or
'author.editor.key.label
{ type$ "proceedings" =
'editor.key.organization.label
{ type$ "manual" =
'author.key.organization.label
'author.key.label
if$
}
if$
}
if$
'short.list :=
}
In your TeX file, you'll need to change this line to account for your newly customized file: \bibliographystyle{abbrvnat-copy}. Other than this one line in your main .tex file and adding a couple missing commas in your .bib file, I did not change any code in your MWE.
Here's the output:
Other aspects that you may want to address (that you didn't ask about) include getting the editor(s) to appear in the bibliography (references list) for misc entries and sorting by editor for misc entries. The example that I provided here and the example provided in the other post that I previously linked should both be helpful in customizing your BST file to achieve your desired bibliography style.

Related

Use exams2pdf or a modified solution.tex template to print solutions not another answer list

I am trying to create a solution pdf for an exam but all I need for it is a simple marked box and not the answer list that follows. For example, I just want the first page from the following compilation and nothing else.
library(exams)
exams2pdf(list(
"boxplots",
c("tstat", "ttest", "confint"),
c("regression", "anova"),
"scatterplot",
"relfreq"
), template = "solution"
)
I don't have a strong grasp of the Latex language so when I try removing for example
\newenvironment{answerlist}{\renewcommand{\labelenumi}{(\alph{enumi})}\begin{enumerate}}{\end{enumerate}}
or
% \exinput{exercises}
It doesn't compile and just complains about a missing item etc
Which part of solution.tex can I remove that retains just the first page?
Solution: You need to delete all of the following lines from your copy of solution.tex:
\newpage
\begin{enumerate}
%% \exinput{exercises}
\end{enumerate}
Details: This LaTeX code starts a new page and includes an enumerated list for the individual exercises. The \exinput{exercises} is replaced with each of the {question} (and optionally {solution}) environments which then produces an \item for each question. So if you just remove the \exinput line, LaTeX complains about missing items because the {enumerate} list is empty.
Documentation: More details for exams2pdf() and its LaTeX templates can be found in vignette("exams", package = "exams").

Automatic bibliography .bib file content generator

I am looking for an online solution, where I enter a book, article, etc., then it searches and finds it, and provides me with the most complete reference that I can include in my .bib file for my article.
For example, let's say I enter the name of an article like:
"Verification of sequential and concurrent programs",
and then it provides me with exactly what I will need to include in my .bib file as follows:
{
AptOlderog91,
author = {K. R. Apt and E.-R. Olderog},
title = {Verification of sequential and concurrent programs},
publisher = {Springer-Verlag},
year = 1991
}
Thanks a lot.
Here is what I do,
Search on scholar.google.com, once you find the right artifact,
look for "cite" link below, on selecting that, you get bib item in 3 default formats (MLA, APA and Chicago).
In the pop up window, there is an option "import to bibtex" that returns a bib source which can be used in the bib file.
Beware, however, some of the bib entries are incomplete/incorrect. For that, there is no other option than going to the source (IEEE, ACM, Elsevier etc) and retrieving the bib.
Hope it helps!

How to set title of TOC in Latex hyperref package

The latex hyperref package makes a really nice, linked table of contents, named according to section name. However, the top level category is by default, the file name. It seems I should be able to change this to the actual title, but I'm not finding any information on how.
Are you sure this is not a 'feature' of your PDF reader? It might try to use the PDFs title (unset by default), which you can set like this:
\hypersetup{
pdftitle = {The title},
pdfauthor = {You}
}
You might also want to check out the TeX StackExchange.

How do I include bibliography (.bbl file) in latex?

I am trying to write my CV, and I want to include a list of publications. To do that, I want to include a .bbl file directly (which was generated using bibtex).
So, in my CV I do
\input{publications.bbl}
This seems to work fine, except for one thing: an asterisk (*) appears on the left to the lists of publications! I don't know where this * comes from and why it appears there. Any idea how I can remove this *?
Thanks.
The thebibliography environment is already included in .bbl files so processing the file with
\input{publications.bbl} should be enough.
The format of the publication list depends on the bibliography style used by BibTex with
the \bibliographystyle command. For more information about available styles take a look at:
https://en.wikibooks.org/wiki/LaTeX/Bibliography_Management#Bibliography_styles
Did you use \nocite{*}? putting \nocite{*} before \bibliographystyle can cause the asterisk to appear.
I had the same issue, this works for me:
\bibliographystyle{IEEEtran}
\nocite{*}
\bibliography{my_bib_file}
I'd have to see some code. but first you do
\begin{thebibliography}{}
\input{publications.bbl}
\end{thebibliography}
Is that what you have? In fact, try this and see if you still get the "error":
\begin{thebibliography}{}
\bibitem{ano05}
A. Nonymous et al.\ 2005, \aap 123, 456\\[-20pt]
\bibitem{oe04}
A.N. Other \& S.O.M. Ebody 2004, \pasp 123, 456\\[-20pt]
\end{thebibliography}

Why is my references section of my LaTeX document empty, and how can I change its name?

In my document I have to specify the references I'm using. I used this code in the preamble:
\bibliographystyle{abbrv}
\bibliography{main}
Where main is the .bib file from the same folder, and contains, for example:
#string{jgr = "J.~Geophys.~Res."}
#MISC{primes,
author = "Charles Louis Xavier Joseph de la Vall{\'e}e Poussin",
note = "A strong form of the prime number theorem, 19th century",
year = 1879
}
#INBOOK{chicago,
title = "The Chicago Manual of Style",
publisher = "University of Chicago Press",
edition = "Thirteenth",
year = 1982,
pages = "400--401",
key = "Chicago"
}
But at the References section nothing is displayed, when generating the .pdf. I have rebuild the .bib and the .tex file, without any changes.
And how can I change that default text, from References to Bibliografie or something else?
I think that you need to put \nocite{*} somewhere within your document -- putting it inside the preamble should cause LaTeX to throw a "cannot be used in preamble" error. If they're still not appearing within your document, is LaTeX giving you any errors and, if so, can you tell us what they are?
To change the default text from "References" to whatever you would like, use the following command:
\renewcommand{\bibsection}{\section*{insert_title_here}}
Note that the asterisk after \section means that it won't be associated with a number. If you want it to be associated with a number, just remove the asterisk.
You have to actually \cite references for them to be included in the bibliography. If instead you want everything in the bib file in the bibliography put \nocite{*} somewhere in the preamble. Read here what this actually does.
You have to either \cite or \nocite a reference for it to appear in your References section. I'm not sure how to change the name of the bibliography. I would start by looking at the LaTeX WikiBook. It looks like there is a tool make makebst that produces a custom bibliography style - take a look at the custom-bib package and this document for more details.

Resources