[Tex/LaTex] Background color of Markdown blocks

colormarkdown

I want to be able to insert Markdown text in a LaTeX document with a simple macro, and I want that text to always have a specific background color (e.g. light gray).

I tried using the markdown package some of the solutions listed below without luck:

I think the challenge that I am facing is that markdown is itself a block.

Here's a MWE where I am trying to use a custom background color for the Markdown block (e.g. light gray).

Ideally the solution is some sort of macro, e.g. mymarkdown.

\documentclass{article}

\usepackage{markdown}

\usepackage{lipsum}  

\begin{document}

\lipsum[1]

\begin{markdown}
This is now inside Markdown

## Here is a Markdown list
+ Create a list by starting a line with `+`, `-`, or `*`
+ Sub-lists are made by indenting 2 spaces:
  - Marker character change forces new list start:
    * Ac tristique libero volutpat at
    + Facilisis in pretium nisl aliquet
    - Nulla volutpat aliquam velit
+ Very easy!

## Here are some Markdown blockquotes
> Blockquotes can also be nested...
>> ...by using additional greater-than signs right next to each other...
> > > ...or with spaces between arrows.][1]][1]


\end{markdown}

This is now outside of Markdown
\begin{itemize}
    \item Item 1
    \item Item 2
    \item Item 3
\end{itemize}
\end{document}

enter image description here

Best Answer

You can use tcolorbox and coerce markdown into opening a tcolorbox before doing its business, issuing \end{tcolorbox} at the end.

Add the desired options to the starting \begin{tcolorbox} (look at the very detailed manual).

\documentclass{article}

\usepackage{markdown}
\usepackage{tcolorbox}
\usepackage{etoolbox}

\pretocmd{\markdown}{\begin{tcolorbox}}{}{}
\def\endmarkdown{\end{tcolorbox}}

\usepackage{lipsum}

\begin{document}

\lipsum[1]

%\begin{tcolorbox}
\begin{markdown}
This is now inside Markdown

## Here is a Markdown list
+ Create a list by starting a line with `+`, `-`, or `*`
+ Sub-lists are made by indenting 2 spaces:
  - Marker character change forces new list start:
    * Ac tristique libero volutpat at
    + Facilisis in pretium nisl aliquet
    - Nulla volutpat aliquam velit
+ Very easy!

## Here are some Markdown blockquotes
> Blockquotes can also be nested...
>> ...by using additional greater-than signs right next to each other...
> > > ...or with spaces between arrows.][1]][1]


\end{markdown}
%\end{tcolorbox}

This is now outside of Markdown
\begin{itemize}
    \item Item 1
    \item Item 2
    \item Item 3
\end{itemize}
\end{document}

enter image description here