Hello,
I am using the following code with Syncfusion.DocIO.Wpf (24.1.41):
using WordDocument document = new WordDocument();
document.EnsureMinimal();
document.LastParagraph.AppendMath(@"A_{e} = A_g-(A_{ft})_{red}-(A_{fb})_{red}-(A_w)_{red} = 12.11");
document.Save(fileName);
And it appears to be formatting the equation box as LaTex in Word but it is not automatically displayed as Professional and clicking on the box and selecting "Professional" changes the equation into the desired formatting. Is it possible to force this professional display programatically?
Hi Natalie,
On further analysis, we found that the syntax for LaTeX is incorrect according
to Syncfusion DocIO, where the values for subscript and superscript should be
enclosed in curly braces. The syntax for subscript and superscript is as
follows:
|
Subscript |
{a}_{b} |
|
Superscript |
{a}^{b} |
Consequently, we have made modifications to the code snippet in order to properly display the professional equation.
|
using WordDocument document = new WordDocument(); document.EnsureMinimal(); document.LastParagraph.AppendMath(@"{A}_{e} = {A}_g-{({A}_{ft})}_{red}-{({A}_{fb})}_{red}-{({A}_{w})}_{red} = 12.11"); document.Save(fileName); |
Additionally, we have included the output document that was
generated using the above code snippet.
Regards,
Sneha.
Thanks for your reply.
Is it possible to apply a different font to the equation text? And additionally, can the font or style be applied to only part of the equation?
For example, I have an equation such as:
x = 2 in
I would like the whole equation to be in Times New Roman and I would like the numerical portion of the equation in italics and the units would not be italicized.
Thanks!
Also, according to this documentation https://help.syncfusion.com/file-formats/docio/working-with-latex#subsuperscript, there does not need to be curly brackets around the items.
LaTex standard does not include the need for brackets around the object which has a sub/superscript, so its curious why this standard is used here. We see this a a large downside as it affects any code which we have previously written in using the LaTex standard. Will this remain permanent or is there a possibility that the LaTex standard will be adopted and the curly brackets will not be needed?
Thanks!
Natalie, please find the details below.
Regarding: Is it possible to apply a different font to the equation text?
Yes, you can apply different fonts to the required equations. To achieve your
requirement (apply “Times New Roman” font to the equation) iterate the Math
equation DOM using DocIO and set the required font for the text.
We have prepared a sample for your requirement and attached it here. Please take
a look at it.
Note: Please find the output Word document generated on our end inside the attached
zip.
Regarding: I would like the numerical portion of the equation in italics and
the units would not be italicized.
When you create an equation using DocIO, the equation will be in italics. As
the default equation is italicized, you can remove italics for the
necessary text by using the below LaTeX syntax.
using WordDocument document = new WordDocument();
document.EnsureMinimal();
document.LastParagraph.AppendMath(@"\mathrm{x} = 2");
document.Save(fileName);
Regarding curly braces:
To identify the structure of the equation and its elements clearly, we strongly
recommend to use a curly brace to separate each element of the element. For
example: normal text and script text in sub/superscript equations. This is not an
issue, which is the behavior of DocIO. If we ignore curly braces, sometimes it
generates irrelevant equations.
Also, we have planned to update the documentation with curly braces for all equations.
I've also run into the curly braces issue when trying out the LaTeX support in the latest release. I'm using a LaTeX equation editor website (https://editor.codecogs.com/) to build my equations and then grab the LaTeX and drop it into the AppendMath calls in my code. With the current DocIO requirement for extra curly braces it adds a substantial amount of unnecessary, error prone work.
The requirement to use curly braces does not appear to be standard in LaTeX, nor Word, nor numerous LaTeX generation websites, nor a competing product to Syncfusion DocIO.
@Akash, can you provide an example where "If we ignore curly braces, sometimes it generates irrelevant equations." causes an issue. Or point us to where in the LaTeX standard this is spelled out. From what I've tried so far, I can paste LaTeX, without the additional curly braces, into Word and it understands it just fine.
Thanks,
Brady
Here's another example that seems to work in Word and other LaTeX sites/apps, but doesn't work in DocIO.
\left( a + b \right)^3
To get the desired result in DocIO you have to use
{\left( a + b \right)}^3
Brady, we are currently investigating the above mentioned problem. We will validate it and provide you with more information by the beginning of next week.
Brady, we
have confirmed that the reported issue with “LaTeX equation is not preserved
properly in DocIO” is a defect and we have logged a defect report. We will
include the fix for this defect in our 2023 Volume 4 SP release, which will be
available in the end of January 2024.
The status of this bug can be tracked through the below link:
https://www.syncfusion.com/feedback/49804/latex-equation-is-not-preserved-properly-in-docio
Disclaimer: Inclusion of this solution in the weekly release may change
due to other factors including but not limited to QA checks and works
reprioritization.
Hi Brady,
We have included the fix for the reported issue with “LaTeX equation is not preserved
properly in DocIO” in our Essential Studio
2023 Volume 4 SP Release V24.2.3. And we are glad to announce that
our Essential Studio 2023 Volume 4 SP Release V24.2.3 is rolled out and is
available for download under the following link.
Essential
Studio 2023 Volume 4 Service Pack Release v24.2.3 is available for download |
Announcements Forums | Syncfusion
The status of this bug can be tracked through the below
link:
https://www.syncfusion.com/feedback/49804/latex-equation-is-not-preserved-properly-in-docio
We thank you for your support and appreciate your
patience in waiting for this release. Please get in touch with us if you would
require any further assistance.
Regards,
Sneha.