Compiling: Scrivener to mmd to latex to Lyx

The short version of my question is, how do I get Scrivener to output an *.mmd" file that looks like this:

[code]Base Header Level: 1

Some Part

Some chapter title

Some section title

Some subsection title

Etiam dapibus ante dapibus, varius tellus et, cursus diam. Integer
eleifend nunc quis leo luctus, non accumsan nunc aliquet.[/code]

instead of like this:

[code]Base Header Level: 1

** # Some Part #**

** ## Some chapter title ##**

** ### Some section title ###**

** #### Some subsection title ####**

Etiam dapibus ante dapibus, varius tellus et, cursus diam. Integer
eleifend nunc quis leo luctus, non accumsan nunc aliquet. [/code]

Here’s the longer version of the question:

I use Linux. I just discovered Scrivener. I’d like to use Scrivener with two writing projects: a short novel and a longish technical, nonfiction book. I don’t need Scrivener to do any formatting or typesetting as I’ll be using Lyx for that. My hope is that Scrivener can output unformatted content suitably marked with hierarchical information (and hopefully also with images, footnotes, marginal notes, references, and etc intact, but one step at a time!).

My first goal with Scrivener is to:

1.Compile a Scrivener project and output a multimarkdown file (say “scriv.mmd”)

  1. Use the terminal command “multimarkdown -t latex scriv.mmd>scriv.tex” to output a latex file “scriv.tex” from the scrivener output file “scriv.mmd”.

  2. Import the latex file “scriv.tex” into Lyx.

I’ve been working at this little project for the last week. I’m somewhat familiar with Lyx, but had never heard of MultiMarkdown (or Markdown) before starting to work with Scrivener.

Here’s what the compiled “scriv.mmd” looks like as produced by my current custom formatting:

[code]Base Header Level: 1

** # Some Part #**

** ## Some chapter title ##**

** ### Some section title ###**

** #### Some subsection title ####**

Etiam dapibus ante dapibus, varius tellus et, cursus diam. Integer
eleifend nunc quis leo luctus, non accumsan nunc aliquet. [/code]

The above “scriv.mmd” output needs to be modified before the terminal command ‘multimarkdown -t latex scriv.mmd>scriv.tex’ will produce a useable latex file: Open “scriv.mmd” with a plain text editor and use “search and replace” twice, first to replace '** ’ with nothing, and then to replace ‘**’ with nothing.

At which point the modified “scriv.mmd” file looks like this:

[code]Base Header Level: 1

Some Part

Some chapter title

Some section title

Some subsection title

Etiam dapibus ante dapibus, varius tellus et, cursus diam. Integer
eleifend nunc quis leo luctus, non accumsan nunc aliquet. [/code]

From this modified “scriv.mmd” file I can use the multimarkdown command given above to produce latex output, which looks like this:

[code]
\part{Some Part}
\label{somepart}

\chapter{Some chapter title}
\label{somechaptertitle}

\section{Some section title}
\label{somesectiontitle}

\subsection{Some subsection title}
\label{somesubsectiontitle}

Etiam dapibus ante dapibus, varius tellus et, cursus diam. Integer
eleifend nunc quis leo luctus, non accumsan nunc aliquet. [/code]

The above multimarkdown-produced latex file imports into Lyx without any issues, appropriately separated into Parts, Chapters, Sections, Subsections, Subsubsections, and paragraphs. Then I can use Lyx to do all formatting, typesetting, exporting to PDF, etc.

However, if I try to compile the original “scriv.mmd” produced by Scrivener directly, without first search/replacing the '** ’ and then ‘**’, then after running the terminal command to produce a latex file, the resulting “scriv.tex” file looks like this:

[code]** # Some Part #**

** ## Some chapter title ##**

** ### Some section title ###**

** #### Some subsection title ####**

Etiam dapibus ante dapibus, varius tellus et, cursus diam. Integer
eleifend nunc quis leo luctus, non accumsan nunc aliquet. [/code]

As you might expect, importing the above latex file into Lyx produces content with no hierarchy, just a bunch of paragraphs with meaningless character strings like this: ** # Some Part #**.

From what I’ve read online, as I tried to figure out how to further modify my custom formatting, ‘**’ says “make this bold”. How do I persuade Scrivener to not add this little bit of formatting information to the hierarchical titles when compiling to output an “mmd” file?

Thanks very, very much for any input,
Lou

I did manage to create and save a custom compile format that outputs an mmd file that doesn’t need any “search and replace” to work. The problem is I don’t know why what I did worked.

The mmd output you are trying to generate is pretty much the default output from the Scrivener mmd compile. That gets me wondering how you have your project set up and how you are setting up the section headings.

The usual arrangement is to have each of your logical sections as a separate document within the binder, with the relative positions within the hierarchy represented by their order and nesting within the binder. On compile, the document titles become the section titles, with the usual #s to indicate the level within the hierarchy. As the insertion of the #s is controlled from the Compile Formatting section there isn’t any need to add them in yourself.

