Witiko / markdown

:notebook_with_decorative_cover: A package for converting and rendering markdown documents in TeX
http://ctan.org/pkg/markdown
LaTeX Project Public License v1.3c
332 stars 31 forks source link

Include a markdown style mermaid diagram inside a LaTeX source #448

Open anubane opened 5 months ago

anubane commented 5 months ago

I love to write in LaTeX for creating publish-quality documents. However, for quick note taking and diagramming, I prefer markdown due the the ease of use.

The problem that I face is how to include the diagrams I have made in markdown into my LaTeX source? To give a concrete example, consider the following two file:

  1. test.md
## This is a mindmap diagram
I use mindmap diagrams for aiding thought building. In mermaid I would write it like this:
```mermaid
mindmap
    root )base-idea(
        sub<br/>idea 1
            ((?))
        sub<br/>idea 2
            ((?))
        sub<br/>idea 3
            ((?))
        sub<br/>idea 4
            ((?))
```
  1. test.tex
\documentclass[a4paper]{article}
\usepackage[]{markdown}

\markdownSetup{}    % We can include 'mermaid' as a setup option?

\begin{document}
    \begin{markdown}
        ## This is a mindmap diagram
        I use mindmap diagrams for aiding thought building. In mermaid I would write it like this:
        ```mermaid
        mindmap
            root )base-idea(
                sub<br/>idea 1
                    ((?))
                sub<br/>idea 2
                    ((?))
                sub<br/>idea 3
                    ((?))
                sub<br/>idea 4
                    ((?))
        ```
    \end{markdown}
\end{document}

As of now, I am using latexmk command to compile my .tex file, and it is simply showing the mermaid code as, well, code.

How can I have the mermaid diagram render inside the LaTeX generated pdf?

Witiko commented 5 months ago

Hi and thanks for using the Markdown package. In order to add support for mermaid diagrams, you would need to run a command such as mmdc that would render each diagram, similar to how the theme witiko/dot typesets GraphViz diagrams:

image

See also the implementation of the theme witiko/dot and another example of how you would use it. Hopefully, you should be able to adapt it to mermaid diagrams with little effort. Please, feel free to ask if anything is unclear!