Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Oct 03, 2023 7:11 pm

I am currently using this code to display a formatted LaTex equation:
var officeMath = new OfficeMath(document);
officeMath.FromLatexMathCode(k_{n+1} = n^2 + k_n^2 - k_{n-1});
paragraph.Items.Add(officeMath);

I would like to know if there is a way to apply character formatting to the paragraph items so I can change the font, justification, and alignment of the equation. Using officeMath.ApplyCharacterFormat() does not apply any changes to the equation formatting.

nataliegracegibbons
 
Posts: 13
Joined: Tue Oct 03, 2023 4:45 pm

Wed Oct 04, 2023 12:41 pm

Hello,

Thanks for your inquiry.
I reproduce your issue with using officeMath.ApplyCharacterFormat(), for this issue, I need to communicate with our Dev team. However, our Mid Autumn Festival and National Day holidays from September 29th to October 6th, I’ll give you feedback after vacation. Sorry for inconvenience caused.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Sun Oct 08, 2023 6:39 am

Hello,

Thanks for your patience.
For the issue, I have logged it into our bug tracking system with the ticket number SPIREDOC-9933. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Wed Oct 18, 2023 2:25 am

Great, thank you.
Currently, is there anyway to format an equation such that is is left or right justified when it is added to the document?

nataliegracegibbons
 
Posts: 13
Joined: Tue Oct 03, 2023 4:45 pm

Wed Oct 18, 2023 3:01 am

Hello,

Thanks for your feedback.
There is indeed an alternative way to implement left-justified or right-justified equation before fixing this issue, you can first add a string (such as a space) in the paragraph where the equation is located, this operation will make it valid for paragraph alignment setting. I put the complete code below for your reference.
If you have any issues, just feel free to contact us.

Code: Select all
Document document = new Document();

            Paragraph paragraph = document.AddSection().AddParagraph();

            // Add a space to paragraph
            paragraph.AppendText(" ");

            var officeMath = new OfficeMath(document);
            officeMath.FromLatexMathCode("k_{ n + 1} = n ^ 2 + k_n ^ 2 - k_{ n - 1}");

            // Add equation to paragraph
            paragraph.Items.Add(officeMath);

            //Set the paragraph alignment to right
            paragraph.Format.HorizontalAlignment = HorizontalAlignment.Right;
            document.SaveToFile(@"../../output/result.docx", FileFormat.Docx);


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Wed Oct 18, 2023 4:03 pm

Thanks for your feedback. The horizontal alignment does not seem to apply when adding a paragraph to a cell in a data table. My code is something like this:

var table = section.AddTable();
table.ResetCells(2, 2);

var dataParagraph = table.Rows[0].Cells[0].AddParagraph();

dataParagraph.AppendText(" ");
dataParagraph.Items.Add(officeMath);
dataParagraph.Format.HorizontalAlignment = HorizontalAlignment.Left;

This does not justify the items to the left. Is there a cell or table format that needs to be applied?

nataliegracegibbons
 
Posts: 13
Joined: Tue Oct 03, 2023 4:45 pm

Thu Oct 19, 2023 1:44 am

Hi,

Thanks for your sharing.
I created a console project with Net Framework4.8 and the latest Version of Spire.Doc (V11.10.3) to test your scenario in Win10, but I can get excepted result document, I put my complete code below and attach the screenshot of result document for your reference.

Code: Select all
  Document document = new Document();

            Section section = document.AddSection();

            // Add a table that have border
            var table = section.AddTable(true);
            table.ResetCells(2, 2);

            Paragraph paragraph = table.Rows[0].Cells[0].AddParagraph();

            // Add a space to paragraph
            paragraph.AppendText(" ");

            var officeMath = new OfficeMath(document);
            officeMath.FromLatexMathCode("k_{ n + 1} = n ^ 2 + k_n ^ 2 - k_{ n - 1}");

            // Add equation to paragraph
            paragraph.Items.Add(officeMath);

            //Set the paragraph alignment to left
            paragraph.Format.HorizontalAlignment = HorizontalAlignment.Left;
            document.SaveToFile(@"../../output/result.docx", FileFormat.Docx);

Snipaste_2023-10-19_09-44-07.png

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Mon Dec 18, 2023 11:29 pm

Hello,
Is there a workaround to apply a specific font and text size to the LaTex equation once it has been converted to OfficeMath?

nataliegracegibbons
 
Posts: 13
Joined: Tue Oct 03, 2023 4:45 pm

Tue Dec 19, 2023 10:06 am

Hi,

Thank you for your feedback.
The issue of ineffective formula font style settings hasn’t been resolved yet. I have once again urged our Dev team and raised the priority of your issue. If there is any progress, I will inform you immediately. Please give us some time, we will do our best to help you.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Return to Spire.Doc