2

In Markdown, use a pair of ``` to block quotes,

enter image description here

How can I achieve it in LaTeX?

I use the packet csquotes and encounter two questions:

  • how to remove double quotes
  • how to add background color
  • Strange: I know ``` to start and end a code block… – clemens Sep 4 '15 at 16:50
  • For those not intimately familiar with markdown, can you elaborate on how one should interpret single and double backticks, as compared with the triple-backtick? – Steven B. Segletes Sep 4 '15 at 16:51
  • Actually I believe markdown itself doesn't make any blocks with backticks but only <code>/</code> pairs. The triple-tic introducing a code block is part of the GitHub-flavored markdown. The triple-tic for a blockquote may be some other flavor? – clemens Sep 4 '15 at 17:18
  • csquotes has its own facilities to create block quotations if a quoted string is longer than a specified length, which you can adjust. Otherwise you can use quote or quotation environment from standard LaTeX. Adding the colorbox would be an extra customization, though. – musarithmia Sep 4 '15 at 17:23
  • @spark, Did you find something easier? Even something for just one word. – Royi Jun 5 '16 at 22:33
6

For the color part of the problem, I used a tcolorbox approach as given in the answer to this question: Change background color for text block

For the markdown parsing one can borrow and adapt from my answer at Use Markdown-style formatting for bold and italic.

Here I interpret triple backticks as delimiters for a myquote environment, using the macro \triplequote. Not knowing from your question how to interpret single and double backticks, I merely show how they are parsed, using placeholders defined in the macros \singlequote and \doublequote.

The macros \quoteON and \quoteOFF are used to enable and disable the active parsing.

\documentclass{article}
\usepackage[most]{tcolorbox}
\definecolor{block-gray}{gray}{0.85}
\newtcolorbox{myquote}{colback=block-gray,grow to right by=-10mm,grow to left by=-10mm,
boxrule=0pt,boxsep=0pt,breakable}
\makeatletter
\def\quoteparse{\@ifnextchar`{\quotex}{\singlequote}}
\def\quotex#1{\@ifnextchar`{\triplequote\@gobble}{\doublequote}}
\makeatother
\def\singlequote#1`{[StartQ]#1[EndQ]\quoteON}
\def\doublequote#1``{[StartQQ]#1[EndQQ]\quoteON}
\long\def\triplequote#1```{\begin{myquote}\parskip 1ex#1\end{myquote}\quoteON}
\def\quoteON{\catcode``=\active}
\def\quoteOFF{\catcode``=12}
\quoteON
\def`{\quoteOFF \quoteparse}
\quoteOFF
\begin{document}
\quoteON
This is a `test of single quoted` material 
and this is a ``test of double quoted material``, and this
is the test of a ```triple quoted material. We will make it long
enough to test line wrapping and we will even\\
add a manual linebreak.

Even a new paragraph.```  Resuming normal text.

\quoteOFF
Here should be triple backticks ```xxx```
\end{document}

enter image description here

Once it is known how single-quoted and double-quoted material should behave, those macros can be adjusted to implement it.

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.