Copy link to clipboard
Copied
For those who looking for, script to insert Latex Math into InDesign as SVG
http://glebosipov.com/latex-svg/
Copy link to clipboard
Copied
Very clever.
Who runs the web site?
P.
Copy link to clipboard
Copied
Wow! Very cool! Thanks for sharing this, Gleb.
On my side -- on Windows -- this line throws an error:
var svgFileName = latexCode.replace("/[^\w\d]/g", '');
because it fails to make a valid file name from a formula.
I suggest changing it to, say, a prefix plus a randomly generated number, like so:
var randomNum = Math.random();
randomNum = String(randomNum);
randomNum = randomNum.replace(/^0\./g, "LtxEqtn_");
var svgFileName = randomNum;
I think it's hardly possible that the same number would be generated twice overwriting an existing formula.
Or, even better a unique date string: up to secs.
Copy link to clipboard
Copied
Store the LaTeX code with the image on the page.
When the image is selected, load the LaTeX code into the palette.
Store baseline / position offsets for the image.
Loads of cools stuff.
Copy link to clipboard
Copied
Sorry man, didn't cheked on Windows, working on Mac. Nice idea and advise, thank you, will fix it!
Copy link to clipboard
Copied
Or, even better a unique date string: up to secs.
Hi @Gleb Osipov , As @Kasyan Servetsky suggests, I use the current time in millisecs for generating unique names:
var n = "Prefix_" + new Date().getTime();
Copy link to clipboard
Copied
Sorry man, didn't cheked on Windows, working on Mac. Nice idea and advise, thank you, will fix it!
Copy link to clipboard
Copied
I get a different error message: 'Failed to connect to latex.codecogs.com'.
Copy link to clipboard
Copied
Try to open in browser latex.codecogs.com maybe it's blocked by provider, that why it's give you that message
Copy link to clipboard
Copied
The site opens without any problem.
Copy link to clipboard
Copied
I'm using this library github.com/grefel/restix to connect script to internet, maybe problem in it 🤔
Copy link to clipboard
Copied
This looks great @Gleb Osipov, thanks for sharing!
Could you add a check for when the active document has never been saved?
- Mark
Copy link to clipboard
Copied
Good remark, thanks, I will add
Copy link to clipboard
Copied
Pickory raises a good point: you need the equation's baseline so that when it's placed as an inline equation, e.g. 'ln', 'x', and 'C' sit on the baseline of the line it's on. Without baseline information, the SVG sits too high, with its bottom on the line's baseline.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
This is in the EPS - when generated by MathMagic and others:
Highlited line is used by all kind of scripts to re-position linked image file vertically.
Copy link to clipboard
Copied
Take a look at this thread. The required properties are outlined there (just ignore the bits about padding, they're not relevant).
Alternatively, add the baseline value to the file name so that each user can use their own method to align the equation. I would prefer that, in fact.
Copy link to clipboard
Copied
Not sure about the Mac's side - don't know the environment - but if you are interested, the Window's part can be literally converted to just two lines of code.
Copy link to clipboard
Copied
Wonderful. Would be even more wonderful if user can select Inline or Block. One can select on the editor page. https://editor.codecogs.com/
Copy link to clipboard
Copied
Do you have user instructions? I can't get it to produce anything at all in InDesign.