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

How to avoid empty space in the inside of the equations

Participant ,
Feb 29, 2024 Feb 29, 2024

Copy link to clipboard

Copied

Dear Team,

 

I need to avoid the empty boundary space around equations inside the frame. I have to exactly fit the equation such that there is no white space. Can you provide or suggest any script related to this request?

Please advise.

 

Or any option available in the mathtype to fix this issue?

 

Please see the screenshot for your reference below:

 

kanagakumar_0-1709272424748.png

 

Thanks

kanagakumar

TOPICS
Scripting

Views

3.0K

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

correct answers 1 Correct answer

Community Expert , Mar 08, 2024 Mar 08, 2024

Hi @kanagakumar and others, really you guys have worked out the hard parts already. So I've written a script that uses your insights, and hopefully this will do what you want.

 

I have assumed that the equations are all eps graphics that are anchored in text. I've included options to set a uniform scale for the equations, and also to fit the frame to the content—this is critical, otherwise the baseline might not be correct.

 

Give it a try and let me know how you go.

- Mark

 

Example, using scal

...

Votes

Translate

Translate
Community Expert ,
Mar 09, 2024 Mar 09, 2024

Copy link to clipboard

Copied

You are right, Robert. Still, if it were my task, I would do this step first anyway—after all I assume they would want the baselines to align. Therefore any cropping required will only be on the left and right sides and, because the script fits frame to content,  it means that if OP decides that the equations need a consisent amount added or subtracted from the sides, than the script can accommodate easily.

- 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 Expert ,
Mar 09, 2024 Mar 09, 2024

Copy link to clipboard

Copied

quote

You are right, Robert. Still, if it were my task, I would do this step first anyway—after all I assume they would want the baselines to align. Therefore any cropping required will only be on the left and right sides and, because the script fits frame to content,  it means that if OP decides that the equations need a consisent amount added or subtracted from the sides, than the script can accommodate easily.

- Mark


By @m1b

 

That wasn't my point. 

 

But to be fair - I see a benefit in your approach - AnchoredObjectSettings instead of Character's BaselineShift. Probably quite significant in some situations. 

 

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 09, 2024 Mar 09, 2024

Copy link to clipboard

Copied

quote

[...] it means that if OP decides that the equations need a consisent amount added or subtracted from the sides, than the script can accommodate easily.


By @m1b

 

If it would be so easy to just crop few pixels on the right & left for all equations in the document - it would've been done long time ago and OP wouldn't ask about that.

I've done it long time ago - 2009:

RobertTkaczyk_0-1709989872139.png

 

 

But there are at least two methods to precisely crop equations.

 

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 09, 2024 Mar 09, 2024

Copy link to clipboard

Copied

Hi Mark, Thanks for the code.

I wonder if an alternative would be a Place script? The eps files have to get placed at some point, and on a place I don’t think you have to worry about the scale and parent bounds because we know the placed scale will be 100%, and the eps and its container frame will have matching bounds. You could also get the surrounding text range and set tracking or apply a Character style to handle the left right spacing. Something like this:

 

var s= app.activeDocument.selection[0];

if (s.parent.hasOwnProperty("baselineShift")) {
	var e = File.openDialog("Select an EPS to Place", "");
    if (e!= null) {
        s.place(e);
        //baseline shift the placed eps
        s.parent.characters[s.index-1].baselineShift = -getBaselineOfEPS(e);

        //optionally track the text range before and after to adjust the left and right spacing
        var tr = s.parent.texts.itemByRange(s.parent.characters[s.index-2], s.parent.characters[s.index]);
        tr.tracking = -50;
    } 
}else{
    alert("Please Select an EPS to Insert")
} 

/**
 * Returns the `baseline` value
 * from the EPS file.
 * @ author Peter Kahrel
 * @ author Rob Day
 * @ author m
 * @ version 2024-03-09
 * @ param eps file path
 * @ returns {Number} - the baseline extracted from the file.
 */

