rstudio / rmarkdown

Dynamic Documents for R
https://rmarkdown.rstudio.com
GNU General Public License v3.0
2.88k stars 979 forks source link

Beamer presentation ignores .numberLines with "AnnArbor" theme #2168

Closed bcm0 closed 3 years ago

bcm0 commented 3 years ago

Checklist

I use bookdown::render_book('code.Rmd') This works:

---
output:
  beamer_presentation:
    theme: default
---

```{.cpp .numberLines}
int main

This shows no line numbers:
````Rmd
---
output:
  beamer_presentation:
    theme: "AnnArbor"
---

```{.cpp .numberLines}
int main


I looked at the resulting .tex files. 
`\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}` 
`\begin{Highlighting}[numbers=left,,]`
The numbers are hidden when `\usetheme[]{AnnArbor}` is used.
cderv commented 3 years ago

Hi, thanks for the report.

As this question concerns beamer_presentation, I moved it in rmarkdown repo.

I don't think this is a rmarkdown issue. Under the hook, Pandoc is used to create the .tex file for beamer slides. I tried this

❯ pandoc -t beamer -s -o default.tex
# header

```{.cpp .numberLines}
int main

^Z


and 

````powershell
❯ pandoc -t beamer -Vtheme=AnnArbor -s -o AnnArbor.tex
# header

```{.cpp .numberLines}
int main

^Z


to compare the file created. The only difference is the theme as expected
````diff
❯ git diff .\default.tex .\AnnArbor.tex
diff --git "a/.\\default.tex" "b/.\\AnnArbor.tex"
index 81f2ed3..b81948b 100644
--- "a/.\\default.tex"
+++ "b/.\\AnnArbor.tex"
@@ -58,6 +58,7 @@
   \defaultfontfeatures{Scale=MatchLowercase}
   \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
 \fi
+\usetheme[]{AnnArbor}
 % Use upquote if available, for straight quotes in verbatim environments
 \IfFileExists{upquote.sty}{\usepackage{upquote}}{}
 \IfFileExists{microtype.sty}{% use microtype if available

So I asked myself if this was supposed to work by using only LaTeX. For code block, the fancyvrb CTAN package is used, with a Verbatim environment, renamed Highlighting

\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}

So I tried to use simple tex file to compile with latexmk

\documentclass{beamer}
\usepackage{fancyvrb}

\begin{document}
\begin{Verbatim}[numbers=left]
First verbatim line.
Second verbatim line.
\end{Verbatim}
Normal text
\end{document}

and it ouptuts as expected image

Then I added the theme

\documentclass{beamer}
\usepackage{fancyvrb}
\usetheme[]{AnnArbor}
\begin{document}
\begin{Verbatim}[numbers=left]
First verbatim line.
Second verbatim line.
\end{Verbatim}
Normal text
\end{document}

and this has no number before line image

So it seems that line numbers is not supported in AnnArbor theme.

Do you happen to know of a .tex example where it works ? This would help understand what missing.

Otherwise, I believed this is not supported by the theme, so it won't be possible from rmarkdown directly.

Hope it helps

bcm0 commented 3 years ago

I have no working .tex example and the only difference is the \usetheme line.

It works on some themes only. I tried the "Berkeley" theme and the line numbers are partially hidden by the theme. Probably beamer's theme definition files don't account enough space. Thank you for checking it.

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.