How to add latex code inline in quarto

Hello everybody,
I'm writing a book with quarto, compiing in tex with TexLive 2022
I am using includes like {{< include >}} to include markdown files
I have noticed that markdown formatting code is not always well traslated to latex, even if it works in HTML output.
I want to include a framed text in an include file as .tex, to get the output as posted here in the second answer, using tcolorbox package.
As this framed colour box needs to be placed inside the markdown text included, I'm not sure how I should tell quarto to include the .tex code. SHould I use an additional .qmd file and put the .tex code in YAML section? I'm quite new to quarto and I'm a bit confused about how to do this.
Thanks in advance

I have just started playing around with Quarto but something like this seems to work.

title: "Latex"
author: "john the toucanite"
format: pdf

  • \usepackage{lipsum}
  • \usepackage{tcolorbox}

a new line\\
$$ y = x^2$$
1 Like

Unless you need to perform deep LaTeX magic, .qmd files can be converted directly to pdf using pandoc under the hood, with the option of further tinkering with the intermediate tex files. The Quarto site has details. For pdf output only (doesn't work with HTML and vice versa), you can inline LaTex.

'title: "stub.pdf"
'format: pdf


    Age & Frequency \\ \hline
    18--25  & 15 \\
    26--35  & 33 \\
    36--45  & 22 \\ \hline

Inline maths: f(x) = y

Inline text:

Example 1: The following paragraph (given in quotes) is an
example of centered alignment using the center environment.

``La\TeX{} is a document preparation system and document markup
language. \LaTeX{} uses the \TeX{} typesetting program for formatting
its output, and is itself written in the \TeX{} macro language.
\LaTeX{} is not the name of a particular (executable) typesetting program, but
refers to the suite of commands (\TeX{} macros) which form the markup
conventions used to typeset \LaTeX{} documents."


1 Like

Did you try adding raw LaTeX code in your .md file ?
It should be preserved and not processed See this part of the doc: Quarto - PDF Basics

Do you mean you want the content of the box to be markdown ? Using raw LaTeX would prevent that.

Quarto has some built in callout out blocks (Quarto - Callout Blocks) and we use tcolorbox internally. It may not suit you style, but at least there is a common markdown syntax for it between PDF and HTML. Those are implemented using Lua filters, which allows to use Markdown syntax in the block ?

Hopefully, with more information, I can try to answer more precisely. Thanks


Thanks, using LaTeX code inside .md works nicely.
That's right, my problem is that I want to write text in markdown outside RStudio (using Typora) and I am using quarto from RStudio to compile markdown text and then some .qmd files with R code. Callouts blocks don't seem to fit in Typora as it traslates badly when included, LaTeX code works perfectly, not when inserted as a markdown code block but as raw text in file.
I have been able to manage .md, .qmd and .tex includes quite well. Image in .md files is a bit more complicated to position without quarto blocks, using LaTeX by now. I keep exploring!


This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.