Open jm-t opened 5 years ago
Currently, you may add the following codes at the beginning of your index.Rmd file to remove the LaTeX commands injected from the default template.
options(bookdown.post.latex = function(x) {
from <- grep("usepackage\\{amsthm\\}", x)
to <- grep("newtheorem\\*\\{solution", x)
x <- x[-c(from:to)]
})
See the Issue 417 and the solution in there.
@jm-t thanks for your patience with this.
The issue is that one user cannot define theorems using any of these names in the preamble. The current workaround would be to define them in the include before body.
Did you try already to define yourself a new theorem environment ?
Currently, if your preamble already include
\newtheorem{theorem}
Then bookdown will not insert any other Theorem or Proof environments. It will let the user add them oneself in the preamble. This is what happens in Latex.R. We do that in order the bookdown book can use these environment without the user knowing how to define them in LaTeX, but we don't add them in the template itself in case someone wants to override it.
Does that work for you ?
I think we can easily add an option to deactivate the inclusion of bookdown supported environment and let the user do it. This would mean that the book would not render if the preamble is not correctly setup.
Something like options(bookdown.theorems_preamble = FALSE)
We could also not include it when \newtheorem{[a-z]+}
is found.
Would that be better than the current way that should work currently ?
@cderv Does options(bookdown.theorem.preamble = FALSE)
work now? https://github.com/rstudio/bookdown/blob/2d692ba4b61f1e466c92e78fd712b0ab08c11d31/R/latex.R#L239
Oh yes I forgot about this issue.
@jm-t setting options(bookdown.theorem.preamble = FALSE)
will prevent bookdown adding any definition in the .tex
file. Users needs to define the environment or use a package already containing these definitions.
So with this, you'll be able to define yourself some theorem environment.
Does that seem ok for you ?
It would be useful to have the option to disable bookdown extension. Or to change where there are injected in the template.
Here is a use case. One basic markdown, one basic preamble.tex
Normal text
% Start of preamble
\newenvironment{FOO}{}
% of of preamble
% Start of preamble
\newenvironment{FOO}{}
% of of preamble
\usepackage{amsthm} \newtheorem{theorem}{Theorem}[section] \newtheorem{lemma}{Lemma}[section] \newtheorem{corollary}{Corollary}[section] \newtheorem{proposition}{Proposition}[section] \newtheorem{conjecture}{Conjecture}[section] \theoremstyle{definition} \newtheorem{definition}{Definition}[section] \theoremstyle{definition} \newtheorem{example}{Example}[section] \theoremstyle{definition} \newtheorem{exercise}{Exercise}[section] \theoremstyle{remark} \newtheorem{remark}{Remark} \newtheorem{solution}{Solution} \let\BeginKnitrBlock\begin \let\EndKnitrBlock\end \begin{document} \maketitle