questions about LaTeX in scrivener

I wish to bring an existing biggish LaTeX project into scrivener to work on a different way and I have a few questions that will inform a decision as to whether to leave in LaTeX bits or convert to MMD first.

Most of the text transformations to MMD would be pretty straightforward (ie convert \textit{…} to , but is there anyway to convert LaTeX style footnotes into either scrivener footnotes or preferably MMD footnotes?

In Scrivener 2.0, is it possible to prepare documents in MMD and then push out an MS Word file or preferably an RTF with footnotes / blockquotes / italics? Is there any work flow for handling images (jpg / png, one on a page by itself), with captions for multiple potential output formats?

Once in MMD, how hard would it be to roll my own xslt? I am a very old school LaTeX user and noticed that most of the existing xslt files use slightly unfamiliar LaTeX syntax. I’m not opposed to using a newer syntax but pretty much just like the regular old default report pdflatex look and feel.

Thanks in advance for any advice…

There’s a special syntax for footnotes in text files that should work for your LaTeX project:

{\SCRV_FN=Footnote.\END_SCRV_FN}

Once you have the footnotes converted to Scrivener’s internal format you can easily convert them to MMD footnotes by exporting and reimporting your document (Scrivener does not change the footnotes back when you import from MMD).

Thanks signinstranger – that’s really helpful…

On a related note… if you’re familiar with unix command line tools I’d recommend pandoc to convert your document from LaTeX to Markdown. That should make the transition to Scrivener fairly easy.

Rolling your own XSLT is not too difficult actually—especially if all you want to do is surface mod the default output, rather than add new features. Adding new features is slightly more involved, but changing what you see is just a matter of going through the file and looking for stuff you recognise, and changing to what you want. You’ll find huge blocks for the skeletal structure of the LaTeX file which you should edit as they will probably include a lot of things you do not need; then just go down looking for familiar things that you want to change, and change them. Anything inside of an xsl:text element is safe to adjust. Using a text editor that is aware of XML and does syntax highlight will help a lot in showing you the “safe areas” for editing.

The best way to go about doing this depends on how radical your revisions are. If you plan on changing nearly everything, you might want to just start with duplicating memoir.xslt and xhtml2latex.xslt. The latter is the backbone, and the former is the most complete practical implementation using it. Call them whatever you like, and be sure to edit the line in memoir that looks like this, near the top:

<xsl:import href="xhtml2latex.xslt"/>

Incidentally that trick is what you would use for a lesser modification. If you only want to tweak a few things, it might be easier to create a more slim wrapper that imports memoir. See article.xslt for a good example of a small XSLT that overrides some of the qualities of the larger XSLTs.

@ AmberV - Thanks for this advice about XSLT. Apologies for the lag in my reply (I had to turn my attention away from my dissertation for a bit and toward a family emergency).

In relation to my original thread, the things I’m wondering about right now are:

  • How does scrivener deliver images to MMD and then what paths exist to get image references from MMD to LaTeX? Or is there a way I can just leave my images in full-on LaTeX and exclude them from the MMD parsing? Any ideas for workflow with \ref for cross-referencing to figures – is this something that can be integrated with scrivener’s internal linking features (which I have not explored)?

  • With the new version of scrivener it preferable to use MMD syntax for bold / italic / footnotes within scrivener or use those features as built into scrivener and then integrate with compile?

Thanks again everyone.

There are three (four if you count just typing in raw LaTeX code) ways to handle images in Scrivener with MMD:

  1. The first method is mostly devoid of any syntax. Without a caption you needn’t do anything special at all, but if you do want a caption, add it in double-quotes on the same line as the image, as shown. The image can be either linked or embedded in the file. Linking is a good way to ensure preservation of the image’s colour calibration, format, and meta-data.
  2. This is probably the best method if you want to stick with using MMD syntax. Just type in the standard image syntax, and where you would put the name of the image, just Opt-drag it from the binder so that it makes a link instead of embedding it.
  3. This is the non-mediated method. Scrivener will do nothing here, you are just establishing the absolute position of an image on your drive using the regular syntax. It’s a good method if you have lots of high-res graphics and don’t want to burden your project file with their bulk.
  4. Hardly an “MMD” method at all, this is just passing through raw LaTeX by embedding it in an HTML comment.

In the first two methods, Scrivener will manage resources for you. It will collect images from within the text files, binder, or external linking locations, and gather copies of them all into a compile folder with everything relatively linked in the text file (so, looking like the LaTeX example).

Which to choose is largely up to taste, with only a few extreme factors weighting the advantage one way or another. For example, if you have a gigabyte of images in the book, you probably don’t want to have Scrivener collecting them all and creating copies every single time you compile—doing direct links with the third method will be the most efficient way to work.

Cross-referencing uses the alt attribute for the label. The alt attribute is set up in the square-bracketed bit of text. So in the third example, the cross-ref label is “externalimagelink”, but you can just use [b][External image link][][/b] in your text. The same function that converts the alt text is used to convert the cross-ref text, so long as both are identical, they will reduce to the same underlying “externalimagelink”. When you use the first method, obviously there is nowhere to put the alt text, Scrivener will be doing that for you when you compile—it will just use the image name. So to cross reference to an automatically generated MMD image, you would type something like this, [b]...see [the chart][somechart.png] for more info.[/b] Subsequently, I like to add a comment to the text with the graphic filename, so that I can easily find it later and know what to link to if I need to cross-ref it.

Incidentally, method #1 is what I use for the Scrivener manual, with a slight twist. The image is placed into the text stream and I cross-ref using its name, but when I actually create the .tex files, it adjust which image directory to use on the fly, based on the format and platform. So the Windows PDF gets Windows screenshots and the Mac PDF gets Mac screenshots all from the same project.

Scrivener’s links themselves are not meant to generate cross-references. If they had a public “face” that survived compile, then it would limit their usefulness to you as a writing tool.

I definitely prefer to use Scrivener’s footnotes rather than come up with ID numbers and type them all in by hand. There is no automatic function for converting bold and italics to syntax though, so you’ll need to stick with asterisks and such. The main reason for the lack of an auto feature is that it is difficult to correct for the inherent sloppiness of RTF style formatting. Because whitespaces can be formatted accidentally (and rather easily), you’d end up with * stuff* like that which doesn’t render very well with MMD.

@AmberV, Thanks again for so much useful information. I am going to be doing some re-engineering this week and will report back on my experience.
Cheers, Rebecca