3

I am getting an error when I try to include a user defined environment in my R markdown document. I have at the top:

header_includes:
- \usepackage{amsmath}
- \usepackage{amssymb}
- \usepackage{amsthm}
- \newtheorem{assumption}{Assumption}

And then in the document itself, if I write

\begin{assumption}
$a > b$
\end{assumption}

I get the error "! Undefined Control Sequence \begin{assumption}" when I click compile.

I don't get an error if I use a regular proof environment or equation environment. That is,

\begin{equation}
a^2 + b^2 = c^2
\end{equation} 

does not give me an error. Of course, including the "header_includes" part in the preamble of a latex document and then using the assumption environment in that latex document is no problem. It would just be nice if I could copy and paste Latex directly into R markdown, since TexStudio has many nice autocompletion features and coloring schemes that make it the better environment to write latex, but Markdown is the easier way to integrate LaTex and code. Any help would be great. Thanks!

  • Could you please post a minimal (non)working example? – Boris Mar 25 '17 at 5:51
3

You don't need to list the \newtheorem macro as a header_includes argument, just put it at the top of your document:

---
title: "Test"
header_includes:
- \usepackage{amsmath}
- \usepackage{amssymb}
- \usepackage{amsthm}
---

\newtheorem{assumption}{Assumption}

Here's my assumption:

\begin{assumption}
$a > b$
\end{assumption}

And done.

enter image description here

  • But why this does not have any effect on html? or notebook? how to tweak this to work for both? – David Aug 8 '18 at 5:48
  • that is when I present this in html slides also this should be visible. how to do that? – David Aug 8 '18 at 5:49
  • LaTeX code is only processed when your output is generated by the LaTeX program. That means pdf or Beamer slides. html slides are generated by a different backend, and that backend doesn't know LaTeX – Tyler Aug 8 '18 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.