Moving LaTeX to Scrivener

Hello all,

I´m quite new to scrivener and just downloaded the trial a few days ago. I have now a few problems to get the system work properly. What I have done so far:

I have LaTeX files I want to move to Scrivener, and put a few parts (\sections) in scrivener files.
Set up LaTeX in the Compile menu (header (my “old” LaTeX header) body and footer)
filled in a few Metadata (BiBTex, Author…)
Set up Export language to German

Now for the problem: When I compile I get the appropriate files, but no German “Umlauts” (works fine in MacTeX). I´ve seen an old post regarding this problem, but for me I´m using the following commands in my LaTeX environment which apparently do not work in Scrivener:

\documentclass[12pt, german, ]{article}
\usepackage[ngerman]{babel}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}

Can anyone give me a hint what I can do?

Greetings from Germany

Mike

If you mean that you’re writing "u for ü, etc., then of course Scrivener won’t interpret that. But you can set replacements for these in the Scrivener Compile settings.
An alternative is to use XeLaTeX (which obviates the need for babel) and just use the Unicode input ü in your LaTeX source.

Thank you for the answer,

I simply moved the existing texts from “native LaTeX” to Scrivener. So in the text there are no "“u”, it is simply (e.q.) “über”, and I would like to have this “compiled” without “translation” into “über”, i.e. no compilation but simply a copy-operation. So I prefer that the plain text is not transformed, but simply copied to the compiled version. This should be possible without having a lot of transformation rules to be applied - but for the moment I see no way to achieve this.

Greetings

Mike

OK, I’ll have to defer to someone who uses Scrivener on Mac. I’ve never had a problem getting UTF-8 output using Scrivener’s “Compile.”

UTF-8 characters compile to tex fine for me on macOS. Note that LaTeX output from Scrivener is via Multimarkdown (MMD), and problems with LaTeX normally involve some configuration issue of MMD. I prefer to use Pandoc for generating LaTeX (and always use XeLaTeX as I want simple elegant opentype support), but certainly your ü should be preserved from Scrivener to MMD. Can you try compiling to plain text MMD and see what you get? What if you then use MMD or Pandoc directly on the compiled.md markdown file, does it then work?

Thank you for the fast answer, for me this seems to be a lot of work to transform LaTeX (I´m very familiar with it) to scrivener. As far as I can see, there would be a different input syntax (MMD) which I have to change for my existing files. So switching to scrivener (Instead of MacTeX I´m currently using) means to apply a different syntax, because I´m writing mathematical stuff, with a lot of numbered equations and so on.

Greetings

Mike

Not correct! You can readily mix LaTeX math and LaTeX environments into markdown without any problems:

pandoc.org/MANUAL.html#raw-tex

You can then gradually simply your workflow when you are ready. There is no need for major changes to your content; keep using \emph{emphasis} until you think emphasis is clearer etc. then mix them together…

Quite a few users mix and match LaTeX in Scrivener, others make the jump to a cleaner writing environment afforded by markdown. I think the only major change is to make best use of the Binder you should let Scrivener generate your section headings etc…

So here is a mix and match of LaTeX and markdown in Scrivener’s editor:

Ad mütat *integre* Co~2~ CO\textsubscript{2} in \emph{concentrations} of 1.34×10^3^ conclüsionemqüe eüm, $e^{ix}=r(\cos \theta +i\sin \theta ).$ tota ütinam scriptorem no cüm.

All makes its way safely to the final TEX file:

Ad mütat \emph{integre} Co\textsubscript{2} CO\textsubscript{2} in \emph{concentrations} of 1.34×10\textsuperscript{3} conclüusionemqüe eüm, \(e^{ix}=r(\cos \theta +i\sin \theta ).\) tota ütinam scriptorem no cüm.

LaTeX environments are not parsed as markdown, and even LaTeX macros are safe in Pandoc…

I also use Scrivener for mathematical writing and export to LaTeX via Markdown. Mike is correct that it’s not completely friction-free to make the transition if you’re writing hardcore mathematics (as opposed to the occasional display equation), but I won’t go into all the details right now. In short, if you’re comfortable and productive with some LaTeX front end it’s probably better to stick with it.