Have you set your project up that way? Or have you used a different method?

Finally, you can get rid of the separate second step of your workflow by selecting the MMD --> Latex compile option, rather than just the MultiMarkdown option.

Hi MrGruff,
Your lovely guide was key in helping me figure out how to create a custom ini file. Thank you very much for creating it.

I have the separate logical sections as folders, with text as desired under the respective folders:

Part folder
Maybe some introductory text
    Chapter folder
    Maybe some introductory text
         Section folder
         Maybe some introductory text
              Subsection folder
              Text

And so on.

I didn’t add any “#s” in. I “searched and replaced” the unwanted '** ’ that were bracketing the “#s”. I now have two custom ini compile files. One produces the unwanted bracketing '** ’ and one does not. The one that doesn’t produce the unwanted '** ’ was modified from an existing format, the “non-fiction manuscript”, that doesn’t have any bold markup. The one that does produce the unwanted '** ’ was modified from an existing format that does include bold markup. I compared the two custom ini files, the only relevant difference is in the undecipherable line: [General] elements=

Compiling straight to latex produces a content latex file, plus nine “formatting and layout” latex files. I don’t know how to get Lyx to see all those extra formatting and layout latex files, and I’m not sure what advantage there would be, as I can set Lyx up to output the content formatted exactly as I want it to be.

The sticking point might be when I start adding in figures, equations, in-document references, footnotes, etc, at which point perhaps it will be simpler to figure out all the MMD to Latex code and how to get Lyx to use all those extra latex files. I’m still learning!

That sounds strange behaviour. On the mac, if I switch from a compile format such as RTF or DOC to an mmd format the formatting shown in the formatting pane of the Compile dialogue changes to plain text with just the appropriate number of hashes.

So from:

Scrivener.jpg

To:

Scrivener2.jpg

I’d always thought the same thing happened on Windows and Linux.

On the Lyx/Latex issue, I have no experience of Lyx, I can only say that the mmd --> Latex compile produces standard Latex \input statements which bring in all the boiler plate latex statements I need at the start of the document. Without them, you don’t get a complete Latex file. If that isn’t an issue in Lyx then the simple mmd compile clearly serves.

Hmm, that’s why it took me so very long to get a custom format that output “file.mmd”.

At least on Linux, here’ what (doesn’t) happen: Just selecting “MultiMarkdown (.mmd)” doesn’t result in Title being bracketed with ### ###; selecting “MultiMarkdown (.mmd)” doesn’t result in the bolding format going away if it was there to beging with; every Level has three hashes on each side, if it has hashes at all and the bolding '** ’ (if present) is OUTside the hashmarks and can’t be deleted using “Modify”.

The only way to get the “###” brackets if the originally selected compile option doesn’t already include outputting a hierarchy is to highlight each line, click “Modify”, click “Section Layout”, make sure “Place prefix inside hashes” and “Place suffix inside hashes” is checked" and then type at least a black space in either the suffix or the prefix box. Otherwise you don’t get the “###” bracketing the Title.

I think the Linux behavior with respect to “file.mmd” output is probably buggy. The behavior you describe for Mac seems much more rational.

As far as Lyx goes, it’s easy enough to output a sample latex file with Lyx, which sample will contain the appropriate latex boiler plate to copy-paste into the top of the tex file generated by using “multimarkdown -t latex file.mmd file.tex”, and then the latex instructions are exactly what Lyx wants.

On to new things! Next step: figure out how to insert an image with a caption and a reference link, in such a way as to convey the image, the caption, and the link to Lyx.

The default LaTeX output from Scrivener goes about creating a .tex file that can be typeset without any further work from you. Given how MMD3+ was designed to not produce a full LaTeX document in a single file, but rather relies upon input to bring in boilerplates, we set things up so that Scrivener’s defaults will engage these meta-data fields for you, and produce the standard boilerplate .tex files in the compile folder so one could just pdflatex the compiled .tex file and be done with it.

But, you can circumvent all of that. This is just Scrivener in it’s “easy” mode (as much as any LaTeX workflow can be described that way!). If you visit the LaTeX compile option pane and switch off the document class to “None”, then all of the automation will be switched off and you should in theory get an identical result from [b]multimarkdown -t latex...[/b].

Instructions for working with captioned images and cross-referencing them are in the user manual, §21.4.1 (pg. 181).

Yeah, that’s an annoying bug in the current system. The described behaviour where all you have to do is flip on the “Title” checkbox is the way it should work. This is broken in Windows as well, so it isn’t just a Linux thing. Unfortunately this bug is tangled up in a rather big mess of how titles are generated, and so fixing it has been deferred to 1.6, when the back-end compiler components are schedule to be refactored.

AmberV,

Thanks very much for the tip about “none” on the Latex compile option pane. That works perfectly. And thanks also for the tip about where the instructions for captioned images/cross-references are. I think I’m going to like Scrivener very much.

Lou