Insert LaTex into pdf

Hello, 

I would like to know if there is a way to show formatted LaTex equations in a PdfDocument? 

Previously, I had been creating a word document and then converting it to PDF, however the conversion is quite slow when using the following code: 

            using (DocToPDFConverter converter = new())

            {

                converter.Settings = new DocToPDFConverterSettings() { ExportBookmarks = ExportBookmarkType.Bookmarks };

                using (PdfDocument pdfDocument = converter.ConvertToPDF(document))

                {

                    pdfDocument.Save(path);

                }

            };


Because that is taking too long, I am trying to create a PdfDocument directly but I need to be able to see the formatted LaTex equation. If instead there is a way to speed up that process, I would be willing to

Thanks. 


7 Replies

DS Dharanya Sakthivel Syncfusion Team November 5, 2024 01:04 PM UTC

Hi Natalie,

We have created a Word document with a LaTeX equation and converted it to PDF. The overall generation took 2 seconds on our end. Internally, DocIO converts the LaTeX string to a Document Object Model (DOM) and maintains it as a Word document object model. During the Word to PDF conversion, DocIO measures each content element to position them using its own layout techniques. As a result, this process can take a considerable amount of time when converting equations from the Word document to PDF. Please refer to the attached sample.

If you feel that the process and conversion are taking too long, please share the following details:

  1. The complete code snippet
  2. The time taken on your end

With this information, we can check the feasibility of improving performance for your scenario.

Regards,
Dharanya.


Attachment: LaTexWordtoPDF_606bd8ef.zip


NW Natalie Westphal November 5, 2024 04:49 PM UTC

Is it possible to add the LaTex equation directly to PdfDocument? Possibly by creating an image file? or by converting it to OfficeMath?  I am considering creating the PdfDocument directly rather than creating the wordDocument and converting it to PDF because that process take a long time. 



DS Dharanya Sakthivel Syncfusion Team November 6, 2024 12:51 PM UTC

Natalie,

Regarding “Is it possible to add the LaTex equation directly to PdfDocument? Possibly by creating an image file? or by converting it to OfficeMath?”:
Unfortunately, we do not offer direct support for converting LaTeX formulas into PDF documents. The process involves first converting the LaTeX into a Word document and then creating a PDF from that Word document. During this conversion, LaTeX formulas are processed into strings, which are then rendered into the PDF document. Therefore, a direct conversion is not possible, and we are unable to fulfill your request at this time.

So, kindly share the following details:

  1. The input document used on your end
  2. The complete code snippet
  3. The time taken for the update

With this information, we will check the possibility of reducing the time required for the updating TOC.

Regards,
Dharanya.




WJ Wartol Joham November 9, 2024 04:56 PM UTC

To insert LaTeX into a PDF, you have several options depending on the tools you’re using and the outcome you want. Here are a few common methods:

1. Using LaTeX with PDF Output

If you’re creating the entire document in LaTeX, you can generate a PDF directly by using software like Overleaf, TeXShop, or MiKTeX. Write your LaTeX code (.tex file) with any text, math, and formatting, then compile it to a PDF output:

latex
\documentclass{article} \usepackage{amsmath} \begin{document} Here is an equation: \begin{equation} E = mc^2 \end{equation} \end{document}

2. Embedding LaTeX Equations into an Existing PDF

If you already have a PDF and want to add LaTeX equations to it, consider these steps:

a. Use Adobe Acrobat and LaTeX Images

  1. Create images of your LaTeX expressions. You can use tools like MathJax or LaTeX editors to render the equations and save them as images.
  2. In Adobe Acrobat, open your PDF and use the "Edit PDF" feature to insert the images of your LaTeX equations where needed.

b. Use Overleaf’s PDF Insert Functionality

On Overleaf, you can import your existing PDF into a new LaTeX project and use pdfpages to include it. Then, you can overlay additional LaTeX content.

latex
\documentclass{article} \usepackage{pdfpages} \begin{document} \includepdf[pages=1]{yourfile.pdf} % Insert the existing PDF page Here is an added equation: \[ E = mc^2 \] \end{document}

c. PDF Editors with LaTeX Support

Some PDF editors (e.g., Inkscape or certain LaTeX-compatible editors) let you add LaTeX directly. For example, Inkscape has LaTeX plugin support for adding equations directly into PDFs.

These methods allow you to integrate LaTeX equations and text into PDFs either by creating a new document or by adding to an existing one.



DS Dharanya Sakthivel Syncfusion Team November 11, 2024 03:00 PM UTC

Natalie,

We will analyze the feasibility of inserting LaTeX equations into PDF documents and will provide you with more details within two days.

Regards,
Dharanya.



DA Dharanitharan Ayyasamy Syncfusion Team November 13, 2024 02:06 PM UTC

Natalie, still we are analyzing the feasibility of inserting LaTeX equations into PDF documents and will provide you with more details within two days.



DA Dharanitharan Ayyasamy Syncfusion Team November 14, 2024 02:46 PM UTC

Natalie, we have considered your requirement “LaTeX (MathML) equation to Image” in our existing backlog feature “Provide API to convert the shape as image” which is used to convert the specific object in the Word document to image. By utilizing this feature, we can extract and render only the specific equation as an image, rather than converting the entire Word document, thereby accelerating your process.

Once this feature is available, you can achieve your requirement like below,
1. Create a Word document with LaTeX.
2. Convert specific LaTeX to Image using DocIO.
3. Insert the converted LaTeX image into PDF document.

At present, we don’t have any immediate plan to implement this feature in our end. We will let you know once this feature has been implemented.

Please track the status of the feature through the feedback link.


Loader.
Up arrow icon