The big advantage of Scrivener is that it’s a fantastic environment for organizing your work. So if you have an extremely disorganized process (raises hand), the tradeoffs of working with Scrivener are well worth it. OTOH, if you’re a more-or-less sane person, you’re probably better served with a LaTeX editor. It kills me to say this because I love Scrivener and there is no LaTeX editor that I like enough to be able to work in. But the reality is that there is still nothing to date which both provides a sophisticated writing environment and also is suitable for professional-level mathematical writing.

@liz: This is the point. I like the way one can organize material AND write a text in ONE environment. But I am completely, to be honest, unfamiliar with MMD, Pandoc and all the stuff. So I´m going to try a bit more and see whether I´m going to get familiar with it. Is there any good source where I can find the necessary transformation rules and this MMD stuff in a comprehensive way?

Greetings from sunny Germany

Mike

@nontroppo: This sounds interesting, but as I got it it is necessary to make an additional, intermediate step: pandoc (which I do not know for the moment), I´m going to read a bit. Can this step be integrated in Scrivener or is it necessary to do this on the command-line (which looks very “old fashioned” for nowadays).

Greetings from Germany

Mike

@Mike I think it’s awesome that you want to use Scrivener for mathematics–I feel like I have some company! But if there is a comprehensive guide for doing this, I haven’t been able to find it. In fact, I’m pretty sure almost nobody else is doing this. So you’ve been warned.

Right this moment I’m not at a machine which has Scrivener installed, but when I am I’ll post with the (rather quirky) things that I do to get Scrivener to speak math in a way that I find usable. You probably already know this, but I’ll also mention that the plain-vanilla option is to just go ahead and write LaTeX as usual and then export as plain text and skip the Markdown.

Hi Mike, I think Liz is obviously much more knowledgeable about LaTeX Maths and Scrivener than I am; I’m a Neuroscientist and while I do need equations, they normally nestle quite happily in my Methods section. I don’t write with lots of equations so I don’t know what the caveats Liz mentions are.

So just a bit of a breakdown — to reiterate you don’t need to learn or use too much new stuff: Scrivener supports LaTeX output natively (using MMD built-in and transparent to the user); Pandoc is entirely optional.

  1. As Liz says, you can just export to plain text, then either open it in a LaTeX GUI add your .tex header and footer or use a commandline script to automate this.
  2. Scrivener has multimarkdown (MMD) built in (it is an internal tool to create LaTeX, you do not need to “know” MMD). This provides native support for LaTeX output. It uses a set of tex templates that you can customise if you need, though I’ve never customised this myself, but there is quite a bit of info on this forum. The Scrivener manual itself is written in Scrivener and typeset in LaTeX through the use the MMD compile route (and some post-processing scripts).
  3. Pandoc is entirely optional and not necessary. But it supports LaTeX comprehensively (lots of academics use it), and reads MMD and offers a lot of customisability. Think of this as an option to optimise your workflow later on. Also you can convert from LaTeX to markdown or docx or many other formats.

The example I gave above for mix-and-match LaTeX conversion also works for standard Scrivener⇨LaTeX export from Scrivener’s compile, the mixed output ends up like so:

Ad CO\textsubscript{2} mütat \emph{integre} CO\textbackslash{}textsubscript\{2\} in \textbackslash{}emph\{concentrations\} of 1.34×10\textsuperscript{3} conclüsionemqüe eüm, $e^{ix}=r(\cos \theta +i\sin \theta ).$ tota ütinam scriptorem no cüm.

There may be some cases for Scrivener⇨LaTeX where you need to escape the TeX and you do this using this markup to force the TeX to be untouched:

<!-- \input{mycustomlatex.tex} -->
<!--  This is raw \LaTeX \[ {e}^{i\pi }+1=0 \] -->

Automation:

Now, one big benefit of a dedicated LaTeX environment is real time preview, and this is something that is simply not possible in Scrivener[1]. Also as you say you don’t want to use the command line, but Scrivener outputs a .tex file so you do need to somehow manually load this or run latexmk on it or something. Now the next version of Scrivener is supposed to have much more powerful compile system, and this should get much easier. But for now, you can start with the command line, then if you want think of some tool to automate this (Folder Actions, Quicksilver etc.) this can be improved to be automatic (watch a folder for a file change, run latexmk, open PDF)…