function getBaselineOfEPS(f) {
    f.encoding = 'BINARY';
    f.open('r');
    var str = f.read();
    f.close();
    try {
        return Number(str.match(/%%Baseline:\s(\d+)/)[1] || 0);
    }catch(e) {
        alert("The Placed File Has No Baseline Info")
        return 0
    }  
};

 

 

 

Before after:

 

Screen Shot 25.pngScreen Shot 26.png

 

 

 

Screen Shot 26.png

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 09, 2024 Mar 09, 2024

Copy link to clipboard

Copied

@rob day Looks great! And we would definitely want a version for cases where the equations weren't already anchored in the story.

 

In most cases I would prefer to adjust the anchored object settings rather than baselineShift, but that's just me.

- 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
Participant ,
Mar 10, 2024 Mar 10, 2024

Copy link to clipboard

Copied

Dear m1b,

 

This script perfectly aligns the base-align, but the left and right sides show extra space due to the empty space in the inside of the equations (padding space).

 

This case only i'm doing maull work now. It is excellent script.

kanagakumar_1-1710129781860.png

 

   kanagakumar_0-1710129708732.png

Thank you very much "Mark"

 

Thanks

kk

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 11, 2024 Mar 11, 2024

Copy link to clipboard

Copied

You can add tracking before and after the equation. Should be easy to add to the script, but you can do it in the interface as well with two GREP queries:

 

Find what: .(?=~a)

Change to: <Leave empty>

Change format: some negative tracking

 

Find what: ~a\K.

Change to: <Leave empty>

Change format: some negative tracking

 

 

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 11, 2024 Mar 11, 2024

Copy link to clipboard

Copied

That one is unnecessarily complicated. One query will do it, it applies tracking to any character  followed by an inline followed by any character. It also works at the end of a paragraph:

 

Find what: .~a

Change to: <Leave empty>

Change format: some negative tracking

 

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
Participant ,
Mar 11, 2024 Mar 11, 2024

Copy link to clipboard

Copied

Thanks for your coding Mr. Peter Kahrel

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 11, 2024 Mar 11, 2024

Copy link to clipboard

Copied

@kanagakumar I have edited my script above to include settings for "leftSidebearing" and "rightSideBearing"—these are the offsets (in points) on left and right sides of each equation. Try it out.

- 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
Participant ,
Mar 11, 2024 Mar 11, 2024

Copy link to clipboard

Copied

Dear Mark,

 

Thank you very much for your coding.

 

After the script was executed, below the display equations merged into the paragraph lines. I need two pica of visual space for the display equations below only.  Inline questions no issues.

 

Display equations are controlled by the paragraph styles:

EQ, EQ-f, EQ-m, EQ-l

 

kanagakumar_0-1710218172518.png

 

My requirement:

kanagakumar_1-1710218636274.png

Thanks

kk

 

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 11, 2024 Mar 11, 2024

Copy link to clipboard

Copied

Hi @kanagakumar, I just need to get the script to know which is which. It looks like if the anchored item is the first character of a paragraph then it is a "display" equation. Is that correct? Can you please share that large equation .eps and a little demo text .indd? It would help.

- 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 Expert ,
Mar 11, 2024 Mar 11, 2024

Copy link to clipboard

Copied

Hi @kanagakumar, I have updated the script above to try to handle "display" equations, assuming—for now—that these are equations that follow a carriage return or forced line break character.

You should make an Object Style for each type of equation, that at least has the Anchored Object Settings. These are what I suggest:

Screenshot 2024-03-12 at 17.18.28.pngScreenshot 2024-03-12 at 17.18.13.png

Do you see where is says 2pt space after? You can change that to your needs.

 

Let me know if I have guessed correctly and that it works the way you want.

- 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
Participant ,
Mar 12, 2024 Mar 12, 2024

Copy link to clipboard

Copied

Dear Mark,

 

Yes, Correct. Your script adjusts the points in the anchor object panel.

 

Now i fixed the overlapping issue using in the object style "Text Wrap" option. And i will apply manaully this object style name  for each display equations.

 

Before style applied:

kanagakumar_0-1710239541247.png

 

After style applied (object style name -- "Eq-text Wrap"):

kanagakumar_1-1710239610541.png

 

Only the paragraph styles "EQ" and "EQ-l" will require this object style to be applied; No need to be applied globally. All of the issues have been resolved if this script add an object style name. Is it possible to apply this object style name to this script based on paragraph style name "EQ" and "EQ-l"?

 

Or how to add object style name "Eq-text Wrap" in the perticular paragraph styles "EQ" and "EQ-l"? Please advise.

 

Thanks

kk

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 12, 2024 Mar 12, 2024

Copy link to clipboard

Copied

Hi @kanagakumar, I have adjusted the script above. You can see the "isDisplayEquation" function now checks the applied paragraph style. If it is "EQ" or "EQ-I" then it will apply the object style you name in settings equationDisplayStyleName variable. I hope that makes sense.

- 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
Participant ,
Mar 12, 2024 Mar 12, 2024

Copy link to clipboard

Copied

Dear Mark,

 

The revised script is not executing in an object style, and the equation number is not aligned with the equation center.

 

Paragraph style:

kanagakumar_2-1710304014004.png

 

Object style is not applying:

kanagakumar_1-1710303931062.png

 

Thanks

kk

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 12, 2024 Mar 12, 2024

Copy link to clipboard

Copied

Can you send me a little demo .indd file with that text so that I can explain what is going wrong? For example in the script I used the ParagraphStyle names "EQ" and "EQ-I" and these must be exact or the script will not change them. There are a lot of factors that could be causing the problem, but if you post an example document I can test properly.

- 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
Participant ,
Mar 18, 2024 Mar 18, 2024

Copy link to clipboard

Copied

LATEST

Dear Mark,

 

Kindly apologize for the delayed response. Kindly see the attached recording file for your reference.

Little bit modified in my side. I need text wrap option inlude in this script directly.  No need to add obejct style request.

 

kanagakumar_0-1710763934415.png

 

After run the script equation 7.22 is not center align the equation number:

 

kanagakumar_1-1710764029130.png

 

Thanks

kk

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
Participant ,
Mar 10, 2024 Mar 10, 2024

Copy link to clipboard

Copied

Dear Mark,

 

Once again, I'm thankful. Your script reduces my lot of manual effort and increases efficiency.

 

Thanks

kk

 

 

 

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 12, 2024 Mar 12, 2024

Copy link to clipboard

Copied

 

@kanagakumar 

 

From the screenshots - you are working on a PC, right?

 

Would you need more options - greater control over individual equations and batch processing of INDD files?

 

And I can see that you work with XML, right?

 

 

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
Participant ,
Mar 12, 2024 Mar 12, 2024

Copy link to clipboard

Copied

Dear Robert,

Yes, I am working on a PC

This is an XML workflow in InDesign.

 

Thanks

kk

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 13, 2024 Mar 13, 2024

Copy link to clipboard

Copied

quote

Dear Robert,

Yes, I am working on a PC

This is an XML workflow in InDesign.


By @kanagakumar

 

Great. I'll send you a message on priv.

 

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 13, 2024 Mar 13, 2024

Copy link to clipboard

Copied

I'll send you a message on priv.

 

You might as well post it here. We all know what'll be 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 13, 2024 Mar 13, 2024

Copy link to clipboard

Copied

quote

I'll send you a message on priv.

 

You might as well post it here. We all know what'll be in it 🙂


By @Peter Kahrel

 

I've just asked what extra functionality he would need. 

 

Import of the equations and setting baseline have been done for years - but after that, with my tool, you can completely forget about using mouse and only use keyboard - so it's much faster and more convenient.

 

And if you add bulk processing of files... 

 

And sometimes, people don't get notifications about messages sent on priv - like me, I've everything set up correctly - yet I don't receive emails about private messages. 

 

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
Participant ,
Mar 14, 2024 Mar 14, 2024

Copy link to clipboard

Copied

Dear Robert,

Thank you for your support.

 

Thanks

kk

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