LaTeX & ePub

Hi,

I’m a bit confused how compiling projects works in Scrivener. I have a written a few stories in RTF format. I thought it would be possible to compile them into LaTeX documents regardles the format in which I wrote them. But now I think that was a misunderstanding of mine because when I did compile them to LaTeX Scrivener did not insert a blank line between two paragrafs. In order to get valid LaTeX documents I had to insert the blank lines myself. I found no way to tell Scrivener to do that. However that messed up the ePub output. Scrivener did not remove the blank lines when I compiled the story into ePub format.

Hence I conclude:

[]When I want to compile a story to LaTeX I must write using mmd syntax. Hence I cannot not compile it cleanly to ePub or Kindle format.[/]
[]When I want to compile a story to ePub oder Kindle format I must write RTF documents. But then I canno compile it cleanly to LaTeX or mmd documents.[/]

In other words: When start working on a project I must decide into which formats(eBook or LaTeX) I want to compile it later and cannot change my decision? Is that correct? In my opinion that would be atleast confusing because the compile dialog offers all output formats regardless in which format the project is written.

Ciao

Maral

If you compose/write in mmd, you can export to LaTeX as you know, and you can also export to HTML. The open source, cross platform program Sigil can then import the HTML file generated into an epub file, and Amazon’s Kindle Previewer program can convert the epub into a kindle file.

This should be a good way for you to proceed, unless AmberV has a better one (I am sure she does).

Also of note is that different formats in compiling can take different options, so it is possible to set up a compile to LaTeX with a substitution, replacing each paragraph end with two, giving you your blank lines. (This does mangle lists however, and is not needed if you just write in mmd in the first place, with blank lines where you want them.)

Read over the manual for Scrivener, it is very good, and poke around in the forum topics - there is a wealth of info here.

  • asotir

Using compile replacements would be a good way forward.

I would be inclined to write with double returns (which will compile properly for Latex), then, when I wanted epub, use a compile replacement which replaces any double returns with single returns. Doing it that way round avoids messing up lists.

However, if you want to be able to go straight to epub from the same source you will need to be careful how much MMD syntax you use, as MMD tables, lists, bold and italic will not work in the standard epub export.

Using double-returns in the document would allow you to use replacements - replace 2 returns with 1 return - when exporting to epub. Other replacements could transform mmd code to HTML (though I wonder if that code would then appear in epub as proper code or as literal characters - less-thans would appear as less-thans. But if it gets in as code and not as literal, you could replace space-* with space-[i] (with brackets understood here to be less-than and greater-than). And return-* would also be replaced with return-[i] … you would only have to set this up once, test to ensure it works as you want, and then save the test project as a template.

Still, all this seems a lot of work … it would be as simple to do global search and replace on a mmd-HTML compiled file and turn that into basic LaTeX, which file would then be included or input into a LaTeX file with your desired definitions and header. (For example, [H2] might change to \part{ … [i] would change to \emph{ … and so on).

  • asotir

Hi,

many thanks for all your replies. I think I will switch to using mmd and create the eBook version with Sigil.

@asotir:
How do I replace 2 returns with 1 returns using the replacement feature? I tried to replace “\n\n” with “\n”. But that does not work.

Ciao

Maral

You could also create the ePub using the MultiMarkdown tool for doing so. :slight_smile: I think that is a much better start than a single HTML file, though Sigil does do a pretty good job of taking a well-formed HTML file and turning it into an ePub file.

Now, as for using Scrivener’s rich text editing tools and rulers for MMD, as you not that isn’t really possible—though you can actually achieve a bit of a balance here, depending on how much formatting you need. For example in the Transformations compile pane you will an option “Convert to plain text”, where you can change paragraph spacing into real newlines. So with that way of working, you would use paragraph spacing in your editor while writing, most likely switching things back to indents using the Formatting pane when producing a rich text document, but when compiling to LaTeX you could flip this option on to get real paragraphs.

Another option in the Transformations pane that lets you work hybrid a bit is the “Convert Markdown to bold and italics”. As it sounds, this only does basic Markdown style formatting to rich text, it is not a full MMD parser. So if your intended ePub has extensive use of formatting this won’t be a total solution.

Finally, consider that images, footnotes and titles can also be intelligently handled by Scrivener per-format. It will turn these things into MMD syntax if needed, or rich text formats and conventions for ePub.

As noted above, Replacements can also do you a lot of good, especially now that they are RegEx capable. You can search for [b]^>\s?[/b], replacing it with nothing, to strip out an MMD block quote signifier. If the base text that had that signifier attach is also block indented using rich text, then you can compile to LaTeX with the “> ” signifier, and use a replacement to strip it out for ePub, using the visual indenting to suffice as quotation indication.

Ultimately I agree with your final conclusion though. It will be easiest to take full advantage of MMD’s syntax, rather than adopting a hybrid workflow, and since it is not impossible to get an ePub file out with MMD, and ePub files can in turn be turned into Mobi files, there aren’t many downsides to taking that option if you are comfortable with it.

Make sure you have the RegEx checkbox enabled for the replacement row. If you do not see that checkbox, you must be using an older version of Scrivener or Mac OS X. You can still do newline replacements though, just use the Option key to insert whitespace characters. It’s a little unwieldy though.

As I say above, if you want to take a hybrid approach, it is much better to use visual paragraph spacing in the editor, the Transformations tool for when you need literal spaces (LaTeX), and the Formatting pane to convert paragraph spacing to indents for traditional publishing. That will be less error-prone than global carriage return search & replace, too.