Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include mermaid graph in latexpdf #73

Open
LuisBL opened this issue May 9, 2021 · 3 comments
Open

include mermaid graph in latexpdf #73

LuisBL opened this issue May 9, 2021 · 3 comments

Comments

@LuisBL
Copy link

LuisBL commented May 9, 2021

With this simple test

$ tree
.
├── _build
├── conf.py
├── index.rst
├── Makefile
├── requirements.txt
├── _static
└── _templates
$
$ tail -1 conf.py
extensions = ['sphinxcontrib.mermaid']
$
$ cat index.rst                             
Test mermaid with `sphinx latexpdf`
====================================

Test mermaid with `sphinx latexpdf`

Try to render::

   graph TD
      A --> B --> C --> A

.. mermaid::

   graph TD
      A --> B --> C --> A

Mermaid rendered above ?
$ 
$ make html
...
$ firefox _build/html/index.html
$

Sélection_714

$ make latexpdf
...
$ evince _build/latex/mermaid_test.pdf `
$

Sélection_713

look's like the SVG is not added to the tex file::

$ tail -20 _build/latex/mermaid_test.tex
\pagestyle{normal}
\phantomsection\label{\detokenize{index::doc}}
Test mermaid with \sphinxtitleref{sphinx latexpdf}
Try to render:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{graph} \PYG{n}{TD}
   \PYG{n}{A} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZgt{}} \PYG{n}{B} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZgt{}} \PYG{n}{C} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZgt{}} \PYG{n}{A}
\end{sphinxVerbatim}

Mermaid rendered above ?
\renewcommand{\indexname}{Index}
\printindex
\end{document}(venv) 
$
@LuisBL LuisBL changed the title have mermaid with make latexpdf include mermaid graph in latexpdf May 9, 2021
@mapio
Copy link

mapio commented Sep 29, 2021

Have you installed https://github.com/mermaid-js/mermaid-cli? In my logs I've found an error related to a missing command.

If you don't want to install the command but use the dockerized version this script can help; save it and point to it with the mermaid_cmd option in your config.py (dont forget to also define mermaid_pdfcrop).

#!/bin/bash

in=$2
out=$4

wd=$(realpath $(pwd))
out=${out#$wd}
outdir=$(dirname $out)
infile=$(basename $in)

cp $in .$outdir/$infile
docker run --rm -v $wd:/wd -u $(id -u) minlag/mermaid-cli -i /wd$outdir/$infile -o /wd${out}

@qu710458643
Copy link

qu710458643 commented Nov 9, 2021

In windows,when you type where mmdc in cmd,you will get two results as follows:

D:\Software\node\mmdc
D:\Software\node\mmdc.cmd

so you should add mermaid_cmd = "D:\\Software\\node\\mmdc.cmd" into your conf.py, and add mermaid_pdfcrop = "path of your pdfcrop" into conf.py too.

@sgaechter
Copy link

As mentioned here, you can alternatively replace pdf with png at row257 in mernaid.py. This forces the rendering process to use 'PNG' files instead pdf's It's not the highest quality, but it's a workaround.
For this solution uncomment mermaid-pdfcrop to prevent some errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants