Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with author information using authblk #1158

Closed
aimundo opened this issue May 19, 2021 · 4 comments
Closed

Issue with author information using authblk #1158

aimundo opened this issue May 19, 2021 · 4 comments

Comments

@aimundo
Copy link

aimundo commented May 19, 2021

Hi! First time reporting an unexpected behavior. I have been using Bookdown to write a manuscript. To add the author information I did not use the pre-defined option from Bookdown as there are multiple authors that have the same affiliation and using the default author information suggested by Bookdown would cause each author to have listed one affiliation, even if the affiliation is the same.

What I have tried instead is to use the LaTeX package authblk to add the author information and affiliation. What I have now is a preamble.pty file in the same directory where my manuscript .Rmd file is. The preamble.pty file contents are as follows:

\usepackage{lineno}
\usepackage{authblk}

%command for the package lineno
\linenumbers

%authors
\author[1]{Benicio del Ox}
\author[2]{Jake A. Motaungh}
\author[1]{Frederick P. Montego \thanks{fpm@insula.edu}}

\affil[1]{\footnotesize Department of Sociology, University of the Insula}
\affil[2]{\footnotesize Department of Psychology, University of Mars}

And here is a minimal reproducible example of the syntax I have in my .Rmd file:

---
title: '**A longitudinal analysis of Twitter trends in the year 2020**'
subtitle: _Political and sociological considerations_
output:  
  bookdown::pdf_document2:
    keep_tex: yes
    includes:
     in_header: preamble.sty
---

The error here is that when the document is compiled to a PDF an extra "and" appears at the end of the author list along with an affiliation superscript:

image

It is as if an additional author is expected on the author block. I have added more authors and author information and the issue persists, an addiional 'and' and a superscript appears at the end. I have been reading through a lot of forums but I have literally found no reason for this behavior. My only guess is that there is something in the LaTeX template from Pandoc that clashes with the authblk package. I also tested

output:
    pdf_document

And got the same result. Literally, I am out of ideas of why this is happening. Of notice, I couldn't find any issues about something similar in tex.stackexchange, and the examples provided there seemed to indicate that authblk worked fine, which is why I am guessing that this has something to do with RMarkdown.

My session info:
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 14393), RStudio 1.4.1106

Locale:
LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
LC_MONETARY=English_United States.1252 LC_NUMERIC=C
LC_TIME=English_United States.1252

Package version:
base64enc_0.1.3 bookdown_0.22 compiler_4.1.0 digest_0.6.27 evaluate_0.14
glue_1.4.2 graphics_4.1.0 grDevices_4.1.0 highr_0.9 htmltools_0.5.1.1
jsonlite_1.7.2 knitr_1.33 magrittr_2.0.1 markdown_1.1 methods_4.1.0
mime_0.10 rlang_0.4.11 rmarkdown_2.8 rticles_0.19 stats_4.1.0
stringi_1.6.1 stringr_1.4.0 tinytex_0.31 tools_4.1.0 utils_4.1.0
xfun_0.23 yaml_2.2.1

@cderv
Copy link
Collaborator

cderv commented May 20, 2021

I believe this is because Pandoc templates does not conditionally insert \author{}:
https://github.com/jgm/pandoc/blob/13021313e87a3074a113c1b81bcd8e5d28a279fb/data/templates/default.latex#L419

This means that your tex file will have an extra empty \author{}. This will look like this:

\usepackage{lineno}
\usepackage{authblk}

%command for the package lineno
\linenumbers

%authors
\author[1]{Benicio del Ox}
\author[2]{Jake A. Motaungh}
\author[1]{Frederick P. Montego \thanks{fpm@insula.edu}}

\affil[1]{\footnotesize Department of Sociology, University of the Insula}
\affil[2]{\footnotesize Department of Psychology, University of Mars}
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi

\title{\textbf{A longitudinal analysis of Twitter trends in the year
2020}}
\usepackage{etoolbox}
\makeatletter
\providecommand{\subtitle}[1]{% add subtitle to \maketitle
  \apptocmd{\@title}{\par {\large #1 \par}}{}{}
}
\makeatother
\subtitle{\emph{Political and sociological considerations}}
\author{}
\date{}

\begin{document}

The last empty author cause the and to be added. If this line is removed before compiling to PDF, I think you get what you want.

With bookdown, you could hack it as a workaround by setting the option bookdown.post.latex to a function that will remove this lines.

Here is an example document:

---
title: '**A longitudinal analysis of Twitter trends in the year 2020**'
subtitle: _Political and sociological considerations_
output: 
  bookdown::pdf_document2:
    keep_tex: TRUE
    includes: 
      in_header: preamble.tex
---

```{cat, engine.opts = list(file = "preamble.tex")}
\usepackage{lineno}
\usepackage{authblk}

%command for the package lineno
\linenumbers

%authors
\author[1]{Benicio del Ox}
\author[2]{Jake A. Motaungh}
\author[1]{Frederick P. Montego \thanks{fpm@insula.edu}}

\affil[1]{\footnotesize Department of Sociology, University of the Insula}
\affil[2]{\footnotesize Department of Psychology, University of Mars}
```

```{r,setup}
remove_author <- function(x) {
  # identify empty author line
  i <- grep("^\\\\author\\{\\}$", x)
  # be sure it is the one pandoc inserts
  if(length(i) != 0 && grepl('^\\\\date\\{', x[i+1])) x <- x[-i]
  x
}
options(bookdown.post.latex = remove_author)
```

# Header

It renders this way:
image

So it is not directly a rmarkdown issue but rather a template issue because you do not use the author field and Pandoc does not make this one conditional (mainly because it is mandatory I think)

Also, a recent change in pandoc (jgm/pandoc@cc08868) put those fields now into preamble before header-includes. So in next version of Pandoc maybe this could help modify how author are rendered (don't really know)

@yihui do you know where the and comes from ? Is it a LaTeX thing when you have multiple author ?
I don't know if there is anything we can help with inside rmarkdown.

You could use your own modified template if you want (building on the one in Pandoc, modifying this part, and passing a custom template using template field in pdf_document function.

Hope it helps. Thanks for the report!

@yihui
Copy link
Member

yihui commented May 20, 2021

do you know where the and comes from ?

Yes, it's from the empty \author{}. I was the person who made it unconditional: jgm/pandoc@ee44d44 but I wasn't aware of this case (i.e. \author{} already defined in preamble) at that time.

As you mentioned, either using bookdown.post.latex to post-process the .tex output or using a custom template should fix the problem.

@aimundo
Copy link
Author

aimundo commented May 20, 2021

Wow thanks @cderv and @yihui for the detailed explanation! I will tried both methods, but I will stick with the function as I read somewhere that custom templates are hard to mantain. Thanks again!

@aimundo aimundo closed this as completed May 20, 2021
@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants