RMarkdown的YAML中的作者和隶属关系 [英] Authors and affiliations in the YAML of RMarkdown

查看:175
本文介绍了RMarkdown的YAML中的作者和隶属关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个论坛过去已经问过这个问题了( 2

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.

问题是我正在使用RMarkdown撰写科学论文,并希望将结果导出为HTML,PDF或Word文件.

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.

更重要的是,有12位作者在文件上签名. 一些作者呈现一个以上隶属关系,而一些作家呈现相同的隶属关系.

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.

我的问题很明确:我如何编辑YAML以将所有作者与YAML中的所有从属关系都包括在内,以便导出为不同的格式(HTML,PDF,DOC)?

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)?

我尝试了这个YAML:

I tried this YAML:

---
title: "My title"
author:
  - name: Mario Modesto-Mata^1,2^
    email: paleomariomm@gmail.com
  - 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输出

这是我将.Rmd文件导出为PDF时看到的:

PDF output

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

我看到的是true,没有任何隶属关系.

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

我看到的是作者,而不是所有的隶属关系编号.隶属关系本身仍然是隐藏的.

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

名称和从属关系都不会出现在最终的Word文件中.

Neither names nor affiliations appear in the final Word file.

我正在使用在Linux Mint 19 Cinnamon上运行的最新RStudio版本(版本1.1.453).

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

---
title: "My title"
author:
  - Mario Modesto-Mata:
      email: paleomariomm@gmail.com
      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
---

推荐答案

据我所知,到目前为止,还没有一种千篇一律"的解决方案.

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

如果目标仅为PDF,我建议RStudio使用 rticles .很好.

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

同样适用于docx的解决方案更加困难.一种可能性是使用pandoc Lua过滤器. 存储库收集有用的过滤器包含两个过滤器,它们将帮助您:

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. (Important disclaimer: I wrote these.)

.lua文件放在目录中,稍微更改YAML结构,并指示pandoc运行过滤器:

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: paleomariomm@gmail.com
      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'
---

这将是PDF输出:

这是在Word中的样子:

while this is what it looks like in Word:

隶属关系和联系信息会添加到正文中,这就是为什么toc显示在正文上方的原因.

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

这篇关于RMarkdown的YAML中的作者和隶属关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