artisticat1 / obsidian-tikzjax

Render LaTeX and TikZ diagrams in your notes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Export to PDF not always drawing

Anatoly03 opened this issue · comments

There is always buggy and random behavior with multiple tikz pictures and while displayed in the editing + reading view they are not always display in pdf export.

Screenshot 2023-07-11 at 16 51 44 Screenshot 2023-07-11 at 21 49 56

(That's how the PDF looks like, sometimes it won't render at all, you might be missing an 'await' somewhere)

I have a similar problem, but in my case the pdf does not even render the "loading circle" image; usually, the first 3 or 4 images get loaded and drawn to the pdf, and then what I get is just nothing; for example, in the following image we can see that the very first elements are indeed being drawn:
image.


Nonetheless, there always is a point after which the images stop being loaded; here's a comparison between the live preview (first image) and the exported pdf (second image):
image
image

I have an update regarding some experiments I've been making in order to try and pinpoint where the problem is;

  • I've tried emptying the cache from the settings, and after I did that I got a situation like yours, in which only the images which are usually drawn were actually replaced by the loading icon in the pdf; however, this only applied to the tikz elements which were already being drawn normally; all the other elements which were entirely skipped, kept getting skipped.
  • After that, I've also tried changing my theme from light to dark to light again; while this may not be connected at all, the result I got when trying to export a pdf after this juggling was that the first 7 tikz elements in my document were actually exported; I think this might somehow be related to the fact that in the meantime the elements were saved to the cache.

Suspecting that this export issue could be related to optimization procedures (e.g. tikz elements not being loaded and thus drawn on the pdf unless they are in view), I tried exporting the document while viewing only the very last element of the document, but the result I got was the exact same as the pdf produced by exporting while viewing the top of the document.
At the moment I suspect that the problem might reside in the fact that this plugin seems to have a script as its markdownCodeBlockProcessor, and I think that same script might be the one causing trouble (e.g. not being able to load elements in time thus leading to an empty export or something like this).

Sadly, I'm very unexperienced in js, ts and obsidian plugin developement in general, so I can't really do much else than speculate.

Still hope this can be of help for someone else who's maybe more skilled than me :)

Your last conclusions make sense, I wonder if it's possible to set a timer on export by printing which elapses after a safe amount of time and thus is rendered. Alternatively a better way I realise would be rather than rendering the image, embedding the cached image. This would mean no rendering is needed and you can write logic to apply to the codeblock only on printing. Having said this, I can't tell whether images are cached anymore, if so where are they cached and how?

I am having this exact same problem, i drew some circuits using the plugin to my document and was expecting to export it to print because i was doing some exercises, but when exporting the pdf, the majority of the diagrams didn't load at all, some loaded and got on the pdf but not all of them

image

Here it shows in left the note and on the right is the pdf, this first diagram did export on the diagram but some diagrams more below on the document didn't

image

Here you can see that this new diagram didn't even got exported.

When i first saw this plugin i felt it was a given to appear to me because it was my first exercise drawing circuits like this, and wanted to include this circuits o my notes in obsidian, and through this plugin it was possible, i'm very grateful, but i would appreciate even more if you could solve this issue.

Thank you so much for your work

@artisticat1 Could this be hot-fixed with a command that exports an alternate version of the file with the SVG files hard-linked in the document?

Was having this problem as well. The first graphic in my notes would export in the pdf but not the second. Switching to light mode and exporting to pdf worked.

Was having this problem as well. The first graphic in my notes would export in the pdf but not the second. Switching to light mode and exporting to pdf worked.

No way, never tried changing to light mode, and after reading your comment it worked on mine too. Thank you.

It's not the best way to solve the problem, because you have to add extra steps to the pdf export to work, if your theme is always dark like mine, but its seems the problem is around the dark mode.