📜 ⬆️ ⬇️

.NET programmer: how to quickly show LaTeX

This article describes several ways to display LaTeX documents in .NET programs. Information is useful primarily for programmers working in the field of education. Everything in question has been tested on its own development experience at the department of higher mathematics at one of the leading Moscow technical universities.

Task

Many scientific documents are automatically created in your software package on LaTeX (as the most appropriate text format for this purpose), each document should be shown to the user as a draft as soon as possible. “Automatic” means that the user does not manually type LaTeX documents, he may not even be aware of what it is. It is understood that when the final version of the document is created, it will either be exported to LaTeX, or converted to PDF by means of the installed TeX distribution and printed. Show drafts should be possible without the use of third-party programs and faster , while their correctness is guaranteed. The size of the documents does not exceed several A4 sheets, the number of formulas is moderate.

It would seem that if you still have to print the document at the end, which is impossible without installing TeX, then why emphasize independence from TeX? The point is the specifics of the software system developed by the author.
')
Solutions


What is the way to choose?

You can present a comparison of methods in the form of a table.

WayBenefitsdisadvantages
"Head-on"
  • The implementation is very simple - you need to run a la pdflatex, wait for the compilation to complete, and open the resulting document.
  • Optimal compatibility - LaTeX will definitely be shown as they wanted, and not as they could.
  • The speed leaves much to be desired. While pdflatex loads its packages, reads the fonts, while something else is going on - a lot of time passes. On a very modern hardware compilation lasts 5-10 seconds (MikTeX).
  • Dependence on the distribution of TeX - you need to put it on each computer where they will use the program. This also can be attributed to the dependence on the PDF viewer and the like. If the program will be used by professors on home computers, you will have to have a lot of patience and show detective skills.
Via Integre techexplorer
  • High speed. techexplorer takes a few seconds the first time it starts up, but its initialization can be done during the launch of the program itself.
  • Independence from TeX distribution.
  • So-so compatibility. techexplorer has a peculiar concept about LaTeX, for example, it requires declaring trigonometric functions before using them in the form of \ define \ sin {\ operatorname {sin}. All that techexplorer does not understand (in fact, a lot), it highlights in red.
  • The implementation is complicated. If techexplorer were better, then you could save the LaTeX document on disk and transfer the file name to WebBrowser.Navigate. However, it is necessary to maintain two versions of the same document - “normal LaTeX” for export and “understood by techexplorer”.
  • Dependence on techexplorer. However, it is put much easier and faster (msi can be included in the distribution of your own software), and ActiveX security restrictions are corrected by a single entry in the registry.
Via MathML
  • High speed if the document is small. Gecko (Firefox engine, the only one of the engines that supports MathML by itself) has some difficulties in displaying large documents, such as scientific articles with a lot of formulas, but in our task there were no requirements for this.
  • The transformation of LaTeX into MathML is done by the open-source latex2mathml self-written library, which the author has laid out on CodePlex . In the event of compatibility errors, it can always be customized.
  • Full independence from third-party software. GeckoFX , a .NET wrapper for the Gecko engine, is used. Gecko itself (xulrunner) can be distributed as part of its program.
  • Compatibility. For many constructs, LaTeX has to implement analogs on XHTML + MathML, which is not always trivial. There is much in latex2mathml.
  • The complexity of the implementation - follows from the previous one.
  • MathML is formally supported by Gecko, however there are some very unpleasant features. For example, complete redrawing and braking when resizing a document.


Below are inserted examples of displaying LaTeX in PDF, in techexplorer, and in MathML / Firefox.





Obviously, PDF leads in display quality, MathML / Firefox and techexplorer have their own mistakes.

Table of comparison of display speeds:

WayTime, s (LaTeX, 8.5 kb, 130 stubb 101 formula)Time, s (LaTeX, 1 kb, 30 lines, 11 formulas)
"Head-on"14eleven
techexplorer33
Mathml123


In the first case, the document was converted to PDF, and then displayed in Adobe Reader. In the second - it was shown directly in Internet Explorer. In the third, it was converted to XHTML + MathML and displayed in Firefox. Computer configuration: Windows 7 x86, Core 2 Duo T7500, 4GB DDR2. You can see how MathML in Firefox is slowing down on relatively large documents.

Subjectively, the first method is the most reliable, but slow, the second is fast and low-quality, the third is using new technologies that are not fully debugged.

As you can see, each method has its advantages and disadvantages. Until recently, the author has used techexplorer, but it has not been developing for 4 years, and will potentially bring problems in the future. Unfortunately, latex2mathml dampness does not allow to achieve results quickly, and is not a universal solution for all.

This article has only presented an overview of ways to solve the problem of quickly displaying LaTeX in .NET programs. If you are interested in details, I will be glad to explain them.

Source: https://habr.com/ru/post/93169/


All Articles