How to compile a Scrivener document to Latex?

Hello everyone! I would like to compile a Scrivener document in order to export it to a Latex editor and I do not find any simple tutorial to do it. I only need to know how to compile a very simple document, made of a short preamble with no refinements. Does anyone know how to do it? Thanks for your advices.

Have you given the “General Non-Fiction (LaTeX)” project template a try yet? It has some example infrastructure provided for supplying a preamble with optional additions (indexing, etc.), and otherwise is intended to convert simple rich text formatting to LaTeX, including in an extensible manner through the style system. It’s very straight-forward if you just want to work in LaTeX from the start to finish.

Otherwise the Pandoc and MultiMarkdown approaches are good options for keeping things simple up front, with minimal actual LaTeX syntax while writing. You would need to learn a little intermediate syntax (and Scrivener can help with some of that), but it’s all no more complicated than formatting a basic plain-text email for the most part—if you’ve ever used Markdown in a web form, like Github or Reddit, it’s basically just that on a much larger scale.

And of course the absolutely most basic approach is to treat Scrivener like a plain-text editor from top to bottom! Type your preamble into the first document of the Draft folder, key in LaTeX syntax where needed, just as you would in an LaTeX editor, and compile to plain-text with no frills added. One can compose a document of any type in Scrivener, given that basic premise—HTML, DocBook, whatever you need.

Thanks for your answer and suggestions! I tried many times to compile a simple document but without success (…). Is there any simple video tutorial to do it? Or, could you, please, tell me how I should insert my preamble into the first document of the draft folder. Do I have to do it as on this screenshot?

What you have in your screenshot here is precisely right. It is that simple, and this should work fine, I don’t know why it is not.

Could you describe how you are compiling? Are you perhaps using a Format that is inserting a lot of extra stuff (most designed for rich text users, mind)? If I leave the compile Format to “Paramètres par défaut”, in the left sidebar and set everything to “Tel Quel” in Affecter les mises en page de section…, then I get a simple text file, with each chunk of text printed one after the other. If the preamble is the first file, then it is at the top as it should be.

This is a screenshot that shows an overview of my document.
Are you telling me that I should copy and paste my document into a latex editor? Or are you suggesting me that I can compile directly my document with this preamble? In this case, which option do I need to choose when I compile: Print? PDF? And do I need to add an \end{document} in the end of my text? Thanks for your answer.

Okay that explains the point of confusion better to me. Scrivener doesn’t have a LaTeX distribution built into it or anything like that. You’re goal is going to be compiling a .tex file and then typesetting that using an editor.

Now in a more advanced sense, you can automate by having Scrivener tap into the macOS shell:

  1. Open Compile.
  2. At the top, set Compile for: Plain Text.
  3. Set up the Section Layout assignments the way I recommended before.
  4. Edit the compile Format.
  5. Now on the upper-right side, you can set the extension to “tex” if you want.
  6. In the Processing pane, enable post-processing. Here you could run latexmk if you want, meaning that when you compile you’ll in fact get a .pdf file.

Personally I like having a .tex file to work with though, unless I’ve got all of the “bugs” worked out of the document and compiling has become routine. But that’s an option if you want it. I have an example post-processing workflow built into the Non-Fiction LaTeX project template starter. If you make a temporary project somewhere using that, check out the Processing compile format pane to see how you can optionally compile to PDF with that template.

Thanks for that suggestion. I tried it and it works well. But, as you guess, I am searching for a simpler way to use both Scrivener and Latex. I mean in such a way I could use also Scrivener as an outliner. But maybe it is not possible at all.

I don’t know, I think it should be possible, but perhaps I don’t understand what you are looking to accomplish, as I am not sure how to think of Scrivener as anything other than an outliner.

