4

so I am using the popular Eisvogel template for my personal work. I basically type everything in markdown and use pandoc to convert it to a pretty pdf.

Using blockquotes ( > text ) results in a pretty bar. However I came across the desire to add more options of styles. Let's say I do not only want to use these block quotes for real quotes, but also for "information panels" or "alert panels". I'd love to have the option to somehow give a prefix or custom-tex command within my markdown file and have the proper box being displayed.

Lets say rather than having: > text which results in a good looking, grey box, with a dash on the left side, I'd like to have something like \alert > text so the box is being rendered in some red, rather than the original blockquote colour.

Sure, the syntax could look totally different, but I just need to find a way to customize this cool pandoc-latex stuff a bit more, preferrably with custom commands. I am a bit familiar with writing pure LaTeX, but using pandoc just goes way faster, since I am also taking notes within my markdown files.

Anyone got an idea?

cheers

2
  • Some loosely connected comments. 1) I tend to write a LaTeX "frame", a main document and then to include pandoc-converted separate content files into it. A Makefile helps to keep everything neat. 2) It is possible to escape to LaTeX with Markdown converters (at least with pandoc it is), even if it breaks somewhat the purpose of Markdown and simpler syntax. 3) Proper Markdown headers allow for custom imports and LaTeX code. Paired with template tweaks, things like using csquotes from usual "..." in Markdown is possible. (Yes, it should work out of the box, but it does not for me.) Commented May 8, 2022 at 0:09
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented May 8, 2022 at 4:47

3 Answers 3

3

Well, looking at the eisvogel template, it looks like it typesets blockquotes inside a special customblockquote environment defined using the mdframed package: see its documentation.

You can define new LaTeX commands for use with pandoc with a header-includes: yaml option. (Or in a separate file included with the -H command line flag.) One option I suppose would be to use such a command to redefine this environment. You'd have to redefine it back to the way the template defines it if you wanted to go back to normal

---
title: My Document
author: Someone
date: 7 May 2022
header-includes: |
    \definecolor{myred}{RGB}{245,20,20}
    \newcommand{\normalquote}{
        \definecolor{blockquote-text}{RGB}{119,119,119}
        \renewmdenv[rightline=false,
            bottomline=false,
            topline=false,
            linewidth=3pt,
            linecolor=blockquote-border,
            skipabove=\parskip]{customblockquote}
    }
    \newcommand{\redalert}{
        \definecolor{blockquote-text}{RGB}{240,240,240}
        \renewmdenv[
            linewidth=2pt,
            linecolor=black,
            leftmargin=10pt,
            rightmargin=10pt,
            backgroundcolor=myred,
            fontcolor=white,
            shadow=true,
            skipabove=\parskip]{customblockquote}
    }

...

This is some regular text.


> This is a regular quote.

\redalert
> This is a *very* red box with a shadow and light text.

\normalquote
> This is a normal blockquote again.

pandoc quote redefinition example

You could of course define as many such styles as you wanted.

Most likely if I knew more about pandoc filters and templates, there would be a more straightforward way, but this may work well enough for your purposes.

3
  • Marvellous, thank you! Do you think it would be possible to put the code you've written into the header-include yaml part, into the Eisvogel.latex file itself, so I don't have to copy & paste the "bloat" in the actual document? Either way, this already helps a lot!
    – mnqn
    Commented May 8, 2022 at 12:07
  • 1
    Probably, but I don't think it's a good idea to mess with an existing template unless you rename it. What I'd do, as I suggested in my answer, is put the stuff under "header includes" in a separate file. (header.tex) and then call pandoc with -H header.tex.
    – frabjous
    Commented May 8, 2022 at 14:20
  • Thank you a lot!
    – mnqn
    Commented May 8, 2022 at 14:47
4

Consider switch to quarto, that aim to be an evolutionary leap of R markdown. Maybe this is not a good idea if you are hooked to a custom template (I am not tested if it could be used asis in quarto, after some/many changes or not used at all), but otherwise quarto include some easy to use predefined "callouts":

mwe


The source (mwe.qmd):

---
format: pdf
---

## Callouts in Quarto

In Quarto (next generation of R markdown) you can use "callouts" 
to show predefined alert boxes. For PDF output, \LaTeX\   
`tcolorbox` package is used in the background automatically.


::: callout-note

There are five types of callouts: 
`note`, `tip`, `warning`, `caution` and   `important`. 

:::

::: callout-tip
## Tip with custom caption

This is an example of a tip with custom caption.

:::
    
::: callout-warning
foo
:::

::: {.callout-caution}
## Take care !  

foo

:::

::: callout-important
foo
:::

Note that in the "classical" R markdown you can use also custom blocks to produce different LaTeX environments. For instance, a simple tcolorbox could be:

::: {.tcolorbox data-latex="[title=Warning]"}
foo 
:::

But as you see, the syntax is a bit more complex even for a default box, and you are in charge of include the packages needed in the template, or the header-includes or so, and make more elaborate boxes will need some extra work (see the link), while in Quarto is just type the simple callout blocks. Moreover, these blocks cannot be exported to another formats, while Quarto's callouts are exported to HTML and DOCX tables that mimic very well the tcolorboxes.

2
  • Thank you for your answer, but since I am relying on markdown for multiple reasons, I do not intend to switch. Will keep that in mind, in case I need it some day.
    – mnqn
    Commented May 8, 2022 at 12:06
  • @mnqn Quarto is also markdown. Convert to Quarto a preexisting markdown or Rmarkdown file is as simple as rename the extension ( .md or .Rmd) to .qmd. Apart from this, note that output: pdf_document is simplified to format: pdf in the YALM header. From RStudio now you can now compile .md, .Rmd and .qmd files, so it is easy to check that is the same beast with another necklace.
    – Fran
    Commented May 8, 2022 at 22:02
0

Since the discussion seems to be leaning towards admonition blocks, I would suggest taking a look at Awesome Boxes:

https://www.nic.funet.fi/pub/TeX/CTAN/graphics/awesomebox/awesomebox.pdf

Easy to use, plays well with markdown and pandoc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .