LaTeXiT formula as image in RTF and code in LaTeX-Export

Hi,

I know it’s not a good time to ask for new features regarding the imminent release of 2.0, but nonetheless I dare to ask because It think that the implementation of my idea could improve the workflow of scientific/technical writing a lot without very much coding effort on your side (as far as I can estimate).

Thanks to LaTeXiT it has been possible for a long time to typeset LaTeX-Code (not just math, but anything) into Scrivener (or any other image-capable Cocoa text view) and turn it into a nicely cropped pdf image. Since LaTeXiT installs typesetting commands into the system wide services menu, one can even easily assign a keyboard shortcut to the conversion.

When exporting to RTF or RTFD, the inline pdfs stay where they are, but when exporting to MMD, which is a pure text file format, they understandably disappear.

I would now suggest that during the conversion to MMD, Scrivener would extract the original LaTeX-Code from the pdf, where it was stored by LaTeXiT during pdf creation. Subsequently, the pdf could be simply replaced by an html comment containing the code. That way the code could be passed to MMD and furthermore through MDD to LaTeX. The advantage of this approach would be, that equations or other LaTeX specials would appear nicely typeset directly within Scrivener while the document could be exported both to RTF/RTFD and to LaTeX without the need for any modification.

To implement this feature one would need to be able to extract the LaTeX-Code from pdfs created by LaTeXiT. Since LaTeXiT is open-source and under a GPL compatible license, I had a look there how to implement such a method. I’m no Cocoa programmer, but I think the method

+(NSDictionary*) metaDataFromPDFData:(NSData*)someData useDefaults:(BOOL)useDefaults

in LatexitEquation.m is the one that checks whether a pdf was created by LaTeXiT and, where appropriate, tries to extract the LaTeX-Code. So maybe it wouldn’t be too complicated to adopt it for Scrivener.

What do you think?

Best regards,
Felix

That’s not a bad idea, and thanks for the tip about LaTeXiT putting the original formula/etc into the PDF meta-data. I never realised it did that. I wouldn’t shock me if it is difficult to do what seems simple though—Cocoa’s inline PDF support is a little flaky, to say the least. It’s usually best to use some other format; EPS perhaps?

First point: next version will support inline image export in the MMD workflow. Simply drop an image into the Cocoa view, and when you compile Scrivener will dump the image into the export folder, and link to it with MMD syntax. A quoted string of text directly following the image will get inserted as a caption, if provided.

Second point: since one would probably want actual formulas and not pictures of formulas if they are using LaTeX, is that you could put the image into an annotation beside the formula itself. That way it gets dropped when compiling.

Hi,

Thanks for the suggestion. This sounds very interesting, and I’ll definitely take a look at it. I probably won’t get time to investigate it properly before 2.0, given the little time left and the bugs I’m still tackling, but I have put it on my list for shortly after if not.

Thanks again,
Keith

Hi,

Just to let you know that I’ve popped this into the “stuff to investigate for 2.1” box. I took a quick look and it’s not entirely trivial (partly because I haven’t got time to spend a couple of days installing the stuff I need to test it properly). For a start, it would entail Scrivener trying to analyse every embedded PDF file and checking them for pertinent data, and some users may not want this. But also, the -metaDataFromPDFData: is quite complex and relies on other methods and values within the LaTeXiT source code. Even if I extracted it from the other code with which it is entwined, it would then mean that it would only work so long as LaTeXiT doesn’t change the way it stores the data.

So: It’s a good idea, but one that is more complicated than it may at first seem. So, it’s on my list for further investigation after 2.0 is out, as I say. Thanks for bringing LaTeXiT to my attention, though - presumably this is useful for many scientific and technical writers using rich text already. (And remember that MathML can always be used with MMD, too.)

Thanks and all the best,
Keith