Add a custom latex command to be used with pandoc/markdown

markdownpandoc

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

Best Answer

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.

Related Question