27

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

\documentclass{article}
\usepackage{fontspec,xltxtra,xunicode}
\setmainfont{Inconsolata}
\begin{document}
hello world
\end{document}

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.
 [1
! 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:

\documentclass[12pt,letterpaper]{article}

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

 \setromanfont[Mapping=tex-text]{Inconsolata}
\begin{document}
hello world
\end{document}

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)`.
12
  • 4
    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? Apr 28, 2011 at 2:23
  • 1
    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, 2011 at 2:25
  • What happens if you try in different directories?
    – Caramdir
    Apr 28, 2011 at 3:22
  • 3
    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. Apr 28, 2011 at 7:34
  • 1
    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. Apr 28, 2011 at 8:07

1 Answer 1

39
! 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
2
  • 11
    Wow, I guess xetex would greatly benefit from a better error management.
    – raphink
    Aug 17, 2011 at 13:22
  • 1
    @ℝaphink and memory management. Jun 29, 2014 at 18:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .