3

I am writing some text with Markdown on the Jupyter notebook. But I am not able to import some Latex packages to the notebook. I tried to follow How to include LaTeX package in R Markdown?. I tried to include the mathtools package, but it does not work.

With

title: "Title"
author: "Me"
header-includes:
   - \usepackage{mathtools}
output:
    pdf_document

I am still not able to call commands like $\xrightarrow[\text{sample text}]$ on Jupyter notebook.

Consideration
  • 55
  • 1
  • 1
  • 5
  • 1
    Welcome to TeX.SE. You cannot write with square brackets [] in your math formula. Replace with {} and your code works. – Ross Sep 16 '20 at 14:05
  • Welcome to TeX.SE. Please show us a minimal working example. including documentclass and etc. –  Sep 16 '20 at 14:07
  • 2
    Before downvoting, kindly note this is markdown, which is converted to LaTeX to render the pdf. As such, it begins with a YAML header, not \documentclass. The OP has given enough code and information to identify the problem. – Ross Sep 16 '20 at 15:07

1 Answers1

3

Welcome to TeX.SE. Don't use square brackets [] in your math expression. Use braces {} only. You wrote: $\xrightarrow[\text{sample text}]$. It should be: $\xrightarrow{\text{sample text}}$.

Edit: Updated to show the use of \Bracket and \Set from the braket package.

enter image description here

---
title: "Title"
author: "Me"
header-includes:
  - \usepackage{array}
  - \usepackage{booktabs}
  - \usepackage{mathtools}
  - \usepackage{braket}
output:
  pdf_document:
    keep_tex: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

\hrule <!-- draw a horizontal line -->

We can write in markdown and add content that uses LaTeX syntax and \LaTeX\ packages to format our document.

Using mathtools package

$\xrightarrow{\text{sample text}}$

<br> <!-- add space, like \bigskip % - this is a comment -->

Using array, booktabs and braket packages

\begingroup \renewcommand*{\arraystretch}{1.7} \setlength{\tabcolsep}{10pt} \begin{tabular}{@{}>{\footnotesize}r>{$\displaystyle}l<{$}@{}} \toprule \verb+\Braket{ \phi | \frac{\partial^2}{\partial t^2} | \psi }+ & \Braket{ \phi | \frac{\partial^2}{\partial t^2} | \psi } \ \verb+\Set{ x\in\mathbf{R}^2 | 0<{|x|}<5 }+ & \Set{ x\in\mathbf{R}^2 | 0<{|x|}<5 } \ \bottomrule \end{tabular} \endgroup

We can do math

result &lt;- 1 + 2
result

Ross
  • 5,656
  • 2
  • 14
  • 38
  • For additional packages, may I just add them right under - \usepackage{mathtools}? For example, I add - \usepackage{braket} right under - \usepackage{mathtools}, but it seems it does not take effect. I still cannot call $\bra{aa}$ etc.. – Consideration Sep 18 '20 at 17:32
  • Yes, just add any additional packages you require under header-includes. See the update. – Ross Sep 19 '20 at 03:03
  • 1
    I copied and pasted your template into jupyter notebook, but it doesn't work for me. – Bohan Lu Apr 08 '21 at 17:28