Page 1 of 3

### How to compile a Scrivener document to Latex?

Posted: Wed Aug 15, 2018 1:04 pm
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.

### Re: How to compile a Scrivener document to Latex?

Posted: Wed Aug 15, 2018 1:17 pm
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.

### Re: How to compile a Scrivener document to Latex?

Posted: Mon Aug 20, 2018 1:41 pm
AmberV wrote: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?
p.jpg (116.5 KiB) Viewed 11509 times

### Re: How to compile a Scrivener document to Latex?

Posted: Mon Aug 20, 2018 3:10 pm
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.

### Re: How to compile a Scrivener document to Latex?

Posted: Mon Aug 20, 2018 6:01 pm
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.

s.jpg (96.69 KiB) Viewed 11486 times

### Re: How to compile a Scrivener document to Latex?

Posted: Mon Aug 20, 2018 8:04 pm
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.

### Re: How to compile a Scrivener document to Latex?

Posted: Mon Aug 20, 2018 8:52 pm
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.

### Re: How to compile a Scrivener document to Latex?

Posted: Mon Aug 20, 2018 11:31 pm
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.

### Re: How to compile a Scrivener document to Latex?

Posted: Wed Aug 22, 2018 7:26 am
AmberV wrote: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.

### Re: How to compile a Scrivener document to Latex?

Posted: Wed Aug 22, 2018 5:25 pm
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.

### Re: How to compile a Scrivener document to Latex?

Posted: Thu Aug 23, 2018 12:39 pm
I just saw your last post. Thanks for your indications. I will take time to read it and come back later.

### Re: How to compile a Scrivener document to Latex?

Posted: Thu Jan 24, 2019 6:30 pm
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.

### Re: How to compile a Scrivener document to Latex?

Posted: Thu Jan 24, 2019 7:14 pm
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.

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.

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.

### Re: How to compile a Scrivener document to Latex?

Posted: Sat Jun 08, 2019 4:40 am
AmberV wrote:Have you given the “General Non-Fiction (LaTeX)” project template a try yet?

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!!!

### Re: How to compile a Scrivener document to Latex?

Posted: Sun Jun 09, 2019 12:14 pm
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.