typing raw latex in the editor window

Hi folks, I am new to scrivener and am attempting to understand how I can make it a nice part of my work flow.

Since I have used LaTeX for 15 years I would like to be able to use scriveners organizational and planning tools but just type my document in LaTeX code directly. I don’t want the hassle of using the markdown add-on. I would just save the document and compile it at the command line (or using texshop).

How would I configure things so that this would work?

R Haynes

I think the key would be to set it up so you have a very plain layout in your editing windows and then when you compile, set it to compile to plain text. You can split your text up so that each section is a separate document, and as documents can contain other documents, presumably you can simply put sub-sections as children of sections, etc. Type your latex sectioning commands within the documents themselves, then when you compile, set it to ignore document titles.

I guess that would work … it’s at least 15 years since I’ve used LaTeX and often think I ought to get the old cogs in my brain turning again, but there are too many other pre-occupations to allow me the leisure to do that.


Yes, as Mark says… In Compile Draft make sure that you have it set up to straighten smart quotes, turn ellipses into three periods and em-dashes into double hyphens etc. You may find it helpful to use a plain text font such as Monaco in the main editor, too (you can change the default font and paragraph style via the Preferences). Also in Compile Draft you are likely to want to change it so that documents only have a return or double return between them, and you will want to uncheck the “Page Break Before” option in folders, I suppose (though LaTeX may just ignore such characters, I’m not sure).

You should be able to generate clean plain text even though Scrivener isn’t set up for plain text, but I have never tried it…

All the best,

Hi, thanks for the pointers… one minor annoyance is that when I try to export to plain text it wants to name the file with a .txt - it will allow for .tex.txt but not having .tex may make it difficult to open quickly in texshop for instance to make tweaks or to print a draft. Anyway to avoid that?

R Haynes

I don’t know if Keith has anything up his sleeve for that, but if you have a file whatever.txt, you can simply rename it in the finder to whatever.tex. I know it’s an extra step … well actually two as you’ll get an alert saying “Do you really want to do this?” to which you have to say “Yes”, but that’s not a huge amount of effort.

Of course you could choose to save it without the extension and then simply add the extension through the finder … but I don’t know if that would work. I know the former does from needing to change .csv files to .txt for a label-making app.


Run the attached Automator workflow and select (you can do a multiple selection in the dialog) your txt files. They’ll be renamed to “tex”.

txt2tex.app.zip (167 KB)

The free way to automate that would be to write an AppleScript and attach it to the folder you export to. Then the only bother with the process is having to wait a second or two, rather than you having to take another step. Hazel (not free) handles this for me, as I run into the “*.md.txt” problem all of the time. I just have it search for full name ending in “.md.txt” and rename to original name sans extension (since it considers the ‘.md’ to be part of the original name).

Why not use the MMD->LaTeX export? MMD can be configured to pass through “raw” LaTeX, so you can completely blank out the Markdown syntax and use LaTeX commands instead. As a bonus, your section commands will be created automatically, which saves you a lot of work.

Hi, I have played with this in a limited fashion but as one of my other posts indicate I had some trouble with some LaTeX characters exporting correctly.

R Haynes

Hi, well coming from a unix background I know a little about shell scripts so I managed to put together a applescript

on adding folder items to this_folder after receiving added_items try do shell script "cd /Users/rhaynes/Documents/MyPapers/InProgress; for i in `ls *.txt`; do newfile=${i%.txt}.tex; mv $i ./TexFiles/$newfile; done" end try end adding folder items to

and then used folder actions which runs the script “on adding folder items”.

R Haynes

Oh sorry, you’re right, this would probably require a major rewrite of MMD. But I think
have I found a much better solution for your problem :smiley:

Since you’re into writing shell scripts, how about using the plain MMD export? This would compile your document into a single plain text file with the addition of some MMD Metadata and section headings (!), but the actual text of your document would remain unchanged. All you have to do is to write a script that strips the MMD-Metadata and replaces the MMD sections with proper LaTeX markup.

Hi, thanks for the reply. Beyond my current abilities (not to mention my threshold for self-inflicted pain) I am afraid! Hopefully my current setup works well.

R Haynes

Umm, em-dashes should be turned into three hyphens; two hyphens represents an en-dash in LaTeX.

I wouldn’t let Scrivener change anything. Smart quotes and en- or em-dashes can be entered directly in LaTeX, provided that the input encoding is UTF-8: \usepackage[utf8]{inputenc}