mermaid-filter icon indicating copy to clipboard operation
mermaid-filter copied to clipboard

format svg option disappears text

Open fdq09eca opened this issue 3 years ago • 6 comments

```{.mermaid width=300 format=svg}
graph TD
   a((3, 1)) --> b 
   a((3, 1)) --> d 
   b((3, 2)) --> c 
   b((3, 2)) --> e 
   d((2, 1)) --> g
   c((3, 3)) --> f[2, 3]
   g((1, 1)) --> h 
   e((2, 2))
   h((1, 2)) --> i[1, 3] 
```

the above code snippet produces the following when I turn it into .pdf with the following pandoc cmd:

pandoc 2018-19-v1.md --pdf-engine=pdflatex -o 2018-19v1.pdf --filter mermaid-filter

image

the following mermaid produces the diagram normally with the same pandoc cmd

```mermaid
graph TD
   a((3, 1)) --> b %% 1
   a((3, 1)) --> d %% 1
   b((3, 2)) --> c %% visit b 1st then d becoz b cost < d cost
   b((3, 2)) --> e 
   d((2, 1)) --> g
   c((3, 3)) --> f[2, 3]
   g((1, 1)) --> h %% visit g 1st then e: becoz g_x < e_x
   e((2, 2))
   h((1, 2)) --> i[1, 3] %% visit i 1st then f becoz h_x < f_x
```

image

fdq09eca avatar Apr 28 '21 09:04 fdq09eca

I see the same issue when using the svg option for any graph that requires text.

john-d-murphy avatar Sep 26 '21 21:09 john-d-murphy

@fdq09eca For now, as a workaround you can use format=pdf. It did the trick for me.

mesaquen avatar Nov 16 '21 14:11 mesaquen

gitGraph the same problem with format=svg

26huitailang avatar Dec 07 '21 02:12 26huitailang

@fdq09eca For now, as a workaround you can use format=pdf. It did the trick for me.

I just tried format=pdf and got error with --pdf-engine=xelatex, I got it working by patching the filter manually and I think it's might help someone else.

Error producing PDF.
! Unable to load picture or PDF file '/private/var/folders/79/y1_gqzxx47g93kdrt
1lryp740000gn/T/tmp.z11Cdyupv8/tex2pdf.-6291c7ad0e584f21/928567e026eb8398e14a84
84a8c4677a81bf400c.png'.
<to be read again>
                   }
l.894 ...67e026eb8398e14a8484a8c4677a81bf400c.png}

It seems that patching the filter it works by passing the pdf path directy(Start at line 83):

    if (options.loc == 'inline') {
        if (options.format === 'svg') {
            var data = fs.readFileSync(savePath, 'utf8')
            newPath = "data:image/svg+xml;base64," + new Buffer(data).toString('base64');
        } else if(options.format === 'pdf'){
            newPath = savePath;
        }
        else  {
            var data = fs.readFileSync(savePath)
            newPath = 'data:image/png;base64,' + new Buffer(data).toString('base64');
        }

Menchen avatar Dec 16 '21 17:12 Menchen

@fdq09eca For now, as a workaround you can use format=pdf. It did the trick for me.

Thanks! This worked for me, but only after changing it from the default inline location to a folder by adding loc=figures.

andreilgeorgescu avatar Nov 07 '23 22:11 andreilgeorgescu