## How to compile a Scrivener document to Latex?

jp
jpkell
Posts: 31
Joined: Thu Aug 03, 2017 8:54 pm
Platform: Mac
AmberV wrote: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.

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!

AmberV
Posts: 24272
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:
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).
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

jp
jpkell
Posts: 31
Joined: Thu Aug 03, 2017 8:54 pm
Platform: Mac
AmberV wrote:As a Section Type, and thus the equation is in its own binder item. ...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).

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

AmberV
Posts: 24272
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:
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.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

jp
jpkell
Posts: 31
Joined: Thu Aug 03, 2017 8:54 pm
Platform: Mac
AmberV wrote:I think there might be some point of confusion here.

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.

AmberV
Posts: 24272
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:
I have never worked with LaTex, and assumed it would not be a good idea to plan to send the press a LaTex document

I’d say it depends on whether they have a boilerplate all set up the way they prefer, and then you would only need to provide the content, which wouldn’t be too complicated. Most of the complications and learning curve in LaTeX are designing the look and behaviour of document itself.

It is something I would consider testing a bit, before committing yourself to a major transition. Put in a chapter or two, see what it takes to get it working properly (you’ll probably have to adopt styles if you aren’t using them already), and then give them a sample, to see if that will work with their system.

One advantage of this approach though is that it was designed to make it possible to use Scrivener more like a word processor to generate .tex files—a bit more like LyX, if you’re familiar. There are some notable exceptions (like the aforementioned lists and tables), but it shouldn’t be as difficult as converting the workflow to Markdown (though on that point, do test the Convert rich text to MultiMarkdown compile setting, in the General Options tab of the main overview screen. That may get you a long way toward what you need—particularly if you create or modify some compile styles that are marked as “Raw markup” in their settings—that will make it possible to paste in LaTeX equations without them being converted to verbatim characters by the RTF → MMD conversion engine.

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.

To clarify one point: you would be compiling to .tex and then using the LaTeX engine to create a PDF file, not Scrivener. If you compile to PDF from Scrivener then your equations will be raw text. It is possible to automate that last step, rather than opening the .tex file in a dedicated LaTeX or coding editor and typesetting from there. Look in the Processing compile format pane, and enable post-processing. I’ve set this template up to perform a simple straight to PDF workflow.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

jp
jpkell
Posts: 31
Joined: Thu Aug 03, 2017 8:54 pm
Platform: Mac
AmberV wrote:
One advantage of this approach though is that it was designed to make it possible to use Scrivener more like a word processor to generate .tex files—a bit more like LyX, if you’re familiar. There are some notable exceptions (like the aforementioned lists and tables), but it shouldn’t be as difficult as converting the workflow to Markdown (though on that point, do test the Convert rich text to MultiMarkdown compile setting, in the General Options tab of the main overview screen.

Thanks for your patience with me. I really appreciate the sage advice. I have been playing with this all weekend and this morning and I feel confident this is my best way forward. One problem though: I cannot for the life of me get the equations to show up numbered. This is why I desperately wanted to see your Scrivener project for the Sample PDF, because I could see how it's done there and why my equations (using your Equation binder item) get centered and printed perfectly, but never get auto-numbered. I very much need numbering to look like "(1.1)", and I can't even get them to show up numbered in the "(1)" format.

AmberV
Posts: 24272
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:
Are you using LaTeX to typeset the compiled .tex file? If not then no, you won’t see any numbers. LaTeX handles all of those mundane details for you, all you do is supply the semantic request for numbering, and by extension how those numbers will be used in cross-references, also automatic.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

jp
jpkell
Posts: 31
Joined: Thu Aug 03, 2017 8:54 pm
Platform: Mac
AmberV wrote:Are you using LaTeX to typeset the compiled .tex file? If not then no, you won’t see any numbers. LaTeX handles all of those mundane details for you, all you do is supply the semantic request for numbering, and by extension how those numbers will be used in cross-references, also automatic.

I'm sorry, I'm not sure I understand what you are asking when you ask "Are you using LaTeX to typeset the compiled .tex file?" Compile is preset for "Compile for: Plain Text (.txt)," and I'm also leaving the preset format "LaTex (Memoir Book). Once compiled, the resulting document is a .tex file. It is that file that is not producing numbered equations when it is converted to PDF (with, e.g.,) Pandoc or TexWorks).

jp
jpkell
Posts: 31
Joined: Thu Aug 03, 2017 8:54 pm
Platform: Mac
AmberV wrote:Are you using LaTeX to typeset the compiled .tex file? If not then no, you won’t see any numbers. LaTeX handles all of those mundane details for you, all you do is supply the semantic request for numbering, and by extension how those numbers will be used in cross-references, also automatic.

P.S. I'm sorry for being so dense on this. I got myself into this jam because I wrote an entire book with Scrivener (which I love!!), and now I have a manuscript with MathType equations that need to be code and not pictures. I feel like using Scrivener as a rich text editor for LaTex is the right approach from here, but the way your template is handling equations is still a mystery for me. Unless we can figure out why I'm having such a hard time with the template's preset rules for equations, I would love to be able to write with rich text and blockquotes using your template's styles, and then insert an equation with standard LaTex syntax when needed, e.g.

Code: Select all

     V = \int_0^\infty  {{N_t}u({c_t})\,{e^{ - \delta t}}dt} \label{eq:SWF}

But even that is not producing a LaTex file on compile that yields numbered equations once outputted as a pdf with Pandoc.

AmberV
Posts: 24272
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:
I’m not familiar with using Pandoc to typeset like that. TeXWorks would be a better place to take the .tex file that Scrivener compiles, I think. I haven’t ever used it myself, but it looks like the kind of tool that would help simplify the typesetting process for you. I’m more familiar with TeXShop, where you can load the .tex file and hit ⌘T (usually two or three times if there are cross-references to resolve) to typeset it.

This is a bit of an “is it plugged in?” question, but do you have LaTeX installed on your Mac? I recommend MacTeX if not. You could perhaps get away with the slim distribution (I haven’t tested it with this template) rather than the huge +3gb download. If you can afford the latter, I’d recommend it purely because figuring out how to augment the slim install with the packages you need would be a bit of an awful way to introduce yourself to LaTeX. Might as well just have the big huge distribution so you will very likely never run into missing package errors.

If you do have LaTeX installed, then try going into the compile settings for this “LaTeX (Memoir Book)” format, and in the Processing pane, enable Post-process on command-line. The rest is all set up to go, so long as you have a typical distribution installed, that should create a PDF when you compile, instead of having to take it into other programs.

Here is what I get if I copy and paste the equation you provided above, into an “Equation” type binder item, with a couple of lorem ipsum text sections around it. I then enabled the “Equation Packages” module in the front matter folder:

P.S. I noticed in your equation snippet you’re including your own \label. You’ll be working at odds against Scrivener’s attempt to label these automatically, that way. In fact it might even throw an error, which might impact numbering.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

jp
jpkell
Posts: 31
Joined: Thu Aug 03, 2017 8:54 pm
Platform: Mac
AmberV wrote:If you do have LaTeX installed, then try going into the compile settings for this “LaTeX (Memoir Book)” format, and in the Processing pane, enable Post-process on command-line. The rest is all set up to go, so long as you have a typical distribution installed, that should create a PDF when you compile, instead of having to take it into other programs.

Wow, OK, so my issue was Pandoc. Converting the .tex to .pdf with Pandoc was producing no numbers, but when I try with TexWorks I get exactly what you got. Huzzah! Unfortunately, however, my native post-processing isn't working. This is the error I get:

Screen Shot 2019-06-10 at 1.38.47 PM.png (126.23 KiB) Viewed 1616 times

Thoughts?

Finally, with regard to the reference workaround offered here: https://www.literatureandlatte.com/forum/viewtopic.php?p=271287#p271287. How can I learn the "scrivauto" id for a specific equation so I can use your referencing trick to block out the name of the equation?

And THANK YOU both for creating this template and for your assistance over the last few days. I *really* appreciate it!

AmberV
Posts: 24272
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:
You’re welcome, it’s my pleasure!

TeX log files are quite long, and generally what broke the process will be located close to the bottom, so I can’t really tell you what is going on from this screenshot.

I suspect though, as noted in my post-script, if you haven’t deleted your own custom \label syntax from the equation, it’s aborting on account of that. That’s how I noticed the problem myself, as I got an error the first time, noted it was complaining about multiple labels, removed \label{eq:SWF} from your equation, and then it compiled and converted to PDF cleanly.

Now what might have happened, to make a guess, is that Pandoc actually found this problem and stripped both labels out. An equation without a label won’t have a number.

How can I learn the “scrivauto” id for a specific equation so I can use your referencing trick to block out the name of the equation?

Have you tried the workaround yet? If it isn’t working as expected, let me know what your desired input (in the editor) and output (in the .tex file) should be. This workaround adjusts how links are created in the output, it requires no modification in the source text—and thus as implemented, it does not require you to know the autoscriv number. It still generates that for you, only it does so on the next line, leaving Scrivener’s title output commented alone.

But to answer your question, there is a way of getting that number and it is same placeholder code I use in compile settings, <$linkID>. So one could manually type in \autoref{scrivauto:<$linkID>} into the editor, select the placeholder part of it, and then internally link it to the intended target (drag and drop from the binder onto the selection in the editor to create a link).

But again, the workaround does not require you to do that. You’d only need to do things manually like that if you wish to use different types of links on a per-link basis.

And also, I just noticed that at the moment there is a small bug in Scrivener with how linked placeholders work in conjunction with the Markup compile pane. Links like this, that are really only links to help enable the placeholder to work properly, shouldn’t be exported as links, but they are. So right now if you try to make your own <$linkID> link in the editor you’ll get a broken output with multiple nesting autoref calls. So don’t actually try to make your own custom links just yet. It’s a useful trick to have in mind though. We’re automating with the compile settings, but all of this can be typed in by hand as well, which can be good to know as automation can be sometimes overly generalised. .:. Ioa Petra'ka “Whole sight, or all the rest is desolation.” —John Fowles jp jpkell Posts: 31 Joined: Thu Aug 03, 2017 8:54 pm Platform: Mac AmberV wrote:I suspect though, as noted in my post-script, if you haven’t deleted your own custom \label syntax from the equation, it’s aborting on account of that. That wasn't it, as I created a new project and used your method from start to finish -- no custom \label syntax at all. But yeah, sorry for thinking I gave you the entire error message. Didn't realize it was much longer than that snippet. Have you tried the workaround yet? If it isn’t working as expected, let me know what your desired input (in the editor) and output (in the .tex file) should be. This workaround adjusts how links are created in the output, it requires no modification in the source text—and thus as implemented, it does not require you to know the autoscriv number. It still generates that for you, only it does so on the next line, leaving Scrivener’s title output commented alone. But to answer your question, there is a way of getting that number and it is same placeholder code I use in compile settings, <$linkID>. So one could manually type in \autoref{scrivauto:<$linkID>} into the editor, select the placeholder part of it, and then internally link it to the intended target (drag and drop from the binder onto the selection in the editor to create a link). The workaround works perfectly if I already know the Equation binder item's scrivauto id (e.g. by digging into the compiled .tex file: Screen Shot 2019-06-10 at 3.07.48 PM.png (56.49 KiB) Viewed 1608 times (The workaround is implemented for the last sentence only.) But if I use your recommended method, i.e. linking "$linkID" to the Equation binder item, I get a reference to the section instead of to the Equation:

Screen Shot 2019-06-10 at 3.17.27 PM.png (56.31 KiB) Viewed 1608 times

Is this the error you mention at the end of your last post? If so, is the only route to hiding the name of the Equation binder item the route where one already knows the scrivauto id number by digging into the .tex file? I hope not!

AmberV
Posts: 24272
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:
(The workaround is implemented for the last sentence only.) But if I use your recommended method, i.e. linking “\$linkID” to the Equation binder item, I get a reference to the section instead of to the Equation:

The workaround adjusts how links are created by the compile process itself, not how you type them into the editor. This wouldn’t be something that would be “on” for one link in the paragraph and “off” for another, it would broadly impact how all cross-references work throughout the project. Make sure you are implementing the workaround as suggested, to the Markup pane.

Again, no modification to your workflow is necessary in the editor. You just drop your equation document into the text where you want the cross-ref.

I would strongly recommend not trying to manually do this yourself in the editor, and instead implement the workaround as suggested in the compiler. You are using serially generated numbers which are calculated based on the entire binder structure. If you so much as add one small equation to chapter one, every single hand-coded autoref to scrivauto:482 (or whatever) would have to be researched all over again from the .tex file. It is scrivauto for that reason.

But yes otherwise, as noted the specific method of linking safely without having to know the number, using the linkID placeholder, is not working. If you do need hand-coded links, I’d recommend placing them into inline annotations for the time being, to avoid confusion and potential syntax errors. You can enable them later by toggling annotation formatting off. That’s another type of busy work to fix later on, but it will be a whole lot more useful and a lot less time consuming than fixing out of sync numbering.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles