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

[BUG] Octave Plotting Syntax #391

Open
trackpadcad opened this issue Dec 16, 2024 · 2 comments
Open

[BUG] Octave Plotting Syntax #391

trackpadcad opened this issue Dec 16, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@trackpadcad
Copy link

trackpadcad commented Dec 16, 2024

Describe the bug
When using Octave's plot() function, fields like title() don't work if declared after the plot() command, but do in Octave.

Software Version
Windows 11 23H2, Execute Code v2.0.0, Obsidian v1.7.7.

To Reproduce
Steps to reproduce the behavior:
Run the following code:

x = -10:0.1:10;
figure
hold on
plot (x, sin(x));
title('title');
hold off

Observe the difference compared to (declaring the title field before the plot command):

x = -10:0.1:10;
figure
hold on
title('title');
plot (x, sin(x));
hold off

Expected behavior
Adds "title" text above the plot

Screenshots
The bugged output
image
The correct output
image

Additional context
I'm assuming this stems from grabbing the figure as soon as the plot command is executed instead of waiting for the hold off signal.
Running sequential plot commands seems to support this theory. The only graph that should display is the second one.

x = -10:0.1:10;
figure
hold on
title('title');
plot(x, sin(x));
plot(x, cos(x));
hold off

image

@trackpadcad trackpadcad added the bug Something isn't working label Dec 16, 2024
@trackpadcad
Copy link
Author

Good news! I've (tentatively) found a fix, by changing the regex for octave to "hold off" (previously the plot command). I did this by directly editing main.js in my obsidian plugins folder, but editing src/transforms/Magic.ts should work too.
var OCTAVE_PLOT_REGEX = /^hold off/gm;

@trackpadcad
Copy link
Author

trackpadcad commented Dec 17, 2024

This line works better (than the original /^plot\s*\(.*\);/gm;)
var OCTAVE_PLOT_REGEX = /^figure\(.*\);\s(\s|.)*?\s(hold off)$/gm;
This will look for

figure(something);
something
hold off

and do so non-greedily (shortest path) so it won't consume

figure(something);
something
hold off
figure(something);
something
hold off

as one match

This runs into an issue where it plots the first figure twice however, which I'm working on
Edit: you need to replace

const tempFile = `${os.tmpdir()}/temp_${Date.now()}.png`.replace(/\\/g, "/");

with

const tempFile = `${os.tmpdir()}/temp_${Date.now()}_${Math.random().toString(36).substr(2, 9)}.png`.replace(/\\/g, "/");

in the addInlinePlotsToOctave function, or something else that ensures the temp file names are different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant