R Markdown: suppress parentheses in specific citations
Asked Answered
E

2

13

I have an R Markdown document that includes some citations. 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. In LaTeX, this sort of thing can be done with the \citealp macro in the "natbib" package. 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. Is there an equivalent feature in R Markdown?


To further illustrate the problem, here is a minimal working example. Assume that "myBib.bib" is

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

and that I have this Rmd file:

---
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. One way to do this is to put the entire sentence within brackets: for example, [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 the bookdown book and the R Markdown cookbook, but I can't see that they offer a solution. I've also searched Stack Overflow and tex.stackexchange.com for related questions, but I haven't found anything that speaks to this question.

Embowed answered 5/10, 2020 at 13:1 Comment(0)
R
5

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

Blah blah [see @doe99, pp. 33-35; also @smith04, ch. 1].
Renaud answered 1/12, 2020 at 9:22 Comment(4)
Thank you -- I see that the approach works. But as I mentioned in my post, it's a cumbersome approach, especially when the sentence is a long one. That's why I'm hoping for a cleaner solution.Embowed
Ah sorry, i was trying to convert a bunch of TeX files \citealp{} to Rmd syntax programmatically and found this post. I agree with you that this solution is not convenient for long sentences and in my case for conversion from TeX. If I am not mistaking [-@smith04] and -@smith04 both output the year only and in-between brackets and it would be nice to suggest to Rmarkdown folks to reprogram -@smith04 to not have brackets. Have you tried to reach out to them on github?Renaud
You also need to escape semi-colons, e.g. for APA style when combining an abbreviation with citations the Fun of Obfuscated Onions [FOO\; Smith et al., -@smith2006; Jones et al., -@Jones2008].Portend
@Portend Have you figured out a way to achieve this (when there is a semi-colon inside the parentheses) without having to type the author name manually? While this method works, when the citations are linked, this results in only the dates being linked, which stands out from the rest of the citations in the document.Bootie
D
-1

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

(See Smith 2020 for details.)

See also a previous question and RStudio's official documentation.

Dinghy answered 6/10, 2020 at 10:7 Comment(1)
Thank you. But when I use that line, I get (See Smith (2020) for details.) The parentheses around the year are not suppressed. And the RStudio documentation to which you link indicates that the result that I get is the intended result: "A minus sign (-) before the @ will suppress mention of the author in the citation," but it does nothing to suppress parentheses around the year. (The documentation to which I linked in the original post makes the same point.)Embowed

© 2022 - 2024 — McMap. All rights reserved.