[R-pkg-devel] How to write a 'cases' environment in .Rd files?
Ben Bolker
bbo|ker @end|ng |rom gm@||@com
Fri Sep 9 22:23:40 CEST 2022
For what it's worth: (1) I think the problems from the original
report are PDF-rendering and not KaTeX-rendering issues
(2) I have worked around this problem with something like this
(\left\{\begin{array}{rl} ... \end{array}\right.)
\left\{
\begin{array}{rl}
1\,, & 0 \le {\cal R}_0 \le 1, \\
\left(\frac{1}{{\cal R}_0}\right)^{k} \,, & 1\le{\cal R}_0.
\end{array}
\right.
(3) amsmath will be available in Rd.sty shortly
https://github.com/wch/r-source/commit/18ab2514504e598f0bf24264dac2d870cf891e1e
On 8/12/22 3:09 AM, matthias-gondan wrote:
> I am currently developing an R package that translates R expressions to Html and Latex, things like dbinom(x, size, prob) to P\left(x; N, \pi\right)Generation of Rd files may be an interesting use case. It's still at an early stage, I appreciate contributions and interesting feature requests.github.com/mgondan/mathmlVon meinem/meiner Galaxy gesendet
> -------- Ursprüngliche Nachricht --------Von: Ivan Krylov <krylov.r00t using gmail.com> Datum: 12.08.22 08:16 (GMT+01:00) An: Marius Hofert <marius.hofert using uwaterloo.ca> Cc: r-package-devel using r-project.org Betreff: Re: [R-pkg-devel] How to write a 'cases' environment in .Rd files? On Thu, 11 Aug 2022 18:43:44 +0000Marius Hofert <marius.hofert using uwaterloo.ca> wrote:> Since recently, r-devel-linux-x86_64-debian-clang and> r-devel-linux-x86_64-debian-gcc trigger the note 'Undefined control> sequence: \cases in F(x) = \cases{...', possibly due to KaTeX> rendering help pages. I looked around quite a bit but couldn't find a> way to implement 'cases' environments. For example,> https://katex.org/docs/supported.html#environments mentions> \begin{cases} \end{cases}, so I tried> > \deqn{F(x) = \begin{cases}> 1,&\text{if}\ x > 0,\\> 0,&\text{if} x = 0.}}{...}> > but that triggers:> > ...> * checking PDF version of manual ... WARNING> LaTeX errors when creating PDF version.> This typically indicates Rd problems.> LaTeX errors found:> ! Misplaced alignment tab character &There is a possible workaround, but it's the opposite of beautiful. Youcan use conditional text to compile one version of the formula for HTMLhelp and another one for PDF help:\ifelse{html}{\eqn{\begin{cases}...}}{\eqn{\cases{...}}{ascii}}It's as tedious as it looks. For extra style(?) points, you can put athree-argument user-defined macro in man/macros/whatever.Rd thatforwards its arguments to one of the \ifelse branches. As far as Iremember, \newcommand{}{} has to fit on one line, but in R ≥ 3.6.0,macros themselves can take multi-line arguments.If you're targeting an earlier version of R, you can make multi-linearguments work by forcing R to cache the parse tree of the man pagewhile building a source tarball with a newer R version using\Sexpr[stage=build]{}, costing you some time during R CMD build and aslightly larger source tarball. (It's an implementation detail that onenormally shouldn't depend upon. Thankfully, as of 2022, there won't beany newer versions of R ≤ 3.5.x to break it.) Support forman/macros/*.Rd only appeared in R-3.2.0, so I haven't researchedcompatibility tricks for even older versions of R.-- Best regards,Ivan______________________________________________R-package-devel using r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-package-devel
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
--
Dr. Benjamin Bolker
Professor, Mathematics & Statistics and Biology, McMaster University
Director, School of Computational Science and Engineering
Graduate chair, Mathematics & Statistics
More information about the R-package-devel
mailing list