简体   繁体   English

R Markdown:在特定引用中取消括号

[英]R Markdown: suppress parentheses in specific citations

I have an R Markdown document that includes some citations.我有一个包含一些引文的 R Markdown 文档。 I am using the default citation style, which usually works well for me.我正在使用默认的引文样式,这通常对我很有效。 But I have some sentences that lie within parentheses, and in these sentences, I want to cite works without adding a second set of parentheses.但是我有一些句子位于括号内,在这些句子中,我想在不添加第二组括号的情况下引用作品。 That is, I want to suppress the parentheses that would normally appear around the year of publication in the citation.也就是说,我想取消引用中通常出现在出版年份前后的括号。 Here is an example of the output that I am trying to create:这是我尝试创建的输出示例:

Lorem ipsum dolor. (Fourscore and seven years ago: see Smith 2020.)

where Smith 2020 is produced with an R Markdown citation like @Smith_2020 .其中Smith 2020是使用 R Markdown 引用(如@Smith_2020 In LaTeX, this sort of thing can be done with the \\citealp macro in the "natbib" package.在 LaTeX 中,这种事情可以通过“natbib”包中的\\citealp宏来完成。 It can also be done with that package's \\citeauthor and \\citeyear macros, which list the author's name and the year of publication, respectively.也可以使用该包的\\citeauthor\\citeyear宏来完成,它们分别列出了作者的姓名和出版年份。 Is there an equivalent feature in R Markdown? R Markdown 中是否有等效功能?


To further illustrate the problem, here is a minimal working example.为了进一步说明问题,这里是一个最小的工作示例。 Assume that "myBib.bib" is假设“myBib.bib”是

@BOOK{Smith_2020,
  AUTHOR       = {John Smith},
  TITLE        = {Some Title},
  YEAR         = {2020},
  PUBLISHER    = {Knopf},
  address      = {New York, NY},
}

and that I have this Rmd file:我有这个 Rmd 文件:

---
output: html_document
bibliography: 'myBib.bib'
---

(See @Smith_2020 for details.)

The output is (See Smith (2020) for details.) I want to eliminate the parentheses around 2020 .输出是(See Smith (2020) for details.)我想消除2020左右的括号。 One way to do this is to put the entire sentence within brackets: for example, [See @Smith_2020 for details.] .一种方法是将整个句子放在括号内:例如, [See @Smith_2020 for details.] But this approach is a bit clunky, especially when the passage within brackets is large.但是这种方法有点笨拙,尤其是当括号内的段落很大时。 Is there another way?还有其他方法吗?

I don't think that changing the default citation style will help, as that citation style is usually what I want.我认为更改默认引用样式不会有帮助,因为该引用样式通常是我想要的。 I just want to suppress parentheses in citations when the citation lies within a passage that is itself parenthesized.当引文位于本身带有括号的段落中时,我只想在引文中取消括号。

I've looked to thebookdown book and the R Markdown cookbook , but I can't see that they offer a solution.我看过bookdown bookR Markdown cookbook ,但我看不出它们提供了解决方案。 I've also searched Stack Overflow and tex.stackexchange.com for related questions, but I haven't found anything that speaks to this question.我还在 Stack Overflow 和 tex.stackexchange.com 上搜索了相关问题,但我没有找到任何与此问题相关的内容。

The correct answer is to put the whole sentence in-between square brackets:正确答案是将整个句子放在方括号之间:

[See Smith -@Smith_2020 for details.]

it follows the first example in the Citation syntax section Rstudio's official doc (link provided in the previous answer).它遵循引用语法部分 Rstudio 官方文档中的第一个示例(上一个答案中提供的链接)。

Blah blah [see @doe99, pp. 33-35; also @smith04, ch. 1].

(See Smith -@Smith_2020 for details.) will show: (See Smith -@Smith_2020 for details.)将显示:

(See Smith 2020 for details.) (有关详细信息,请参阅 Smith 2020。)

See also a previous question and RStudio's official documentation .另请参阅上一个问题RStudio 的官方文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM