rstudio / rticles

LaTeX Journal Article Templates for R Markdown
https://pkgs.rstudio.com/rticles/
1.47k stars 519 forks source link

Nested code chunks in list #476

Closed nbenn closed 2 years ago

nbenn commented 2 years ago

Using the current MyJSSArticle.Rmd template, I run into an issue when nesting a code chunk with a list. The following markdown renders to tex as I'd expect:

1. My first entry.

1. My second entry.

gives

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  My first entry.
\item
  My second entry.
\end{enumerate}

However, when I try adding a code chunk (with 4 space indentation), the list is split:

1. My first entry.

    ```{r}
    x <- 1:10
    x
  1. My second entry.

now gives

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  My first entry.
\end{enumerate}

\begin{CodeChunk}
\begin{CodeInput}
R> x <- 1:10
R> x
\end{CodeInput}
\begin{CodeOutput}
 [1]  1  2  3  4  5  6  7  8  9 10
\end{CodeOutput}
\end{CodeChunk}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  My second entry.
\end{enumerate}

This is not specific to JSS, but when trying out the rjournal template, the same behavior can be observed. Is this intentional or a bug?

When using vanilla pdf_document, this of course behaves differently, the tex that is produced is

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  My first entry.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{x }\OtherTok{\textless{}{-}} \DecValTok{1}\SpecialCharTok{:}\DecValTok{10}
\NormalTok{x}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
##  [1]  1  2  3  4  5  6  7  8  9 10
\end{verbatim}
\item
  My second entry.
\end{enumerate}

By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

> xfun::session_info('rticles')
# R version 4.1.3 (2022-03-10)
# Platform: aarch64-apple-darwin20 (64-bit)
# Running under: macOS Monterey 12.3
#
# Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8
#
# Package version:
#   base64enc_0.1.3 bslib_0.3.1     digest_0.6.29   evaluate_0.15
#   fastmap_1.1.0   fs_1.5.2        glue_1.6.2      graphics_4.1.3
#   grDevices_4.1.3 highr_0.9       htmltools_0.5.2 jquerylib_0.1.4
#   jsonlite_1.8.0  knitr_1.37      magrittr_2.0.2  methods_4.1.3
#   R6_2.5.1        rappdirs_0.3.3  rlang_1.0.2     rmarkdown_2.13
#   rticles_0.23    sass_0.4.0      stats_4.1.3     stringi_1.7.6
#   stringr_1.4.0   tinytex_0.37    tools_4.1.3     utils_4.1.3
#   xfun_0.30       yaml_2.3.5
cderv commented 2 years ago

Thanks for catching that up. I can reproduce and I need to look closer. I think this due to the indentation not being preserved while we are processing the code chunk source and outputs with knitr. We need a special processing which explain why there is not issue with default format.

I'll try to fix that quickly

nbenn commented 2 years ago

Thanks. In case anyone else runs into this in the meantime, there's a temporary workaround outlined in #477.

cderv commented 2 years ago

This should now work ok in dev version of the package.

remotes::install_github("rstudio/rticles")

Thanks!

github-actions[bot] commented 2 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.