pandoc-ext / diagram

Generate diagrams from embedded code; supports Mermaid, Dot/GraphViz, PlantUML, Asymptote, and TikZ.
MIT License
53 stars 9 forks source link

Change mermaid output from svg (bug) to pdf #1

Closed lsignac closed 1 year ago

lsignac commented 1 year ago

Continuation of https://github.com/pandoc/lua-filters/pull/266 svg output does not work for graphs so the mermaid filter has been changed to produce pdf output instead.

tarleb commented 1 year ago

Thanks. It's surprising that this would be necessary, I'll take a closer look.

The old code should be removed instead of commented out. We'll also have either install Inkscape for the Mermaid CI tests, or switch to LaTeX as the output format for those tests.

lsignac commented 1 year ago

Sorry for old code. I just forgot to remove it.

For the svg problem... I thought it was related to https://github.com/mermaid-js/mermaid-cli/issues/112. But I am not sure anymore...

I tested with this file :

test.md

Document is compiled to pdf with :

pandoc --lua-filter diagram_without_my_PR.lua test.md -t latex -o test.pdf

In the PDF result values 1 and 2 do not appear in the nodes.

But with :

pandoc --lua-filter diagram_with_my_PR.lua test.md -t latex -o test.pdf

Then, values 1 and 2 appear.

BUT... ( :) )

If I manually compile the mermaid graph to svg (mmdc --input graph.mmd --output graph.svg)

graph TD
      A["1"]
      B["2"]
      A --> B

The resulting graph.svg seems OK in firefox (1 and 2 printed inside nodes).

Then I do :

---
title: Sample file 2
---

![](graph.svg)

and compile this file with pandoc... and numbers have disappeared. So may be the problem is related to the way pandoc processes svg...

tarleb commented 1 year ago

I checked and indeed, this seems to be a PDF-to-SVG conversion issue. I'll modify the code and pass an indicator to the generator that indicates whether is should prefer PDF over SVG. That should fix it.

tarleb commented 1 year ago

I didn't like the PDF output produced by mermaid, so the filter opts for PNG output when PDF/LaTeX is the targeted output format.

lsignac commented 1 year ago

You didn't like ? It seemed to me that images were exactly the same, except that you can not zoom PNG indefinitely and you wll have to finely tune resolution to get a high quality printed document without generating 100Meg pngs. Just to be sure, can you explain what's wrong with PDF output ?

tarleb commented 1 year ago

pdf-mermaid.pdf png-mermaid.pdf

tarleb commented 1 year ago

I see now that you included the -f flag in the PR. That should fix it.

lsignac commented 1 year ago

Oh yes. Please, add the -f flag and keep pdf output that is better quality than png. I hope the issue with svg (mermaid or pandoc...) will be addressed soon and that it will be safe for your filter to fall back to svg everywhere. Thank you.

tarleb commented 1 year ago

Already done :slightly_smiling_face: