Raw LaTeX, Scrivener 3 and compile process

User avatar
nontroppo
Posts: 1219
Joined: Mon Mar 05, 2007 5:22 pm
Platform: Mac
Location: Airstrip One

Thu Jun 07, 2018 1:01 am Post

AmberV wrote:The plain-text mode will be getting access to the Processing pane in the next update. So you would be able to, among other things, graft a mklatex or pdflatex workflow into the compile settings and end up with a PDF instead of a .tex file, if you want.


Cool! 8)

JR
JRV
Posts: 18
Joined: Sun Oct 07, 2012 11:42 pm
Platform: Mac
Location: Southern California

Thu Jun 21, 2018 12:05 am Post

I'm using AmberV's template with LaTex output. I'm generally quite happy. Have been relearning LaTeX which I haven't used for about 15 years.

I'm writing an actual memoir (for the family) with a lot of figures.

There is one problem that I haven't been able to reproduce with a simple example. But it seems that when I move figures around or retitle them in the referenced document, Scrivener remembers what was there before when recompiling unless I close the project and re-open it. The latest issue was that I had changed the name of the image in the linked file, and re-inserted it, but then when compiling the image I had reinserted wasn't in the compiled folder (which normally includes the LaTeX source and all the figures that were inserted).

When I closed the project and reopened I got the right figure.

I'm using

Code: Select all

insert -> image linked to file


I hope this is clear enough. I will try some more to get a simple but complete example of the problem.

Another thing to pass on -- not a problem, but an obseration:

I have found that I won't be using the Figure style as (1) I'm not always happy with the [htpb] option set, and (2) I have decided to put in figure labels. Possibly this could be done with the Figure Style, but I personally don't mind simply typing \begin{figure} \centering... \end{figure}. Could even do this with text replacement instead of a style, I guess.

Also, I'm using wrapfig.sty quite a bit. I tried putting in a style for that when I was starting out but abandoned that effort for similar reason -- in fact there were even more custom options per figure!

Thanks for the template. Other than the problem I seem to be having that requires closing the project and reopening it every now and then I am very happy with it.

mc
mcd
Posts: 39
Joined: Tue Nov 03, 2009 7:06 pm

Thu Jun 21, 2018 12:13 am Post

JRV wrote:There is one problem that I haven't been able to reproduce with a simple example. But it seems that when I move figures around or retitle them in the referenced document, Scrivener remembers what was there before when recompiling unless I close the project and re-open it. The latest issue was that I had changed the name of the image in the linked file, and re-inserted it, but then when compiling the image I had reinserted wasn't in the compiled folder (which normally includes the LaTeX source and all the figures that were inserted).

When I closed the project and reopened I got the right figure.


Just a guess, but you often need to LaTeX a file twice to get the correct output; it's possible the template isn't doing anything wrong. You should be able to tell by looking at the LaTeX output, or by running LaTeX again on the initial output without reopening the Scrivener project.

User avatar
AmberV
Posts: 24272
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Thu Jun 21, 2018 12:00 pm Post

Or you might also be describing Scrivener, and how it works with linked images. When you first click on a section in the binder that has linked images, it will load and cache the images from the disk, displaying a thumbnail in the editor for your convenience. If the image later changes on the disk during that session, then the software will not react to that change because it is loading from fast cache rather than going back to the original (potentially large and slow) files on the disk every time.

You can manually force a cache update without reloading the software, by right-clicking on the image and using the “Reload from Original Image” ccontextual menu command (which will also reset the dimensions to what is on the disk, and thus something to make a good habit of doing if you change image sizes externally).

I have found that I won’t be using the Figure style as (1) I’m not always happy with the [htpb] option set, and (2) I have decided to put in figure labels.


You can change that and any other style output (and well, everything for that matter, the whole thing is built from Blank, so what can be built can be unbuilt ;)). Search for “Figure Customisation” in the help file for more info—but the basic idea should be self-evident by going through the various styles in the Styles compile format pane.

For labels, that is what the Label style is for. It’s usage is illustrated in the example figure a few paragraphs above the customisation documentation. Using styles to mark stuff like labels is pretty nice, because you can use that Edit ▸ Find ▸ Find by Formatting... tool to look specifically for styled text. If you don’t remember precisely where an figure is that you want to refer to, you can scan for it more easily that way.

Also, I’m using wrapfig.sty quite a bit. I tried putting in a style for that when I was starting out but abandoned that effort for similar reason – in fact there were even more custom options per figure!


Well yeah… it really does depend on what you need and whether it makes sense to abstract a thing into a Section Layout or Style. The main thing I want to illustrate with the template is that you can, and provide practical examples for how that could be done. For example with wrapfig, you could take the example of how I insert a \caption in the “Figure w/ Caption” Layout, where in the Suffix tab we have:

Code: Select all

\caption{<$custom:Caption>}
\label{scrivauto:<$linkID>}
\end{figure}


This takes the contents of the “Caption” custom metadata field in the inspector sidebar for that figure and insert it into the syntax. Taking that same principle, one could create additional (even multi-choice lists) metadata, and have in the Prefix tab:

Code: Select all

\begin{wrapfig}{<$custom:ImagePlacement>}{0pt}
\centering


Or you could have a field to type in the width into the sidebar, or even manage a way to use regular expressions and somehow get the natural width of the image into that spot. And you could move the Label over to custom metadata as well, instead of going with my auto-generated example in the Suffix. Having the label as a custom field adds the benefit of being able to add it as a column in the outliner, making lookups extremely simple:

  1. Project Search for section type “Figure” (possibly saving that to a saved search collection).
  2. In the Outliner, Cmd-F and search for the figure by name or caption.
  3. Copy the label you want and return to where you were to paste the cross-ref.

To my mind it’s all about exposing data to organisational features where it makes sense to. If someone isn’t adding dozens of cross-references on a daily basis, that workflow would be overkill. But the idea behind that workflow might be used to augment some particular thing you do a lot of that is entirely different.

And like you say, often it is easier to just type it in or use Replacements—this template is designed after all for those that don’t mind and maybe even like writing in LaTeX. :) I’m not sure if I would want to encapsulate wrapfig like that either, or have to look up and type in stuff into the inspector every time. Just wanted to point out what is possible, if one were inclined.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

User avatar
AmberV
Posts: 24272
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Thu Jun 21, 2018 1:49 pm Post

With Scrivener 3.0.3 available, this template is now included in the base install, under the Non-Fiction category. Thanks to everyone that helped test it and provide feedback!
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

JR
JRV
Posts: 18
Joined: Sun Oct 07, 2012 11:42 pm
Platform: Mac
Location: Southern California

Fri Jun 22, 2018 2:13 pm Post

Thanks AmberV for your very thorough response to my somewhat muddled question. Since posting I had read about Scrivener's caching mechanism and had decided I had run afoul of that, but your reply really helped clarify it for me, And I the other info you included is very helpful .

el
elorie
Posts: 2
Joined: Thu Jun 28, 2018 3:38 pm
Platform: Windows

Thu Jun 28, 2018 3:40 pm Post

AmberV wrote:With Scrivener 3.0.3 available, this template is now included in the base install, under the Non-Fiction category. Thanks to everyone that helped test it and provide feedback!


Hello AmberV,
is there any chance to get this template another way?

I am using Scrivener on Windows and Scrivener 3 for Windows is still a little bit away and I am writing my master thesis now ;)

User avatar
AmberV
Posts: 24272
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Thu Jun 28, 2018 3:50 pm Post

Unfortunately that template is going to be of no use to you at all on Windows, sorry to say. It depends heavily upon 3.0 level features, not all of which are yet implemented in even the beta version of Windows.

Your best bet right now will be to use the MultiMarkdown based approach in your current version, or to simply compose LaTeX directly into the editor, as many have done, and compile to plain .txt, changing the extension.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

el
elorie
Posts: 2
Joined: Thu Jun 28, 2018 3:38 pm
Platform: Windows

Thu Jun 28, 2018 3:53 pm Post

Thank you for your quick answer. I'll try it "the old way" again.

al
alexbruton
Posts: 2
Joined: Mon Jul 23, 2018 8:03 pm
Platform: Mac

Mon Jul 23, 2018 8:15 pm Post

Hi there,

The General Non-Fiction (LaTeX) template in Scrivener 3 is super helpful. Thank you for that.

Would you be able to share the project for the version you used to create the Sample PDF embedded therein? I'm new to Scrivener and even that little bit more detail would be helpful.

And, do you have some directions on the basics? E.g.: I'm familiar with LaTeX but how do you create the equation that gets inserted into the binder? Then how do you add that within the text? Can you view/edit the LaTeX code for an equation from within Scrivener?

With thanks.

Alex.

User avatar
AmberV
Posts: 24272
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Tue Jul 24, 2018 3:24 pm Post

Glad to hear you’re finding it useful!

I’m familiar with LaTeX but how do you create the equation that gets inserted into the binder?


The project comes with a few example document templates that are set up to work with compile out of the box. To create an equation item in the binder, use the Project ▸ New from Template ▸  submenu to select one of the equation options. The difference between the two is that the standard “Equation” type comes with a LaTeX label. You can reference the equation from elsewhere in the text by dragging the binder item into the editor, causing Scrivener to create a hyperlink to the equation. It will generate the autoref and match the label for you.

Then how do you add that within the text?


Not sure what you mean—but in case it isn’t clear, it’s just a text file in the binder. Granted, it’s a type of text item, set up to format the contents as an equation, but what you type into it will be printed into the output like all of the other text items you add to the binder. This is perhaps a little more straightforward than you may be thinking.

Put it this way, if you type “2 + 2 = 5” into an equation binder item, and it is between two chunks of text, then if you select those three items in the binder and view them as Scrivenings, you’d see:

Image

That’s what you see and what you work with while writing. The “Test” hyperlink by the way is pointing to the equation binder item (called “Test” in the binder). However when this is all compiled, you get:

Code: Select all

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

\begin{equation} \label{scrivauto:7}
2 + 2 = 5
\end{equation}

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur see Test (\autoref{scrivauto:7}). Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.


The Section Layout assigned to “Equation” binder items will insert the stuff around the equation itself, including the automatic label, which will be used by the link to create an autoref.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

al
alexbruton
Posts: 2
Joined: Mon Jul 23, 2018 8:03 pm
Platform: Mac

Tue Jul 24, 2018 4:07 pm Post

Thank you for the quick reply. Together with having done some homework in the meantime, this answered almost everything for me.

One quick one though. How do I change how the “Test” hyperlink would output in the resulting compiled document?

E.g. For equations I'm getting Equation Title (Equation #) in the output, and for figures it's Figure Title (Figure #). But I would want just Equation # and Figure #.

Also, the default numbering for the figures seems to start at Figure 11. Is there a way to adjust this, e.g. to start at Figure 1?

Thanks!

Alex.

User avatar
AmberV
Posts: 24272
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Wed Jul 25, 2018 10:41 am Post

If you check earlier in this thread, you will find discussion on how to modify the functioning and form of hyperlinks.

As to what you are attempting specifically, with the understanding that this will impact how all cross-references work, including section and chapter references, you could achieve what you are looking for with a bit of a LaTeX-based workaround. The problem is that Scrivener is always going to export the name of the item you link to—that’s just how it is programmed to work, and in keeping with how hyperlinks work in general, where the text that is linked is not meant to be wholly transformed or erased by the output engine. So we can’t actually get rid of the “Name of Equation” text, but thanks to LaTeX’s commenting syntaxing, we can certainly hide it.

Prefix:

Code: Select all

%


Suffix:

Code: Select all


\autoref{scrivauto:<$linkID>}


The removal of the parentheses from the default settings aside, the carriage return at the top of the suffix is most important. The result in LaTeX will be a bit ugly, which is why I would consider it a workaround, but it works. It places a comment indicator directly in front of the text of the hyperlink, then the carriage return that leads off the suffix starts a new line in the file, which won’t be commenting, leaving the autoref visible, as well as any subsequent text in the paragraph.

And of course if you do want the name of the thing you’re referencing, you would now have to type it in separately from the hyperlink like so, “Refer to Processing Photographs in Raw Format (Processing Photographs in Raw Format), for further information.”

Also, the default numbering for the figures seems to start at Figure 11. Is there a way to adjust this, e.g. to start at Figure 1?


I don’t know how to answer that without more context, but generally speaking that isn’t something Scrivener has anything to do with; it might be something odd in your preamble.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles