MMD -> PDF with custom LaTeX Header

Hi - I’m trying to compile an MMD Scrivener project directly to a PDF with a custom LaTeX Header defined in Scrivener. But pdflatex breaks because of

! LaTeX Error: File `mmd-scrivcustom-header.tex’ not found.

  1. Why is it looking for a scrivcustom-header file?
  2. And where should i put this file in? (Output Directory does not work)

This file should be created automatically by Scrivener, based upon the contents of the three tabs in the LaTeX compile option pane, when “Custom” is selected. Three .tex files, including the primary .tex file including your work and any figures will be compiled to a temporary folder, processed with pdflatex, and then discarded once the PDF is produced and saved to your requested location. In short the whole process should be opaque, so something must be going wrong here. The first thing I would check is that you actually have something inserted into each of these three tabs. We should probably produce an empty .tex file here so that the result you got does not happen. For instance if someone does not need to separate the preamble into two pieces, they should be safe in leaving one of the tabs empty.

So in the meanwhile, at least insert a %comment into the tab you do not need.

Second possibility: there is a character in one of the text fields that has jammed up Scrivener’s ability to write out the file. If each tab does have content, try running the contents through a cleaner to strip out any Unicode control characters and such.

Hi Ioa. Thanks for your suggestions. I’ve made an empty Project with the following LaTeX Options:

Custom Header:

Begin Document:


WIth MMD -> LaTeX I get a folder with all the necessary .tex files for compiling the document without any errors using pdflatex. Using MMD -> PDF I still get the error message:

! LaTeX Error: File `mmd-scrivcustom-header.tex’ not found.

I can reproduce this on two different machines with a standard user account.

Interesting, can you make an ePub file? That uses a temp folder as well, and I’m wondering if maybe there is a permissions issue. If ePub doesn’t work either, you might want to run disk repair and the -permission fixer. Are you using the MAS version or direct-sale?

There is no problem in creating an ePub. Disk Repair didn’t change anything. But using an admin account on both machines solved the problem. Can you reproduce this behavior?

Interesting, that doesn’t map over to my machine unfortunately. I tested with a vanilla standard account and was able to produce a PDF with custom LaTeX headers, using the direct-sale version. What version of Mac OS X are you using?

I’m using OS X 10.8.4 with a direct-sale version of Scrivener (2.4.1 22817), but a german language system. I’ve created a vanilla standard account and everything is running fine.
Is my shell setup (.zshrc, $PATH, etc.) relevant for compilation, or is anything in ~/Library I should looking for or remove?

Thanks, I am checking with the developer on the particulars of the temp file creation to see if what if any user dot files might impact it. It does sound like a configuration issue with the account though, and if you have it happening on two machines it is probably a deliberate setting somewhere.

It only gets stranger. The methods used to create an ePub are in fact identical to those used to create a PDF, as I suspected. So there is something specific impacting pdflatex’s performance, rather than something general such as a permissions fault in the temp folder area. That would lend more credence to the theory that a dot file has a misconfiguration, perhaps in such a way that LaTeX cannot find .tex files in the system /var/tmp folder. It seems to otherwise be configured correctly for finding .tex files in the working folder, since you mentioned compiling to .tex and typesetting from that location works fine. So I would check and see if there is anything strange in your LaTeX configuration or path.

One thing you could try as a test, to verify this theory, is to set aside pdflatex for safekeeping, and replace it with a shell script set to executable:


echo $PWD
cat mmd-scrivcustom-begin-doc.tex
echo "\n----------------------------------------------------------------"
cat mmd-scrivcustom-footer.tex
echo "\n----------------------------------------------------------------"
cat mmd-scrivcustom-header.tex

That would dump the contents of Scrivener’s three generated include files to STDOUT, which will be recorded in the compile log window. You’ll still get a compile failure at the end (because no PDF will be generated), but at least you can check the log. If the contents of all three tabs are printed in the window, then you know that (a) the files exist and (b) they are readable to the Scrivener shell process that is executing the workflow. I highly suspect this will work, since ePub works, but it could be worth a check. This will also print the working folder that Scrivener uses, on the first line, which might be useful in tracking down why this doesn’t work from that specific location.

Hi Ioa. I moved all my shell dotfiles away, changed my account to an admin account and used your script just to get the following message:

[code]cat: mmd-scrivcustom-begin-doc.tex: No such file or directory
cat: mmd-scrivcustom-footer.tex: No such file or directory
cat: mmd-scrivcustom-header.tex: No such file or directory


Even if I create the missing .tex files in the temp folder I will get this error message (no such file) !?

But I found a solution. If I put the latex header in an extra file and use the compile option ‘None/Meta Data’ with ‘latex input’ as a Meta Data entry I can compile a PDF directly.

I would really like to know the answer for my problem, but if this is just a problem with my setup I’m fine with the external solution.

Kind Regards,

Interesting, I am not sure what to make of those results. How is it possible that Scrivener is creating the main matter .tex file into the temp folder, but not the boilerplate .tex files? The operations used to generate these files are identical. But then, you say even if there are definitely correctly named .tex files in this location you still get the error. But what we do know, whatever is wrong, it’s not a LaTeX configuration problem or something, because a simple Bash script using cat couldn’t even access the files from the directory that it was executing from. I’m not sure what that means, to be honest. It sounds more like a Mac problem than anything higher level, like Scrivener or LaTeX.

But yes, as you note you can just put the .tex file somewhere and call it in meta-data. A refinement on that technique would be to put your boilerplate files into the ~/Library/texmf/tex/latex/mmd folder. They can be called something more meaningful to you, and then named from the MMD meta-data block. Since this location is accesssible to pdflatex, it should allow you to compile straight to PDF without having to manage the .tex files and compile folder together.