[1] Well, if you use more markdown, you can use a great tool called Marked to get a live preview of the markdown transformed maths using MathJax…

@Mike I suspect most of this won’t be that useful for your purposes, but I’ll set it down here anyway.

Notation: Here “Compile” (capitalized) refers to Scrivener’s confusingly named output engine, and “compile” is for LaTeX.

First of all, these are the motivations for my rather idiosyncratic choices:

  • My primary concern is readability of my LaTeX “source code,” that is, what I write in Scrivener.
  • I want to be able to take my Scrivener output and open it up in TeXMaker as ready-to-compile LaTeX without the extra step of piping it through something else (such as Pandoc).
  • I do not want to have to compile to PDF every ten minutes just so I can see what I’ve written. The optimum number of exports from Scrivener to TeXMaker to PDF is one.
  • I want to be able to use RTF formatting as part of my writing/editing process, but I do not want it showing up in the LaTeX output.
  • I prefer to let MMD handle designating sections, subsections, etc., because I change my mind about this constantly and I want to use the Binder to set the levels. This is the main reason I go through MMD instead of just exporting as plain text.

Here’s what I do:

  • I use the math-environment delimiters (…) and set a replacement to MMD-style \(…\). I personally don’t like $…$, but if you do you should use that instead.
  • I write almost all of my mathematical symbols using Unicode literals (rather than LaTeX commands) and compile with XeLaTeX and the package unicode-math.
  • For complicated expressions, I make an image using a web LaTeX compiler and insert it as a comment.
  • I like “section” as the base level with theorems numbered as subsubsections. To do this, add the Scrivener metadata key (in the Compile menu) called “base header level” and set it to 3, so that 1 = section, 2 = subsection, 3 = subsubsection. The MMD default is 1 = part, 2 = chapter, etc.
  • Note that if you are exporting to LaTeX via MMD, the confusingly named “Compile As-Is” option will not bypass the MMD parser; it just ignores the Scrivener formatting specified in the Compile pane. I use this option for theorems because I don’t want theorems to have titles, unlike subsubsections. (You need to comment out to bypass MMD.)
  • I let MMD convert text to \emph{text} and text to \strong{text}.
  • I let MMD do bib citations, but I usually couple it with that \cite conversion macro I mentioned in the other thread.
  • I use a Scrivener replacement to write {{…}} instead of \ref and #{…}# instead of \label, just a personal preference.
  • I use amsthm and use Scrivener replacements with prop{…}prop for \begin{prop}…\end{prop}, etc. This is also a personal preference, but note that MMD does not have suitable analogs for the various theoremstyles, so you’re stuck with raw LaTeX.
  • Each theorem is on a separate document which I title with its label. One advantage of doing this is that you can Alt+drag (probably Opt+drag on Mac) a document to get a Scrivener-linked \ref.

Putting it together, my theorems look like

[code]thm{ #{doc.title.label}#
This is the statement of the theorem in AMS style with some math like ( ∑α_i^2 ).
}thm

Proof. Text of proof with {{scrivener.ref.label}} and [loc][#bib.key]. ( ∎ )[/code]

Bonus: I recently had the idea that it would be useful (and fun) to automatically generate dependency diagrams from my draft so that I could see the overall structure of an argument at a glance. I was fooling around a bit with Aeon Timeline (search this forum), but Aeon is both too much and too little for this specific purpose. I haven’t actually done this yet, but I think a better option is to use GraphViz, with input generated by a Python script that extracts the \ref dependencies for a given \label. Of course this could be done with any LaTeX file, but a good Scrivener Compile setting would facilitate bounding the loops in such a script.

Hope all this is useful to somebody. I would really like to see more alternatives to the monolithic text-editor-cum-PDF-viewer way of producing research-level mathematical writing. It’s very outdated and generally a crappy way to work. Yes, there’s LyX, but that has its own set of problems.