TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Every so often I'll be working and all of a sudden xelatex won't work, saying "I can't write on file `test.pdf'". But why not? Is it something I did? Did I insult xelatex? Now it won't even compile my test.tex.

This is XeTeX, Version 3.1415926-2.2-0.9995.2 (TeX Live 2009/Debian) (format=xelatex 2011.4.22). Ubuntu 10.04.

The input

hello world

The error

LaTeX Font Info:    Overwriting math alphabet `\mathsf' in version `bold'
(Font)                  OT1/cmss/bx/n --> EU1/lmss/bx/n on input line 4.
LaTeX Font Info:    Overwriting math alphabet `\mathtt' in version `bold'
(Font)                  OT1/cmtt/m/n --> EU1/lmtt/bx/n on input line 4.
! I can't write on file `test.pdf'.
(Press Enter to retry, or Control-D to exit; default file extension is `.pdf')
Please type another file name for output: 
! Emergency stop.
<to be read again> 
                   \endgroup \set@typeset@protect 
l.6 \end{document}

End of file on the terminal!

Here is how much of TeX's memory you used:
 5003 strings out of 495724
 81422 string characters out of 1189346
 150108 words of memory out of 3000000
 8144 multiletter control sequences out of 15000+50000
 3664 words of font info for 17 fonts, out of 3000000 for 9000
 28 hyphenation exceptions out of 8191
 40i,4n,27p,455b,147s stack positions out of 5000i,500n,10000p,200000b,50000s
No pages of output.

The inconsistency of it all

Ten minutes later (now), after tinkering around, it works. So I delete the contents of the file, and paste what I posted here, and, it works. Then I delete test.* except for the tex file, try xelatex again, and it doesn't work. The tinkering was to change the tex file to this:


 \usepackage{fontspec}% provides font selecting commands
 \usepackage{xunicode}% provides unicode character macros
 \usepackage{xltxtra} % provides some fixes/extras

hello world

strace -f

Strace shows a memory error right before the "cannot create pdf" line. I'm experimenting with adding more swap. Currently my system is down its last 300-400 MiB of ram, and I'm seeing xelatex using upwards of 200 MiB. Which means a couple more browser tabs or another pdf window could foul things up..

clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7887738) = -1 ENOMEM (Cannot allocate memory)`.
share|improve this question
It sounds to me like your operating system is for some reason locking the pdf file. What operating system do you use? Do you by any chance have the pdf file open in adobe reader when the error happens? – Jan Hlavacek Apr 28 '11 at 2:23
Running Ubuntu Linux, and no, the pdf is closed. Also, the pdf is deleted, per the deleting everything but the tex file. – djeikyb Apr 28 '11 at 2:25
What happens if you try in different directories? – Caramdir Apr 28 '11 at 3:22
Run the xelatex command under strace -f and look for the relevant open() or stat() call. It will tell you the number of the error being encountered. – Andrey Vihrov Apr 28 '11 at 7:34
The log (or terminal?) snippet is rather curious. The error message doesn't look like a xetex message. xetex itself doesn't try to write a pdf, it generates a xdv and then calls xdvipdfmx. So why should xetex complain at \end{document}? If xdvipdfmx can't write the pdf I (with miktex) get Error 1 (driver return code) generating output; at the end of the log and I doubt that this is different with TeXLive. You should better show the complete log-file so that we can see what versions you are using. – Ulrike Fischer Apr 28 '11 at 8:07
up vote 29 down vote accepted
! I can't write on file `skills.pdf'.

In this case, the error is caused by not having enough memory. The clone(...) = -1 ENOMEM (Cannot allocate memory) error from strace prompted me to check my ram usage. Running xelatex with 150M of free ram provokes the write/clone() error. Running with at least 500M of free ram consistently avoids the error. I haven't experimented enough to know exactly how much free ram is enough, but I suppose that also depends on the complexity of the tex file.

To compensate, I created a swap file (fwiw, I usually don't have one).

dd if=/dev/zero of=/var/512mb.swap bs=1M count=512
mkswap /var/512mb.swap
swapon /var/512mb.swap
share|improve this answer
Wow, I guess xetex would greatly benefit from a better error management. – ℝaphink Aug 17 '11 at 13:22
@ℝaphink and memory management. – user2529583 Jun 29 '14 at 18:19

protected by Community Jan 9 '14 at 13:51

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.