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

Latex to SVG / InDesign Script

Community Beginner ,
Mar 04, 2024 Mar 04, 2024

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

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

 

preview.png

TOPICS
Experiment , Scripting
2.6K
Translate
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

Very clever.

 

Who runs the web site?

 

P.

Translate
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
Valorous Hero ,
Mar 04, 2024 Mar 04, 2024

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.

Translate
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

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.

Translate
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

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

Translate
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

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

 

Translate
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

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

Translate
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

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

Translate
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

Try to open in browser latex.codecogs.com maybe it's blocked by provider, that why it's give you that message

Translate
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

The site opens without any problem.

Translate
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

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

Translate
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

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

Translate
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

Good remark, thanks, I will add

Translate
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

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.

Translate
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

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

Translate
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
LEGEND ,
Mar 05, 2024 Mar 05, 2024

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

 

Translate
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

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.

Translate
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
LEGEND ,
Mar 05, 2024 Mar 05, 2024

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

 

Translate
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

Wonderful. Would be even more wonderful if user can select Inline or Block. One can select on the editor page. https://editor.codecogs.com/

Translate
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
LATEST

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

Translate
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