Authors and affiliations in the YAML of RMarkdown
Asked Answered
B

1

21

I know this question was already asked in the past in this forum (1, 2, 3). Before you mark this as duplicated, I tried all the answers with no success. Most of the questions were asked long ago, and some updates related with pandoc might affect nowadays results.

The issue is that I am writing a scientific paper using RMarkdown, and would like to export the results either in HTML, PDF or Word files.

More importantly is that there are 12 authors signing the papers. Some of the authors present more than one affiliation, and some authors presenting the same affiliation.

My question is very clear: How can I edit the YAML to include all the authors with all the affiliations in the YAML in order to export to different formats (HTML, PDF, DOC)?

I tried this YAML:

---
title: "My title"
author:
  - name: Mario Modesto-Mata^1,2^
    email: [email protected]
  - name: Christopher^1^
  - name: Seaghán Mhartain^2^
  - name: Rita Yuri Ynoue^1^
address:
  - code: 1
    address: Instituto de Astronomía, Geofísica e Ciências Atmosféricas, Universidade de São Paulo
  - code: 2
    address: Faculdade de Medicina, Universidade de São Paulo
date: "1 October 2018"
output: 
  pdf_document: 
    number_sections: yes
    toc: yes
    toc_depth: 4
  word_document:
    toc: yes
  html_document:
    css: Scripts accesorios/estiloboton.css
    number_sections: yes
    theme: sandstone
    toc: yes
    toc_depth: 4
bibliography: references.bib
csl: science.csl
---

PDF output

This is what I see when I export to PDF the .Rmd file:

enter image description here

Instead of the authors, I see true and no affiliations.

HTML output

I see the authors and not all the affiliation numbers. The affiliations themselves remain hidden.

enter image description here

DOCX output

Neither names nor affiliations appear in the final Word file.

My system

I am using the latest RStudio version (Version 1.1.453), running on Linux Mint 19 Cinnamon.

UPDATE: original example

---
title: "My title"
author:
  - Mario Modesto-Mata:
      email: [email protected]
      institute: [cenieh, ucl1, ppex]
      correspondence: true
  - M. Christopher Dean:
    institute: [ucl2, nhm]
  - Yuliet Quintino:
    institute: ubu
  - Rebeca García-González:
    institute: ubu
  - Rodrigo S. Lacruz:
    institute: nyu
  - Timothy G. Bromage:
    institute: nyu
  - Cecilia García-Campos:
    institute: [cenieh, ucl1]
  - Marina Martínez de Pinillos:
    institute: cenieh
  - Laura Martín-Francés:
    institute: [bor, cenieh]
  - María Martinón-Torres:
    institute: [cenieh, ucl1]
  - Eudald Carbonell:
    institute: [iphes, urv]
  - Juan Luis Arsuaga:
    institute: [isciii, ucm]
  - José María Bermúdez de Castro:
    institute: [cenieh, ucl1]
institute:
  - cenieh: Centro Nacional de Investigación sobre la Evolución Humana (CENIEH), Paseo Sierra de Atapuerca 3, 09002, Burgos, Spain
  - ucl1: Department of Anthropology, University College London, London, WC1H 0BW, UK
  - ucl2: Department of Cell and Developmental Biology, University College London, Gower Street, London, WC1E 6BT, UK
  - ubu: Laboratorio de Evolución Humana, Unierisdad de Burgos, Edificio I+D+i, Burgos, Spain
  - ppex: Equipo Primeros Pobladores de Extremadura, Casa de Cultura Rodríguez Moñino, Cáceres, Spain
  - nhm: Centre for Human Evolution Research (CHER), Department of Earth Sciences, Natural History Museum, London, SW7 5BD, UK
  - nyu: New York University
  - bor: De la Préhistoire à l'Actuel - Culture, Environnement et Anthropologie, University of Bordeaux, CNRS, MCC, PACE, UMR 5199 F_33615, Pessac Cedex, France
  - iphes: Institut Català de Paleoecologia Humana i Evolució Social (IPHES), Zona Educacional 4, Campus Sescelades, Edifici W3, Universitat Rovira i Virgili, Tarragona, Spain
  - urv: Àrea de Prehistòria, Universitat Rovira i Virgili, Avinguda de Catalunya 35, 43002, Tarragona, Spain
  - isciii: Centro mixto UCM-ISCIII de Evolución y Comportamiento humanos, Madrid, Spain
  - ucm: Departamento de Geodinámica, Estratigrafía y Paleontología, Facultad de Ciencias Geológicas, Universidad Complutense de Madrid, Spain
date: "1 October 2018"
output: 
  pdf_document: 
    number_sections: yes
    toc: yes
    toc_depth: 4
    pandoc_args:
      - '--lua-filter=scholarly-metadata.lua'
      - '--lua-filter=author-info-blocks.lua'
  html_document:
    css: Scripts accesorios/estiloboton.css
    number_sections: yes
    theme: sandstone
    toc: yes
    toc_depth: 4
  word_document:
    toc: yes
    pandoc_args:
      - '--lua-filter=scholarly-metadata.lua'
      - '--lua-filter=author-info-blocks.lua'
bibliography: references.bib
csl: science.csl
---
Baseborn answered 21/10, 2018 at 18:49 Comment(1)
Hi did you find an alternative solution to this?Bridgeport
D
31

There is, to the best of my knowledge, no one-size-fits-it-all solution as of now.

If the target was only PDF, I'd suggest rticles by RStudio. It's great.

A solution which also works with docx is more difficult. One possibility is to use pandoc Lua filters. The repository collecting useful filters contains two filters which will help you: scholarly-metadata and author-info-blocks. (Disclosure: I wrote these.)

Place the .lua files in your directory, change the YAML structure a bit, and instruct pandoc to run the filters:

---
title: "My title"
author:
  - Mario Modesto-Mata:
      email: [email protected]
      institute: [astro, med]
      correspondence: true
  - name: Christopher
    institute: astro
  - name: Seaghán Mhartain
    institute: med
  - name: Rita Yuri Ynoue
    institute: astro
institute:
  - astro: Instituto de Astronomía, Geofísica e Ciências Atmosféricas, Universidade de São Paulo
  - med: Faculdade de Medicina, Universidade de São Paulo
date: "1 October 2018"
output: 
  word_document:
    toc: yes
    pandoc_args:
      - '--lua-filter=scholarly-metadata.lua'
      - '--lua-filter=author-info-blocks.lua'
  pdf_document: 
    number_sections: yes
    toc: yes
    toc_depth: 4
    pandoc_args:
      - '--lua-filter=scholarly-metadata.lua'
      - '--lua-filter=author-info-blocks.lua'
---

This will be the PDF output:

example pdf output

while this is what it looks like in Word:

enter image description here

The affiliation and contact information is added to the body text, which is why the toc is displayed above it.

Dear answered 21/10, 2018 at 19:51 Comment(9)
I dowloaded both filters .lua and placed in my directory folder. However, it gives an error saying unrecognized option and Error: pandoc document conversion failed with error 2.Baseborn
Seems to be an old pandoc version. Can you update RStudio?Dear
It's my last version of RStudio. Is there a way to update pandoc alone?Baseborn
According to my Linux version, I have installed the 1.19.2.4 of PandocBaseborn
I updated pandoc to the version 2.3 downloading the .deb file in the official webpage. Now I get Error running filter scholarly-metadata.lua: Error while running filter function: [string "scholarly-metadata.lua"]:95: not a named object: table: 0x66be820 Error: pandoc document conversion failed with error 83 Execution haltedBaseborn
That's odd. Has the YAML metadata been updated according to the schema I posted above? The script won't be able to handle your original method of specifying metadata, so that might be the cause. Can you try in a new document using just the snippet I posted?Dear
Interesting. It seems to work with the example shown, but not with the real one. I updated the question including the original. What might be wrong with the real one? The error is the same as two comments before...Baseborn
Thanks. The author's institute fields should be indented by two more spaces. It works for me if I do that.Dear
Please don't hesitate to open an issue on GitHub if you have other problems, wishes, or feature requests.Dear

© 2022 - 2024 — McMap. All rights reserved.