LaurentRDC / pandoc-plot

Render and include figures in Pandoc documents using your plotting toolkit of choice
https://laurentrdc.github.io/pandoc-plot/
GNU General Public License v2.0
224 stars 8 forks source link

Plot using MATLAB does not work #27

Closed kele14x closed 3 years ago

kele14x commented 3 years ago

Hi,

I'm trying to use pandoc-plot as pandoc filter to generate plot figure with MATLAB, however ERROR is returned.

Command line:

pandoc --filter pandoc-plot -i .\input.md -o output.html
[pandoc-plot] ERROR | Running command
[pandoc-plot] ERROR |     matlab.exe  -batch "run('C:\Users\<username>\AppData\Local\Temp\pandocplot1453168419.m')"
[pandoc-plot] ERROR | ended with exit code ExitFailure 1
[pandoc-plot] ERROR | *******
[pandoc-plot] ERROR | Error using exportgraphics
[pandoc-plot] ERROR | The value of 'destination' is invalid. Cannot create output file 'plots\13451727385949682572.png'.
[pandoc-plot] ERROR |
[pandoc-plot] ERROR | Error in pandocplot1453168419 (line 11)
[pandoc-plot] ERROR |     exportgraphics(gcf, 'plots\13451727385949682572.png', 'Resolution', 80);
[pandoc-plot] ERROR |
[pandoc-plot] ERROR | Error in run (line 91)
[pandoc-plot] ERROR | evalin('caller', strcat(script, ';'));
[pandoc-plot] ERROR |
[pandoc-plot] ERROR | ERROR: MATLAB error Exit Status: 0x00000001
[pandoc-plot] ERROR |
[pandoc-plot] ERROR | *******
[pandoc-plot] ERROR | Command "matlab.exe  -batch "run('C:\Users\<username>\AppData\Local\Temp\pandocplot1453168419.m')"" failed with exit code 1. The script source was:
[pandoc-plot] ERROR |
[pandoc-plot] ERROR | 1 > % Generated by pandoc-plot 1.2.2
[pandoc-plot] ERROR | 2 >
[pandoc-plot] ERROR | 3 > x  = 0: .1 : 2*pi;
[pandoc-plot] ERROR | 4 > y1 = cos(x);
[pandoc-plot] ERROR | 5 > y2 = sin(x);
[pandoc-plot] ERROR | 6 >
[pandoc-plot] ERROR | 7 > figure
[pandoc-plot] ERROR | 8 > plot(x, y1, 'b', x, y2, 'r-.', 'LineWidth', 2)
[pandoc-plot] ERROR |

input.md:

```{.matlabplot caption="This is a simple figure with a **Markdown** caption"}
x  = 0: .1 : 2*pi;
y1 = cos(x);
y2 = sin(x);

figure
plot(x, y1, 'b', x, y2, 'r-.', 'LineWidth', 2)


Seems that when MATLAB running the line `exportgraphics(gcf, 'plots\13451727385949682572.png', 'Resolution', 80);`, it tries to put the **png** file under **%TEMP%** folder. Since there is no folder **plots** exists, MATLAB return a error. But pandoc-plot expect MATLAB output it with **md** file, so create **plots** folder alone with **md**.

Versions:

- pandoc-plot 1.2.2
- pandoc: 2.14.0.1
- MATLAB: 9.10.0.1602886 (R2021a)
LaurentRDC commented 3 years ago

Hello,

Let me download MATLAB R2021a and make sure I can reproduce the bug. Stay tuned!

LaurentRDC commented 3 years ago

Indeed, I was able to reproduce the error. The problem is that MATLAB changes the working directory before executing external scripts. I don't know if this behavior has changed in recent years?

In any case, this has been fixed in the latest commit (87b7f39). Once tests have passed, I will create a new release (1.2.3) which should be available by the end of the day.

LaurentRDC commented 3 years ago

@kele14x Please try the new version (1.2.3) and tell me if your problem has been resolved. Thanks!

kele14x commented 3 years ago

Hi @LaurentRDC,

Thanks for your investigating. The issue has been fixed. Now I can generate right figure with MATLAB.

I'm not sure when MATLAB change the behavior since I rarely run it in batch mode. But absolute path should work more solid.

Thanks.