• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
12

Latex to SVG / InDesign Script

Community Beginner ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

For those who looking for, script to insert Latex Math into InDesign as SVG

http://glebosipov.com/latex-svg/ 

 

preview.png

 

TOPICS
Experiment , Scripting

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

Very clever.

 

Who runs the web site?

 

P.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 04, 2024 Mar 04, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 04, 2024 Mar 04, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

Sorry man, didn't cheked on Windows, working on Mac. Nice idea and advise, thank you, will fix it!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2024 Mar 04, 2024

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();

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

Sorry man, didn't cheked on Windows, working on Mac. Nice idea and advise, thank you, will fix it!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

I get a different error message: 'Failed to connect to latex.codecogs.com'.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 04, 2024 Mar 04, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

The site opens without any problem.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 05, 2024 Mar 05, 2024

Copy link to clipboard

Copied

I'm using this library github.com/grefel/restix to connect script to internet, maybe problem in it 🤔

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2024 Mar 04, 2024

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?

Screenshot 2024-03-05 at 10.49.35.png

 

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

Good remark, thanks, I will add

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2024 Mar 05, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 05, 2024 Mar 05, 2024

Copy link to clipboard

Copied

but if SVG inside the text block with the baseline what properties I shoud give it to? Otherwise it's aligned by the bottom line

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2024 Mar 05, 2024

Copy link to clipboard

Copied

@Gleb Osipov 

 

This is in the EPS - when generated by MathMagic and others:

 

RobertTkaczyk_0-1709651101643.png

 

Highlited line is used by all kind of scripts to re-position linked image file vertically.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2024 Mar 05, 2024

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).

 

https://community.adobe.com/t5/indesign-discussions/how-to-avoid-empty-space-in-the-inside-of-the-eq...

 

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2024 Mar 05, 2024

Copy link to clipboard

Copied

@Gleb Osipov

 

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. 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 10, 2024 Mar 10, 2024

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/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 02, 2024 Aug 02, 2024

Copy link to clipboard

Copied

LATEST

Do you have user instructions? I can't get it to produce anything at all in InDesign.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines