Dec 312007
I suddenly realized just now that the line breaks for LaTeX code in Rd files are also \cr instead of \\ (which I thought to be in the past). R CMD CHECK will replace your \cr with \\ when producing LaTeX documentation files. If you write \\ directly in Rd files, it will be recognized as “an escape character + a backslash“, which surely is not a line break symbol.
I found such a problem in the documentation file for the function brownian.motion() in my package “animation“. The original code is:
\deqn{x_{k + 1} = x_{k} + rnorm(1)\\
y_{k + 1} = y_{k} + rnorm(1)}{x[k + 1] = x[k] + rnorm(1)\cr y[k + 1] = y[k] + rnorm(1)}
And actually it should be:
\deqn{x_{k + 1} = x_{k} + rnorm(1)\cr
y_{k + 1} = y_{k} + rnorm(1)}{x[k + 1] = x[k] + rnorm(1)\cr y[k + 1] = y[k] + rnorm(1)}
I was just to write an email for help but I understood the reason for my problem (by checking the result from R CMD CHECK) before I sent my email.
Related Posts
One Response to “Line Breaks for LaTeX Code in R Documentation Files”
Comments (1)
Sorry, but the solution above is NOT correct! And currently it’s not allowed to insert line breaks, as the LaTeX style file “
Rd.sty” defines the command “deqn” as:\newcommand{deqn}[2]{[#1]}It means equations are put in the “
displaymath” environment, so it’s impossible to break a line under such conditions as LaTeX does not allow line breaks in the “displaymath” environment. The only solution, I think, is to use “eqnarray” instead, which allows multiple lines of math formulae. To suppress the numbering, you need to use “eqnarray*“:\newcommand{deqn}[2]{\begin{eqnarray*}#1end{eqnarray*}}