Has anyone ever created a .pdf document within their C#/WPF application using LaTeX? We're creating reports and displaying them to the screen and we've looked into creating the reports with HTML and LaTeX. The HTML option is easy, but creating a LaTeX document within C# seems non-trivial which I personally find a bit odd; I'd think people have done this many times before. Anyone know of any LaTeX libraries to look at or some other way of doing it?
-
Are you planning to actually markup the TeX document or also do the processing to produce a pdf? – IanNorton Apr 27 '11 at 07:28
-
What do you mean by non-trivial? Creating a LaTeX document, being a text format, is not more difficult than creating a HTML document. Producing a PDF from the output is trivial, using a LaTeX processor. So please clarify which of the steps you are having problems with. – Konrad Rudolph Apr 27 '11 at 11:34
-
It's the "using a LaTeX processor" part I'm unsure about how to proceed. I'm fairly new to using LaTeX altogether. I've used it on one or two papers, but I did so in an IDE and so have little experience with the 'compiling and creation of a PDF' part. I do know that of course creating the actual text of the file would be just as easy as producing the HTML file, but I'm unsure what I would need to create the PDF document within the application itself ("in the background"). – JToland Apr 27 '11 at 14:17
-
I have installed a full version of MikTeX 2.8 on every client computer, and generating the .tex source dynamically and then invoking the compiler twice for a good measure. It takes a few seconds, it is finniky, but works for my purposes, though it might not work for you. – Leonid May 13 '12 at 14:52
4 Answers
I've been working on a C# port of the iosMath LaTeX library. As I write this, it produces good results in most cases. I'm working on the remaining ones.

- 26,513
- 49
- 182
- 323
I'm not aware of any LaTeX libraries and like you said it doesn't seem to be trivial to do so which I also find a bit strange. I've always written the documents myself using the TeXnic Center IDE which I've found really useful.
You could always try writing the source for the document to a file using a StreamWriter and then run a new pdflatex process through the command prompt in code to compile the document to a pdf?
Other than that I did manage to stumble across a list of open source pdf generating libraries for C# which might be worth taking a look at here (I don't think any of them are for LaTeX unfortunately):
http://en.csharp-online.net/Open_Source_PDF_Libraries
iTextSharp seems to be recommended quite a lot by people so it might be worth looking at that. Hopefully somebody else will be able to point you towards a LaTeX library but if they can't and running the pdflatex as a process through your code isn't viable then atleast these might give you a decent alternative.
Hope this helps.

- 385
- 4
- 18
This C# library 'KaTeX Sharp Runner' can parse raw LaTeX strings or expressions within markdown text. It wraps the KaTeX JavaScript library for use in .NET applications using Jint.

- 6,729
- 9
- 59
- 100
I build Latex text in C#, which I then compile with a Process.Start() with pdfLatex.exe. I built some routines to more easily (and less error-prone) build equations and tables of parameters in the style
length 2.3 m
mass 45.5 kg
Without these routines and just C#-write an equation as a long Latex string with all its comma's, (curly) braces etc. is hell.
An internationalizeable equation in my program looks like:
Equation
(
"equation_name_in_Swahili",
new List<string[]>{
new[] {$"F_{{{Str("cable")}}}", null}, eq,
new[] {"\\sqrt", "\\sqrt"},
curl1,
new[] {"(", "("},
new[] {$"F_{{{ltxGrav},X}}", $"{Fg * Math.Cos(Ag):G5}"},
plus,
new[] {$"F_{{{ltxWind},X}}", $"{Fw * Math.Cos(Aw):G5}"},
new[] {")", ")"},
new[] {"^2", "^2"},
plus,
new[] {$"F_{{{ltxGrav},Y}}^2", $"{Fg * Math.Sin(Ag):G5}^2"},
plus,
new[] {$"F_{{{ltxWind},Z}}^2", $"{Fw * Math.Cos(Aw):G5}^2"},
curl2
}
)
the first column is the equation with formal parameter names, and the second is the same, but with the values. You can guess what the "plus"and "dots"do.

- 894
- 1
- 8
- 25