Bookdown "Remark" environment - r

I'm trying to add numbered remarks (like in the definition or theorem environments) that I could referenced in a bookdown document. Something like:
```{remark, mylab}
my comment
```
In Remark \#ref(rem:mylab) we discussed...
which would produce:
Remark 1.1 my comment
In Remark 1.1 we discussed ...
Would anyone know if this is possible? Also, is it possible to change the numbering to A, B and so on? That is to have instead:
Remark A my comment
In Remark A we discussed ...
Thank you very much!

The general solution is:
Choose one of the predefined theorem like environments that you are not using otherwise, e.g. example.
Redefine the printed name for that environment in _bookdown.yml (c.f. https://bookdown.org/yihui/bookdown/internationalization.html) via:
language:
label:
exm: 'Remark '
In your Rmd files use
```{example, mylab}
my comment
```
In Remark \#ref(exm:mylab) we discussed...
Note that you have to use example and the correspoding label prefix exm.
I do not know of a general solution to use alphabetic instead of numeric numbering. I am sure that this would be possible if one would use only LaTeX/PDF output.

Related

Are there any drawbacks when chunk labels are not quoted?

Yihui Xie, the creator of knitr, writes in the official knitr chunk option documentation (emphasis by me):
(...) in theory, the chunk label should be quoted as well, but for the sake of convenience it will be automatically quoted if you did not quote it (e.g. ```{r, 2a} will become ```{r, '2a'})
As I understand this, the results of quoted and unquoted chunk labels should always be the same. Is this really true? Or might there be any (edge) cases where quoting vs. not quoting the chunk labels actually matters?
Especially, I'd like to know if there might be any differences in results if one adheres to the following recommendation also found in the knitr chunk option documentation:
(...) in general it is recommended to use alphabetic characters with words separated by - and avoid other characters (...)
The only edge case I can think of is when your chunk label contains a comma, e.g., a,b. In this case, it has to be quoted as 'a,b', otherwise a will be treated as the chunk label.
Chunk labels are automatically quoted via the internal function knitr:::quote_label(). You may try to find out other possible edge cases by yourself:
> knitr:::quote_label("a")
[1] "'a'"
> knitr:::quote_label("a,b")
[1] "'a',b"
> knitr:::quote_label('"a,b"')
[1] "\"a,b\""
> knitr:::quote_label("a a a,b=1")
[1] "'a a a',b=1"
> knitr:::quote_label("a},b=1")
[1] "'a}',b=1"

LyX: citation style author, year

I would like to use the citation style: author, year. Which configuration do I have to use? If I do \usepackage[comma]{natbib} it collides with the preferences where I can only chose between numerical and author-year.
It does not need to be natbib, I even prefer the Standard plain style, but simply would have author,year instead of [1].
Would be thankful for any help.
Maybe you'd like style authordate1, see here for sme examples: http://www.cs.stir.ac.uk/~kjt/software/latex/showbst.html
Nothing bibliography related has to be written to the preamble. Select natbib/plainnat and author-year in Documents -> Settings -> Bibliography. Then, right-click on inserted references and select desired citation style.

Escaping characters for text mode in AUCTeX [duplicate]

When editing an Sweave document in LaTeX (using the Noweb mode), Emacs knows to "ignore" code that is in <<>>= blocks. However, for interstitial \Sexpr{} blocks, this isn't the case. Given that R references by columns via '$' and LaTeX uses $ to set-off equations, these \Sexpr{} blocks often break the syntax highlighting, like so:
I have a very rudimentary understanding the elisp & Emacs syntax highlighting, but my hope is that it might be possible to add something to .emacs that will disable any parsing/$ detection within \Sexpr{}'s.
I thought emacs with ESS has correct syntax highlighting for Sweave?
Anyway, the easiest "fix" is to just not use the $ operator but [[ instead. For example:
foo$p.value
foo[['p.value']]
Should give the same result. I think foo$p.value is just short for foo[["p.value",exact=FALSE]]
I don't have a fix either, but I'll pass along my workaround, which is to never (well, rarely) do any processing in \Sexpr chunks but instead to store things I want to use in \Sexpr in variables, and to do so in the same chunk I do the main calculations in.
<<echo=FALSE, results=hide>>=
t1 <- chisq.test(someVar)
p1 <- formatC(t1$p.value, format="%f", digits=2)
#
\dots with a $p$-value of \Sexpr{p1}.
While there are some downsides to this, I find it helps me to better keep track of what I want to present, and how I want to present it.
As an aside, consider using formatC instead of round as it can keep significant zeros (ie, 0.10 instead of 0.1).
I have no good answer for you as I am not an Emacs hacker, so I usually do one of two things:
Either add a simple % $ comment at the of the line to "close" the math expression from $ to $,
Or rewrite the expression to not use $-based subsetting:
round(as.numeric(chisq.test(someVar)["p.value"]), 2).

Get Emacs to ignore contents of \Sexpr{} command in Sweave document to prevent incorrect $-based syntax highlighting

When editing an Sweave document in LaTeX (using the Noweb mode), Emacs knows to "ignore" code that is in <<>>= blocks. However, for interstitial \Sexpr{} blocks, this isn't the case. Given that R references by columns via '$' and LaTeX uses $ to set-off equations, these \Sexpr{} blocks often break the syntax highlighting, like so:
I have a very rudimentary understanding the elisp & Emacs syntax highlighting, but my hope is that it might be possible to add something to .emacs that will disable any parsing/$ detection within \Sexpr{}'s.
I thought emacs with ESS has correct syntax highlighting for Sweave?
Anyway, the easiest "fix" is to just not use the $ operator but [[ instead. For example:
foo$p.value
foo[['p.value']]
Should give the same result. I think foo$p.value is just short for foo[["p.value",exact=FALSE]]
I don't have a fix either, but I'll pass along my workaround, which is to never (well, rarely) do any processing in \Sexpr chunks but instead to store things I want to use in \Sexpr in variables, and to do so in the same chunk I do the main calculations in.
<<echo=FALSE, results=hide>>=
t1 <- chisq.test(someVar)
p1 <- formatC(t1$p.value, format="%f", digits=2)
#
\dots with a $p$-value of \Sexpr{p1}.
While there are some downsides to this, I find it helps me to better keep track of what I want to present, and how I want to present it.
As an aside, consider using formatC instead of round as it can keep significant zeros (ie, 0.10 instead of 0.1).
I have no good answer for you as I am not an Emacs hacker, so I usually do one of two things:
Either add a simple % $ comment at the of the line to "close" the math expression from $ to $,
Or rewrite the expression to not use $-based subsetting:
round(as.numeric(chisq.test(someVar)["p.value"]), 2).

Latex Math Symbol: Vitanyi puts a tiny plus symbol over his equals. How do I do that?

For example, in http://homepages.cwi.nl/~paulv/papers/algorithmicstatistics.pdf at the bottom of page 5 and top of page 6, he uses a plus/equal symbol and a similar plus/lessthan symbol. I can't figure out how to make that symbol, and I'd like to quote him.
Any help?
Try $\stackrel{top}{bottom}$
You'd want something like this:
$X \stackrel{+}{=} Y$
This positions the plus sign above the equals sign. For example, the following code:
$K(x,y|z) \stackrel{+}{=} K(x|z) \stackrel{+}{<} I(x:y|z)$
produces the following output:
The Comprehensive LaTeX Symbol List (from here) is a great resource, and start for questions like this. You could also contact the author, it's possible he did some LaTex voodoo (math accents and such) to get it to work.
Best of luck.
PS: isn't \pm plus-minus, not plus-equals?
Here's the list of Latex Math Symbols. I don't see the two from the PDF you linked to. Do you know what they mean? You might be able to find an equivalent in the Latex list.

Resources