English is not my native language, therefore I don’t express myself precisely. I meant that I’ve been using Scrivener and latex for years now, in order to write a doctoral thesis and the way I proceeded was the following : a complex preamble with a lot of refinements and, for each part, chapter, section, directly into the text, portions of latex code such as \chapter{This chapter}, \subsubsection{This subsubsection}, and so on. Then, I copied and pasted the whole into my latex editor. In this configuration, I had to rewrite the code every time I had to change a section: for instance, if a section was suddenly a subsection, I had to rename the section instead of changing the place of the section, as you can do when you use the outliner in Scrivener. And I thought I could use Scrivener without having to copy and paste, just by compiling my document.

I think I better understand. Scrivener can take care of routine LaTeX code like the \section codes for you, and even in such a way that if you move a folder up a level it can automatically become a \chapter.

Earlier I recommended you take a look at the General Non-Fiction (LaTeX) project template. I am sorry it is only documented in English, but hopefully it explains itself. Even if it has more things than you would want to use in it, there are aspects of how it works that could be learned, and added to your own project:

  1. Create a blank copy of the LaTeX template for testing.
  2. Open Compile.
  3. Scroll through the middle preview column. See how \chapter, \label, and \section are being added to the chunks of text in the preview tiles?
  4. Click on the 4th one down, labelled “Section”, and you’ll see the example section file within the chapter, on the right side, highlighted. Click the “Chapter” example, and the folder is highlighted.

How does this work?

  1. Close compile (just cancel).
  2. Click on the Draft folder, and open the Outliner view. You will see a “Section Type” column.
  3. Select the sample “Section” file and un-indent it (⇧⌘←).

See how the Section Type goes from “Section” to “Chapter”, just based on the indent level? You can try another test, make a new file and indent it beneath a Section file. You will see it becomes a “Subsection” by doing so—and it will automatically compile that way, with \subsection.

What makes that work is in Project ▸ Project Settings…, under the “Section Type” pane. The first tab is a simple list of all the Types this project. The second tab sets up the default Type based on indent and icon type (folder/file/group).

Feel free to copy what you want from this template into your project, or if you want to try your data in it, some of the preamble is in the “Front Matter” folder, but the parts that set up how the document itself looks, like the documentclass, are in the Compile Format, under the “Text Layout” pane.

Let me know if anything above does not make sense, I will be happy to clarify. I think Scrivener can do what you want—as an outliner, using that outline to make LaTeX.

I just saw your last post. Thanks for your indications. I will take time to read it and come back later.

I believe that I am in the same place as dominique was in August, The main attraction to me of Scrivener is the binder and corkboard types of features, but I basically want to write in full LaTeX. I gather from this string that there is facility in Scrivener to output a .tex file, that I could compile elsewhere, If this is the case, it seems like a cumbersome process. Is there a way to use Scrivener like explorer–work in a full LaTeX editor but save my .tex files directly to a project, where I would see all the little tidbits that I would save in Scrivener.

It might help to try it out, as I don’t see what could be streamlined further. Out of the box the project creates a .tex file and it’s up to you to do what you will with it, but the instructions in the template show how you can flip a switch in its settings to have it create a PDF instead, handling the typesetting phase for you. I leave that setting off by default since it is better used once the work is essentially done. Otherwise having detailed log files is far better, and you’ll get a better testing environment from Sublime, Atom or special-purpose LaTeX editors like TexShop, in that regard.

I’m not following what it is you are looking for there. To me it seems Scrivener already could be described this way. What might be the matter is that I don’t think by default the importer considers .tex to be a plain-text file format. If you’re getting read-only files when you import, check the Plain text import formats table, in the Sharing: Import preference pane.

The fundamental point here is that Scrivener is a tool for assembling a file from many small fragments of text. It doesn’t care one bit what you type into that text, so if you type in LaTeX from start to finish and compile, you’ll get a .tex file. If you type in HTML from scratch, you’ll compile an .html file.

What was being discussed above is a template we ship with the software that has a lot of compile settings built-in, basically demonstrating different ways in which you can make further use of Scrivener’s features while writing a LaTeX document. You can use figures in the text if you want, instead of managing all of that by hand and typing out the figure environments yourself. You can use footnotes, comments, etc., and even convert the outline structure of your Draft folder into .tex heading structure.

Would you be able to share the Scrivener document that was used as the source for the Sample PDF included in the General Non-Fiction (LaTeX)” project template? I think I could learn a lot by seeing how things were done behind the scenes to produce various elements of the final PDF. (Sorry if I’m missing where this is already available.)

Thanks!!!

I don’t think I have that project any longer, but I believe everything that it demonstrates is documented in the template’s readme file, at the top of the binder. So if you’re curious how I made an index with it, search for “index” in that file, and you’ll find a “Creating an Index” section. :slight_smile:

Bummer! I’m trying right now to fully understand how to work with equations in the way you’ve done on p. 3 of the Sample PDF. In particular I’d like to understand how to achieve the auto-numbering of equations (e.g. “(1.1)”). (I’d be using the LaTex equation code generated by MathType, FYI). I’m also not exactly sure how to achieve indented paragraphs for blockquoting (as with the verse on p. 3). If I could understand those two things, I’d be golden.

Thanks!

Good spot, it looks like I haven’t fully described how to use equations in the help file (though the sample PDF actually does go into more detail if you read the text around them). Basically there are two different approaches:

  • As a Section Type, and thus the equation is in its own binder item. To facilitate that, there are two Document Templates, “Equation” and “Unnumbered Equation”, both of which are fully set up to compile as expected. You use the Project ▸ New From Template ▸ Equation command and then type the LaTeX syntax into the text editor, where the sample text is provided. To create a cross-reference to a numbered equation, you simply use Scrivener’s internal links in the text. It will add the autoref command for you (and as well it will create the label in the equation to act as an anchor for the autoref).
  • Style-based inline equations. For that use the appropriately named character style is what you want. These of course won’t be numbered or capable of being referred to.

Blockquotes: just use the “Block Quote” style on those paragraphs.

That should provide a general way to find how most of the things work in this template. They are either going to be style based or section type based (and for most if not all of those, I’ve created document templates to make things easier).

Thank you! I wasn’t computing before that the indented equation is its own section. I got that now, thanks!

But I am having a hard time inserting LaTex code in there and having it turn out well. Your sample equation in the template is “2+2=5”, but the Sample PDF’s equation is much more complicated than that. When I try to insert LaTex equation code into the template Equation binder item for a complicated equation, Pandoc gives me an error when compiling to docx. I feel like I must be missing something obvious about how to use the template’s Equation binder item to insert a complicated equation using LaTex code coped from MathType…

I think there might be some point of confusion here. LaTeX is a document typesetting system, and the purpose of this template is to produce a .tex file for it. It has nothing to do with Pandoc, and would be a pretty inefficient way to create a Microsoft Word document.

In short it sounds like you need to use Markdown in Scrivener, and I’d suggest reading Chapter 21 in the user manual to brief yourself on how that is done. There is a Pandoc → DOCX compile setup built-in, and we provide a compile format starter. You really don’t need much more than that, Markdown is a lot simpler than LaTeX, especially with Scrivener.

Sorry for the confusion. I’m in panic mode, and I’m not doing a great job figuring my way of out it. I used Scrivener to write a book manuscript that contained lots of Mathtype equations. I only recently learned that these compile to docx as images, not editable equations in Word. The press wants either a docx with editable equations, or a LaTex file. I have never worked with LaTex, and assumed it would not be a good idea to plan to send the press a LaTex document. So I thought I wanted a docx. I knew that Pandoc can take MathType-supplied LaTex code and create editable equations in Word. So I thought I might use your General Nonfiction template, insert LaTex equation code where I need it, compile to .tex, and then use Pandoc to convert the LaTex document to Word.

But perhaps I should just get comfortable with the fact that since my book manuscript has very few fancy elements beyond equations, I should just use your Gen Nonfiction (LaTex) template, insert LaTex equation code where needed, and compile to PDF for my viewing pleasure, with the ultimate aim of supplying the press with the final LaTex file. It just makes me very nervous to send a final version to the press in a format I am very very uncomfortable working with.